diff --git a/src/libsysprof-ui/sysprof-cpu-visualizer-row.c b/src/libsysprof-ui/sysprof-cpu-visualizer-row.c index bce83e94..789bfe65 100644 --- a/src/libsysprof-ui/sysprof-cpu-visualizer-row.c +++ b/src/libsysprof-ui/sysprof-cpu-visualizer-row.c @@ -67,7 +67,8 @@ sysprof_cpu_visualizer_counter_found (const SysprofCaptureFrame *frame, for (guint i = 0; i < def->n_counters; i++) { - if (g_str_equal (def->counters[i].category, state->self->category)) + if (strcmp (def->counters[i].category, state->self->category) == 0 && + strstr (def->counters[i].name, "(Combined)") == NULL) { guint id = def->counters[i].id; g_array_append_val (state->counters, id); diff --git a/src/libsysprof-ui/sysprof-visualizer-list.c b/src/libsysprof-ui/sysprof-visualizer-list.c index af0468d9..65687ccf 100644 --- a/src/libsysprof-ui/sysprof-visualizer-list.c +++ b/src/libsysprof-ui/sysprof-visualizer-list.c @@ -44,6 +44,7 @@ typedef struct GHashTable *mark_groups; guint fps_counter; guint pixels_counter; + guint combined_cpu_counter; GArray *memory; guint has_cpu : 1; guint has_sample : 1; @@ -235,7 +236,11 @@ discover_new_rows_frame_cb (const SysprofCaptureFrame *frame, { const SysprofCaptureCounter *ctr = &def->counters[i]; - if (!state->has_cpu && + if (!state->combined_cpu_counter && + strcmp (ctr->category, "CPU Percent") == 0 && + strcmp (ctr->name, "Combined") == 0) + state->combined_cpu_counter = ctr->id; + else if (!state->has_cpu && strstr (ctr->category, "CPU Percent") != NULL) state->has_cpu = TRUE; else if (!state->fps_counter && @@ -295,7 +300,30 @@ handle_capture_results (GObject *object, * select what sort of data collections they'd like to see. */ - if (state->has_cpu) + if (state->combined_cpu_counter != 0) + { + GdkRGBA rgba; + + GtkWidget *row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER_ROW, + /* Translators: CPU is the processor. */ + "title", _("CPU (Combined)"), + "height-request", 35, + "selectable", FALSE, + "visible", TRUE, + "y-lower", 0.0, + "y-upper", 100.0, + NULL); + gdk_rgba_parse (&rgba, "#3465a4"); + sysprof_line_visualizer_row_add_counter (SYSPROF_LINE_VISUALIZER_ROW (row), + state->combined_cpu_counter, + &rgba); + rgba.alpha = 0.5; + sysprof_line_visualizer_row_set_fill (SYSPROF_LINE_VISUALIZER_ROW (row), + state->combined_cpu_counter, + &rgba); + gtk_container_add (GTK_CONTAINER (self), row); + } + else if (state->has_cpu) { GtkWidget *row = g_object_new (SYSPROF_TYPE_CPU_VISUALIZER_ROW, "category", "CPU Percent", diff --git a/src/libsysprof/sysprof-hostinfo-source.c b/src/libsysprof/sysprof-hostinfo-source.c index 9e12bfc2..5a7f8991 100644 --- a/src/libsysprof/sysprof-hostinfo-source.c +++ b/src/libsysprof/sysprof-hostinfo-source.c @@ -41,6 +41,7 @@ struct _SysprofHostinfoSource guint handler; gint n_cpu; gint stat_fd; + guint combined_id; GArray *freqs; @@ -243,9 +244,10 @@ publish_cpu (SysprofHostinfoSource *self) { SysprofCaptureCounterValue *counter_values; guint *counter_ids; + glong total_usage = 0; - counter_ids = alloca (sizeof *counter_ids * self->n_cpu * 2); - counter_values = alloca (sizeof *counter_values * self->n_cpu * 2); + counter_ids = alloca (sizeof *counter_ids * (self->n_cpu * 2 + 1)); + counter_values = alloca (sizeof *counter_values * (self->n_cpu * 2 + 1)); for (guint i = 0; i < self->n_cpu; i++) { @@ -261,15 +263,21 @@ publish_cpu (SysprofHostinfoSource *self) *id = info->counter_base + 1; value->vdbl = get_cpu_freq (self, i); + + total_usage += info->total; } + /* Add combined counter */ + counter_ids[self->n_cpu * 2] = self->combined_id; + counter_values[self->n_cpu * 2].vdbl = total_usage / (gdouble)self->n_cpu; + sysprof_capture_writer_set_counters (self->writer, SYSPROF_CAPTURE_CURRENT_TIME, -1, - getpid (), + -1, counter_ids, counter_values, - self->n_cpu * 2); + self->n_cpu * 2 + 1); } static gboolean @@ -380,6 +388,7 @@ sysprof_hostinfo_source_prepare (SysprofSource *source) { SysprofHostinfoSource *self = (SysprofHostinfoSource *)source; SysprofCaptureCounter *counters; + SysprofCaptureCounter *combined; gint cpuinfo_fd; g_assert (SYSPROF_IS_HOSTINFO_SOURCE (self)); @@ -402,7 +411,7 @@ sysprof_hostinfo_source_prepare (SysprofSource *source) g_array_set_size (self->cpu_info, 0); - counters = alloca (sizeof *counters * self->n_cpu * 2); + counters = alloca (sizeof *counters * (self->n_cpu * 2 + 1)); for (guint i = 0; i < self->n_cpu; i++) { @@ -457,12 +466,22 @@ sysprof_hostinfo_source_prepare (SysprofSource *source) g_array_append_val (self->cpu_info, info); } + /* Now add combined counter */ + self->combined_id = sysprof_capture_writer_request_counter (self->writer, 1); + combined = &counters[self->n_cpu * 2]; + combined->id = self->combined_id; + combined->type = SYSPROF_CAPTURE_COUNTER_DOUBLE; + combined->value.vdbl = 0; + g_strlcpy (combined->category, "CPU Percent", sizeof combined->category); + g_snprintf (combined->name, sizeof combined->name, "Combined"); + g_snprintf (combined->description, sizeof combined->description, "Combined CPU usage"); + sysprof_capture_writer_define_counters (self->writer, - SYSPROF_CAPTURE_CURRENT_TIME, - -1, - getpid (), - counters, - self->n_cpu * 2); + SYSPROF_CAPTURE_CURRENT_TIME, + -1, + -1, + counters, + self->n_cpu * 2 + 1); sysprof_source_emit_ready (SYSPROF_SOURCE (self)); }