e_info: add -win_id option to fps 07/292807/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Wed, 10 May 2023 11:37:27 +0000 (20:37 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 15 May 2023 06:04:34 +0000 (15:04 +0900)
winfo -fps -win_id [win_id] : print client fps.

Change-Id: Ia524c8edd19ba95b6e52cd32a16dd3252a27d539

src/bin/e_client.c
src/bin/e_client.h
src/bin/e_comp_wl.c
src/bin/e_info_client.c
src/bin/e_info_server.c
src/bin/e_info_shared_types.h

index 6269ea2..9c9a1c8 100644 (file)
@@ -9119,3 +9119,62 @@ e_client_from_surface_resource(struct wl_resource *surface_resource)
 {
    return wl_resource_get_user_data(surface_resource);
 }
+
+EINTERN void
+e_client_fps_update(E_Client *ec)
+{
+   double dt;
+   double tim;
+
+   EINA_SAFETY_ON_NULL_RETURN(ec);
+
+   if (!ec->fps.enabled) return;
+
+   tim = ecore_time_get();
+
+   dt = tim - ec->fps.frametimes[0];
+
+   ec->fps.frametimes[0] = tim;
+   ec->fps.time += dt;
+   ec->fps.cframes++;
+
+   if (ec->fps.lapse == 0.0)
+     {
+        ec->fps.lapse = tim;
+        ec->fps.flapse = ec->fps.cframes;
+     }
+   else if ((tim - ec->fps.lapse) >= 0.5)
+     {
+        ec->fps.fps = (ec->fps.cframes - ec->fps.flapse) /
+                      (tim - ec->fps.lapse);
+        ec->fps.lapse = tim;
+        ec->fps.flapse = ec->fps.cframes;
+        ec->fps.time = 0.0;
+     }
+}
+
+EINTERN Eina_Bool
+e_client_fps_get(E_Client *ec, double *fps)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
+
+   if (ec->fps.old_fps == ec->fps.fps)
+     return EINA_FALSE;
+
+   if (ec->fps.fps > 0.0)
+     {
+        *fps = ec->fps.fps;
+        ec->fps.old_fps = ec->fps.fps;
+        return EINA_TRUE;
+     }
+
+   return EINA_FALSE;
+}
+
+EINTERN void
+e_client_fps_enable(E_Client *ec, Eina_Bool enable)
+{
+   EINA_SAFETY_ON_NULL_RETURN(ec);
+
+   ec->fps.enabled = enable;
+}
index 873dfe2..b3f3704 100644 (file)
@@ -1069,6 +1069,18 @@ struct E_Client
 
    E_Maximize_Direction maximize_dir;
    Eina_Bool apply_layout;
+
+   struct
+   {
+      Eina_Bool            enabled;
+      double               fps;
+      double               old_fps;
+      double               frametimes[122];
+      double               time;
+      double               lapse;
+      int                  cframes;
+      int                  flapse;
+   } fps;
 };
 
 #define e_client_focus_policy_click(ec) \
@@ -1344,6 +1356,9 @@ EINTERN Eina_Bool e_client_desk_zoom_enable_get(E_Client *ec);
 EINTERN void e_client_layout_apply(E_Client *ec, Eina_Bool apply);
 E_API Eina_Bool e_client_is_layout_apply(E_Client *ec);
 
