mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-gtk: add track for samples with context switches
This commit is contained in:
@ -73,6 +73,7 @@ struct _SysprofDocument
|
||||
EggBitset *allocations;
|
||||
EggBitset *file_chunks;
|
||||
EggBitset *samples;
|
||||
EggBitset *samples_with_context_switch;
|
||||
EggBitset *traceables;
|
||||
EggBitset *processes;
|
||||
EggBitset *mmaps;
|
||||
@ -250,6 +251,7 @@ sysprof_document_finalize (GObject *object)
|
||||
g_clear_pointer (&self->pids, egg_bitset_unref);
|
||||
g_clear_pointer (&self->processes, egg_bitset_unref);
|
||||
g_clear_pointer (&self->samples, egg_bitset_unref);
|
||||
g_clear_pointer (&self->samples_with_context_switch, egg_bitset_unref);
|
||||
g_clear_pointer (&self->traceables, egg_bitset_unref);
|
||||
|
||||
g_clear_pointer (&self->mark_groups, g_hash_table_unref);
|
||||
@ -358,6 +360,7 @@ sysprof_document_init (SysprofDocument *self)
|
||||
self->pids = egg_bitset_new_empty ();
|
||||
self->processes = egg_bitset_new_empty ();
|
||||
self->samples = egg_bitset_new_empty ();
|
||||
self->samples_with_context_switch = egg_bitset_new_empty ();
|
||||
self->traceables = egg_bitset_new_empty ();
|
||||
|
||||
self->files_first_position = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
@ -911,6 +914,30 @@ sysprof_document_load_worker (GTask *task,
|
||||
g_strdup (file_chunk->path),
|
||||
GUINT_TO_POINTER (self->frames->len));
|
||||
}
|
||||
else if (tainted->type == SYSPROF_CAPTURE_FRAME_SAMPLE)
|
||||
{
|
||||
const SysprofCaptureSample *sample = (const SysprofCaptureSample *)tainted;
|
||||
guint n_addrs = self->needs_swap ? GUINT16_SWAP_LE_BE (sample->n_addrs) : sample->n_addrs;
|
||||
const guint8 *endptr = (const guint8 *)tainted + frame_len;
|
||||
|
||||
/* If the sample contains a context-switch, record it */
|
||||
if ((const guint8 *)sample + (n_addrs * sizeof (SysprofAddress)) <= endptr)
|
||||
{
|
||||
SysprofAddressContext last_context = SYSPROF_ADDRESS_CONTEXT_USER;
|
||||
|
||||
for (guint i = 0; i < n_addrs; i++)
|
||||
{
|
||||
SysprofAddress addr = self->needs_swap ? GUINT64_SWAP_LE_BE (sample->addrs[i]) : sample->addrs[i];
|
||||
|
||||
if (sysprof_address_is_context_switch (addr, &last_context) &&
|
||||
last_context == SYSPROF_ADDRESS_CONTEXT_KERNEL)
|
||||
{
|
||||
egg_bitset_add (self->samples_with_context_switch, self->frames->len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tainted->type == SYSPROF_CAPTURE_FRAME_MARK)
|
||||
{
|
||||
const SysprofCaptureMark *mark = (const SysprofCaptureMark *)tainted;
|
||||
@ -1392,6 +1419,23 @@ sysprof_document_list_samples (SysprofDocument *self)
|
||||
return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), self->samples);
|
||||
}
|
||||
|
||||
/**
|
||||
* sysprof_document_list_samples_with_context_switch:
|
||||
* @self: a #SysprofDocument
|
||||
*
|
||||
* Gets a #GListModel containing #SysprofDocumentSample found within
|
||||
* the #SysprofDocument which contain a context switch.
|
||||
*
|
||||
* Returns: (transfer full): a #GListModel of #SysprofDocumentSample
|
||||
*/
|
||||
GListModel *
|
||||
sysprof_document_list_samples_with_context_switch (SysprofDocument *self)
|
||||
{
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT (self), NULL);
|
||||
|
||||
return _sysprof_document_bitset_index_new (G_LIST_MODEL (self), self->samples_with_context_switch);
|
||||
}
|
||||
|
||||
/**
|
||||
* sysprof_document_list_processes:
|
||||
* @self: a #SysprofDocument
|
||||
|
||||
@ -55,6 +55,9 @@ GListModel *sysprof_document_list_allocations (SysprofDocume
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_samples (SysprofDocument *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_samples_with_context_switch
|
||||
(SysprofDocument *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_processes (SysprofDocument *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GListModel *sysprof_document_list_jitmaps (SysprofDocument *self);
|
||||
|
||||
@ -37,6 +37,12 @@ typedef enum _LineFlags
|
||||
LINE_FLAGS_NO_SPLINE = 1 << 1,
|
||||
} LineFlags;
|
||||
|
||||
typedef struct _SysprofTrackSamples
|
||||
{
|
||||
SysprofSession *session;
|
||||
GListModel *samples;
|
||||
} SysprofTrackSamples;
|
||||
|
||||
typedef struct _SysprofTrackCounter
|
||||
{
|
||||
const char *track_name;
|
||||
@ -99,6 +105,26 @@ static const SysprofTrackCounter discovery_counters[] = {
|
||||
|
||||
};
|
||||
|
||||
static void
|
||||
sysprof_track_samples_free (SysprofTrackSamples *samples)
|
||||
{
|
||||
g_clear_object (&samples->samples);
|
||||
g_clear_weak_pointer (&samples->session);
|
||||
g_free (samples);
|
||||
}
|
||||
|
||||
static SysprofTrackSamples *
|
||||
sysprof_track_samples_new (SysprofSession *session,
|
||||
GListModel *samples)
|
||||
{
|
||||
SysprofTrackSamples *state;
|
||||
|
||||
state = g_new0 (SysprofTrackSamples, 1);
|
||||
state->samples = g_object_ref (samples);
|
||||
g_set_weak_pointer (&state->session, session);
|
||||
return state;
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_track_counter_chart_free (SysprofTrackCounterChart *info)
|
||||
{
|
||||
@ -158,24 +184,23 @@ filter_counters (GListModel *model,
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_chart_for_samples (SysprofSession *session,
|
||||
SysprofTrack *track)
|
||||
create_chart_for_samples (SysprofTrack *track,
|
||||
SysprofTrackSamples *state)
|
||||
{
|
||||
g_autoptr(SysprofSeries) xy_series = NULL;
|
||||
g_autoptr(SysprofAxis) y_axis = NULL;
|
||||
SysprofChartLayer *layer;
|
||||
SysprofDocument *document;
|
||||
SysprofChart *chart;
|
||||
SysprofAxis *x_axis = NULL;
|
||||
|
||||
g_assert (SYSPROF_IS_SESSION (session));
|
||||
g_assert (state != NULL);
|
||||
g_assert (SYSPROF_IS_SESSION (state->session));
|
||||
g_assert (SYSPROF_IS_TRACK (track));
|
||||
|
||||
document = sysprof_session_get_document (session);
|
||||
x_axis = sysprof_session_get_visible_time_axis (session);
|
||||
x_axis = sysprof_session_get_visible_time_axis (state->session);
|
||||
y_axis = sysprof_value_axis_new (0, 128);
|
||||
xy_series = sysprof_xy_series_new (sysprof_track_get_title (track),
|
||||
sysprof_document_list_samples (document),
|
||||
g_object_ref (state->samples),
|
||||
gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_SAMPLE, NULL, "time"),
|
||||
gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_SAMPLE, NULL, "stack-depth"));
|
||||
|
||||
@ -196,12 +221,14 @@ sysprof_session_discover_sampler (SysprofSession *self,
|
||||
GListStore *tracks)
|
||||
{
|
||||
g_autoptr(GListModel) samples = NULL;
|
||||
g_autoptr(GListModel) samples_with_context_switch = 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);
|
||||
samples_with_context_switch = sysprof_document_list_samples_with_context_switch (document);
|
||||
|
||||
if (g_list_model_get_n_items (samples) > 0)
|
||||
{
|
||||
@ -210,12 +237,29 @@ sysprof_session_discover_sampler (SysprofSession *self,
|
||||
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_signal_connect_data (track,
|
||||
"create-chart",
|
||||
G_CALLBACK (create_chart_for_samples),
|
||||
sysprof_track_samples_new (self, samples),
|
||||
(GClosureNotify)sysprof_track_samples_free,
|
||||
0);
|
||||
g_list_store_append (tracks, track);
|
||||
|
||||
if (g_list_model_get_n_items (samples_with_context_switch))
|
||||
{
|
||||
g_autoptr(SysprofTrack) subtrack = NULL;
|
||||
|
||||
subtrack = g_object_new (SYSPROF_TYPE_TRACK,
|
||||
"title", _("Context Switches"),
|
||||
NULL);
|
||||
g_signal_connect_data (subtrack,
|
||||
"create-chart",
|
||||
G_CALLBACK (create_chart_for_samples),
|
||||
sysprof_track_samples_new (self, samples_with_context_switch),
|
||||
(GClosureNotify)sysprof_track_samples_free,
|
||||
0);
|
||||
_sysprof_track_add_subtrack (track, subtrack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user