mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-29 05:12:41 +00:00
${top} improvements for FreeBSD
- Displaying of CPU time of the processes now works - ${top_time} (sorting by CPU time) works - Using memcpy() instead of many sequential assignments (more clear, less lines, maybe faster, less effort to change something) Signed-off-by: Alexander Graf <agraf@znc.in> Signed-off-by: Pavel Labath <pavelo@centrum.sk>
This commit is contained in:
parent
53b167a84a
commit
b0e5e2cd22
@ -70,7 +70,7 @@
|
|||||||
kvm_t *kd;
|
kvm_t *kd;
|
||||||
|
|
||||||
__attribute__((gnu_inline)) inline void
|
__attribute__((gnu_inline)) inline void
|
||||||
proc_find_top(struct process **cpu, struct process **mem);
|
proc_find_top(struct process **cpu, struct process **mem, struct process **time);
|
||||||
|
|
||||||
static short cpu_setup = 0;
|
static short cpu_setup = 0;
|
||||||
|
|
||||||
@ -597,7 +597,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
|
|||||||
|
|
||||||
int update_top(void)
|
int update_top(void)
|
||||||
{
|
{
|
||||||
proc_find_top(info.cpu, info.memu);
|
proc_find_top(info.cpu, info.memu, info.time);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -733,8 +733,15 @@ int comparemem(const void *a, const void *b)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int comparetime(const void *va, const void *vb)
|
||||||
|
{
|
||||||
|
struct process *a = (struct process *)va, *b = (struct process *)vb;
|
||||||
|
|
||||||
|
return b->total_cpu_time - a->total_cpu_time;
|
||||||
|
}
|
||||||
|
|
||||||
__attribute__((gnu_inline)) inline void
|
__attribute__((gnu_inline)) inline void
|
||||||
proc_find_top(struct process **cpu, struct process **mem)
|
proc_find_top(struct process **cpu, struct process **mem, struct process **time)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *p;
|
struct kinfo_proc *p;
|
||||||
int n_processes;
|
int n_processes;
|
||||||
@ -758,6 +765,9 @@ proc_find_top(struct process **cpu, struct process **mem)
|
|||||||
processes[j].amount = 100.0 * p[i].ki_pctcpu / FSCALE;
|
processes[j].amount = 100.0 * p[i].ki_pctcpu / FSCALE;
|
||||||
processes[j].vsize = p[i].ki_size;
|
processes[j].vsize = p[i].ki_size;
|
||||||
processes[j].rss = (p[i].ki_rssize * getpagesize());
|
processes[j].rss = (p[i].ki_rssize * getpagesize());
|
||||||
|
/* ki_runtime is in microseconds, total_cpu_time in centiseconds.
|
||||||
|
* Therefore we divide by 10000. */
|
||||||
|
processes[j].total_cpu_time = p[i].ki_runtime / 10000;
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -767,11 +777,7 @@ proc_find_top(struct process **cpu, struct process **mem)
|
|||||||
struct process *tmp, *ttmp;
|
struct process *tmp, *ttmp;
|
||||||
|
|
||||||
tmp = (process *) malloc(sizeof(struct process));
|
tmp = (process *) malloc(sizeof(struct process));
|
||||||
tmp->pid = processes[i].pid;
|
memcpy(tmp, &processes[i], sizeof(struct process));
|
||||||
tmp->amount = processes[i].amount;
|
|
||||||
tmp->name = strndup(processes[i].name, text_buffer_size);
|
|
||||||
tmp->rss = processes[i].rss;
|
|
||||||
tmp->vsize = processes[i].vsize;
|
|
||||||
|
|
||||||
ttmp = mem[i];
|
ttmp = mem[i];
|
||||||
mem[i] = tmp;
|
mem[i] = tmp;
|
||||||
@ -786,11 +792,7 @@ proc_find_top(struct process **cpu, struct process **mem)
|
|||||||
struct process *tmp, *ttmp;
|
struct process *tmp, *ttmp;
|
||||||
|
|
||||||
tmp = (process *) malloc(sizeof(struct process));
|
tmp = (process *) malloc(sizeof(struct process));
|
||||||
tmp->pid = processes[i].pid;
|
memcpy(tmp, &processes[i], sizeof(struct process));
|
||||||
tmp->amount = processes[i].amount;
|
|
||||||
tmp->name = strndup(processes[i].name, text_buffer_size);
|
|
||||||
tmp->rss = processes[i].rss;
|
|
||||||
tmp->vsize = processes[i].vsize;
|
|
||||||
|
|
||||||
ttmp = cpu[i];
|
ttmp = cpu[i];
|
||||||
cpu[i] = tmp;
|
cpu[i] = tmp;
|
||||||
@ -800,6 +802,21 @@ proc_find_top(struct process **cpu, struct process **mem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsort(processes, j - 1, sizeof(struct process), comparetime);
|
||||||
|
for (i = 0; i < 10 && i < n_processes; i++) {
|
||||||
|
struct process *tmp, *ttmp;
|
||||||
|
|
||||||
|
tmp = (process *) malloc(sizeof(struct process));
|
||||||
|
memcpy(tmp, &processes[i], sizeof(struct process));
|
||||||
|
|
||||||
|
ttmp = time[i];
|
||||||
|
time[i] = tmp;
|
||||||
|
if (ttmp != NULL) {
|
||||||
|
free(ttmp->name);
|
||||||
|
free(ttmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(FREEBSD_DEBUG)
|
#if defined(FREEBSD_DEBUG)
|
||||||
printf("=====\nmem\n");
|
printf("=====\nmem\n");
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user