From 321fc18eee3f5310f484fb526c2a6e3cb9610f26 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 26 Sep 2016 22:14:44 -0700 Subject: [PATCH] cpu-visualizer-row: stop after locating counters In practice, we do a single counter definition for the CPU definitions. So we can stop iterating the samples after we successfully locate an item. --- lib/sp-cpu-visualizer-row.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/sp-cpu-visualizer-row.c b/lib/sp-cpu-visualizer-row.c index 62ac7ec7..7a746396 100644 --- a/lib/sp-cpu-visualizer-row.c +++ b/lib/sp-cpu-visualizer-row.c @@ -35,19 +35,26 @@ sp_cpu_visualizer_counter_found (const SpCaptureFrame *frame, { const SpCaptureFrameCounterDefine *def = (SpCaptureFrameCounterDefine *)frame; GArray *counters = user_data; + gboolean found = FALSE; g_assert (frame->type == SP_CAPTURE_FRAME_CTRDEF); + /* + * In practice, all the CPU counters are defined at once, so we can avoid + * walking the rest of the capture by returning after we find our CTRDEF. + */ + for (guint i = 0; i < def->n_counters; i++) { if (g_str_equal (def->counters[i].category, "CPU Percent")) { guint id = def->counters[i].id; g_array_append_val (counters, id); + found = TRUE; } } - return TRUE; + return !found; } static void