Read information from memory/swap and CPU

This commit is the second of an incremental serie. There will be other
commits with the information about tasks and the support for BSD and
Solaris once things are settled.

The TaskManager class is build with a new source task-manager-linux.c
that provides functions specific to the Linux implementation. It has
functions to read the usage of the memory/swap and the CPU.
This commit is contained in:
Mike Massonnet
2010-05-02 15:15:15 +02:00
parent 9a49bf015a
commit 4f04ca5cb7
6 changed files with 152 additions and 3 deletions

View File

@@ -136,6 +136,24 @@ xtm_task_manager_get_tasklist (XtmTaskManager *manager)
void
xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gushort *cpu, gushort *memory, gushort *swap)
{
guint64 memory_used, swap_used;
/* Set number of processes */
*num_processes = 0;//manager->tasks->len;
/* Set memory and swap usage */
get_memory_usage (&manager->memory_total, &manager->memory_free, &manager->memory_cache, &manager->memory_buffers,
&manager->swap_total, &manager->swap_free);
memory_used = manager->memory_total - manager->memory_free - manager->memory_cache - manager->memory_buffers;
swap_used = manager->swap_total - manager->swap_free;
*memory = (manager->memory_total != 0) ? memory_used * 100 / manager->memory_total : 0;
*swap = (manager->swap_total != 0) ? swap_used * 100 / manager->swap_total : 0;
/* Set CPU usage */
get_cpu_usage (&manager->cpu_count, &manager->cpu_user, &manager->cpu_system);
*cpu = manager->cpu_user + manager->cpu_system;
}
void