From 06c0cc0bb42d0a3f1c72e0c0d85d15107a392069 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 17 Aug 2013 12:32:17 +0100 Subject: [PATCH] overlay: Show GPU waits Signed-off-by: Chris Wilson --- overlay/chart.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- overlay/chart.h | 12 ++++++++++-- overlay/overlay.c | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 82 insertions(+), 20 deletions(-) diff --git a/overlay/chart.c b/overlay/chart.c index 89b3f41..f98ba91 100644 --- a/overlay/chart.c +++ b/overlay/chart.c @@ -20,12 +20,25 @@ int chart_init(struct chart *chart, const char *name, int num_samples) return 0; } -void chart_set_rgba(struct chart *chart, float red, float green, float blue, float alpha) +void chart_set_mode(struct chart *chart, enum chart_mode mode) { - chart->rgb[0] = red; - chart->rgb[1] = green; - chart->rgb[2] = blue; - chart->rgb[3] = alpha; + chart->mode = mode; +} + +void chart_set_stroke_rgba(struct chart *chart, float red, float green, float blue, float alpha) +{ + chart->stroke_rgb[0] = red; + chart->stroke_rgb[1] = green; + chart->stroke_rgb[2] = blue; + chart->stroke_rgb[3] = alpha; +} + +void chart_set_fill_rgba(struct chart *chart, float red, float green, float blue, float alpha) +{ + chart->fill_rgb[0] = red; + chart->fill_rgb[1] = green; + chart->fill_rgb[2] = blue; + chart->fill_rgb[3] = alpha; } void chart_set_position(struct chart *chart, int x, int y) @@ -119,17 +132,36 @@ void chart_draw(struct chart *chart, cairo_t *cr) cairo_translate(cr, x, -chart->range[0]); cairo_new_path(cr); + if (chart->mode != CHART_STROKE) + cairo_move_to(cr, 0, 0); for (n = 0; n < max; n++) { cairo_curve_to(cr, n-2/3., value_at(chart, i + n -1) + gradient_at(chart, i + n - 1)/3., n-1/3., value_at(chart, i + n) - gradient_at(chart, i + n)/3., n, value_at(chart, i + n)); } + if (chart->mode != CHART_STROKE) + cairo_line_to(cr, max, 0); cairo_identity_matrix(cr); - cairo_set_line_width(cr, 1); - cairo_set_source_rgba(cr, chart->rgb[0], chart->rgb[1], chart->rgb[2], chart->rgb[3]); - cairo_stroke(cr); - + cairo_set_line_width(cr, 2); + switch (chart->mode) { + case CHART_STROKE: + cairo_set_source_rgba(cr, chart->stroke_rgb[0], chart->stroke_rgb[1], chart->stroke_rgb[2], chart->stroke_rgb[3]); + cairo_stroke(cr); + break; + case CHART_FILL: + cairo_set_source_rgba(cr, chart->fill_rgb[0], chart->fill_rgb[1], chart->fill_rgb[2], chart->fill_rgb[3]); + cairo_fill(cr); + break; + case CHART_FILL_STROKE: + cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); + cairo_set_source_rgba(cr, chart->fill_rgb[0], chart->fill_rgb[1], chart->fill_rgb[2], chart->fill_rgb[3]); + cairo_fill_preserve(cr); + cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); + cairo_set_source_rgba(cr, chart->stroke_rgb[0], chart->stroke_rgb[1], chart->stroke_rgb[2], chart->stroke_rgb[3]); + cairo_stroke(cr); + break; + } cairo_restore(cr); } diff --git a/overlay/chart.h b/overlay/chart.h index c0f0065..72e19af 100644 --- a/overlay/chart.h +++ b/overlay/chart.h @@ -4,13 +4,21 @@ struct chart { int num_samples; int current_sample; int range_automatic; - float rgb[4]; + float fill_rgb[4]; + float stroke_rgb[4]; + enum chart_mode { + CHART_STROKE = 0, + CHART_FILL, + CHART_FILL_STROKE, + } mode; double range[2]; double *samples; }; int chart_init(struct chart *chart, const char *name, int num_samples); -void chart_set_rgba(struct chart *chart, float red, float green, float blue, float alpha); +void chart_set_mode(struct chart *chart, enum chart_mode mode); +void chart_set_fill_rgba(struct chart *chart, float red, float green, float blue, float alpha); +void chart_set_stroke_rgba(struct chart *chart, float red, float green, float blue, float alpha); void chart_set_position(struct chart *chart, int x, int y); void chart_set_size(struct chart *chart, int w, int h); void chart_set_range(struct chart *chart, double min, double max); diff --git a/overlay/overlay.c b/overlay/overlay.c index 62639b6..99a56a9 100644 --- a/overlay/overlay.c +++ b/overlay/overlay.c @@ -53,7 +53,8 @@ static void overlay_hide(cairo_surface_t *surface) struct overlay_gpu_top { struct gpu_top gpu_top; - struct chart chart[MAX_RINGS]; + struct chart busy[MAX_RINGS]; + struct chart wait[MAX_RINGS]; }; static void init_gpu_top(struct overlay_gpu_top *gt, @@ -70,16 +71,31 @@ static void init_gpu_top(struct overlay_gpu_top *gt, gpu_top_init(>->gpu_top); for (n = 0; n < gt->gpu_top.num_rings; n++) { - chart_init(>->chart[n], + chart_init(>->busy[n], gt->gpu_top.ring[n].name, 120); - chart_set_position(>->chart[n], 12, 12); - chart_set_size(>->chart[n], + chart_set_position(>->busy[n], 12, 12); + chart_set_size(>->busy[n], cairo_image_surface_get_width(surface)-24, 100); - chart_set_rgba(>->chart[n], - rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3]); - chart_set_range(>->chart[n], 0, 100); + chart_set_stroke_rgba(>->busy[n], + rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3]); + chart_set_mode(>->busy[n], CHART_STROKE); + chart_set_range(>->busy[n], 0, 100); + } + + for (n = 0; n < gt->gpu_top.num_rings; n++) { + chart_init(>->wait[n], + gt->gpu_top.ring[n].name, + 120); + chart_set_position(>->wait[n], 12, 12); + chart_set_size(>->wait[n], + cairo_image_surface_get_width(surface)-24, + 100); + chart_set_fill_rgba(>->wait[n], + rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3] * 0.70); + chart_set_mode(>->wait[n], CHART_FILL); + chart_set_range(>->wait[n], 0, 100); } } @@ -90,9 +106,15 @@ static void show_gpu_top(cairo_t *cr, struct overlay_gpu_top *gt) update = gpu_top_update(>->gpu_top); for (n = 0; n < gt->gpu_top.num_rings; n++) { if (update) - chart_add_sample(>->chart[n], + chart_add_sample(>->wait[n], + gt->gpu_top.ring[n].u.u.wait + gt->gpu_top.ring[n].u.u.sema); + chart_draw(>->wait[n], cr); + } + for (n = 0; n < gt->gpu_top.num_rings; n++) { + if (update) + chart_add_sample(>->busy[n], gt->gpu_top.ring[n].u.u.busy); - chart_draw(>->chart[n], cr); + chart_draw(>->busy[n], cr); } cairo_set_source_rgb(cr, 1, 1, 1); -- 2.7.4