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.
This commit is contained in:
Christian Hergert
2016-09-26 22:14:44 -07:00
parent f600a96364
commit 321fc18eee

View File

@ -35,19 +35,26 @@ sp_cpu_visualizer_counter_found (const SpCaptureFrame *frame,
{ {
const SpCaptureFrameCounterDefine *def = (SpCaptureFrameCounterDefine *)frame; const SpCaptureFrameCounterDefine *def = (SpCaptureFrameCounterDefine *)frame;
GArray *counters = user_data; GArray *counters = user_data;
gboolean found = FALSE;
g_assert (frame->type == SP_CAPTURE_FRAME_CTRDEF); 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++) for (guint i = 0; i < def->n_counters; i++)
{ {
if (g_str_equal (def->counters[i].category, "CPU Percent")) if (g_str_equal (def->counters[i].category, "CPU Percent"))
{ {
guint id = def->counters[i].id; guint id = def->counters[i].id;
g_array_append_val (counters, id); g_array_append_val (counters, id);
found = TRUE;
} }
} }
return TRUE; return !found;
} }
static void static void