mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-gtk: use .ui file for test
This will allow us to iterate a bit more easier.
This commit is contained in:
@ -71,7 +71,7 @@ sysprof_normalized_series_update_missing (gpointer user_data)
|
|||||||
|
|
||||||
g_assert (SYSPROF_IS_NORMALIZED_SERIES (self));
|
g_assert (SYSPROF_IS_NORMALIZED_SERIES (self));
|
||||||
|
|
||||||
model = g_object_ref (G_LIST_MODEL (self->series));
|
model = g_object_ref (sysprof_series_get_model (self->series));
|
||||||
bitset = egg_bitset_ref (self->missing);
|
bitset = egg_bitset_ref (self->missing);
|
||||||
|
|
||||||
if (egg_bitset_iter_init_first (&iter, bitset, &position))
|
if (egg_bitset_iter_init_first (&iter, bitset, &position))
|
||||||
|
|||||||
@ -30,7 +30,7 @@ enum {
|
|||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_FINAL_TYPE (SysprofXYLayer, sysprof_xy_layer, SYSPROF_TYPE_CHART_LAYER)
|
G_DEFINE_TYPE (SysprofXYLayer, sysprof_xy_layer, SYSPROF_TYPE_CHART_LAYER)
|
||||||
|
|
||||||
static GParamSpec *properties [N_PROPS];
|
static GParamSpec *properties [N_PROPS];
|
||||||
|
|
||||||
@ -201,6 +201,9 @@ sysprof_xy_layer_set_series (SysprofXYLayer *self,
|
|||||||
|
|
||||||
g_binding_group_set_source (self->series_bindings, series);
|
g_binding_group_set_source (self->series_bindings, series);
|
||||||
|
|
||||||
|
sysprof_normalized_series_set_series (self->normal_x, SYSPROF_SERIES (series));
|
||||||
|
sysprof_normalized_series_set_series (self->normal_y, SYSPROF_SERIES (series));
|
||||||
|
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SERIES]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SERIES]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,8 +23,15 @@ libsysprof_gtk_testsuite_deps = [
|
|||||||
libsysprof_gtk_static_dep,
|
libsysprof_gtk_static_dep,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
tests_resources = gnome.compile_resources(
|
||||||
|
'tests-resources',
|
||||||
|
'tests.gresource.xml',
|
||||||
|
c_name: 'tests',
|
||||||
|
)
|
||||||
|
|
||||||
foreach test, params: libsysprof_gtk_testsuite
|
foreach test, params: libsysprof_gtk_testsuite
|
||||||
test_exe = executable(test, '@0@.c'.format(test),
|
test_exe = executable(test,
|
||||||
|
['@0@.c'.format(test), tests_resources[0]],
|
||||||
c_args: libsysprof_gtk_testsuite_c_args,
|
c_args: libsysprof_gtk_testsuite_c_args,
|
||||||
dependencies: libsysprof_gtk_testsuite_deps,
|
dependencies: libsysprof_gtk_testsuite_deps,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -32,16 +32,38 @@ static const GOptionEntry entries[] = {
|
|||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define TEST_TYPE_CHARTS (test_charts_get_type())
|
||||||
|
G_DECLARE_FINAL_TYPE (TestCharts, test_charts, TEST, CHARTS, GtkWindow)
|
||||||
|
|
||||||
|
struct _TestCharts
|
||||||
|
{
|
||||||
|
GtkWindow parent_instance;
|
||||||
|
|
||||||
|
SysprofDocument *document;
|
||||||
|
SysprofSession *session;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_FINAL_TYPE (TestCharts, test_charts, GTK_TYPE_WINDOW)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_0,
|
||||||
|
PROP_DOCUMENT,
|
||||||
|
PROP_SESSION,
|
||||||
|
N_PROPS
|
||||||
|
};
|
||||||
|
|
||||||
|
static GParamSpec *properties [N_PROPS];
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
activate_layer_item_cb (SysprofChart *chart,
|
activate_layer_item_cb (SysprofChart *chart,
|
||||||
SysprofChartLayer *layer,
|
SysprofChartLayer *layer,
|
||||||
gpointer item,
|
gpointer item,
|
||||||
SysprofDocument *document)
|
TestCharts *test)
|
||||||
{
|
{
|
||||||
g_assert (SYSPROF_IS_CHART (chart));
|
g_assert (SYSPROF_IS_CHART (chart));
|
||||||
g_assert (SYSPROF_IS_CHART_LAYER (layer));
|
g_assert (SYSPROF_IS_CHART_LAYER (layer));
|
||||||
g_assert (G_IS_OBJECT (item));
|
g_assert (G_IS_OBJECT (item));
|
||||||
g_assert (SYSPROF_IS_DOCUMENT (document));
|
g_assert (TEST_IS_CHARTS (test));
|
||||||
|
|
||||||
g_print ("Activated %s in layer '%s' [%s]\n",
|
g_print ("Activated %s in layer '%s' [%s]\n",
|
||||||
G_OBJECT_TYPE_NAME (item),
|
G_OBJECT_TYPE_NAME (item),
|
||||||
@ -69,7 +91,7 @@ activate_layer_item_cb (SysprofChart *chart,
|
|||||||
SysprofAddressContext final_context;
|
SysprofAddressContext final_context;
|
||||||
guint n_symbols = G_N_ELEMENTS (symbols);
|
guint n_symbols = G_N_ELEMENTS (symbols);
|
||||||
|
|
||||||
n_symbols = sysprof_document_symbolize_traceable (document,
|
n_symbols = sysprof_document_symbolize_traceable (test->document,
|
||||||
item,
|
item,
|
||||||
symbols,
|
symbols,
|
||||||
n_symbols,
|
n_symbols,
|
||||||
@ -83,6 +105,111 @@ activate_layer_item_cb (SysprofChart *chart,
|
|||||||
return GDK_EVENT_STOP;
|
return GDK_EVENT_STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_set_document (TestCharts *self,
|
||||||
|
SysprofDocument *document)
|
||||||
|
{
|
||||||
|
if (g_set_object (&self->document, document))
|
||||||
|
{
|
||||||
|
g_clear_object (&self->session);
|
||||||
|
|
||||||
|
self->session = sysprof_session_new (self->document);
|
||||||
|
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DOCUMENT]);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SESSION]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_dispose (GObject *object)
|
||||||
|
{
|
||||||
|
TestCharts *self = (TestCharts *)object;
|
||||||
|
|
||||||
|
g_clear_object (&self->document);
|
||||||
|
g_clear_object (&self->session);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (test_charts_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
TestCharts *self = TEST_CHARTS (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_DOCUMENT:
|
||||||
|
g_value_set_object (value, self->document);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_SESSION:
|
||||||
|
g_value_set_object (value, self->session);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
TestCharts *self = TEST_CHARTS (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_DOCUMENT:
|
||||||
|
test_charts_set_document (self, g_value_get_object (value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_class_init (TestChartsClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
|
object_class->dispose = test_charts_dispose;
|
||||||
|
object_class->get_property = test_charts_get_property;
|
||||||
|
object_class->set_property = test_charts_set_property;
|
||||||
|
|
||||||
|
properties [PROP_DOCUMENT] =
|
||||||
|
g_param_spec_object ("document", NULL, NULL,
|
||||||
|
SYSPROF_TYPE_DOCUMENT,
|
||||||
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
properties [PROP_SESSION] =
|
||||||
|
g_param_spec_object ("session", NULL, NULL,
|
||||||
|
SYSPROF_TYPE_SESSION,
|
||||||
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
|
|
||||||
|
gtk_widget_class_set_template_from_resource (widget_class, "/test-charts.ui");
|
||||||
|
gtk_widget_class_bind_template_callback (widget_class, activate_layer_item_cb);
|
||||||
|
|
||||||
|
g_type_ensure (SYSPROF_TYPE_CHART);
|
||||||
|
g_type_ensure (SYSPROF_TYPE_CHART_LAYER);
|
||||||
|
g_type_ensure (SYSPROF_TYPE_COLUMN_LAYER);
|
||||||
|
g_type_ensure (SYSPROF_TYPE_VALUE_AXIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_charts_init (TestCharts *self)
|
||||||
|
{
|
||||||
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -90,23 +217,8 @@ main (int argc,
|
|||||||
g_autoptr(GOptionContext) context = g_option_context_new ("- test various charts");
|
g_autoptr(GOptionContext) context = g_option_context_new ("- test various charts");
|
||||||
g_autoptr(SysprofDocumentLoader) loader = NULL;
|
g_autoptr(SysprofDocumentLoader) loader = NULL;
|
||||||
g_autoptr(SysprofDocument) document = NULL;
|
g_autoptr(SysprofDocument) document = NULL;
|
||||||
g_autoptr(SysprofSession) session = NULL;
|
|
||||||
g_autoptr(SysprofXYSeries) samples_series = NULL;
|
|
||||||
g_autoptr(SysprofXYSeries) num_series = NULL;
|
|
||||||
g_autoptr(SysprofTimeSeries) marks_series = NULL;
|
|
||||||
g_autoptr(GListModel) samples = NULL;
|
|
||||||
g_autoptr(GListModel) marks = NULL;
|
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
const SysprofTimeSpan *time_span;
|
|
||||||
GtkWidget *chart;
|
|
||||||
GtkWidget *layer;
|
|
||||||
GtkWidget *split;
|
|
||||||
GtkWindow *window;
|
GtkWindow *window;
|
||||||
GtkWidget *box;
|
|
||||||
GdkRGBA blue = {0,0,1,1};
|
|
||||||
GdkRGBA red = {1,0,0,1};
|
|
||||||
guint n_samples;
|
|
||||||
guint n_marks;
|
|
||||||
|
|
||||||
sysprof_clock_init ();
|
sysprof_clock_init ();
|
||||||
|
|
||||||
@ -131,127 +243,14 @@ main (int argc,
|
|||||||
main_loop = g_main_loop_new (NULL, FALSE);
|
main_loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
loader = sysprof_document_loader_new (filename);
|
loader = sysprof_document_loader_new (filename);
|
||||||
|
|
||||||
if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
|
if (!(document = sysprof_document_loader_load (loader, NULL, &error)))
|
||||||
g_error ("Failed to load document: %s", error->message);
|
g_error ("Failed to load document: %s", error->message);
|
||||||
|
|
||||||
g_print ("loaded\n");
|
window = g_object_new (TEST_TYPE_CHARTS,
|
||||||
|
|
||||||
session = sysprof_session_new (document);
|
|
||||||
time_span = sysprof_document_get_time_span (document);
|
|
||||||
marks = sysprof_document_list_marks (document);
|
|
||||||
|
|
||||||
/* Generate an XY Series using the stacktraces depth for Y */
|
|
||||||
samples = sysprof_document_list_samples (document);
|
|
||||||
n_samples = g_list_model_get_n_items (samples);
|
|
||||||
samples_series = sysprof_xy_series_new (samples, time_span->begin_nsec, 0, time_span->end_nsec, 128);
|
|
||||||
for (guint i = 0; i < n_samples; i++)
|
|
||||||
{
|
|
||||||
g_autoptr(SysprofDocumentTraceable) sample = g_list_model_get_item (samples, i);
|
|
||||||
gint64 time = sysprof_document_frame_get_time (SYSPROF_DOCUMENT_FRAME (sample));
|
|
||||||
guint depth = sysprof_document_traceable_get_stack_depth (sample);
|
|
||||||
|
|
||||||
sysprof_xy_series_add (samples_series, time, depth, i);
|
|
||||||
}
|
|
||||||
sysprof_xy_series_sort (samples_series);
|
|
||||||
|
|
||||||
num_series = sysprof_xy_series_new (NULL, 0, 0, 100, 100);
|
|
||||||
for (guint i = 0; i < 100; i++)
|
|
||||||
sysprof_xy_series_add (num_series, i, g_random_int_range (0, 100), 0);
|
|
||||||
|
|
||||||
g_print ("series built\n");
|
|
||||||
|
|
||||||
marks_series = sysprof_time_series_new (marks, *sysprof_document_get_time_span (document));
|
|
||||||
n_marks = g_list_model_get_n_items (marks);
|
|
||||||
for (guint i = 0; i < n_marks; i++)
|
|
||||||
{
|
|
||||||
g_autoptr(SysprofDocumentMark) mark = g_list_model_get_item (marks, i);
|
|
||||||
gint64 time = sysprof_document_frame_get_time (SYSPROF_DOCUMENT_FRAME (mark));
|
|
||||||
gint64 duration = sysprof_document_mark_get_duration (mark);
|
|
||||||
|
|
||||||
sysprof_time_series_add (marks_series,
|
|
||||||
(SysprofTimeSpan) {time, time+duration},
|
|
||||||
i);
|
|
||||||
}
|
|
||||||
sysprof_time_series_sort (marks_series);
|
|
||||||
|
|
||||||
window = g_object_new (GTK_TYPE_WINDOW,
|
|
||||||
"default-width", 800,
|
"default-width", 800,
|
||||||
"default-height", 600,
|
"default-height", 600,
|
||||||
|
"document", document,
|
||||||
NULL);
|
NULL);
|
||||||
g_signal_connect_swapped (window,
|
|
||||||
"close-request",
|
|
||||||
G_CALLBACK (g_main_loop_quit),
|
|
||||||
main_loop);
|
|
||||||
|
|
||||||
box = g_object_new (GTK_TYPE_BOX,
|
|
||||||
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
||||||
NULL);
|
|
||||||
gtk_window_set_child (window, GTK_WIDGET (box));
|
|
||||||
|
|
||||||
chart = g_object_new (SYSPROF_TYPE_CHART,
|
|
||||||
"session", session,
|
|
||||||
"title", "Samples",
|
|
||||||
"height-request", 128,
|
|
||||||
NULL);
|
|
||||||
g_signal_connect (chart,
|
|
||||||
"activate-layer-item",
|
|
||||||
G_CALLBACK (activate_layer_item_cb),
|
|
||||||
document);
|
|
||||||
layer = g_object_new (SYSPROF_TYPE_COLUMN_LAYER,
|
|
||||||
"series", samples_series,
|
|
||||||
"title", "Stack Depth",
|
|
||||||
NULL);
|
|
||||||
sysprof_chart_add_layer (SYSPROF_CHART (chart),
|
|
||||||
SYSPROF_CHART_LAYER (layer));
|
|
||||||
gtk_box_append (GTK_BOX (box), chart);
|
|
||||||
|
|
||||||
chart = g_object_new (SYSPROF_TYPE_CHART,
|
|
||||||
"session", session,
|
|
||||||
"height-request", 128,
|
|
||||||
NULL);
|
|
||||||
split = g_object_new (SYSPROF_TYPE_SPLIT_LAYER,
|
|
||||||
"top", g_object_new (SYSPROF_TYPE_LINE_LAYER,
|
|
||||||
"series", num_series,
|
|
||||||
"title", "Stack Depth as Line",
|
|
||||||
"fill", TRUE,
|
|
||||||
NULL),
|
|
||||||
"bottom", g_object_new (SYSPROF_TYPE_LINE_LAYER,
|
|
||||||
"series", num_series,
|
|
||||||
"title", "Stack Depth as Line",
|
|
||||||
"flip-y", TRUE,
|
|
||||||
NULL),
|
|
||||||
NULL);
|
|
||||||
sysprof_chart_add_layer (SYSPROF_CHART (chart),
|
|
||||||
SYSPROF_CHART_LAYER (split));
|
|
||||||
gtk_box_append (GTK_BOX (box), chart);
|
|
||||||
|
|
||||||
chart = g_object_new (SYSPROF_TYPE_CHART,
|
|
||||||
"session", session,
|
|
||||||
"height-request", 128,
|
|
||||||
NULL);
|
|
||||||
layer = g_object_new (SYSPROF_TYPE_LINE_LAYER,
|
|
||||||
"series", num_series,
|
|
||||||
"use-curves", TRUE,
|
|
||||||
"fill", TRUE,
|
|
||||||
"dashed", TRUE,
|
|
||||||
NULL),
|
|
||||||
sysprof_chart_add_layer (SYSPROF_CHART (chart),
|
|
||||||
SYSPROF_CHART_LAYER (layer));
|
|
||||||
gtk_box_append (GTK_BOX (box), chart);
|
|
||||||
|
|
||||||
chart = g_object_new (SYSPROF_TYPE_CHART,
|
|
||||||
"session", session,
|
|
||||||
"height-request", 24,
|
|
||||||
NULL);
|
|
||||||
layer = g_object_new (SYSPROF_TYPE_TIME_SPAN_LAYER,
|
|
||||||
"color", &blue,
|
|
||||||
"event-color", &red,
|
|
||||||
"series", marks_series,
|
|
||||||
NULL),
|
|
||||||
sysprof_chart_add_layer (SYSPROF_CHART (chart),
|
|
||||||
SYSPROF_CHART_LAYER (layer));
|
|
||||||
gtk_box_append (GTK_BOX (box), chart);
|
|
||||||
|
|
||||||
gtk_window_present (window);
|
gtk_window_present (window);
|
||||||
g_main_loop_run (main_loop);
|
g_main_loop_run (main_loop);
|
||||||
|
|||||||
58
src/libsysprof-gtk/tests/test-charts.ui
Normal file
58
src/libsysprof-gtk/tests/test-charts.ui
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<template class="TestCharts" parent="GtkWindow">
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="hscrollbar-policy">never</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkListBox">
|
||||||
|
<child>
|
||||||
|
<object class="SysprofChart">
|
||||||
|
<property name="height-request">128</property>
|
||||||
|
<child>
|
||||||
|
<object class="SysprofColumnLayer">
|
||||||
|
<binding name="x-axis">
|
||||||
|
<lookup name="selected-time-axis" type="SysprofSession">
|
||||||
|
<lookup name="session">TestCharts</lookup>
|
||||||
|
</lookup>
|
||||||
|
</binding>
|
||||||
|
<property name="y-axis">
|
||||||
|
<object class="SysprofValueAxis">
|
||||||
|
<property name="min-value">0</property>
|
||||||
|
<property name="max-value">128</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
<property name="series">
|
||||||
|
<object class="SysprofXYSeries">
|
||||||
|
<property name="model">
|
||||||
|
<object class="GtkFilterListModel">
|
||||||
|
<binding name="filter">
|
||||||
|
<lookup name="filter" type="SysprofSession">
|
||||||
|
<lookup name="session">TestCharts</lookup>
|
||||||
|
</lookup>
|
||||||
|
</binding>
|
||||||
|
<binding name="model">
|
||||||
|
<lookup name="samples" type="SysprofDocument">
|
||||||
|
<lookup name="document">TestCharts</lookup>
|
||||||
|
</lookup>
|
||||||
|
</binding>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
<property name="x-expression">
|
||||||
|
<lookup name="time" type="SysprofDocumentFrame"/>
|
||||||
|
</property>
|
||||||
|
<property name="y-expression">
|
||||||
|
<lookup name="stack-depth" type="SysprofDocumentTraceable"/>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
||||||
6
src/libsysprof-gtk/tests/tests.gresource.xml
Normal file
6
src/libsysprof-gtk/tests/tests.gresource.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<gresources>
|
||||||
|
<gresource prefix="/">
|
||||||
|
<file preprocess="xml-stripblanks">test-charts.ui</file>
|
||||||
|
</gresource>
|
||||||
|
</gresources>
|
||||||
Reference in New Issue
Block a user