overlay: Add number of running processes to CPU display

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2013-08-27 23:51:32 +01:00
parent 11567e318e
commit a18023f678
3 changed files with 23 additions and 4 deletions

View File

@ -23,6 +23,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
@ -44,7 +45,7 @@ int cpu_top_update(struct cpu_top *cpu)
struct cpu_stat *s = &cpu->stat[cpu->count++&1]; struct cpu_stat *s = &cpu->stat[cpu->count++&1];
struct cpu_stat *d = &cpu->stat[cpu->count&1]; struct cpu_stat *d = &cpu->stat[cpu->count&1];
uint64_t d_total, d_idle; uint64_t d_total, d_idle;
char buf[4096]; char buf[4096], *b;
int fd, len = -1; int fd, len = -1;
fd = open("/proc/stat", 0); fd = open("/proc/stat", 0);
@ -66,6 +67,10 @@ int cpu_top_update(struct cpu_top *cpu)
&s->user, &s->nice, &s->sys, &s->idle); &s->user, &s->nice, &s->sys, &s->idle);
#endif #endif
b = strstr(buf, "procs_running");
if (b)
cpu->nr_running = atoi(b+sizeof("procs_running")) - 1;
s->total = s->user + s->nice + s->sys + s->idle; s->total = s->user + s->nice + s->sys + s->idle;
if (cpu->count == 1) if (cpu->count == 1)
return EAGAIN; return EAGAIN;

View File

@ -30,6 +30,7 @@
struct cpu_top { struct cpu_top {
uint8_t busy; uint8_t busy;
int nr_cpu; int nr_cpu;
int nr_running;
int count; int count;
struct cpu_stat { struct cpu_stat {

View File

@ -183,6 +183,8 @@ static void show_gpu_top(struct overlay_context *ctx, struct overlay_gpu_top *gt
int y, y1, y2, n, update, len; int y, y1, y2, n, update, len;
cairo_pattern_t *linear; cairo_pattern_t *linear;
char txt[160]; char txt[160];
int rewind;
int do_rewind;
update = gpu_top_update(&gt->gpu_top); update = gpu_top_update(&gt->gpu_top);
@ -222,9 +224,20 @@ static void show_gpu_top(struct overlay_context *ctx, struct overlay_gpu_top *gt
y = PAD + 12 - 2; y = PAD + 12 - 2;
cairo_set_source_rgba(ctx->cr, 0.75, 0.25, 0.75, 1.); cairo_set_source_rgba(ctx->cr, 0.75, 0.25, 0.75, 1.);
cairo_move_to(ctx->cr, PAD, y); cairo_move_to(ctx->cr, PAD, y);
len = sprintf(txt, "CPU: %3d%% busy", gt->cpu_top.busy * gt->cpu_top.nr_cpu); rewind = len = sprintf(txt, "CPU: %3d%% busy", gt->cpu_top.busy * gt->cpu_top.nr_cpu);
if (gt->cpu_top.nr_cpu) do_rewind = 1;
sprintf(txt + len, " (%d cores)", gt->cpu_top.nr_cpu); len += sprintf(txt + len, " (");
if (gt->cpu_top.nr_cpu > 1) {
len += sprintf(txt + len, "%s%d cores", do_rewind ? "" : ", ", gt->cpu_top.nr_cpu);
do_rewind = 0;
}
if (gt->cpu_top.nr_running) {
len += sprintf(txt + len, "%s%d processes", do_rewind ? "" : ", ", gt->cpu_top.nr_running);
do_rewind = 0;
}
sprintf(txt + len, ")");
if (do_rewind)
txt[rewind] = '\0';
cairo_show_text(ctx->cr, txt); cairo_show_text(ctx->cr, txt);
y += 14; y += 14;