[Xfce4-commits] <xfce4-taskmanager:master> Don't recount CPU count in Linux implementation

Mike Massonnet noreply at xfce.org
Sun May 16 12:30:02 CEST 2010


Updating branch refs/heads/master
         to 0be1d45507fea8ab4b4937670d643d3fa414e67e (commit)
       from b961822ba4ee1962d23622ea8ace0639f5377397 (commit)

commit 0be1d45507fea8ab4b4937670d643d3fa414e67e
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sun May 16 12:28:28 2010 +0200

    Don't recount CPU count in Linux implementation

 src/task-manager-linux.c |   22 +++++++++++++++-------
 src/task-manager.h       |   16 ++++++++--------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index d16ba36..ba92f2e 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -70,13 +70,19 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
 	fgets (buffer, 1024, file);
 	sscanf (buffer, "cpu\t%u %u %u %u", &user, &user_nice, &system, &idle);
 
-	_cpu_count = 0;
-	while (fgets (buffer, 1024, file) != NULL)
+	if (_cpu_count == 0)
 	{
-		if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
-			break;
-		_cpu_count += 1;
+		_cpu_count = 0;
+		while (fgets (buffer, 1024, file) != NULL)
+		{
+			if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
+				break;
+			_cpu_count += 1;
+		}
+		if (_cpu_count == 0)
+			_cpu_count += 1;
 	}
+
 	fclose (file);
 
 	old_jiffies_user = cur_jiffies_user;
@@ -89,8 +95,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
 
 	*cpu_user = (old_jiffies > 0) ? (cur_jiffies_user - old_jiffies_user) * 100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
 	*cpu_system = (old_jiffies > 0) ? (cur_jiffies_system - old_jiffies_system) * 100 / (gdouble)(cur_jiffies - old_jiffies) : 0;
-	*cpu_count = (_cpu_count > 0) ? _cpu_count : 1;
-	_cpu_count = *cpu_count;
+	*cpu_count = _cpu_count;
 
 	return TRUE;
 }
@@ -158,6 +163,9 @@ get_cpu_percent (guint pid, gulong jiffies_user, gfloat *cpu_user, gulong jiffie
 	g_hash_table_insert (hash_cpu_user, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_user));
 	g_hash_table_insert (hash_cpu_system, GUINT_TO_POINTER (pid), GUINT_TO_POINTER (jiffies_system));
 
+	if (jiffies_user < jiffies_user_old || jiffies_system < jiffies_system_old)
+		return;
+
 	if (_cpu_count > 0)
 	{
 		*cpu_user = (jiffies_user_old > 0) ? (jiffies_user - jiffies_user_old) / (gfloat)_cpu_count : 0;
diff --git a/src/task-manager.h b/src/task-manager.h
index c8fc891..df6e939 100644
--- a/src/task-manager.h
+++ b/src/task-manager.h
@@ -63,10 +63,10 @@ enum
  * OS specific implementation.
  */
 
-gboolean	get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free);
-gboolean	get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
-gboolean	get_task_list (GArray *task_list);
-gboolean	pid_is_sleeping (guint pid);
+gboolean	get_memory_usage	(guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free);
+gboolean	get_cpu_usage		(gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
+gboolean	get_task_list		(GArray *task_list);
+gboolean	pid_is_sleeping		(guint pid);
 
 /**
  * GObject class used to update the graphical widgets.
@@ -93,9 +93,9 @@ void			xtm_task_manager_update_model			(XtmTaskManager *manager);
  * Helper functions.
  */
 
-void			get_owner_uid					(guint *owner_uid, gchar **owner_uid_name);
-gchar *			get_hostname					();
-gboolean		send_signal_to_pid				(guint pid, gint signal);
-gboolean		set_priority_to_pid				(guint pid, gint priority);
+void		get_owner_uid		(guint *owner_uid, gchar **owner_uid_name);
+gchar *		get_hostname		();
+gboolean	send_signal_to_pid	(guint pid, gint signal);
+gboolean	set_priority_to_pid	(guint pid, gint priority);
 
 #endif /* !TASK_MANAGER_H */



More information about the Xfce4-commits mailing list