Merge branch 'gbsneto/mark-name-in-waterfall' into 'master'

sysprof: show mark name in waterfall marks

See merge request GNOME/sysprof!98
This commit is contained in:
Christian Hergert
2024-08-07 20:34:55 +00:00
5 changed files with 56 additions and 6 deletions

View File

@ -83,3 +83,7 @@ timescrubber timecode {
flamegraph { flamegraph {
font-size: 11px; font-size: 11px;
} }
timespanlayer {
font-size: 10px;
}

View File

@ -42,6 +42,25 @@ struct _SysprofMarksSection
G_DEFINE_FINAL_TYPE (SysprofMarksSection, sysprof_marks_section, SYSPROF_TYPE_SECTION) G_DEFINE_FINAL_TYPE (SysprofMarksSection, sysprof_marks_section, SYSPROF_TYPE_SECTION)
static char *
format_mark_label (gpointer unused,
SysprofDocumentMark *mark)
{
const char *message;
const char *name;
if (mark == NULL)
return NULL;
name = sysprof_document_mark_get_name (mark);
message = sysprof_document_mark_get_message (mark);
if (name && *name && message && *message)
return g_strdup_printf ("%s %s", name, message);
else
return g_strdup_printf ("%s", name);
}
static char * static char *
format_number (gpointer unused, format_number (gpointer unused,
guint number) guint number)
@ -74,6 +93,7 @@ sysprof_marks_section_class_init (SysprofMarksSectionClass *klass)
gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, mark_table); gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, mark_table);
gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, median_column); gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, median_column);
gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, summary_column_view); gtk_widget_class_bind_template_child (widget_class, SysprofMarksSection, summary_column_view);
gtk_widget_class_bind_template_callback (widget_class, format_mark_label);
gtk_widget_class_bind_template_callback (widget_class, format_number); gtk_widget_class_bind_template_callback (widget_class, format_number);
g_type_ensure (SYSPROF_TYPE_CHART); g_type_ensure (SYSPROF_TYPE_CHART);

View File

@ -175,9 +175,9 @@
</object> </object>
</property> </property>
<property name="label-expression"> <property name="label-expression">
<lookup name="message" type="SysprofDocumentMark"> <closure type="gchararray" function="format_mark_label">
<lookup name="item" type="SysprofSessionModelItem"/> <lookup name="item" type="SysprofSessionModelItem"/>
</lookup> </closure>
</property> </property>
<property name="begin-time-expression"> <property name="begin-time-expression">
<lookup name="time" type="SysprofDocumentMark"> <lookup name="time" type="SysprofDocumentMark">

View File

@ -330,7 +330,6 @@ sysprof_time_series_dup_label (SysprofTimeSeries *self,
if (!(item = g_list_model_get_item (model, position))) if (!(item = g_list_model_get_item (model, position)))
return NULL; return NULL;
g_value_init (&value, G_TYPE_STRING);
gtk_expression_evaluate (self->label_expression, item, &value); gtk_expression_evaluate (self->label_expression, item, &value);
return g_value_dup_string (&value); return g_value_dup_string (&value);
} }

View File

@ -216,12 +216,28 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
gtk_snapshot_append_color (snapshot, color, &rect); gtk_snapshot_append_color (snapshot, color, &rect);
} }
if (rect.size.width > 20) if (label != NULL)
{ {
gboolean rect_fits_text;
int right_empty_space;
int label_width;
if (label != NULL) pango_layout_set_text (layout, label, -1);
pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
pango_layout_get_pixel_size (layout, &label_width, NULL);
/* If it fits 75% of the text inside the rect, it's enough and
* won't look too busy.
*/
rect_fits_text = ((rect.size.width - 6) / (float) label_width) > 0.75;
right_empty_space = width - (rect.origin.x + rect.size.width) - 6;
/* Draw inside the rect if the label fits, or if there's not more
* space outside the rect.
*/
if (rect_fits_text || (rect.size.width - 6) > right_empty_space)
{ {
pango_layout_set_text (layout, label, -1);
pango_layout_set_width (layout, (rect.size.width - 6) * PANGO_SCALE); pango_layout_set_width (layout, (rect.size.width - 6) * PANGO_SCALE);
gtk_snapshot_save (snapshot); gtk_snapshot_save (snapshot);
@ -229,6 +245,15 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
gtk_snapshot_append_layout (snapshot, layout, label_color); gtk_snapshot_append_layout (snapshot, layout, label_color);
gtk_snapshot_restore (snapshot); gtk_snapshot_restore (snapshot);
} }
else if (n_values == 1 && right_empty_space > 20)
{
pango_layout_set_width (layout, right_empty_space * PANGO_SCALE);
gtk_snapshot_save (snapshot);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (rect.origin.x + rect.size.width + 3, layout_y));
gtk_snapshot_append_layout (snapshot, layout, label_color);
gtk_snapshot_restore (snapshot);
}
} }
} }
} }
@ -472,6 +497,8 @@ sysprof_time_span_layer_class_init (SysprofTimeSpanLayerClass *klass)
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_css_name (widget_class, "timespanlayer");
} }
static void static void