Merge branch 'wip/chergert/flamegraph'

This commit is contained in:
Christian Hergert
2023-08-24 17:19:48 -07:00
13 changed files with 842 additions and 51 deletions

View File

@ -71,6 +71,8 @@ struct _SysprofCallgraph
GDestroyNotify augment_func_data_destroy;
SysprofCallgraphNode root;
guint height;
};
void _sysprof_callgraph_new_async (SysprofDocument *document,

View File

@ -247,6 +247,7 @@ sysprof_callgraph_add_trace (SysprofCallgraph *self,
if (_sysprof_symbol_equal (iter->summary->symbol, symbol))
{
node = iter;
node->count++;
goto next_symbol;
}
}
@ -256,6 +257,7 @@ sysprof_callgraph_add_trace (SysprofCallgraph *self,
node->summary = sysprof_callgraph_get_summary (self, symbol);
node->parent = parent;
node->next = parent->children;
node->count = 1;
if (parent->children)
parent->children->prev = node;
parent->children = node;
@ -421,6 +423,9 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self,
symbols[n_symbols++] = _sysprof_document_process_symbol (self->document, pid);
symbols[n_symbols++] = everything;
if (n_symbols > self->height)
self->height = n_symbols;
node = sysprof_callgraph_add_trace (self,
symbols,
n_symbols,
@ -428,7 +433,6 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self,
!!(self->flags & SYSPROF_CALLGRAPH_FLAGS_HIDE_SYSTEM_LIBRARIES));
node->is_toplevel = TRUE;
node->count++;
if (node && self->augment_func)
self->augment_func (self,
@ -441,6 +445,50 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self,
_sysprof_callgraph_categorize (self, node);
}
static int
sort_by_symbol_name (gconstpointer a,
gconstpointer b)
{
const SysprofCallgraphNode *node_a = *(const SysprofCallgraphNode * const *)a;
const SysprofCallgraphNode *node_b = *(const SysprofCallgraphNode * const *)b;
return g_utf8_collate (node_a->summary->symbol->name, node_b->summary->symbol->name);
}
static void
sort_children (SysprofCallgraphNode *node)
{
SysprofCallgraphNode **children;
guint n_children = 0;
guint i = 0;
if (node->children == NULL)
return;
for (SysprofCallgraphNode *child = node->children; child; child = child->next)
{
sort_children (child);
n_children++;
}
children = g_alloca (sizeof (SysprofCallgraphNode *) * (n_children + 1));
for (SysprofCallgraphNode *child = node->children; child; child = child->next)
children[i++] = child;
children[i] = NULL;
qsort (children, n_children, sizeof (SysprofCallgraphNode *), sort_by_symbol_name);
node->children = children[0];
node->children->prev = NULL;
node->children->next = children[1];
for (i = 1; i < n_children; i++)
{
children[i]->next = children[i+1];
children[i]->prev = children[i-1];
}
}
static void
sysprof_callgraph_new_worker (GTask *task,
gpointer source_object,
@ -471,6 +519,11 @@ sysprof_callgraph_new_worker (GTask *task,
sysprof_callgraph_add_traceable (self, traceable, i);
}
/* Sort callgraph nodes alphabetically so that we can use them in the
* flamegraph without any further processing.
*/
sort_children (&self->root);
g_task_return_pointer (task, g_object_ref (self), g_object_unref);
}

View File

@ -129,6 +129,7 @@ sysprof_descendants_model_add_trace (SysprofDescendantsModel *self,
if (_sysprof_symbol_equal (iter->summary->symbol, symbol))
{
node = iter;
node->count++;
goto next_symbol;
}
}
@ -144,6 +145,7 @@ sysprof_descendants_model_add_trace (SysprofDescendantsModel *self,
node->summary = summary;
node->parent = parent;
node->next = parent->children;
node->count = 1;
if (parent->children)
parent->children->prev = node;
parent->children = node;
@ -211,7 +213,6 @@ sysprof_descendants_model_add_traceable (SysprofDescendantsModel *self,
node = sysprof_descendants_model_add_trace (self, symbols, n_symbols);
node->is_toplevel = TRUE;
node->count++;
if (node && self->callgraph->augment_func)
self->callgraph->augment_func (self->callgraph,

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
height="16px"
viewBox="0 0 16 16"
width="16px"
version="1.1"
id="svg5033"
sodipodi:docname="threads-symbolic.svg"
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs5037" />
<sodipodi:namedview
id="namedview5035"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="4.3979077"
inkscape:cx="-115.1684"
inkscape:cy="34.902961"
inkscape:window-width="1920"
inkscape:window-height="1011"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg5033" />
<path
d="M 2.188,2 C 0.982,2 0,3.018 0,4.219 v 7.562 C 0,12.982 0.982,14 2.188,14 H 13.812 C 15.018,14 16,12.981999 16,11.781 V 4.22 C 16,3.018 15.018,2 13.812,2 Z m 0,2 H 13.812 C 13.932,4 14,4.08 14,4.219 v 7.562 C 14,11.919999 13.933,12 13.812,12 H 2.188 C 2.068,12 2,11.919999 2,11.781 V 4.22 C 2,4.08 2.067,4 2.188,4 Z"
style="font-weight:400;line-height:normal;-inkscape-font-specification:'Bitstream Vera Sans';text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;fill:#2e3436;marker:none"
color="#bebebe"
font-family="'Bitstream Vera Sans'"
overflow="visible"
id="path113" />
<path
d="m 3,9 h 1 v 2 H 3 Z m 0,0"
id="path5029"
style="stroke-width:0.392232" />
<path
d="m 5,5 h 1 v 6 H 5 Z m 0,0"
id="path5029-3"
style="stroke-width:0.679374" />
<path
d="m 7,8 h 1 v 3 H 7 Z m 0,0"
id="path5029-3-7"
style="stroke-width:0.48039" />
<path
d="m 9,6 h 1 v 5 H 9 Z m 0,0"
id="path5029-3-7-5"
style="stroke-width:0.620181" />
<path
d="m 3,10 h 10 v 1 H 3 Z m 0,0"
id="path5029-3-3"
style="stroke-width:0.877071" />
<path
d="m 12,8 h 1 v 3 h -1 z m 0,0"
id="path5029-3-3-6"
style="stroke-width:0.480391" />
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -20,6 +20,7 @@ sysprof_sources = [
'sysprof-energy-section.c',
'sysprof-entry-popover.c',
'sysprof-files-section.c',
'sysprof-flame-graph.c',
'sysprof-frame-utility.c',
'sysprof-graphics-section.c',
'sysprof-greeter.c',

View File

@ -91,3 +91,7 @@ timescrubber timecode {
font-feature-settings: 'tnum';
font-size: .8em;
}
flamegraph {
font-size: 10px;
}

View File

@ -168,3 +168,12 @@ sysprof_category_icon_set_category (SysprofCategoryIcon *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CATEGORY]);
gtk_widget_queue_draw (GTK_WIDGET (self));
}
const GdkRGBA *
sysprof_callgraph_category_get_color (SysprofCallgraphCategory category)
{
if (category < G_N_ELEMENTS (category_colors) && category_colors[category].alpha > 0)
return &category_colors[category];
return NULL;
}

View File

@ -34,4 +34,6 @@ SysprofCallgraphCategory sysprof_category_icon_get_category (SysprofCategoryIcon
void sysprof_category_icon_set_category (SysprofCategoryIcon *self,
SysprofCallgraphCategory category);
const GdkRGBA *sysprof_callgraph_category_get_color (SysprofCallgraphCategory category);
G_END_DECLS

View File

@ -0,0 +1,577 @@
/* sysprof-flame-graph.c
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include "sysprof-callgraph-private.h"
#include "sysprof-category-icon.h"
#include "sysprof-color-iter-private.h"
#include "sysprof-symbol-private.h"
#include "sysprof-flame-graph.h"
#define ROW_HEIGHT 14
typedef struct
{
SysprofCallgraphNode *node;
guint16 x;
guint16 y;
guint16 w;
guint16 h;
} FlameRectangle;
struct _SysprofFlameGraph
{
GtkWidget parent_instance;
SysprofCallgraph *callgraph;
GskRenderNode *rendered;
GArray *nodes;
double motion_x;
double motion_y;
};
enum {
PROP_0,
PROP_CALLGRAPH,
N_PROPS
};
G_DEFINE_FINAL_TYPE (SysprofFlameGraph, sysprof_flame_graph, GTK_TYPE_WIDGET)
static GParamSpec *properties [N_PROPS];
typedef struct
{
graphene_point_t point;
int width;
} FlameSearch;
static int
search_compare (gconstpointer key,
gconstpointer item)
{
const FlameSearch *search = key;
const FlameRectangle *rect = item;
graphene_rect_t area;
area = GRAPHENE_RECT_INIT (rect->x / (double)G_MAXUINT16 * search->width,
rect->y,
rect->w / (double)G_MAXUINT16 * search->width,
rect->h);
if (search->point.y < area.origin.y)
return -1;
if (search->point.y > area.origin.y + area.size.height)
return 1;
if (search->point.x < area.origin.x)
return -1;
if (search->point.x > area.origin.x + area.size.width)
return 1;
return 0;
}
static FlameRectangle *
find_node_at_coord (SysprofFlameGraph *self,
double x,
double y)
{
FlameSearch search;
if (self->nodes == NULL)
return NULL;
search.point.x = x;
search.point.y = y;
search.width = gtk_widget_get_width (GTK_WIDGET (self));
return bsearch (&search, self->nodes->data, self->nodes->len, sizeof (FlameRectangle), search_compare);
}
static void
sysprof_flame_graph_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
SysprofFlameGraph *self = (SysprofFlameGraph *)widget;
FlameRectangle *highlight = NULL;
graphene_point_t point;
int width;
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_assert (GTK_IS_SNAPSHOT (snapshot));
if (self->nodes == NULL || self->nodes->len == 0)
return;
point = GRAPHENE_POINT_INIT (self->motion_x, self->motion_y);
width = gtk_widget_get_width (widget);
if (self->rendered == NULL)
{
GtkSnapshot *child_snapshot = gtk_snapshot_new ();
const GdkRGBA *default_color;
PangoLayout *layout;
SysprofColorIter iter;
sysprof_color_iter_init (&iter);
default_color = sysprof_color_iter_next (&iter);
layout = gtk_widget_create_pango_layout (widget, NULL);
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
for (guint i = 0; i < self->nodes->len; i++)
{
FlameRectangle *rect = &g_array_index (self->nodes, FlameRectangle, i);
SysprofCallgraphCategory category = SYSPROF_CALLGRAPH_CATEGORY_UNMASK (rect->node->category);
const GdkRGBA *color = sysprof_callgraph_category_get_color (category);
graphene_rect_t area;
if (color == NULL)
color = default_color;
area = GRAPHENE_RECT_INIT (rect->x / (double)G_MAXUINT16 * width,
rect->y,
rect->w / (double)G_MAXUINT16 * width,
rect->h);
if (!highlight && graphene_rect_contains_point (&area, &point))
highlight = rect;
gtk_snapshot_append_color (child_snapshot, color, &area);
if (area.size.width > ROW_HEIGHT)
{
pango_layout_set_text (layout, rect->node->summary->symbol->name, -1);
pango_layout_set_width (layout, PANGO_SCALE * area.size.width - 4);
gtk_snapshot_save (child_snapshot);
gtk_snapshot_translate (child_snapshot,
&GRAPHENE_POINT_INIT (round (area.origin.x) + 2,
area.origin.y + area.size.height - ROW_HEIGHT));
gtk_snapshot_append_layout (child_snapshot, layout, &(GdkRGBA) {1,1,1,1});
gtk_snapshot_restore (child_snapshot);
}
}
self->rendered = gtk_snapshot_free_to_node (child_snapshot);
g_object_unref (layout);
}
if (self->motion_x || self->motion_y)
{
if (highlight == NULL)
highlight = find_node_at_coord (self, self->motion_x, self->motion_y);
}
gtk_snapshot_append_node (snapshot, self->rendered);
if (highlight)
{
graphene_rect_t area;
area = GRAPHENE_RECT_INIT (highlight->x / (double)G_MAXUINT16 * width,
highlight->y,
highlight->w / (double)G_MAXUINT16 * width,
highlight->h);
gtk_snapshot_append_color (snapshot, &(GdkRGBA) {1,1,1,.25}, &area);
}
}
static void
sysprof_flame_graph_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
SysprofFlameGraph *self = (SysprofFlameGraph *)widget;
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
*minimum_baseline = -1;
*natural_baseline = -1;
if (orientation == GTK_ORIENTATION_VERTICAL)
{
if (self->callgraph != NULL)
*minimum = ROW_HEIGHT * self->callgraph->height + self->callgraph->height + 1;
*natural = *minimum;
}
else
{
*minimum = 1;
*natural = 500;
}
}
static void
sysprof_flame_graph_motion_enter_cb (SysprofFlameGraph *self,
double x,
double y,
GtkEventControllerMotion *motion)
{
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_assert (GTK_IS_EVENT_CONTROLLER_MOTION (motion));
self->motion_x = x;
self->motion_y = y;
gtk_widget_queue_draw (GTK_WIDGET (self));
}
static void
sysprof_flame_graph_motion_motion_cb (SysprofFlameGraph *self,
double x,
double y,
GtkEventControllerMotion *motion)
{
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_assert (GTK_IS_EVENT_CONTROLLER_MOTION (motion));
self->motion_x = x;
self->motion_y = y;
gtk_widget_queue_draw (GTK_WIDGET (self));
}
static void
sysprof_flame_graph_motion_leave_cb (SysprofFlameGraph *self,
GtkEventControllerMotion *motion)
{
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_assert (GTK_IS_EVENT_CONTROLLER_MOTION (motion));
self->motion_x = 0;
self->motion_y = 0;
gtk_widget_queue_draw (GTK_WIDGET (self));
}
static void
sysprof_flame_graph_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
SysprofFlameGraph *self = (SysprofFlameGraph *)widget;
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_clear_pointer (&self->rendered, gsk_render_node_unref);
}
static gboolean
sysprof_flame_graph_query_tooltip (GtkWidget *widget,
int x,
int y,
gboolean keyboard_tooltip,
GtkTooltip *tooltip)
{
SysprofFlameGraph *self = SYSPROF_FLAME_GRAPH (widget);
FlameRectangle *rect;
if ((rect = find_node_at_coord (self, x, y)))
{
g_autoptr(GString) string = g_string_new (NULL);
SysprofSymbol *symbol = rect->node->summary->symbol;
g_string_append (string, symbol->name);
if (symbol->binary_nick && symbol->binary_nick[0])
g_string_append_printf (string, " [%s]", symbol->binary_nick);
if (symbol->binary_path && symbol->binary_path[0])
g_string_append_printf (string, "\n%s", symbol->binary_path);
gtk_tooltip_set_text (tooltip, string->str);
return TRUE;
}
return FALSE;
}
static void
sysprof_flame_graph_dispose (GObject *object)
{
SysprofFlameGraph *self = (SysprofFlameGraph *)object;
g_clear_pointer (&self->rendered, gsk_render_node_unref);
g_clear_pointer (&self->nodes, g_array_unref);
g_clear_object (&self->callgraph);
G_OBJECT_CLASS (sysprof_flame_graph_parent_class)->dispose (object);
}
static void
sysprof_flame_graph_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofFlameGraph *self = SYSPROF_FLAME_GRAPH (object);
switch (prop_id)
{
case PROP_CALLGRAPH:
g_value_set_object (value, sysprof_flame_graph_get_callgraph (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_flame_graph_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
SysprofFlameGraph *self = SYSPROF_FLAME_GRAPH (object);
switch (prop_id)
{
case PROP_CALLGRAPH:
sysprof_flame_graph_set_callgraph (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_flame_graph_class_init (SysprofFlameGraphClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = sysprof_flame_graph_dispose;
object_class->get_property = sysprof_flame_graph_get_property;
object_class->set_property = sysprof_flame_graph_set_property;
widget_class->snapshot = sysprof_flame_graph_snapshot;
widget_class->measure = sysprof_flame_graph_measure;
widget_class->size_allocate = sysprof_flame_graph_size_allocate;
widget_class->query_tooltip = sysprof_flame_graph_query_tooltip;
properties[PROP_CALLGRAPH] =
g_param_spec_object ("callgraph", NULL, NULL,
SYSPROF_TYPE_CALLGRAPH,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_css_name (widget_class, "flamegraph");
}
static void
sysprof_flame_graph_init (SysprofFlameGraph *self)
{
GtkEventController *motion;
gtk_widget_add_css_class (GTK_WIDGET (self), "view");
gtk_widget_set_has_tooltip (GTK_WIDGET (self), TRUE);
motion = gtk_event_controller_motion_new ();
g_signal_connect_object (motion,
"enter",
G_CALLBACK (sysprof_flame_graph_motion_enter_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (motion,
"leave",
G_CALLBACK (sysprof_flame_graph_motion_leave_cb),
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (motion,
"motion",
G_CALLBACK (sysprof_flame_graph_motion_motion_cb),
self,
G_CONNECT_SWAPPED);
gtk_widget_add_controller (GTK_WIDGET (self), motion);
}
GtkWidget *
sysprof_flame_graph_new (void)
{
return g_object_new (SYSPROF_TYPE_FLAME_GRAPH, NULL);
}
SysprofCallgraph *
sysprof_flame_graph_get_callgraph (SysprofFlameGraph *self)
{
g_return_val_if_fail (SYSPROF_IS_FLAME_GRAPH (self), NULL);
return self->callgraph;
}
static void
sysprof_flame_graph_generate_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
g_autoptr(SysprofFlameGraph) self = user_data;
g_autoptr(GArray) nodes = NULL;
GTask *task = (GTask *)result;
g_assert (SYSPROF_IS_FLAME_GRAPH (self));
g_assert (G_IS_TASK (task));
if ((nodes = g_task_propagate_pointer (task, NULL)))
{
g_clear_pointer (&self->nodes, g_array_unref);
self->nodes = g_steal_pointer (&nodes);
gtk_widget_queue_draw (GTK_WIDGET (self));
}
}
static void
generate (GArray *array,
SysprofCallgraphNode *node,
const graphene_rect_t *area)
{
FlameRectangle rect;
g_assert (array != NULL);
g_assert (node != NULL);
g_assert (area != NULL);
rect.x = area->origin.x;
rect.y = area->origin.y + area->size.height - ROW_HEIGHT - 1;
rect.w = area->size.width;
rect.h = ROW_HEIGHT;
rect.node = node;
g_array_append_val (array, rect);
if (node->children != NULL)
{
graphene_rect_t child_area;
guint64 weight = 0;
child_area.origin.x = area->origin.x;
child_area.origin.y = area->origin.y;
child_area.size.height = area->size.height - ROW_HEIGHT - 1;
for (SysprofCallgraphNode *child = node->children; child; child = child->next)
weight += child->count;
for (SysprofCallgraphNode *child = node->children; child; child = child->next)
{
double ratio = child->count / (double)weight;
double width;
width = ratio * area->size.width;
child_area.size.width = width;
generate (array, child, &child_area);
child_area.origin.x += width;
}
}
}
static int
sort_by_coord (gconstpointer a,
gconstpointer b)
{
const FlameRectangle *rect_a = a;
const FlameRectangle *rect_b = b;
if (rect_a->y < rect_b->y)
return -1;
if (rect_a->y > rect_b->y)
return 1;
if (rect_a->x < rect_b->x)
return -1;
if (rect_a->x > rect_b->x)
return 1;
return 0;
}
static void
sysprof_flame_graph_generate_worker (GTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
{
SysprofCallgraph *callgraph = task_data;
g_autoptr(GArray) array = NULL;
int height;
g_assert (SYSPROF_IS_CALLGRAPH (callgraph));
array = g_array_sized_new (FALSE, FALSE, sizeof (FlameRectangle), callgraph->root.count);
height = callgraph->height * ROW_HEIGHT + callgraph->height + 1;
generate (array,
&callgraph->root,
&GRAPHENE_RECT_INIT (0, 0, G_MAXUINT16, height));
g_array_sort (array, sort_by_coord);
g_task_return_pointer (task, g_steal_pointer (&array), (GDestroyNotify)g_array_unref);
}
void
sysprof_flame_graph_set_callgraph (SysprofFlameGraph *self,
SysprofCallgraph *callgraph)
{
g_return_if_fail (SYSPROF_IS_FLAME_GRAPH (self));
g_return_if_fail (!callgraph || SYSPROF_IS_CALLGRAPH (callgraph));
if (g_set_object (&self->callgraph, callgraph))
{
g_clear_pointer (&self->rendered, gsk_render_node_unref);
g_clear_pointer (&self->nodes, g_array_unref);
if (callgraph != NULL)
{
g_autoptr(GTask) task = NULL;
task = g_task_new (NULL, NULL, sysprof_flame_graph_generate_cb, g_object_ref (self));
g_task_set_task_data (task, g_object_ref (callgraph), g_object_unref);
g_task_run_in_thread (task, sysprof_flame_graph_generate_worker);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CALLGRAPH]);
gtk_widget_queue_resize (GTK_WIDGET (self));
}
}

View File

@ -0,0 +1,38 @@
/* sysprof-flame-graph.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gtk/gtk.h>
#include <sysprof.h>
G_BEGIN_DECLS
#define SYSPROF_TYPE_FLAME_GRAPH (sysprof_flame_graph_get_type())
G_DECLARE_FINAL_TYPE (SysprofFlameGraph, sysprof_flame_graph, SYSPROF, FLAME_GRAPH, GtkWidget)
GtkWidget *sysprof_flame_graph_new (void);
SysprofCallgraph *sysprof_flame_graph_get_callgraph (SysprofFlameGraph *self);
void sysprof_flame_graph_set_callgraph (SysprofFlameGraph *self,
SysprofCallgraph *callgraph);
G_END_DECLS

View File

@ -22,6 +22,7 @@
#include "sysprof-chart.h"
#include "sysprof-column-layer.h"
#include "sysprof-flame-graph.h"
#include "sysprof-sampled-model.h"
#include "sysprof-samples-section.h"
#include "sysprof-session-model-item.h"
@ -80,6 +81,7 @@ sysprof_samples_section_class_init (SysprofSamplesSectionClass *klass)
g_type_ensure (SYSPROF_TYPE_COLUMN_LAYER);
g_type_ensure (SYSPROF_TYPE_DOCUMENT_SAMPLE);
g_type_ensure (SYSPROF_TYPE_DOCUMENT_TRACEABLE);
g_type_ensure (SYSPROF_TYPE_FLAME_GRAPH);
g_type_ensure (SYSPROF_TYPE_SAMPLED_MODEL);
g_type_ensure (SYSPROF_TYPE_TIME_FILTER_MODEL);
g_type_ensure (SYSPROF_TYPE_TIME_SCRUBBER);

View File

@ -80,64 +80,99 @@
</object>
</child>
<child>
<object class="SysprofWeightedCallgraphView" id="callgraph_view">
<object class="AdwViewStack" id="stack">
<property name="vexpand">true</property>
<binding name="include-threads">
<lookup name="include-threads" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="hide-system-libraries">
<lookup name="hide-system-libraries" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="bottom-up">
<lookup name="bottom-up" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="categorize-frames">
<lookup name="categorize-frames" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="ignore-process-0">
<lookup name="ignore-process-0" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="document">
<lookup name="document" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<property name="traceables">
<object class="GtkFilterListModel">
<binding name="filter">
<lookup name="filter">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<property name="model">
<object class="SysprofTimeFilterModel">
<property name="inclusive">false</property>
<binding name="time-span">
<lookup name="selected-time" type="SysprofSession">
<child>
<object class="AdwViewStackPage">
<property name="icon-name">threads-symbolic</property>
<property name="title" translatable="yes">Callgraph</property>
<property name="child">
<object class="SysprofWeightedCallgraphView" id="callgraph_view">
<property name="vexpand">true</property>
<binding name="include-threads">
<lookup name="include-threads" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="model">
<lookup name="samples" type="SysprofDocument">
<lookup name="document" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
<binding name="hide-system-libraries">
<lookup name="hide-system-libraries" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="bottom-up">
<lookup name="bottom-up" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="categorize-frames">
<lookup name="categorize-frames" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="ignore-process-0">
<lookup name="ignore-process-0" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="document">
<lookup name="document" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<property name="traceables">
<object class="GtkFilterListModel">
<binding name="filter">
<lookup name="filter">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<property name="model">
<object class="SysprofTimeFilterModel">
<property name="inclusive">false</property>
<binding name="time-span">
<lookup name="selected-time" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</binding>
<binding name="model">
<lookup name="samples" type="SysprofDocument">
<lookup name="document" type="SysprofSession">
<lookup name="session">SysprofSamplesSection</lookup>
</lookup>
</lookup>
</binding>
</object>
</property>
</object>
</property>
</object>
</property>
</object>
</property>
</child>
<child>
<object class="AdwViewStackPage">
<property name="icon-name">flamegraph-symbolic</property>
<property name="title" translatable="yes">Flamegraph</property>
<property name="child">
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
<property name="child">
<object class="SysprofFlameGraph">
<binding name="callgraph">
<lookup name="callgraph">callgraph_view</lookup>
</binding>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwViewSwitcherBar" id="switcher">
<property name="reveal">true</property>
<property name="stack">stack</property>
</object>
</child>
</object>

View File

@ -7,6 +7,7 @@
<file preprocess="xml-stripblanks">icons/scalable/actions/dbus-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/empty-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/energy-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/flamegraph-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/graphics-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/mark-chart-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/mark-table-symbolic.svg</file>