sysinfo: added sysinfo util to show cpu usage 89/46089/4 accepted/tizen/mobile/20150817.024445 accepted/tizen/tv/20150817.024458 accepted/tizen/wearable/20150817.024516 submit/tizen/20150817.004638
authorGwanglim Lee <gl77.lee@samsung.com>
Fri, 14 Aug 2015 14:32:56 +0000 (23:32 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Sat, 15 Aug 2015 13:32:05 +0000 (22:32 +0900)
Change-Id: Id450d0db61f7b55fa82173cae0454218ef198111

src/Makefile.am
src/e_mod_main.c
src/e_mod_main.h
src/e_mod_sysinfo.c [new file with mode: 0644]
src/e_mod_sysinfo.h [new file with mode: 0644]
src/e_mod_wl.c

index 13d4c03..b0de3e2 100644 (file)
@@ -22,6 +22,8 @@ module_la_SOURCES      = e_mod_config.c \
 if HAVE_WAYLAND_ONLY
 module_la_SOURCES += e_mod_wl.c \
                                         e_mod_wl.h \
+                                        e_mod_sysinfo.c \
+                                        e_mod_sysinfo.h \
                                         e_mod_rotation_wl.c \
                                         e_mod_rotation_wl.h \
                                         tizen_policy_ext-protocol.c \
index 1f8629f..9392e40 100644 (file)
@@ -4,6 +4,7 @@
 #include "e_mod_notification.h"
 #ifdef HAVE_WAYLAND_ONLY
 #include "e_mod_wl.h"
+#include "e_mod_sysinfo.h"
 #else
 #include "e_mod_atoms.h"
 #endif
@@ -192,6 +193,8 @@ _pol_client_del(Pol_Client *pc)
 static Eina_Bool
 _pol_client_normal_check(E_Client *ec)
 {
+   Pol_Client *pc;
+
    if ((e_client_util_ignored_get(ec)) ||
        (!ec->pixmap))
      {
@@ -207,23 +210,28 @@ _pol_client_normal_check(E_Client *ec)
    if (e_mod_pol_client_is_keyboard(ec) ||
        e_mod_pol_client_is_keyboard_sub(ec))
      {
-        Pol_Client *pc;
         pc = eina_hash_find(hash_pol_clients, &ec);
         if (pc) _pol_client_del(pc);
 
         e_mod_pol_keyboard_layout_apply(ec);
         return EINA_FALSE;
      }
-
-   if (e_mod_pol_client_is_volume(ec))
-     return EINA_FALSE;
-
-   if (!e_util_strcmp("e_demo", ec->icccm.window_role))
+   else if (e_mod_pol_client_is_volume(ec))
+     {
+        pc = eina_hash_find(hash_pol_clients, &ec);
+        if (pc) _pol_client_del(pc);
+        return EINA_FALSE;
+     }
+   else if (!e_util_strcmp("e_demo", ec->icccm.window_role))
+     {
+        pc = eina_hash_find(hash_pol_clients, &ec);
+        if (pc) _pol_client_del(pc);
+        return EINA_FALSE;
+     }
+   else if (e_mod_pol_client_is_sysinfo(ec))
      {
-        Pol_Client *pc;
         pc = eina_hash_find(hash_pol_clients, &ec);
         if (pc) _pol_client_del(pc);
-
         return EINA_FALSE;
      }
 
@@ -603,6 +611,7 @@ _pol_cb_client_remove(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
    EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON);
 
 #ifdef HAVE_WAYLAND_ONLY
+   e_mod_pol_sysinfo_client_del(ev->ec);
    e_mod_pol_wl_client_del(ev->ec);
 #endif
    e_mod_pol_stack_cb_client_remove(ev->ec);
@@ -629,6 +638,7 @@ _pol_cb_client_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
    e_mod_pol_client_window_opaque_set(ev->ec);
 #ifdef HAVE_WAYLAND_ONLY
    e_mod_pol_wl_client_add(ev->ec);
+   e_mod_pol_sysinfo_client_add(ev->ec);
 #endif
 
    return ECORE_CALLBACK_PASS_ON;
@@ -655,6 +665,7 @@ _pol_cb_client_resize(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
 {
    E_Event_Client *ev;
    E_Client *ec;
+   int zh = 0;
 
    ev = (E_Event_Client *)event;
    EINA_SAFETY_ON_NULL_RETURN_VAL(ev, ECORE_CALLBACK_PASS_ON);
@@ -672,13 +683,19 @@ _pol_cb_client_resize(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
 #endif
      }
 
-   /* re-calculate volume popup's position with changed size */
+   /* re-calculate window's position with changed size */
    if (e_mod_pol_client_is_volume(ec))
      {
-        int zh = 0;
         e_zone_useful_geometry_get(ec->zone, NULL, NULL, NULL, &zh);
         evas_object_move(ec->frame, 0, (zh / 2) - (ec->h / 2));
      }
+   /*
+   else if (e_mod_pol_client_is_sysinfo(ec))
+     {
+        e_zone_useful_geometry_get(ec->zone, NULL, NULL, NULL, &zh);
+        evas_object_move(ec->frame, 0, (zh / 2) - (ec->h / 2));
+     }
+   */
 
    /* calculate e_client visibility */
    e_mod_pol_visibility_calc();
@@ -923,6 +940,18 @@ e_mod_pol_client_is_volume(E_Client *ec)
    return EINA_FALSE;
 }
 
+Eina_Bool
+e_mod_pol_client_is_sysinfo(E_Client *ec)
+{
+   E_OBJECT_CHECK_RETURN(ec, EINA_FALSE);
+   E_OBJECT_TYPE_CHECK_RETURN(ec, E_CLIENT_TYPE, EINA_FALSE);
+
+   if (!e_util_strcmp(ec->icccm.window_role, "e_sysinfo"))
+     return EINA_TRUE;
+
+   return EINA_FALSE;
+}
+
 #undef E_CLIENT_HOOK_APPEND
 #define E_CLIENT_HOOK_APPEND(l, t, cb, d) \
   do                                      \
@@ -972,6 +1001,7 @@ e_modapi_init(E_Module *m)
    e_mod_pol_notification_init();
 #ifdef HAVE_WAYLAND_ONLY
    e_mod_pol_wl_init();
+   e_mod_pol_sysinfo_init();
 #endif
 
    /* initialize configure and config data type */
@@ -1056,6 +1086,7 @@ e_modapi_shutdown(E_Module *m)
    e_mod_pol_visibility_shutdown();
    e_mod_pol_rotation_shutdown();
 #ifdef HAVE_WAYLAND_ONLY
+   e_mod_pol_sysinfo_shutdown();
    e_mod_pol_wl_shutdown();
 #endif
 
index 05531f8..d304d5c 100644 (file)
@@ -112,6 +112,7 @@ EINTERN Eina_Bool        e_mod_pol_client_is_home_screen(E_Client *ec);
 EINTERN Eina_Bool        e_mod_pol_client_is_quickpanel(E_Client *ec);
 EINTERN Eina_Bool        e_mod_pol_client_is_conformant(E_Client *ec);
 EINTERN Eina_Bool        e_mod_pol_client_is_volume(E_Client *ec);
+EINTERN Eina_Bool        e_mod_pol_client_is_sysinfo(E_Client *ec);
 
 EINTERN Pol_Softkey     *e_mod_pol_softkey_add(E_Zone *zone);
 EINTERN void             e_mod_pol_softkey_del(Pol_Softkey *softkey);
diff --git a/src/e_mod_sysinfo.c b/src/e_mod_sysinfo.c
new file mode 100644 (file)
index 0000000..e074ad4
--- /dev/null
@@ -0,0 +1,310 @@
+#include "e_mod_main.h"
+#include "e_mod_sysinfo.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/param.h>
+
+#define WIN_WIDTH  500
+#define WIN_HEIGHT 1080
+
+typedef struct _E_Sysinfo
+{
+   Eina_Bool    show;
+   E_Client    *ec;
+   Evas_Object *btn;
+
+   // FPS
+   Evas_Object *fps, *fps_text;
+   Ecore_Animator *fps_anim;
+   double       fps_src;
+   double       fps_target;
+   double       fps_curr;
+   double       fps_start_t;
+   Eina_Bool    fps_update;
+   Ecore_Timer *fps_timer;
+
+   struct
+   {
+      Elm_Transit *trans;
+   } effect;
+
+} E_Sysinfo;
+
+static E_Sysinfo *e_sysinfo = NULL;
+static Eina_List *handlers = NULL;
+
+static void
+_win_effect_cb_trans(Elm_Transit_Effect *eff EINA_UNUSED, Elm_Transit *trans EINA_UNUSED, double progress)
+{
+   E_Client *ec;
+   double curr, col, fps_y;
+
+   ec = e_sysinfo->ec;
+   EINA_SAFETY_ON_NULL_RETURN(ec);
+   if (e_object_is_del(E_OBJECT(ec))) return;
+   EINA_SAFETY_ON_NULL_RETURN(ec->frame);
+
+   if (progress < 0.0) progress = 0.0;
+
+   if (e_sysinfo->show)
+     {
+        curr = -WIN_WIDTH + (WIN_WIDTH * progress);
+        col = 255 * progress;
+        if (col <= 0) col = 0;
+
+        fps_y = 10 + (60 * progress);
+     }
+   else
+     {
+        curr = -(WIN_WIDTH * progress);
+        col = 255 - (255 * progress);
+        if (col <= 0) col = 0;
+
+        fps_y = 70 - (60 * progress);
+     }
+
+   evas_object_color_set(ec->frame, col, col, col, col);
+   evas_object_move(ec->frame, curr, 0);
+
+   evas_object_color_set(e_sysinfo->fps, col, col, col, col);
+   evas_object_move(e_sysinfo->fps, 155, fps_y);
+
+   ELOGF("SYSINFO", "EFF DO   |t:0x%08x prog:%.3f", NULL, NULL, (unsigned int)e_sysinfo->effect.trans, progress);
+}
+
+static void
+_win_effect_cb_trans_end(Elm_Transit_Effect *eff EINA_UNUSED, Elm_Transit *trans EINA_UNUSED)
+{
+   ELOGF("SYSINFO", "EFF END  |t:0x%08x", NULL, NULL, (unsigned int)e_sysinfo->effect.trans);
+   e_sysinfo->effect.trans = NULL;
+}
+
+static void
+_win_effect_cb_trans_del(void *data EINA_UNUSED, Elm_Transit *transit EINA_UNUSED)
+{
+   ELOGF("SYSINFO", "EFF DEL  |t:0x%08x", NULL, NULL, (unsigned int)e_sysinfo->effect.trans);
+   e_sysinfo->effect.trans = NULL;
+}
+
+static void
+_win_effect_init(void)
+{
+   if (e_sysinfo->effect.trans)
+     {
+        elm_transit_del_cb_set(e_sysinfo->effect.trans, NULL, NULL);
+        elm_transit_del(e_sysinfo->effect.trans);
+     }
+
+   e_sysinfo->effect.trans = elm_transit_add();
+   elm_transit_del_cb_set(e_sysinfo->effect.trans, _win_effect_cb_trans_del, NULL);
+
+   elm_transit_effect_add(e_sysinfo->effect.trans,
+                          _win_effect_cb_trans,
+                          NULL,
+                          _win_effect_cb_trans_end);
+
+   elm_transit_smooth_set(e_sysinfo->effect.trans, EINA_FALSE);
+   elm_transit_tween_mode_set(e_sysinfo->effect.trans, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
+   elm_transit_objects_final_state_keep_set(e_sysinfo->effect.trans, EINA_FALSE);
+   elm_transit_duration_set(e_sysinfo->effect.trans, 0.8f);
+}
+
+static void
+_win_show(void)
+{
+   if ((!e_sysinfo->ec) || (!e_sysinfo->ec->frame)) return;
+
+   e_comp->calc_fps = EINA_TRUE;
+
+   _win_effect_init();
+   EINA_SAFETY_ON_NULL_RETURN(e_sysinfo->effect.trans);
+
+   ELOGF("SYSINFO", "EFF SHOW |t:0x%08x", NULL, NULL, (unsigned int)e_sysinfo->effect.trans);
+
+   if (!evas_object_visible_get(e_sysinfo->fps))
+     {
+        evas_object_color_set(e_sysinfo->fps, 0, 0, 0, 0);
+        evas_object_show(e_sysinfo->fps);
+     }
+
+   elm_transit_go(e_sysinfo->effect.trans);
+}
+
+static void
+_win_hide(void)
+{
+   if ((!e_sysinfo->ec) || (!e_sysinfo->ec->frame)) return;
+
+   e_comp->calc_fps = EINA_FALSE;
+
+   _win_effect_init();
+   EINA_SAFETY_ON_NULL_RETURN(e_sysinfo->effect.trans);
+
+   ELOGF("SYSINFO", "EFF HIDE |t:0x%08x", NULL, NULL, (unsigned int)e_sysinfo->effect.trans);
+
+   elm_transit_go(e_sysinfo->effect.trans);
+}
+
+static void
+_btn_cb_mouse_up(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
+{
+   if (e_sysinfo->show) _win_hide();
+   else _win_show();
+
+   e_sysinfo->show = !e_sysinfo->show;
+}
+
+void
+e_mod_pol_sysinfo_client_add(E_Client *ec)
+{
+   if (!e_mod_pol_client_is_sysinfo(ec)) return;
+
+   ELOGF("SYSINFO",
+         "ADD      |internale_elm_win:0x%08x %dx%d",
+         ec->pixmap, ec,
+         (unsigned int)ec->internal_elm_win,
+         ec->w, ec->h);
+
+   e_sysinfo->ec = ec;
+
+   if (e_sysinfo->show) _win_show();
+}
+
+void
+e_mod_pol_sysinfo_client_del(E_Client *ec)
+{
+   if (e_sysinfo->ec != ec) return;
+
+   ELOGF("SYSINFO",
+         "DEL      |internale_elm_win:0x%08x %dx%d",
+         ec->pixmap, ec,
+         (unsigned int)ec->internal_elm_win,
+         ec->w, ec->h);
+
+   e_sysinfo->ec = NULL;
+}
+
+static Eina_Bool
+_sysinfo_cb_fps_clear(void *data EINA_UNUSED)
+{
+   e_sysinfo->fps_src = e_sysinfo->fps_curr;
+   e_sysinfo->fps_target = 0.0f;
+   e_sysinfo->fps_start_t = ecore_time_get();
+   e_sysinfo->fps_update = EINA_TRUE;
+   e_sysinfo->fps_timer = NULL;
+
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool
+_sysinfo_cb_fps_anim(void *data EINA_UNUSED)
+{
+   double curr_t, dt;
+   char buf[256];
+
+   if (!e_sysinfo->fps_text) return ECORE_CALLBACK_RENEW;
+   if (!e_sysinfo->fps_update) return ECORE_CALLBACK_RENEW;
+
+   curr_t = ecore_time_get();
+   dt = curr_t - e_sysinfo->fps_start_t;
+
+   if (dt == 0.0f) return ECORE_CALLBACK_RENEW;
+
+   if (dt > 1.0f)
+     {
+        e_sysinfo->fps_curr = e_sysinfo->fps_target;
+        e_sysinfo->fps_update = EINA_FALSE;
+     }
+   else
+     e_sysinfo->fps_curr = e_sysinfo->fps_src + ((e_sysinfo->fps_target - e_sysinfo->fps_src) * (dt));
+
+   sprintf(buf, "%.1f", e_sysinfo->fps_curr);
+   evas_object_text_text_set(e_sysinfo->fps_text, buf);
+
+   return ECORE_CALLBACK_RENEW;
+}
+
+static Eina_Bool
+_sysinfo_cb_comp_fps_update(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
+{
+   ELOGF("SYSINFO", "FPS      |%.2f", NULL, NULL, e_comp->fps);
+
+   if (!e_sysinfo->fps_anim)
+     e_sysinfo->fps_anim = ecore_animator_add(_sysinfo_cb_fps_anim, NULL);
+
+   if (e_sysinfo->fps_timer)
+     ecore_timer_del(e_sysinfo->fps_timer);
+   e_sysinfo->fps_timer = ecore_timer_add(3.0f, _sysinfo_cb_fps_clear, NULL);
+
+   e_sysinfo->fps_src = e_sysinfo->fps_curr;
+   e_sysinfo->fps_target = e_comp->fps;
+   e_sysinfo->fps_start_t = ecore_time_get();
+   e_sysinfo->fps_update = EINA_TRUE;
+
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+Eina_Bool
+e_mod_pol_sysinfo_init(void)
+{
+   Evas_Object *o, *comp_obj, *text;
+
+   e_sysinfo = E_NEW(E_Sysinfo, 1);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_sysinfo, EINA_FALSE);
+
+   o = evas_object_rectangle_add(e_comp->evas);
+   evas_object_color_set(o, 0, 0, 0, 0);
+   evas_object_resize(o, 64, 64);
+   evas_object_move(o, 0, 0);
+
+   comp_obj = e_comp_object_util_add(o, E_COMP_OBJECT_TYPE_NONE);
+   evas_object_layer_set(comp_obj, E_LAYER_POPUP);
+   evas_object_event_callback_add(comp_obj, EVAS_CALLBACK_MOUSE_UP, _btn_cb_mouse_up, NULL);
+   evas_object_show(comp_obj);
+
+   e_sysinfo->btn = comp_obj;
+
+   text = evas_object_text_add(e_comp->evas);
+   evas_object_text_font_set(text, "TizenSans", 75);
+   evas_object_size_hint_align_set(text, EVAS_HINT_FILL, 0.0);
+   evas_object_text_text_set(text, "0.0");
+   evas_object_move(text, 200, 200);
+   comp_obj = e_comp_object_util_add(text, E_COMP_OBJECT_TYPE_NONE);
+   evas_object_layer_set(comp_obj, E_LAYER_POPUP);
+
+   e_sysinfo->fps_text = text;
+   e_sysinfo->fps = comp_obj;
+   e_sysinfo->fps_src = 0.0f;
+   e_sysinfo->fps_target = 0.0f;
+   e_sysinfo->fps_curr = 0.0f;
+
+   E_LIST_HANDLER_APPEND(handlers, E_EVENT_COMPOSITOR_FPS_UPDATE, _sysinfo_cb_comp_fps_update, NULL);
+
+   return EINA_TRUE;
+}
+
+void
+e_mod_pol_sysinfo_shutdown(void)
+{
+   E_FREE_LIST(handlers, ecore_event_handler_del);
+
+   if (!e_sysinfo) return;
+
+   if (e_sysinfo->fps_anim)
+     ecore_animator_del(e_sysinfo->fps_anim);
+
+   if (e_sysinfo->effect.trans)
+     {
+        elm_transit_del_cb_set(e_sysinfo->effect.trans, NULL, NULL);
+        elm_transit_del(e_sysinfo->effect.trans);
+        e_sysinfo->effect.trans = NULL;
+     }
+
+   evas_object_del(e_sysinfo->fps);
+   evas_object_del(e_sysinfo->btn);
+
+   E_FREE(e_sysinfo);
+}
diff --git a/src/e_mod_sysinfo.h b/src/e_mod_sysinfo.h
new file mode 100644 (file)
index 0000000..b326bc4
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef E_MOD_SYSINFO_H
+#define E_MOD_SYSINFO_H
+
+#include "config.h"
+#ifdef HAVE_WAYLAND_ONLY
+
+#define E_COMP_WL
+#include <e.h>
+
+Eina_Bool e_mod_pol_sysinfo_init(void);
+void      e_mod_pol_sysinfo_shutdown(void);
+void      e_mod_pol_sysinfo_client_add(E_Client *ec);
+void      e_mod_pol_sysinfo_client_del(E_Client *ec);
+
+#endif /* HAVE_WAYLAND_ONLY */
+#endif /* E_MOD_SYSINFO_H */
index 271a145..de69390 100644 (file)
@@ -1166,6 +1166,11 @@ _tzpol_iface_cb_role_set(struct wl_client *client EINA_UNUSED, struct wl_resourc
         evas_object_layer_set(ec->frame, E_LAYER_CLIENT_NOTIFICATION_HIGH);
         ec->lock_client_location = 1;
      }
+   else if (!e_util_strcmp("e_sysinfo", role))
+     {
+        evas_object_layer_set(ec->frame, E_LAYER_CLIENT_NOTIFICATION_HIGH);
+        ec->lock_client_location = 1;
+     }
 }
 
 // --------------------------------------------------------