Enlightenment CVS committal
Author : handyande
Project : e17
Module : apps/e_modules
Dir : e17/apps/e_modules/src/modules/monitor
Modified Files:
e_mod_main.c e_mod_main.h linux_2.6.c linux_2.6.h monitor.edc
Added Files:
memory.png
Log Message:
Added latest changes for monitor module from ekrunch - now includes a memory
watcher
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_modules/src/modules/monitor/e_mod_main.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- e_mod_main.c 22 May 2005 03:07:06 -0000 1.1
+++ e_mod_main.c 19 Jul 2005 11:38:21 -0000 1.2
@@ -28,6 +28,8 @@
void *event_info);
static void _monitor_cpu_text_update_callcack(Flow_Chart *chart, void *data);
+static void _monitor_mem_real_text_update_callback(Flow_Chart *chart, void
*data);
+static void _monitor_mem_swap_text_update_callback(Flow_Chart *chart, void
*data);
static void _monitor_net_in_text_update_callcack(Flow_Chart *chart, void
*data);
static void _monitor_net_out_text_update_callcack(Flow_Chart *chart, void
*data);
@@ -89,7 +91,6 @@
int
e_modapi_info(E_Module *module)
{
- char buf[4096];
module->label = strdup("Monitor");
module->icon_file = strdup(PACKAGE_LIB_DIR
"/e_modules/monitor/module_icon.png");
@@ -223,8 +224,6 @@
Chart_Container *chart_con;
Flow_Chart *flow_chart;
- char buf[256];
-
face = E_NEW(Monitor_Face, 1);
if (!face) return NULL;
@@ -233,6 +232,10 @@
evas_event_freeze(con->bg_evas);
+ /* setup intervals */
+ face->cpu_rate = 1.0;
+ face->mem_rate = 1.0;
+ face->net_rate = 1.0;
/* setup monitor object */
o = edje_object_add(con->bg_evas);
@@ -264,6 +267,7 @@
flow_chart = flow_chart_new();
flow_chart_color_set(flow_chart, 33, 100, 220, 255);
flow_chart_get_value_function_set(flow_chart, cpu_usage_get);
+ flow_chart_update_rate_set(flow_chart, face->cpu_rate);
chart_container_chart_add(chart_con, flow_chart);
face->chart_cpu = chart_con;
flow_chart_callback_set(flow_chart, _monitor_cpu_text_update_callcack,
face);
@@ -275,7 +279,43 @@
_monitor_face_cb_mouse_down, face);
evas_object_show(o);
+ /* setup mem */
+ o = edje_object_add(con->bg_evas);
+ face->mem = o;
+ edje_object_file_set(o, PACKAGE_LIB_DIR
+ "/e_modules/monitor/monitor.edj",
+ "monitor/mem");
+ e_table_pack(face->table_object, o, 1, 0, 1, 1);
+ e_table_pack_options_set(o, 1, 1, 1, 1, 0.5, 0.5, 0, 0, -1, -1);
+ evas_object_layer_set(o, evas_object_layer_get(face->monitor_object)+1);
+ evas_object_show(o);
+ /* add mem charts */
+ chart_con = chart_container_new(con->bg_evas,0,0,0,0);
+ flow_chart = flow_chart_new();
+ flow_chart_color_set(flow_chart, 213, 91, 91, 255);
+ flow_chart_get_value_function_set(flow_chart, mem_real_usage_get);
+ flow_chart_update_rate_set(flow_chart, face->mem_rate);
+ chart_container_chart_add(chart_con, flow_chart);
+ face->chart_mem = chart_con;
+ flow_chart_callback_set(flow_chart, _monitor_mem_real_text_update_callback,
+ face);
+ flow_chart = flow_chart_new();
+ flow_chart_color_set(flow_chart, 51, 181, 69, 255);
+ flow_chart_get_value_function_set(flow_chart, mem_swap_usage_get);
+ flow_chart_update_rate_set(flow_chart, face->mem_rate);
+ flow_chart_alignment_set(flow_chart, 0);
+ chart_container_chart_add(chart_con, flow_chart);
+ flow_chart_callback_set(flow_chart, _monitor_mem_swap_text_update_callback,
+ face);
+
+
+ o = evas_object_rectangle_add(con->bg_evas);
+ face->mem_ev_obj = o;
+ evas_object_color_set(o, 255,255,255,0);
+ evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
+ _monitor_face_cb_mouse_down, face);
+ evas_object_show(o);
/* setup net */
o = edje_object_add(con->bg_evas);
@@ -283,7 +323,7 @@
edje_object_file_set(o, PACKAGE_LIB_DIR
"/e_modules/monitor/monitor.edj",
"monitor/net");
- e_table_pack(face->table_object, o, 1, 0, 1, 1);
+ e_table_pack(face->table_object, o, 2, 0, 1, 1);
e_table_pack_options_set(o, 1, 1, 1, 1, 0.5, 0.5, 0, 0, -1, -1);
evas_object_layer_set(o, evas_object_layer_get(face->monitor_object)+1);
evas_object_show(o);
@@ -292,6 +332,7 @@
flow_chart = flow_chart_new();
flow_chart_color_set(flow_chart, 213, 91, 91, 255);
flow_chart_get_value_function_set(flow_chart, net_in_usage_get);
+ flow_chart_update_rate_set(flow_chart, face->net_rate);
chart_container_chart_add(chart_con, flow_chart);
face->chart_net = chart_con;
flow_chart_callback_set(flow_chart, _monitor_net_in_text_update_callcack,
@@ -300,6 +341,7 @@
flow_chart = flow_chart_new();
flow_chart_color_set(flow_chart, 51, 181, 69, 255);
flow_chart_get_value_function_set(flow_chart, net_out_usage_get);
+ flow_chart_update_rate_set(flow_chart, face->net_rate);
flow_chart_alignment_set(flow_chart, 0);
chart_container_chart_add(chart_con, flow_chart);
flow_chart_callback_set(flow_chart, _monitor_net_out_text_update_callcack,
@@ -324,7 +366,7 @@
E_GADMAN_POLICY_VSIZE);
e_gadman_client_min_size_set(face->gmc, 14, 7);
e_gadman_client_align_set(face->gmc, 1.0, 1.0);
- e_gadman_client_resize(face->gmc, 64, 32);
+ e_gadman_client_resize(face->gmc, 160, 40);
e_gadman_client_change_func_set(face->gmc, _monitor_face_cb_gmc_change,
face);
e_gadman_client_load(face->gmc);
@@ -338,7 +380,6 @@
_monitor_cpu_text_update_callcack(Flow_Chart *chart, void *data)
{
Monitor_Face *face;
- Evas_Object *o;
char buf[64];
face = data;
@@ -348,10 +389,49 @@
}
static void
+_monitor_mem_real_text_update_callback(Flow_Chart *chart, void *data)
+{
+ Monitor_Face *face;
+ char buf[64];
+
+ long bytes = mem_real_get();
+
+ face = data;
+
+ if (bytes > 1048576 )
+ snprintf(buf, 64, "%ldMB", bytes/1048576);
+ else if (bytes > 1024 && bytes < 1048576 )
+ snprintf(buf, 64, "%ldKB", bytes/1024);
+ else
+ snprintf(buf, 64, "%ldB", bytes);
+
+ edje_object_part_text_set(face->mem, "mem-real-text", buf);
+}
+
+static void
+_monitor_mem_swap_text_update_callback(Flow_Chart *chart, void *data)
+{
+ Monitor_Face *face;
+ char buf[64];
+
+ long bytes = mem_swap_get();
+
+ face = data;
+
+ if (bytes > 1048576 )
+ snprintf(buf, 64, "%ldMB", bytes/1048576);
+ else if (bytes > 1024 && bytes < 1048576 )
+ snprintf(buf, 64, "%ldKB", bytes/1024);
+ else
+ snprintf(buf, 64, "%ldB", bytes);
+
+ edje_object_part_text_set(face->mem, "mem-swap-text", buf);
+}
+
+static void
_monitor_net_in_text_update_callcack(Flow_Chart *chart, void *data)
{
Monitor_Face *face;
- Evas_Object *o;
char buf[64];
long bytes = net_bytes_in_get();
@@ -359,11 +439,11 @@
face = data;
if (bytes > 1048576 )
- snprintf(buf, 64, "%iMB", bytes/1048576);
+ snprintf(buf, 64, "%ldMB", bytes/1048576);
else if (bytes > 1024 && bytes < 1048576 )
- snprintf(buf, 64, "%iKB", bytes/1024);
+ snprintf(buf, 64, "%ldKB", bytes/1024);
else
- snprintf(buf, 64, "%iB", bytes);
+ snprintf(buf, 64, "%ldB", bytes);
edje_object_part_text_set(face->net, "net-in-text", buf);
}
@@ -372,7 +452,6 @@
_monitor_net_out_text_update_callcack(Flow_Chart *chart, void *data)
{
Monitor_Face *face;
- Evas_Object *o;
char buf[64];
long bytes = net_bytes_out_get();
@@ -380,11 +459,11 @@
face = data;
if (bytes > 1048576 )
- snprintf(buf, 64, "%iMB", bytes/1048576);
+ snprintf(buf, 64, "%ldMB", bytes/1048576);
else if (bytes > 1024 && bytes < 1048576 )
- snprintf(buf, 64, "%iKB", bytes/1024);
+ snprintf(buf, 64, "%ldKB", bytes/1024);
else
- snprintf(buf, 64, "%iB", bytes);
+ snprintf(buf, 64, "%ldB", bytes);
edje_object_part_text_set(face->net, "net-out-text", buf);
}
@@ -397,10 +476,13 @@
evas_object_del(face->cpu);
evas_object_del(face->cpu_ev_obj);
+ evas_object_del(face->mem);
+ evas_object_del(face->mem_ev_obj);
evas_object_del(face->net);
evas_object_del(face->net_ev_obj);
chart_container_del(face->chart_cpu);
+ chart_container_del(face->chart_mem);
chart_container_del(face->chart_net);
if (face->monitor_object) evas_object_del(face->monitor_object);
@@ -476,6 +558,11 @@
chart_container_move(face->chart_cpu, x+2,y+2);
chart_container_resize(face->chart_cpu, w-4,h-4);
+ evas_object_geometry_get(face->mem, &x, &y, &w, &h);
+ evas_object_move(face->mem_ev_obj, x, y);
+ evas_object_resize(face->mem_ev_obj, w, h);
+ chart_container_move(face->chart_mem, x+2,y+2);
+ chart_container_resize(face->chart_mem, w-4,h-4);
evas_object_geometry_get(face->net, &x, &y, &w, &h);
evas_object_move(face->net_ev_obj, x, y);
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_modules/src/modules/monitor/e_mod_main.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- e_mod_main.h 22 May 2005 03:07:06 -0000 1.1
+++ e_mod_main.h 19 Jul 2005 11:38:21 -0000 1.2
@@ -37,12 +37,15 @@
E_Menu *menu;
Config_Face *conf;
- Evas_Object *cpu, *net;
- Evas_Object *cpu_ev_obj, *net_ev_obj;
+ Evas_Object *cpu, *net, *mem;
+ Evas_Object *cpu_ev_obj, *net_ev_obj, *mem_ev_obj;
Evas_Object *table_object, *monitor_object;
+ double cpu_rate;
+ double mem_rate;
+ double net_rate;
- Chart_Container *chart_cpu, *chart_net;
+ Chart_Container *chart_cpu, *chart_net, *chart_mem;
E_Gadman_Client *gmc;
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_modules/src/modules/monitor/linux_2.6.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- linux_2.6.c 30 May 2005 16:07:43 -0000 1.2
+++ linux_2.6.c 19 Jul 2005 11:38:21 -0000 1.3
@@ -13,7 +13,8 @@
if ( !(stat = fopen ("/proc/stat", "r")) )
return -1;
- while (fscanf (stat, "cp%s %*lu %*lu %*lu %*lu %*lu %*lu %*lu %*lu\n", &tmp)
== 1)
+ while (fscanf (stat, "cp%s %*u %*u %*u %*u %*u %*u %*u %*u\n",
+ &tmp) == 1)
{
cpu++;
}
@@ -33,8 +34,10 @@
char dummy[16];
FILE *stat;
- if ( !(stat = fopen ("/proc/stat", "r")) )
+ if ( !(stat = fopen ("/proc/stat", "r")) ) {
+ fprintf(stderr, "can't open /proc/stat");
return -1;
+ }
if (fscanf (stat, "%s %lu %lu %lu %lu %lu %lu %lu", dummy,
&new_u, &new_n, &new_s, &new_i, &new_wa, &new_hi, &new_si) < 5)
@@ -82,7 +85,6 @@
int
cpu_usage_get(void)
{
- static int old_load = 0;
int u, n, s, i, load;
if ( four_cpu_numbers( &u, &n, &s, &i ) == -1 )
@@ -106,10 +108,6 @@
int
get_net_input_output(unsigned long *in, unsigned long *out, const char *dev)
{
- static unsigned long old_in = 0, old_out = 0;
- static double top_in = 10, top_out = 10;
-
- double tmp_in = 0, tmp_out = 0;
unsigned long new_in, new_out;
unsigned long dummy;
char iface[64];
@@ -215,3 +213,109 @@
{
return out_usage;
}
+
+long mem_real = 0;
+long mem_swap = 0;
+int mem_real_usage = 0;
+int mem_swap_usage = 0;
+
+
+/* Begin memory monitor code */
+
+void memory_check(int ignore_buffers, int ignore_cached)
+{
+ FILE *pmeminfo = NULL;
+ int cursor = 0;
+ char *line, *field;
+ unsigned char c;
+ long int value = 0, mtotal = 0, stotal = 0, mfree = 0, sfree = 0;
+ ldiv_t ldresult;
+ long int liresult;
+
+ /* open /proc/meminfo */
+ if ( !(pmeminfo = fopen("/proc/meminfo", "r")) ) {
+ fprintf(stderr, "can't open /proc/meminfo");
+ return;
+ }
+
+ /* parse /proc/meminfo */
+ line = (char *) calloc(64, sizeof(char));
+ while (fscanf(pmeminfo, "%c", &c) != EOF) {
+ if (c != '\n') {
+ line[cursor++] = c;
+ }
+ else {
+ field = (char *) malloc(strlen(line) * sizeof(char));
+ sscanf(line, "%s %ld kB", field, &value);
+ if (strcmp(field, "MemTotal:") == 0)
+ mtotal = value;
+ else if (strcmp(field, "MemFree:") == 0)
+ mfree = value;
+ else if (ignore_buffers && strcmp(field, "Buffers:") == 0)
+ mfree += value;
+ else if (ignore_cached && strcmp(field, "Cached:") == 0)
+ mfree += value;
+ else if (ignore_cached && strcmp(field, "SwapCached:") == 0)
+ sfree += value;
+ else if (strcmp(field, "SwapTotal:") == 0)
+ stotal = value;
+ else if (strcmp(field, "SwapFree:") == 0)
+ sfree = value;
+ free(line);
+ free(field);
+ cursor = 0;
+ line = (char *) calloc(64, sizeof(char));
+ }
+ }
+ fclose(pmeminfo);
+
+ /* calculate memory usage in percent */
+ /* FIXME : figure out a better way to do this */
+ ldresult = ldiv(mtotal, 100);
+ liresult = ldresult.quot;
+ ldresult = ldiv((mtotal - mfree), liresult);
+ mem_real_usage = ldresult.quot;
+
+ /* calculate swap usage in percent */
+ if (stotal < 1) {
+ mem_swap_usage = 0;
+ }
+ else {
+ ldresult = ldiv(stotal, 100);
+ liresult = ldresult.quot;
+ ldresult = ldiv((stotal - sfree), liresult);
+ mem_swap_usage = ldresult.quot;
+ }
+
+ mem_real = mtotal - mfree;
+ mem_swap = stotal - sfree;
+
+}
+
+long
+mem_real_get(void)
+{
+ return mem_real;
+}
+
+long
+mem_swap_get(void)
+{
+ return mem_swap;
+}
+
+int
+mem_real_usage_get(void)
+{
+ /* FIXME
+ * Need a menu option to change the ignore buffers and ignore cache options
+ */
+ memory_check(0, 0);
+ return mem_real_usage;
+}
+
+int
+mem_swap_usage_get(void)
+{
+ return mem_swap_usage;
+}
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_modules/src/modules/monitor/linux_2.6.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- linux_2.6.h 22 May 2005 03:07:06 -0000 1.1
+++ linux_2.6.h 19 Jul 2005 11:38:21 -0000 1.2
@@ -3,9 +3,16 @@
#define LINUX_2_6
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
int cpu_usage_get(void);
+long mem_real_get(void);
+long mem_swap_get(void);
+int mem_real_usage_get(void);
+int mem_swap_usage_get(void);
+
int net_in_usage_get(void);
long net_bytes_in_get(void);
int net_out_usage_get(void);
===================================================================
RCS file:
/cvsroot/enlightenment/e17/apps/e_modules/src/modules/monitor/monitor.edc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- monitor.edc 22 May 2005 03:07:06 -0000 1.1
+++ monitor.edc 19 Jul 2005 11:38:21 -0000 1.2
@@ -6,6 +6,7 @@
image, "over_res.png" COMP;
image, "cpu.png" COMP;
image, "eth_dev.png" COMP;
+ image, "memory.png" COMP;
}
fonts
@@ -132,6 +133,95 @@
}//close group cpu
+group
+ {
+ name, "monitor/mem";
+
+ parts{
+
+ part {
+ name, "overlay";
+ mouse_events, 0;
+ description {
+ state, "default" 0.0;
+ rel1 { offset, 1 1; }
+ rel2 { offset, -2 -2; }
+ image { normal, "over_res.png";
+ border, 2 2 2 2;
+ middle, 0;
+ }
+ fill { smooth, 0; }
+ color, 255 255 255 64;
+ }
+ description {
+ state, "active" 0.0;
+ inherit, "default" 0.0;
+ color, 255 255 255 255;
+ }
+ }
+
+
+ part {
+ name, "mem";
+ mouse_events, 0;
+ description {
+ state, "default" 0.0;
+ color, 255 255 255 128;
+ aspect: 1.0 1.0;
+ rel1{ offset, 4 4; }
+ rel2{ offset, -5 -5; }
+ image { normal, "memory.png"; }
+ fill { smooth, 0; }
+ }
+ }
+
+ part
+ {
+ name, "mem-real-text";
+ type, TEXT;
+ effect, SOFT_SHADOW;
+ mouse_events, 0;
+ description {
+ state, "default" 0.0;
+ align, 1.0 0.0;
+ rel1 { relative, 1.0 0.0; to_x, "overlay"; offset, -2 1; }
+ rel2 { relative, 1.0 0.0; }
+ color, 255 255 255 255;
+ color3, 0 0 0 100;
+ text {
+ text, "memory-real"; font, "VeraMono";
+ size, 8; min, 1 1;
+ align, 1.0 0.0;
+ }
+ }
+ }
+
+
+ part
+ {
+ name, "mem-swap-text";
+ type, TEXT;
+ effect, SOFT_SHADOW;
+ mouse_events, 0;
+ description {
+ state, "default" 0.0;
+ align, 1.0 0.0;
+ rel1 { relative, 1.0 1.0; to_x, "overlay"; offset, -2 -10; }
+ rel2 { relative, 1.0 1.0; }
+ color, 255 255 255 255;
+ color3, 0 0 0 100;
+ text {
+ text, "memory-swap"; font, "VeraMono";
+ size, 8; min, 1 1;
+ align, 1.0 0.0;
+ }
+ }
+ }
+
+
+ }
+
+ }//close group memory
group
{
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs