e_info: Add the option to print the elapsed time of key events 58/315158/2
authorInhong Han <inhong1.han@samsung.com>
Wed, 24 Jul 2024 06:51:27 +0000 (15:51 +0900)
committerDoyoun Kang <doyoun.kang@samsung.com>
Fri, 26 Jul 2024 01:34:24 +0000 (01:34 +0000)
Change-Id: I8782807e7b21ee8a34c901674bd25acd11b3789e

src/bin/debug/e_info_client.c
src/bin/debug/e_info_server.c
src/bin/debug/e_info_server_input.c
src/bin/debug/e_info_server_input_intern.h
src/bin/inputmgr/e_input_backend.c
src/bin/inputmgr/e_input_backend_intern.h

index daabf06..f457ad2 100644 (file)
@@ -6618,6 +6618,32 @@ _e_info_client_proc_input_subtype_set(int argc, char **argv)
      }
 }
 
+void
+_e_info_client_proc_key_elapsed_time(int argc, char **argv)
+{
+   int count = 0;
+
+   if (argc == 3)
+     {
+        count = atoi(argv[2]);
+        if (count <= 0)
+          {
+             printf("Error Check Args: enlightenment_info -key_elapsed_time [count > 0]\n");
+             return;
+          }
+
+        if (!_e_info_client_eldbus_message_with_args("key_elapsed_time", NULL, "i", count))
+          printf("_e_info_client_eldbus_message_with_args error");
+     }
+   else
+     {
+        printf("Error Check Args: enlightenment_info -key_elapsed_time [count > 0]\n");
+        return;
+     }
+
+   return;
+}
+
 static void
 _e_info_client_proc_kvm_transparent_set(int argc, char **argv)
 {
@@ -7191,6 +7217,12 @@ ProcInfo procs_to_input[] =
       "Set input device's subtype(subclas)",
       _e_info_client_proc_input_subtype_set
    },
+   {
+      "key_elapsed_time",      /* Option */
+      "NULL",/* Params */
+      "Print key events elapsed time (default path:/tmp/elapsed_time.txt)", /* Description */
+      _e_info_client_proc_key_elapsed_time /* func */
+   },
 };
 
 static Eina_List *list_tracelogs = NULL;
index 42a3371..22a4575 100644 (file)
@@ -7331,6 +7331,27 @@ end:
    return reply;
 }
 
