mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-08 06:00:54 +00:00
libsysprof: show a combined cpu counter by default
We need a way to show the individual counters, but this is a good first start. To do the combined counters, we need to come up with something that allows expanding of rows and what not.
This commit is contained in:
@ -67,7 +67,8 @@ sysprof_cpu_visualizer_counter_found (const SysprofCaptureFrame *frame,
|
|||||||
|
|
||||||
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, 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;
|
guint id = def->counters[i].id;
|
||||||
g_array_append_val (state->counters, id);
|
g_array_append_val (state->counters, id);
|
||||||
|
|||||||
@ -44,6 +44,7 @@ typedef struct
|
|||||||
GHashTable *mark_groups;
|
GHashTable *mark_groups;
|
||||||
guint fps_counter;
|
guint fps_counter;
|
||||||
guint pixels_counter;
|
guint pixels_counter;
|
||||||
|
guint combined_cpu_counter;
|
||||||
GArray *memory;
|
GArray *memory;
|
||||||
guint has_cpu : 1;
|
guint has_cpu : 1;
|
||||||
guint has_sample : 1;
|
guint has_sample : 1;
|
||||||
@ -235,7 +236,11 @@ discover_new_rows_frame_cb (const SysprofCaptureFrame *frame,
|
|||||||
{
|
{
|
||||||
const SysprofCaptureCounter *ctr = &def->counters[i];
|
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)
|
strstr (ctr->category, "CPU Percent") != NULL)
|
||||||
state->has_cpu = TRUE;
|
state->has_cpu = TRUE;
|
||||||
else if (!state->fps_counter &&
|
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.
|
* 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,
|
GtkWidget *row = g_object_new (SYSPROF_TYPE_CPU_VISUALIZER_ROW,
|
||||||
"category", "CPU Percent",
|
"category", "CPU Percent",
|
||||||
|
|||||||
@ -41,6 +41,7 @@ struct _SysprofHostinfoSource
|
|||||||
guint handler;
|
guint handler;
|
||||||
gint n_cpu;
|
gint n_cpu;
|
||||||
gint stat_fd;
|
gint stat_fd;
|
||||||
|
guint combined_id;
|
||||||
|
|
||||||
GArray *freqs;
|
GArray *freqs;
|
||||||
|
|
||||||
@ -243,9 +244,10 @@ publish_cpu (SysprofHostinfoSource *self)
|
|||||||
{
|
{
|
||||||
SysprofCaptureCounterValue *counter_values;
|
SysprofCaptureCounterValue *counter_values;
|
||||||
guint *counter_ids;
|
guint *counter_ids;
|
||||||
|
glong total_usage = 0;
|
||||||
|
|
||||||
counter_ids = alloca (sizeof *counter_ids * 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);
|
counter_values = alloca (sizeof *counter_values * (self->n_cpu * 2 + 1));
|
||||||
|
|
||||||
for (guint i = 0; i < self->n_cpu; i++)
|
for (guint i = 0; i < self->n_cpu; i++)
|
||||||
{
|
{
|
||||||
@ -261,15 +263,21 @@ publish_cpu (SysprofHostinfoSource *self)
|
|||||||
|
|
||||||
*id = info->counter_base + 1;
|
*id = info->counter_base + 1;
|
||||||
value->vdbl = get_cpu_freq (self, i);
|
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_writer_set_counters (self->writer,
|
||||||
SYSPROF_CAPTURE_CURRENT_TIME,
|
SYSPROF_CAPTURE_CURRENT_TIME,
|
||||||
-1,
|
-1,
|
||||||
getpid (),
|
-1,
|
||||||
counter_ids,
|
counter_ids,
|
||||||
counter_values,
|
counter_values,
|
||||||
self->n_cpu * 2);
|
self->n_cpu * 2 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -380,6 +388,7 @@ sysprof_hostinfo_source_prepare (SysprofSource *source)
|
|||||||
{
|
{
|
||||||
SysprofHostinfoSource *self = (SysprofHostinfoSource *)source;
|
SysprofHostinfoSource *self = (SysprofHostinfoSource *)source;
|
||||||
SysprofCaptureCounter *counters;
|
SysprofCaptureCounter *counters;
|
||||||
|
SysprofCaptureCounter *combined;
|
||||||
gint cpuinfo_fd;
|
gint cpuinfo_fd;
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_HOSTINFO_SOURCE (self));
|
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);
|
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++)
|
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);
|
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_writer_define_counters (self->writer,
|
||||||
SYSPROF_CAPTURE_CURRENT_TIME,
|
SYSPROF_CAPTURE_CURRENT_TIME,
|
||||||
-1,
|
-1,
|
||||||
getpid (),
|
-1,
|
||||||
counters,
|
counters,
|
||||||
self->n_cpu * 2);
|
self->n_cpu * 2 + 1);
|
||||||
|
|
||||||
sysprof_source_emit_ready (SYSPROF_SOURCE (self));
|
sysprof_source_emit_ready (SYSPROF_SOURCE (self));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user