mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 15:10:53 +00:00
libsysprof-gtk: allow finding matching sub-tracks by counter
This commit is contained in:
@ -25,24 +25,84 @@
|
|||||||
#include "sysprof-session-private.h"
|
#include "sysprof-session-private.h"
|
||||||
#include "sysprof-track.h"
|
#include "sysprof-track.h"
|
||||||
|
|
||||||
|
typedef struct _SysprofTrackCounter
|
||||||
|
{
|
||||||
|
const char *category;
|
||||||
|
const char *name;
|
||||||
|
const char *subtracks_name_glob;
|
||||||
|
const char *track_name;
|
||||||
|
} SysprofTrackCounter;
|
||||||
|
|
||||||
|
static const SysprofTrackCounter discovery_counters[] = {
|
||||||
|
{ "CPU Percent", "Combined", "Total CPU *", N_("CPU Usage") },
|
||||||
|
};
|
||||||
|
|
||||||
|
static GListModel *
|
||||||
|
filter_counters (GListModel *model,
|
||||||
|
const char *category,
|
||||||
|
const char *name_glob)
|
||||||
|
{
|
||||||
|
g_autoptr(GListStore) store = NULL;
|
||||||
|
g_autoptr(GPatternSpec) spec = NULL;
|
||||||
|
guint n_items;
|
||||||
|
|
||||||
|
g_assert (G_IS_LIST_MODEL (model));
|
||||||
|
g_assert (category != NULL);
|
||||||
|
g_assert (name_glob != NULL);
|
||||||
|
|
||||||
|
store = g_list_store_new (SYSPROF_TYPE_DOCUMENT_COUNTER);
|
||||||
|
spec = g_pattern_spec_new (name_glob);
|
||||||
|
n_items = g_list_model_get_n_items (model);
|
||||||
|
|
||||||
|
for (guint i = 0; i < n_items; i++)
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofDocumentCounter) counter = g_list_model_get_item (model, i);
|
||||||
|
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))
|
||||||
|
g_list_store_append (store, counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_list_model_get_n_items (G_LIST_MODEL (store)) == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return G_LIST_MODEL (g_steal_pointer (&store));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_sysprof_session_discover_tracks (SysprofSession *self,
|
_sysprof_session_discover_tracks (SysprofSession *self,
|
||||||
SysprofDocument *document,
|
SysprofDocument *document,
|
||||||
GListStore *tracks)
|
GListStore *tracks)
|
||||||
{
|
{
|
||||||
g_autoptr(SysprofDocumentCounter) cpu = NULL;
|
g_autoptr(GListModel) counters = NULL;
|
||||||
|
|
||||||
g_assert (SYSPROF_IS_SESSION (self));
|
g_assert (SYSPROF_IS_SESSION (self));
|
||||||
g_assert (SYSPROF_IS_DOCUMENT (document));
|
g_assert (SYSPROF_IS_DOCUMENT (document));
|
||||||
g_assert (G_IS_LIST_STORE (tracks));
|
g_assert (G_IS_LIST_STORE (tracks));
|
||||||
|
|
||||||
if ((cpu = sysprof_document_find_counter (document, "CPU Percent", "Combined")))
|
counters = sysprof_document_list_counters (document);
|
||||||
{
|
|
||||||
g_autoptr(SysprofTrack) cpu_track = NULL;
|
|
||||||
|
|
||||||
cpu_track = g_object_new (SYSPROF_TYPE_TRACK,
|
for (guint i = 0; i < G_N_ELEMENTS (discovery_counters); i++)
|
||||||
"title", _("CPU Usage"),
|
{
|
||||||
|
const SysprofTrackCounter *info = &discovery_counters[i];
|
||||||
|
g_autoptr(SysprofDocumentCounter) counter = NULL;
|
||||||
|
|
||||||
|
if ((counter = sysprof_document_find_counter (document, info->category, info->name)))
|
||||||
|
{
|
||||||
|
g_autoptr(SysprofTrack) track = NULL;
|
||||||
|
g_autoptr(GListModel) subcounters = NULL;
|
||||||
|
|
||||||
|
track = g_object_new (SYSPROF_TYPE_TRACK,
|
||||||
|
"title", g_dgettext (GETTEXT_PACKAGE, info->track_name),
|
||||||
NULL);
|
NULL);
|
||||||
g_list_store_append (tracks, cpu_track);
|
|
||||||
|
if ((subcounters = filter_counters (counters, info->category, info->subtracks_name_glob)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
g_list_store_append (tracks, track);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user