overlay: Show GPU waits
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 17 Aug 2013 11:32:17 +0000 (12:32 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Sat, 17 Aug 2013 11:35:50 +0000 (12:35 +0100)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
overlay/chart.c
overlay/chart.h
overlay/overlay.c

index 89b3f41..f98ba91 100644 (file)
@@ -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);
 }
index c0f0065..72e19af 100644 (file)
@@ -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);
index 62639b6..99a56a9 100644 (file)
@@ -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(&gt->gpu_top);
 
        for (n = 0; n < gt->gpu_top.num_rings; n++) {
-               chart_init(&gt->chart[n],
+               chart_init(&gt->busy[n],
                           gt->gpu_top.ring[n].name,
                           120);
-               chart_set_position(&gt->chart[n], 12, 12);
-               chart_set_size(&gt->chart[n],
+               chart_set_position(&gt->busy[n], 12, 12);
+               chart_set_size(&gt->busy[n],
                               cairo_image_surface_get_width(surface)-24,
                               100);
-               chart_set_rgba(&gt->chart[n],
-                              rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3]);
-               chart_set_range(&gt->chart[n], 0, 100);
+               chart_set_stroke_rgba(&gt->busy[n],
+                                   rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3]);
+               chart_set_mode(&gt->busy[n], CHART_STROKE);
+               chart_set_range(&gt->busy[n], 0, 100);
+       }
+
+       for (n = 0; n < gt->gpu_top.num_rings; n++) {
+               chart_init(&gt->wait[n],
+                          gt->gpu_top.ring[n].name,
+                          120);
+               chart_set_position(&gt->wait[n], 12, 12);
+               chart_set_size(&gt->wait[n],
+                              cairo_image_surface_get_width(surface)-24,
+                              100);
+               chart_set_fill_rgba(&gt->wait[n],
+                                   rgba[n][0], rgba[n][1], rgba[n][2], rgba[n][3] * 0.70);
+               chart_set_mode(&gt->wait[n], CHART_FILL);
+               chart_set_range(&gt->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(&gt->gpu_top);
        for (n = 0; n < gt->gpu_top.num_rings; n++) {
                if (update)
-                       chart_add_sample(&gt->chart[n],
+                       chart_add_sample(&gt->wait[n],
+                                        gt->gpu_top.ring[n].u.u.wait + gt->gpu_top.ring[n].u.u.sema);
+               chart_draw(&gt->wait[n], cr);
+       }
+       for (n = 0; n < gt->gpu_top.num_rings; n++) {
+               if (update)
+                       chart_add_sample(&gt->busy[n],
                                         gt->gpu_top.ring[n].u.u.busy);
-               chart_draw(&gt->chart[n], cr);
+               chart_draw(&gt->busy[n], cr);
        }
 
        cairo_set_source_rgb(cr, 1, 1, 1);