Don't recount CPU count in Linux implementation
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user