[Goodies-commits] r2347 - in xfce4-taskmanager/trunk: . src
Nick Schermer
nick at xfce.org
Fri Jan 12 18:19:12 CET 2007
Author: nick
Date: 2007-01-12 17:19:11 +0000 (Fri, 12 Jan 2007)
New Revision: 2347
Modified:
xfce4-taskmanager/trunk/ChangeLog
xfce4-taskmanager/trunk/src/callbacks.c
xfce4-taskmanager/trunk/src/callbacks.h
xfce4-taskmanager/trunk/src/functions.c
xfce4-taskmanager/trunk/src/interface.c
xfce4-taskmanager/trunk/src/types.h
xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.c
xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.h
Log:
Apply patch from bug 2714.
Fix all typos and compiler warnings.
Modified: xfce4-taskmanager/trunk/ChangeLog
===================================================================
--- xfce4-taskmanager/trunk/ChangeLog 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/ChangeLog 2007-01-12 17:19:11 UTC (rev 2347)
@@ -1,3 +1,7 @@
+2007-01-12 Nick Schermer <nick at xfce.org>
+ * Apply patch from bug 2714.
+ * Fix all typo and compiler warnings.
+
2006-06-26 20:20 Johannes
* rewrite of the taskmanager ;)
Modified: xfce4-taskmanager/trunk/src/callbacks.c
===================================================================
--- xfce4-taskmanager/trunk/src/callbacks.c 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/callbacks.c 2007-01-12 17:19:11 UTC (rev 2347)
@@ -85,9 +85,15 @@
else
show_other_tasks = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem));
- change_task_view();
+ change_task_view();
}
+void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gint uid)
+{
+ show_cached_as_free = !show_cached_as_free;
+ change_task_view();
+}
+
void on_quit(void)
{
save_config();
Modified: xfce4-taskmanager/trunk/src/callbacks.h
===================================================================
--- xfce4-taskmanager/trunk/src/callbacks.h 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/callbacks.h 2007-01-12 17:19:11 UTC (rev 2347)
@@ -36,6 +36,7 @@
void on_info1_activate (GtkMenuItem *menuitem, gpointer user_data);
void handle_task_menu(GtkWidget *widget, gchar *signal);
void on_show_tasks_toggled (GtkMenuItem *menuitem, gint uid);
+void on_show_cached_as_free_toggled (GtkMenuItem *menuitem, gint uid);
void on_quit(void);
Modified: xfce4-taskmanager/trunk/src/functions.c
===================================================================
--- xfce4-taskmanager/trunk/src/functions.c 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/functions.c 2007-01-12 17:19:11 UTC (rev 2347)
@@ -19,14 +19,17 @@
*/
#include "functions.h"
+#include "xfce-taskmanager-linux.h"
+static system_status *sys_stat =NULL;
+
gboolean refresh_task_list(void)
{
gint i, j;
GArray *new_task_list;
gchar *cpu_tooltip, *mem_tooltip;
gdouble cpu_usage;
- system_status *sys_stat;
+ guint memory_used;
/* gets the new task list */
new_task_list = (GArray*) get_task_list();
@@ -49,7 +52,6 @@
tmp->time_percentage = (gdouble)(tmp->time - tmp->old_time) * (gdouble)(1000.0 / REFRESH_INTERVAL);
-
if((gint)tmp->ppid != (gint)new_tmp->ppid || strcmp(tmp->state,new_tmp->state) || (unsigned int)tmp->size != (unsigned int)new_tmp->size || (unsigned int)tmp->rss != (unsigned int)new_tmp->rss || (unsigned int)tmp->time != (unsigned int)tmp->old_time)
{
tmp->ppid = new_tmp->ppid;
@@ -106,21 +108,26 @@
g_array_free(new_task_list, TRUE);
/* update the CPU and memory progress bars */
- sys_stat = g_new (system_status, 1);
+ if (sys_stat == NULL)
+ sys_stat = g_new (system_status, 1);
get_system_status (sys_stat);
- mem_tooltip = g_strdup_printf (_("%d kB of %d kB used"), sys_stat->mem_total - sys_stat->mem_free, sys_stat->mem_total);
+ memory_used = sys_stat->mem_total - sys_stat->mem_free;
+ if ( show_cached_as_free )
+ {
+ memory_used-=sys_stat->mem_cached;
+ }
+ mem_tooltip = g_strdup_printf (_("%d kB of %d kB used"), memory_used, sys_stat->mem_total);
gtk_tooltips_set_tip (tooltips, mem_usage_progress_bar_box, mem_tooltip, NULL);
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (mem_usage_progress_bar), 1.0 - ( (gdouble) sys_stat->mem_free / sys_stat->mem_total ));
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (mem_usage_progress_bar), (gdouble)memory_used / sys_stat->mem_total);
cpu_usage = get_cpu_usage (sys_stat);
- cpu_tooltip = g_strdup_printf (_("%0.0f %%"), cpu_usage * 100);
+ cpu_tooltip = g_strdup_printf (_("%0.0f %%"), cpu_usage * 100.0);
gtk_tooltips_set_tip (tooltips, cpu_usage_progress_bar_box, cpu_tooltip, NULL);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (cpu_usage_progress_bar), cpu_usage);
g_free (mem_tooltip);
g_free (cpu_tooltip);
- g_free (sys_stat);
return TRUE;
}
@@ -128,16 +135,38 @@
gdouble get_cpu_usage(system_status *sys_stat)
{
gdouble cpu_usage = 0.0;
- gint i = 0;
-
- for(i = 0; i < task_array->len; i++)
+ guint current_jiffies;
+ guint current_used;
+ guint delta_jiffies;
+
+ if ( get_cpu_usage_from_proc( sys_stat ) == FALSE )
{
- struct task *tmp = &g_array_index(task_array, struct task, i);
- cpu_usage += tmp->time_percentage;
+ gint i = 0;
+
+ for(i = 0; i < task_array->len; i++)
+ {
+ struct task *tmp = &g_array_index(task_array, struct task, i);
+ cpu_usage += tmp->time_percentage;
+ }
+
+ cpu_usage = cpu_usage / (sys_stat->cpu_count * 100.0);
+ } else {
+
+ if ( sys_stat->cpu_old_jiffies > 0 ) {
+ current_used =
+ sys_stat->cpu_user +
+ sys_stat->cpu_nice +
+ sys_stat->cpu_system;
+ current_jiffies =
+ current_used +
+ sys_stat->cpu_idle;
+ delta_jiffies =
+ current_jiffies - (gdouble)sys_stat->cpu_old_jiffies;
+
+ cpu_usage = (gdouble)( current_used - sys_stat->cpu_old_used ) /
+ (gdouble)delta_jiffies ;
+ }
}
-
- cpu_usage = cpu_usage / (sys_stat->cpu_count * 100.0);
-
return cpu_usage;
}
@@ -153,6 +182,7 @@
show_user_tasks = xfce_rc_read_bool_entry(rc_file, "show_user_tasks", TRUE);
show_root_tasks = xfce_rc_read_bool_entry(rc_file, "show_root_tasks", FALSE);
show_other_tasks = xfce_rc_read_bool_entry(rc_file, "show_other_tasks", FALSE);
+ show_cached_as_free = xfce_rc_read_bool_entry(rc_file, "show_cached_as_free", TRUE);
full_view = xfce_rc_read_bool_entry(rc_file, "full_view", FALSE);
@@ -171,10 +201,11 @@
xfce_rc_write_bool_entry(rc_file, "show_user_tasks", show_user_tasks);
xfce_rc_write_bool_entry(rc_file, "show_root_tasks", show_root_tasks);
xfce_rc_write_bool_entry(rc_file, "show_other_tasks", show_other_tasks);
+ xfce_rc_write_bool_entry(rc_file, "show_cached_as_free", show_cached_as_free);
xfce_rc_write_bool_entry(rc_file, "full_view", full_view);
- gtk_window_get_size(GTK_WINDOW (main_window), &win_width, &win_height);
+ gtk_window_get_size(GTK_WINDOW (main_window), (gint *) &win_width, (gint *) &win_height);
xfce_rc_write_int_entry(rc_file, "win_width", win_width);
xfce_rc_write_int_entry(rc_file, "win_height", win_height);
Modified: xfce4-taskmanager/trunk/src/interface.c
===================================================================
--- xfce4-taskmanager/trunk/src/interface.c 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/interface.c 2007-01-12 17:19:11 UTC (rev 2347)
@@ -212,6 +212,7 @@
GtkWidget *show_user_tasks1;
GtkWidget *show_root_tasks1;
GtkWidget *show_other_tasks1;
+ GtkWidget *show_cached_as_free1;
GtkAccelGroup *accel_group;
accel_group = gtk_accel_group_new ();
@@ -242,10 +243,16 @@
gtk_widget_show (show_other_tasks1);
gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_other_tasks1);
+ show_cached_as_free1 = gtk_check_menu_item_new_with_mnemonic (_("Show memory used by cache as free"));
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(show_cached_as_free1), show_cached_as_free);
+ gtk_widget_show (show_cached_as_free1);
+ gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), show_cached_as_free1);
+
g_signal_connect ((gpointer) info1, "activate", G_CALLBACK (on_info1_activate), NULL);
g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)own_uid);
g_signal_connect ((gpointer) show_root_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)0);
g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-1);
+ g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0);
gtk_menu_set_accel_group (GTK_MENU (mainmenu), accel_group);
@@ -289,7 +296,7 @@
gchar *rss = g_strdup_printf("%i kB", task->rss);
gchar *name = g_strdup_printf("%s", task->name);
gchar *uname = g_strdup_printf("%s", task->uname);
- gchar *time = g_strdup_printf("%.1f%%", task->time_percentage);
+ gchar *time = g_strdup_printf("%0d%%", (guint)task->time_percentage);
gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_NAME, name, -1);
gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PID, pid, -1);
Modified: xfce4-taskmanager/trunk/src/types.h
===================================================================
--- xfce4-taskmanager/trunk/src/types.h 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/types.h 2007-01-12 17:19:11 UTC (rev 2347)
@@ -43,9 +43,17 @@
typedef struct
{
- gint mem_total;
- gint mem_free;
- gint cpu_count;
+ guint mem_total;
+ guint mem_free;
+ guint mem_cached;
+ guint cpu_count;
+ guint cpu_idle;
+ guint cpu_user;
+ guint cpu_nice;
+ guint cpu_system;
+ guint cpu_old_jiffies;
+ guint cpu_old_used;
+ gboolean valid_proc_reading;
} system_status;
GtkWidget *main_window;
@@ -60,6 +68,8 @@
gboolean show_root_tasks;
gboolean show_other_tasks;
+gboolean show_cached_as_free; /* Show memory used Cache as free memory */
+
gboolean full_view;
guint win_width;
Modified: xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.c
===================================================================
--- xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.c 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.c 2007-01-12 17:19:11 UTC (rev 2347)
@@ -1,3 +1,4 @@
+
#include "xfce-taskmanager-linux.h"
struct task get_task_details(gint pid)
@@ -121,7 +122,7 @@
return task;
}
-GArray *get_task_list()
+GArray *get_task_list(void)
{
DIR *dir;
struct dirent *dir_entry;
@@ -153,6 +154,57 @@
return task_list;
}
+gboolean get_cpu_usage_from_proc(system_status *sys_stat)
+{
+ const gchar *file_name = "/proc/stat";
+ gchar buffer[100];
+ gboolean retval = FALSE;
+ FILE *file;
+
+ if ( sys_stat->valid_proc_reading == TRUE ) {
+ sys_stat->cpu_old_jiffies =
+ sys_stat->cpu_user +
+ sys_stat->cpu_nice +
+ sys_stat->cpu_system+
+ sys_stat->cpu_idle;
+ sys_stat->cpu_old_used =
+ sys_stat->cpu_user +
+ sys_stat->cpu_nice +
+ sys_stat->cpu_system;
+ } else {
+ sys_stat->cpu_old_jiffies = 0;
+ }
+
+ sys_stat->valid_proc_reading = FALSE;
+
+ if (!g_file_test (file_name, G_FILE_TEST_EXISTS))
+ {
+ return FALSE;
+ }
+
+
+ file = fopen (file_name, "r");
+
+ if (file)
+ {
+ if ( fgets (buffer, 100, file) != NULL )
+ {
+ if ( sscanf (buffer, "cpu\t%u %u %u %u",
+ &sys_stat->cpu_user,
+ &sys_stat->cpu_nice,
+ &sys_stat->cpu_system,
+ &sys_stat->cpu_idle
+ ) == 4 )
+ {
+ sys_stat->valid_proc_reading = TRUE;
+ retval = TRUE;
+ }
+ }
+ fclose( file );
+ }
+ return retval;
+}
+
gboolean get_system_status (system_status *sys_stat)
{
FILE *file;
@@ -175,8 +227,9 @@
{
while (fgets (buffer, 100, file) != NULL)
{
- sscanf (buffer, "MemTotal:\t%i kB", &sys_stat->mem_total);
- sscanf (buffer, "MemFree:\t%i kB", &sys_stat->mem_free);
+ sscanf (buffer, "MemTotal:\t%u kB", &sys_stat->mem_total);
+ sscanf (buffer, "MemFree:\t%u kB", &sys_stat->mem_free);
+ sscanf (buffer, "Cached:\t%u kB", &sys_stat->mem_cached);
}
fclose (file);
}
Modified: xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.h
===================================================================
--- xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.h 2007-01-12 17:03:02 UTC (rev 2346)
+++ xfce4-taskmanager/trunk/src/xfce-taskmanager-linux.h 2007-01-12 17:19:11 UTC (rev 2347)
@@ -12,7 +12,8 @@
#include "types.h"
struct task get_task_details(gint pid);
-GArray *get_task_list();
+GArray *get_task_list(void);
gboolean get_system_status(system_status *sys_stat);
+gboolean get_cpu_usage_from_proc(system_status *sys_stat);
#endif
More information about the Goodies-commits
mailing list