+EINTERN Eina_Bool e_client_fps_get(E_Client *ec, double *fps);
+EINTERN void e_client_fps_update(E_Client *ec);
+EINTERN void e_client_fps_enable(E_Client *ec, Eina_Bool enable);
 /**
  * Move window to coordinates that do not account client decorations yet.
  *
index 3ee1844..9b701d7 100644 (file)
@@ -3019,6 +3019,8 @@ _e_comp_wl_surface_cb_attach(struct wl_client *client EINA_UNUSED, struct wl_res
    ec->comp_data->pending.sx = sx;
    ec->comp_data->pending.sy = sy;
    ec->comp_data->pending.new_attach = EINA_TRUE;
+
+   e_client_fps_update(ec);
 }
 
 static void
index 69a4d95..6056648 100644 (file)
@@ -3610,15 +3610,54 @@ finish:
      }
 }
 
+#define FPS_USAGE \
+  "[COMMAND] [ARG]...\n" \
+  "\t-help             : print this message.\n" \
+  "\t-win_id           : print client fps.\n" \
+  "Example:\n" \
+  "\twinfo -fps\n" \
+  "\twinfo -fps -win_id [win_id]\n" \
+
 static void
 _e_info_client_proc_fps_info(int argc, char **argv)
 {
+   char *win_id = "none";
+
+   if (argc == 2)
+     {
+        if (!strcmp(argv[1], "-help"))
+          {
+             printf(FPS_USAGE);
+             return;
+          }
+     }
+   else if (argc == 4)
+     {
+        if (!strcmp(argv[2], "-win_id"))
+          {
+             win_id = argv[3];
+          }
+        else
+          {
+             printf("Invalid argument: %s\n", argv[1]);
+             printf(FPS_USAGE);
+             return;
+          }
+     }
+   else
+     {
+        printf("Invalid argument: %s\n", argv[1]);
+        printf(FPS_USAGE);
+        return;
+     }
+
    do
      {
         Eina_List *l;
         E_Fps_Info *fps;
 
-        if (!_e_info_client_eldbus_message("get_fps_info", _cb_fps_info_get))
+        if (!_e_info_client_eldbus_message_with_args("get_fps_info", _cb_fps_info_get,
+                                                     "s", win_id))
           return;
 
         if (!e_info_client.fps_list)
@@ -3653,6 +3692,12 @@ _e_info_client_proc_fps_info(int argc, char **argv)
                          fps->output,
                          fps->fps);
                }
+             else if (fps->type == E_INFO_FPS_TYPE_CLIENT_WIN)
+               {
+                  printf("Client-Win_ID(0x%x)...%3.1f\n",
+                         fps->window,
+                         fps->fps);
+               }
           }
 
         E_FREE_LIST(e_info_client.fps_list, _e_fps_info_free);
@@ -6773,7 +6818,8 @@ static ProcInfo procs_to_printinfo[] =
       _e_info_client_proc_show_pending_commit
    },
    {
-      "fps", NULL,
+      "fps",
+      FPS_USAGE,
       "Print FPS in every sec per",
       _e_info_client_proc_fps_info
    },
index 3cd2aeb..658f57b 100644 (file)
@@ -5079,8 +5079,52 @@ e_info_server_cb_show_pending_commit(const Eldbus_Service_Interface *iface EINA_
    return reply;
 }
 
+static E_Client *
+_e_info_server_find_client_by_win_id(uint64_t win_id)
+{
+   Ecore_Window win;
+   Evas_Object *o;
+   E_Client *ec;
+
+   for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
+     {
+        ec = evas_object_data_get(o, "E_Client");
+        if (!ec) continue;
+
+        win = e_client_util_win_get(ec);
+        if (win == win_id)
+          return ec;
+     }
+
+   return NULL;
+}
+
 static void
-_msg_fps_append(Eldbus_Message_Iter *iter)
+_msg_client_fps_append(Eldbus_Message_Iter *iter, E_Client *ec)
+{
+   Eldbus_Message_Iter *array_of_fps, *struct_of_fps;
+   double fps = 0.0;
+
+   eldbus_message_iter_arguments_append(iter, "a("VALUE_TYPE_FOR_FPS")", &array_of_fps);
+
+   if (e_client_fps_get(ec, &fps))
+     {
+        eldbus_message_iter_arguments_append(array_of_fps, "("VALUE_TYPE_FOR_FPS")", &struct_of_fps);
+        eldbus_message_iter_arguments_append(struct_of_fps,
+                                            VALUE_TYPE_FOR_FPS,
+                                            E_INFO_FPS_TYPE_CLIENT_WIN,
+                                            "none",
+                                            -999,
+                                            e_client_util_win_get(ec),
+                                            fps);
+        eldbus_message_iter_container_close(array_of_fps, struct_of_fps);
+     }
+
+   eldbus_message_iter_container_close(iter, array_of_fps);
+}
+
+static void
+_msg_output_fps_append(Eldbus_Message_Iter *iter)
 {
    Eina_List *output_l, *plane_l, *hwc_l;
    Eldbus_Message_Iter *array_of_fps;
@@ -5181,14 +5225,36 @@ _msg_fps_append(Eldbus_Message_Iter *iter)
 static Eldbus_Message *
 _e_info_server_cb_fps_info_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
 {
+   const char *win_str;
+   uint64_t win_id = 0;
+   unsigned long tmp;
+   E_Client *ec;
    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
 
-   if (!e_comp->calc_fps)
+   if (!eldbus_message_arguments_get(msg, "s", &win_str))
      {
-        e_comp->calc_fps = 1;
+        ERR("Error getting arguments");
+        return reply;
      }
 
-   _msg_fps_append(eldbus_message_iter_get(reply));
+   if (e_util_strcmp(win_str, "none"))
+     {
+        if (!e_util_string_to_ulong(win_str, &tmp, 16))
+          return reply;
+
+        win_id = (uint64_t)tmp;
+
+        ec = _e_info_server_find_client_by_win_id(win_id);
+        if (!ec) return reply;
+
+        e_client_fps_enable(ec, EINA_TRUE);
+        _msg_client_fps_append(eldbus_message_iter_get(reply), ec);
+     }
+   else
+     {
+        e_comp->calc_fps = 1;
+        _msg_output_fps_append(eldbus_message_iter_get(reply));
+     }
 
    return reply;
 }
@@ -7534,7 +7600,7 @@ static const Eldbus_Method methods[] = {
    { "hwc", ELDBUS_ARGS({"i", "hwc"}), NULL, e_info_server_cb_hwc, 0},
    { "show_plane_state", NULL, NULL, e_info_server_cb_show_plane_state, 0},
    { "show_pending_commit", NULL, ELDBUS_ARGS({"a("VALUE_TYPE_FOR_PENDING_COMMIT")", "array of pending commit"}), e_info_server_cb_show_pending_commit, 0},
-   { "get_fps_info", NULL, ELDBUS_ARGS({"a("VALUE_TYPE_FOR_FPS")", "array of fps"}), _e_info_server_cb_fps_info_get, 0},
+   { "get_fps_info", ELDBUS_ARGS({"s", "fps request"}), ELDBUS_ARGS({"a("VALUE_TYPE_FOR_FPS")", "array of fps"}), _e_info_server_cb_fps_info_get, 0},
    { "get_keymap", NULL, ELDBUS_ARGS({"hi", "keymap fd"}), _e_info_server_cb_keymap_info_get, 0},
    { "effect_control", ELDBUS_ARGS({"i", "effect_control"}), NULL, e_info_server_cb_effect_control, 0},
    { "quickpanel_control", ELDBUS_ARGS({"i", "operation"}, {"s","window id" }), NULL, e_info_server_cb_quickpanel_control, 0},
index 4ca2504..ea93cd1 100644 (file)
@@ -246,6 +246,7 @@ typedef enum
    E_INFO_FPS_TYPE_LAYER,
    E_INFO_FPS_TYPE_HWC_WIN,
    E_INFO_FPS_TYPE_HWC_COMP,
+   E_INFO_FPS_TYPE_CLIENT_WIN,
 } E_Info_Fps_Type;
 
 /* -------------------------------------------------------------------------- */