+static Eldbus_Message *
+_e_info_server_cb_key_elapsed_time(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
+{
+   Eldbus_Message *reply;
+   char *result = NULL;
+   int count = 0;
+
+   if (!eldbus_message_arguments_get(msg, "i", &count))
+     {
+        return eldbus_message_error_new(msg, "Key_elapsed_timeFailed",
+                                        "input_log: an attempt to set key_elapsed_time from method call message failed");
+     }
+
+   result = e_info_server_input_key_elapsed_time(count);
+   reply = eldbus_message_method_return_new(msg);
+
+   eldbus_message_arguments_append(reply, "s", result);
+
+   return reply;
+}
+
 //{ "method_name", arguments_from_client, return_values_to_client, _method_cb, ELDBUS_METHOD_FLAG },
 static const Eldbus_Method methods[] = {
    { "get_window_info", NULL, ELDBUS_ARGS({"iiiiisiiia("VALUE_TYPE_FOR_TOPVWINS")", "array of ec"}), _e_info_server_cb_window_info_get, 0 },
@@ -7431,6 +7452,7 @@ static const Eldbus_Method methods[] = {
    { "kvm_transparent", ELDBUS_ARGS({"i", "set kvm service window to transparent"}), NULL, _e_info_server_cb_kvm_transparent_set, 0 },
    { "log_control", ELDBUS_ARGS({"s","log type" }, {"i", "enable"}), NULL, _e_info_server_cb_log_control, 0},
    { VIDEO_SHELL_BORDER_ENABLED_SET_METHOD_NAME, ELDBUS_ARGS({"b", "enable border of video viewport"}), NULL, _e_info_server_cb_video_shell_border_enabled_set, 0},
+   { "key_elapsed_time", ELDBUS_ARGS({"i", "key elapsed time"}), ELDBUS_ARGS({"s", "result message"}), _e_info_server_cb_key_elapsed_time, 0},
    { NULL, NULL, NULL, NULL, 0 }
 };
 
index 845ae23..8a5120e 100644 (file)
@@ -6,6 +6,7 @@
 #include "e_input_intern.h"
 #include "e_comp_wl_input_intern.h"
 #include "e_utils_intern.h"
+#include "e_input_backend_intern.h"
 
 # include <fcntl.h>
 #include <linux/uinput.h>
@@ -615,3 +616,13 @@ e_info_server_input_log_enable_set(int state)
 
    return "Input proper value [1: on][0: off]";
 }
+
+EINTERN char *
+e_info_server_input_key_elapsed_time(int count)
+{
+   if (count <= 0) return "count is not valid";
+
+   e_input_backend_key_elapsed_time_print(count);
+
+   return E_INFO_INPUT_RESULT_NONE;
+}
\ No newline at end of file
index ef0cd28..1dca8ec 100644 (file)
@@ -7,5 +7,6 @@
 #define INPUT_ARG_NAME    "input"
 
 EINTERN char *e_info_server_input_log_enable_set(int state);
+EINTERN char *e_info_server_input_key_elapsed_time(int count);
 
 #endif
index 1b4d9bf..c696a22 100644 (file)
@@ -42,6 +42,8 @@ static gboolean input_thread_prepare(GSource *source, gint *time);
 static E_Input_Backend *g_input_backend = NULL;
 static E_Input_Event_Source *g_input_event_source = NULL;
 static GList *_key_event_list = NULL;
+static GList *_elapsed_time_list = NULL;
+static int _print_count = 0;
 
 GSourceFuncs input_event_funcs = {
    .prepare = input_thread_prepare,
@@ -799,6 +801,71 @@ _cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
    return EINA_TRUE;
 }
 
+static double
+_e_input_stddev_get(double avg)
+{
+   double sum = 0;
+   GList *list = g_list_first(_elapsed_time_list);
+   while (list)
+     {
+        unsigned int elapsed_time = (unsigned int)list->data;
+        sum += (elapsed_time - avg) * (elapsed_time - avg);
+        list = list->next;
+     }
+
+   return sqrt(sum / _print_count);
+}
+
+static void
+_e_input_key_elapsed_time_print()
+{
+   char file_path[128] = {'\0', };
+   FILE *fp = NULL;
+   int min = G_MAXINT;
+   int max = 0;
+   double sum = 0;
+   double avg = 0;
+   double std = 0;
+
+   snprintf(file_path, sizeof(file_path), "/tmp/elapsed_time.txt");
+   if (!e_util_file_realpath_check(file_path, EINA_TRUE))
+     WRN("File is already exist");
+
+   fp = fopen(file_path, "w");
+   if (fp)
+     {
+        fprintf(fp, "count=%d\n", _print_count);
+        GList *elapsed_time_list = g_list_first(_elapsed_time_list);
+        while (elapsed_time_list)
+          {
+             unsigned int elapsed_time = (unsigned int)elapsed_time_list->data;
+             if (min > elapsed_time) min = elapsed_time;
+             if (max < elapsed_time) max = elapsed_time;
+
+             sum += elapsed_time;
+             elapsed_time_list = elapsed_time_list->next;
+             fprintf(fp, "%u\n", elapsed_time);
+          }
+
+        avg = sum / _print_count;
+        std = _e_input_stddev_get(avg);
+
+        fprintf(fp, "min=%d\n", min);
+        fprintf(fp, "max=%d\n", max);
+        fprintf(fp, "avg=%.2f\n", avg);
+        fprintf(fp, "std=%.2f\n", std);
+
+        fclose(fp);
+        fp = NULL;
+     }
+   else
+     ERR("Failed to create /tmp/elapsed_time.txt");
+
+   _print_count = 0;
+   g_list_free(_elapsed_time_list);
+   _elapsed_time_list = NULL;
+}
+
 static void
 _e_input_delayed_key_events_print()
 {
@@ -814,6 +881,13 @@ _e_input_delayed_key_events_print()
         Ecore_Event_Key *key = (Ecore_Event_Key *)key_list->data;
         if (!key) continue;
 
+        if (_print_count > 0)
+          {
+             _elapsed_time_list = g_list_append(_elapsed_time_list, (void *)(time - key->timestamp));
+             if (_print_count == g_list_length(_elapsed_time_list))
+               _e_input_key_elapsed_time_print();
+          }
+
         if (e_config->key_input_time_limit <= (time - key->timestamp))
           ERR("Delayed key event : keyname(%s), keycode(%u), timestamp(%u), elapsed_time(%u ms)", key->keyname, key->keycode, key->timestamp, time - key->timestamp);
 
@@ -1897,3 +1971,25 @@ e_input_backend_log_level_set(E_Input_Backend *input, unsigned int level)
           break;
      }
 }
+
+static void
+_e_input_thread_cb_print_count_set(void *data)
+{
+   int count;
+   EINA_SAFETY_ON_NULL_RETURN(data);
+
+   count = *(int *)data;
+   _print_count = count;
+
+   if (_elapsed_time_list)
+     {
+        g_list_free(_elapsed_time_list);
+        _elapsed_time_list = NULL;
+     }
+}
+
+EINTERN void
+e_input_backend_key_elapsed_time_print(int count)
+{
+   e_input_backend_thread_safe_call(_e_input_thread_cb_print_count_set, &count, sizeof(int));
+}
\ No newline at end of file
index e82ddd0..e767d38 100644 (file)
@@ -51,5 +51,6 @@ EINTERN void             e_input_backend_destroy(E_Input_Backend *input);
 
 EINTERN Eina_Bool        e_input_backend_libinput_context_create(E_Input_Backend *input);
 EINTERN void             e_input_backend_log_level_set(E_Input_Backend *input, unsigned int level);
+EINTERN void             e_input_backend_key_elapsed_time_print(int count);
 
 #endif