mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: use signals to create charts
This allows us to keep the final type for tracks like I want and instead move various logic into signal handlers which are kept within the same source file for discovery.
This commit is contained in:
@ -22,37 +22,63 @@
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "sysprof-counter-track-private.h"
|
||||
#include "sysprof-chart.h"
|
||||
#include "sysprof-chart-layer.h"
|
||||
#include "sysprof-column-layer.h"
|
||||
#include "sysprof-session-private.h"
|
||||
#include "sysprof-track-private.h"
|
||||
#include "sysprof-value-axis.h"
|
||||
|
||||
typedef struct _SysprofTrackCounter
|
||||
{
|
||||
const char *track_name;
|
||||
|
||||
/* Used to layer values into main view */
|
||||
const char *category;
|
||||
const char *name;
|
||||
const char *subtracks_name_glob;
|
||||
const char *track_name;
|
||||
|
||||
/* Used to split out sub views */
|
||||
const char *subtracks_category;
|
||||
const char *subtracks_name;
|
||||
} SysprofTrackCounter;
|
||||
|
||||
static const SysprofTrackCounter discovery_counters[] = {
|
||||
{ "CPU Percent", "Combined", "Total CPU *", N_("CPU Usage") },
|
||||
{
|
||||
N_("CPU"),
|
||||
"CPU Percent", "Combined",
|
||||
"CPU Percent", "*",
|
||||
},
|
||||
|
||||
{ N_("Memory"), "Memory", "Used", NULL, NULL },
|
||||
|
||||
{
|
||||
N_("Energy"),
|
||||
"RAPL", "*",
|
||||
"RAPL *", "*",
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
static GListModel *
|
||||
filter_counters (GListModel *model,
|
||||
const char *category,
|
||||
const char *category_glob,
|
||||
const char *name_glob)
|
||||
{
|
||||
g_autoptr(GListStore) store = NULL;
|
||||
g_autoptr(GPatternSpec) spec = NULL;
|
||||
g_autoptr(GPatternSpec) cat_spec = NULL;
|
||||
g_autoptr(GPatternSpec) name_spec = NULL;
|
||||
guint n_items;
|
||||
|
||||
g_assert (G_IS_LIST_MODEL (model));
|
||||
g_assert (category != NULL);
|
||||
g_assert (name_glob != NULL);
|
||||
|
||||
if (category_glob == NULL || name_glob == NULL)
|
||||
return NULL;
|
||||
|
||||
store = g_list_store_new (SYSPROF_TYPE_DOCUMENT_COUNTER);
|
||||
spec = g_pattern_spec_new (name_glob);
|
||||
|
||||
cat_spec = g_pattern_spec_new (category_glob);
|
||||
name_spec = g_pattern_spec_new (name_glob);
|
||||
|
||||
n_items = g_list_model_get_n_items (model);
|
||||
|
||||
for (guint i = 0; i < n_items; i++)
|
||||
@ -61,8 +87,8 @@ filter_counters (GListModel *model,
|
||||
const char *ctrcat = sysprof_document_counter_get_category (counter);
|
||||
const char *ctrname = sysprof_document_counter_get_name (counter);
|
||||
|
||||
if (g_strcmp0 (category, ctrcat) == 0 &&
|
||||
g_pattern_spec_match (spec, strlen (ctrname), ctrname, NULL))
|
||||
if (g_pattern_spec_match (cat_spec, strlen (ctrcat), ctrcat, NULL) ||
|
||||
g_pattern_spec_match (name_spec, strlen (ctrname), ctrname, NULL))
|
||||
g_list_store_append (store, counter);
|
||||
}
|
||||
|
||||
@ -72,10 +98,75 @@ filter_counters (GListModel *model,
|
||||
return G_LIST_MODEL (g_steal_pointer (&store));
|
||||
}
|
||||
|
||||
void
|
||||
_sysprof_session_discover_tracks (SysprofSession *self,
|
||||
static GtkWidget *
|
||||
create_chart_for_samples (SysprofSession *session,
|
||||
SysprofTrack *track)
|
||||
{
|
||||
g_autoptr(SysprofSeries) xy_series = NULL;
|
||||
g_autoptr(SysprofAxis) y_axis = NULL;
|
||||
g_autoptr(GListModel) samples = NULL;
|
||||
SysprofChartLayer *layer;
|
||||
SysprofDocument *document;
|
||||
SysprofChart *chart;
|
||||
SysprofAxis *x_axis = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (session));
|
||||
g_assert (SYSPROF_IS_TRACK (track));
|
||||
|
||||
document = sysprof_session_get_document (session);
|
||||
x_axis = sysprof_session_get_visible_time_axis (session);
|
||||
y_axis = sysprof_value_axis_new (0, 128);
|
||||
xy_series = sysprof_xy_series_new (_("Stack Depth"),
|
||||
sysprof_document_list_samples (document),
|
||||
gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_SAMPLE, NULL, "time"),
|
||||
gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_SAMPLE, NULL, "stack-depth"));
|
||||
|
||||
chart = g_object_new (SYSPROF_TYPE_CHART,
|
||||
"height-request", 48,
|
||||
NULL);
|
||||
layer = g_object_new (SYSPROF_TYPE_COLUMN_LAYER,
|
||||
"series", xy_series,
|
||||
"x-axis", x_axis,
|
||||
"y-axis", y_axis,
|
||||
NULL);
|
||||
sysprof_chart_add_layer (chart, layer);
|
||||
|
||||
return GTK_WIDGET (chart);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_session_discover_sampler (SysprofSession *self,
|
||||
SysprofDocument *document,
|
||||
GListStore *tracks)
|
||||
{
|
||||
g_autoptr(GListModel) samples = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (self));
|
||||
g_assert (SYSPROF_IS_DOCUMENT (document));
|
||||
g_assert (G_IS_LIST_STORE (tracks));
|
||||
|
||||
samples = sysprof_document_list_samples (document);
|
||||
|
||||
if (g_list_model_get_n_items (samples) > 0)
|
||||
{
|
||||
g_autoptr(SysprofTrack) track = NULL;
|
||||
|
||||
track = g_object_new (SYSPROF_TYPE_TRACK,
|
||||
"title", _("Profiler"),
|
||||
NULL);
|
||||
g_signal_connect_object (track,
|
||||
"create-chart",
|
||||
G_CALLBACK (create_chart_for_samples),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
g_list_store_append (tracks, track);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_session_discover_counters (SysprofSession *self,
|
||||
SysprofDocument *document,
|
||||
GListStore *tracks)
|
||||
{
|
||||
g_autoptr(GListModel) counters = NULL;
|
||||
|
||||
@ -88,34 +179,25 @@ _sysprof_session_discover_tracks (SysprofSession *self,
|
||||
for (guint i = 0; i < G_N_ELEMENTS (discovery_counters); i++)
|
||||
{
|
||||
const SysprofTrackCounter *info = &discovery_counters[i];
|
||||
g_autoptr(SysprofDocumentCounter) counter = NULL;
|
||||
g_autoptr(GListModel) track_counters = filter_counters (counters, info->category, info->name);
|
||||
|
||||
if ((counter = sysprof_document_find_counter (document, info->category, info->name)))
|
||||
if (track_counters != NULL)
|
||||
{
|
||||
g_autoptr(SysprofTrack) track = NULL;
|
||||
g_autoptr(GListModel) subcounters = NULL;
|
||||
g_autoptr(GListModel) subtrack_counters = filter_counters (counters, info->subtracks_category, info->subtracks_name);
|
||||
|
||||
track = sysprof_counter_track_new (self,
|
||||
g_dgettext (GETTEXT_PACKAGE, info->track_name),
|
||||
counter);
|
||||
|
||||
if ((subcounters = filter_counters (counters, info->category, info->subtracks_name_glob)))
|
||||
{
|
||||
guint n_items = g_list_model_get_n_items (subcounters);
|
||||
|
||||
for (guint j = 0; j < n_items; j++)
|
||||
{
|
||||
g_autoptr(SysprofDocumentCounter) subcounter = g_list_model_get_item (subcounters, j);
|
||||
g_autoptr(SysprofTrack) subtrack = NULL;
|
||||
|
||||
subtrack = sysprof_counter_track_new (self,
|
||||
sysprof_document_counter_get_name (subcounter),
|
||||
subcounter);
|
||||
_sysprof_track_add_subtrack (track, subtrack);
|
||||
}
|
||||
}
|
||||
|
||||
g_list_store_append (tracks, track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_sysprof_session_discover_tracks (SysprofSession *self,
|
||||
SysprofDocument *document,
|
||||
GListStore *tracks)
|
||||
{
|
||||
g_assert (SYSPROF_IS_SESSION (self));
|
||||
g_assert (SYSPROF_IS_DOCUMENT (document));
|
||||
g_assert (G_IS_LIST_STORE (tracks));
|
||||
|
||||
sysprof_session_discover_sampler (self, document, tracks);
|
||||
sysprof_session_discover_counters (self, document, tracks);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user