mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-09 08:56:11 +00:00
overlay: Include CPU usage in the overview chart
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
98572f0446
commit
6a64ee938b
@ -12,6 +12,8 @@ intel_gpu_overlay_SOURCES = \
|
|||||||
overlay.c \
|
overlay.c \
|
||||||
chart.h \
|
chart.h \
|
||||||
chart.c \
|
chart.c \
|
||||||
|
cpu-top.h \
|
||||||
|
cpu-top.c \
|
||||||
gem-objects.h \
|
gem-objects.h \
|
||||||
gem-objects.c \
|
gem-objects.c \
|
||||||
gpu-top.h \
|
gpu-top.h \
|
||||||
|
44
overlay/cpu-top.c
Normal file
44
overlay/cpu-top.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "cpu-top.h"
|
||||||
|
|
||||||
|
int cpu_top_update(struct cpu_top *cpu)
|
||||||
|
{
|
||||||
|
struct cpu_stat *s = &cpu->stat[cpu->count++&1];
|
||||||
|
struct cpu_stat *d = &cpu->stat[cpu->count&1];
|
||||||
|
uint64_t d_total, d_idle;
|
||||||
|
char buf[4096];
|
||||||
|
int fd, len = -1;
|
||||||
|
|
||||||
|
fd = open("/proc/stat", 0);
|
||||||
|
if (fd < 0)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
len = read(fd, buf, sizeof(buf)-1);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (len < 0)
|
||||||
|
return EIO;
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
#ifdef __x86_64__
|
||||||
|
sscanf(buf, "cpu %lu %lu %lu %lu",
|
||||||
|
&s->user, &s->nice, &s->sys, &s->idle);
|
||||||
|
#else
|
||||||
|
sscanf(buf, "cpu %llu %llu %llu %llu",
|
||||||
|
&s->user, &s->nice, &s->sys, &s->idle);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
s->total = s->user + s->nice + s->sys + s->idle;
|
||||||
|
if (cpu->count == 1)
|
||||||
|
return EAGAIN;
|
||||||
|
|
||||||
|
d_total = s->total - d->total;
|
||||||
|
d_idle = s->idle - d->idle;
|
||||||
|
cpu->busy = 100 - 100 * d_idle / d_total;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
13
overlay/cpu-top.h
Normal file
13
overlay/cpu-top.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
struct cpu_top {
|
||||||
|
uint8_t busy;
|
||||||
|
|
||||||
|
int count;
|
||||||
|
struct cpu_stat {
|
||||||
|
uint64_t user, nice, sys, idle;
|
||||||
|
uint64_t total;
|
||||||
|
} stat[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
int cpu_top_update(struct cpu_top *cpu);
|
@ -10,6 +10,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
|
#include "cpu-top.h"
|
||||||
#include "gpu-top.h"
|
#include "gpu-top.h"
|
||||||
#include "gpu-perf.h"
|
#include "gpu-perf.h"
|
||||||
#include "gem-objects.h"
|
#include "gem-objects.h"
|
||||||
@ -59,8 +60,10 @@ struct overlay_context {
|
|||||||
|
|
||||||
struct overlay_gpu_top {
|
struct overlay_gpu_top {
|
||||||
struct gpu_top gpu_top;
|
struct gpu_top gpu_top;
|
||||||
|
struct cpu_top cpu_top;
|
||||||
struct chart busy[MAX_RINGS];
|
struct chart busy[MAX_RINGS];
|
||||||
struct chart wait[MAX_RINGS];
|
struct chart wait[MAX_RINGS];
|
||||||
|
struct chart cpu;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void init_gpu_top(struct overlay_gpu_top *gt,
|
static void init_gpu_top(struct overlay_gpu_top *gt,
|
||||||
@ -75,6 +78,16 @@ static void init_gpu_top(struct overlay_gpu_top *gt,
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
gpu_top_init(>->gpu_top);
|
gpu_top_init(>->gpu_top);
|
||||||
|
memset(>->cpu, 0, sizeof(gt->cpu));
|
||||||
|
|
||||||
|
chart_init(>->cpu, "CPU", 120);
|
||||||
|
chart_set_position(>->cpu, 12, 12);
|
||||||
|
chart_set_size(>->cpu,
|
||||||
|
cairo_image_surface_get_width(surface)-24,
|
||||||
|
100);
|
||||||
|
chart_set_stroke_rgba(>->cpu, 0.75, 0.25, 0.75, 1.);
|
||||||
|
chart_set_mode(>->cpu, CHART_STROKE);
|
||||||
|
chart_set_range(>->cpu, 0, 100);
|
||||||
|
|
||||||
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
||||||
chart_init(>->busy[n],
|
chart_init(>->busy[n],
|
||||||
@ -107,9 +120,15 @@ static void init_gpu_top(struct overlay_gpu_top *gt,
|
|||||||
|
|
||||||
static void show_gpu_top(struct overlay_context *ctx, struct overlay_gpu_top *gt)
|
static void show_gpu_top(struct overlay_context *ctx, struct overlay_gpu_top *gt)
|
||||||
{
|
{
|
||||||
int y, n, update;
|
int y, n, update, len;
|
||||||
|
char txt[160];
|
||||||
|
|
||||||
update = gpu_top_update(>->gpu_top);
|
update = gpu_top_update(>->gpu_top);
|
||||||
|
|
||||||
|
if (update && cpu_top_update(>->cpu_top) == 0)
|
||||||
|
chart_add_sample(>->cpu, gt->cpu_top.busy);
|
||||||
|
chart_draw(>->cpu, ctx->cr);
|
||||||
|
|
||||||
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
||||||
if (update)
|
if (update)
|
||||||
chart_add_sample(>->wait[n],
|
chart_add_sample(>->wait[n],
|
||||||
@ -126,10 +145,14 @@ static void show_gpu_top(struct overlay_context *ctx, struct overlay_gpu_top *gt
|
|||||||
cairo_set_source_rgb(ctx->cr, 1, 1, 1);
|
cairo_set_source_rgb(ctx->cr, 1, 1, 1);
|
||||||
|
|
||||||
y = 12;
|
y = 12;
|
||||||
|
cairo_set_source_rgba(ctx->cr, 0.75, 0.25, 0.75, 1.);
|
||||||
|
cairo_move_to(ctx->cr, 12, y);
|
||||||
|
sprintf(txt, "CPU: %d%% busy", gt->cpu_top.busy);
|
||||||
|
cairo_show_text(ctx->cr, txt);
|
||||||
|
y += 14;
|
||||||
|
|
||||||
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
for (n = 0; n < gt->gpu_top.num_rings; n++) {
|
||||||
struct chart *c =>->busy[n];
|
struct chart *c =>->busy[n];
|
||||||
char txt[160];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = sprintf(txt, "%s: %d%% busy",
|
len = sprintf(txt, "%s: %d%% busy",
|
||||||
gt->gpu_top.ring[n].name,
|
gt->gpu_top.ring[n].name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user