[gnome-builder] sysprof: port to SysprofNotebook API
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] sysprof: port to SysprofNotebook API
- Date: Thu, 30 May 2019 01:10:56 +0000 (UTC)
commit abab58b338dd1714bccb227f3cc146e22f8c92e0
Author: Christian Hergert <chergert redhat com>
Date: Wed May 29 18:10:26 2019 -0700
sysprof: port to SysprofNotebook API
src/plugins/sysprof/gbp-sysprof-surface.c | 212 +------------
src/plugins/sysprof/gbp-sysprof-surface.h | 12 +-
src/plugins/sysprof/gbp-sysprof-surface.ui | 91 +-----
src/plugins/sysprof/gbp-sysprof-workspace-addin.c | 363 +++++-----------------
4 files changed, 97 insertions(+), 581 deletions(-)
---
diff --git a/src/plugins/sysprof/gbp-sysprof-surface.c b/src/plugins/sysprof/gbp-sysprof-surface.c
index 65ffac8ed..c102b805b 100644
--- a/src/plugins/sysprof/gbp-sysprof-surface.c
+++ b/src/plugins/sysprof/gbp-sysprof-surface.c
@@ -21,91 +21,33 @@
#define G_LOG_DOMAIN "gbp-sysprof-surface"
#include <glib/gi18n.h>
-#include <sysprof.h>
#include <sysprof-ui.h>
#include "gbp-sysprof-surface.h"
struct _GbpSysprofSurface
{
- IdeSurface parent_instance;
-
- SysprofCaptureReader *reader;
-
- GtkStack *stack;
- SysprofCallgraphView *callgraph_view;
- GtkLabel *info_bar_label;
- GtkButton *info_bar_close;
- GtkRevealer *info_bar_revealer;
- SysprofVisualizerView *visualizers;
- SysprofRecordingStateView *recording_view;
- SysprofZoomManager *zoom_manager;
+ IdeSurface parent_instance;
+ SysprofNotebook *notebook;
};
-static void gbp_sysprof_surface_reload (GbpSysprofSurface *self);
-
G_DEFINE_TYPE (GbpSysprofSurface, gbp_sysprof_surface, IDE_TYPE_SURFACE)
-static void
-hide_info_bar (GbpSysprofSurface *self,
- GtkButton *button)
-{
- g_assert (GBP_IS_SYSPROF_SURFACE (self));
-
- gtk_revealer_set_reveal_child (self->info_bar_revealer, FALSE);
-}
-
-static void
-gbp_sysprof_surface_selection_changed (GbpSysprofSurface *self,
- SysprofSelection *selection)
-{
- g_assert (GBP_IS_SYSPROF_SURFACE (self));
- g_assert (SYSPROF_IS_SELECTION (selection));
-
- gbp_sysprof_surface_reload (self);
-}
-
-static void
-gbp_sysprof_surface_finalize (GObject *object)
-{
- GbpSysprofSurface *self = (GbpSysprofSurface *)object;
-
- g_clear_pointer (&self->reader, sysprof_capture_reader_unref);
-
- G_OBJECT_CLASS (gbp_sysprof_surface_parent_class)->finalize (object);
-}
-
static void
gbp_sysprof_surface_class_init (GbpSysprofSurfaceClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = gbp_sysprof_surface_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/plugins/sysprof/gbp-sysprof-surface.ui");
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, callgraph_view);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, info_bar_label);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, info_bar_close);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, info_bar_revealer);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, stack);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, recording_view);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, visualizers);
- gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, zoom_manager);
+ gtk_widget_class_bind_template_child (widget_class, GbpSysprofSurface, notebook);
- g_type_ensure (SYSPROF_TYPE_CALLGRAPH_VIEW);
- g_type_ensure (SYSPROF_TYPE_CPU_VISUALIZER_ROW);
- g_type_ensure (SYSPROF_TYPE_EMPTY_STATE_VIEW);
- g_type_ensure (SYSPROF_TYPE_FAILED_STATE_VIEW);
- g_type_ensure (SYSPROF_TYPE_RECORDING_STATE_VIEW);
- g_type_ensure (SYSPROF_TYPE_VISUALIZER_VIEW);
+ g_type_ensure (SYSPROF_TYPE_NOTEBOOK);
}
static void
gbp_sysprof_surface_init (GbpSysprofSurface *self)
{
DzlShortcutController *controller;
- SysprofSelection *selection;
gtk_widget_init_template (GTK_WIDGET (self));
@@ -119,154 +61,24 @@ gbp_sysprof_surface_init (GbpSysprofSurface *self)
"<alt>2",
DZL_SHORTCUT_PHASE_GLOBAL,
"win.surface('profiler')");
-
- g_signal_connect_object (self->info_bar_close,
- "clicked",
- G_CALLBACK (hide_info_bar),
- self,
- G_CONNECT_SWAPPED);
-
- selection = sysprof_visualizer_view_get_selection (self->visualizers);
-
- g_signal_connect_object (selection,
- "changed",
- G_CALLBACK (gbp_sysprof_surface_selection_changed),
- self,
- G_CONNECT_SWAPPED);
-}
-
-static void
-generate_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- SysprofCallgraphProfile *profile = (SysprofCallgraphProfile *)object;
- g_autoptr(GbpSysprofSurface) self = user_data;
- g_autoptr(GError) error = NULL;
-
- g_assert (SYSPROF_IS_CALLGRAPH_PROFILE (profile));
- g_assert (GBP_IS_SYSPROF_SURFACE (self));
-
- if (!sysprof_profile_generate_finish (SYSPROF_PROFILE (profile), result, &error))
- {
- g_warning ("Failed to generate profile: %s", error->message);
- return;
- }
-
- sysprof_callgraph_view_set_profile (self->callgraph_view, profile);
-}
-
-static void
-gbp_sysprof_surface_reload (GbpSysprofSurface *self)
-{
- SysprofSelection *selection;
- g_autoptr(SysprofProfile) profile = NULL;
-
- g_assert (GBP_IS_SYSPROF_SURFACE (self));
-
- if (self->reader == NULL)
- return;
-
- /* If we failed, ignore the (probably mostly empty) reader */
- if (g_strcmp0 (gtk_stack_get_visible_child_name (self->stack), "failed") == 0)
- return;
-
- selection = sysprof_visualizer_view_get_selection (self->visualizers);
- profile = sysprof_callgraph_profile_new_with_selection (selection);
-
- sysprof_profile_set_reader (profile, self->reader);
- sysprof_profile_generate (profile, NULL, generate_cb, g_object_ref (self));
-
- sysprof_visualizer_view_set_reader (self->visualizers, self->reader);
-
- gtk_stack_set_visible_child_name (self->stack, "results");
-}
-
-SysprofCaptureReader *
-gbp_sysprof_surface_get_reader (GbpSysprofSurface *self)
-{
- g_return_val_if_fail (GBP_IS_SYSPROF_SURFACE (self), NULL);
-
- return sysprof_visualizer_view_get_reader (self->visualizers);
}
void
-gbp_sysprof_surface_set_reader (GbpSysprofSurface *self,
- SysprofCaptureReader *reader)
+gbp_sysprof_surface_open (GbpSysprofSurface *self,
+ GFile *file)
{
g_assert (GBP_IS_SYSPROF_SURFACE (self));
+ g_assert (G_IS_FILE (file));
- if (reader != self->reader)
- {
- SysprofSelection *selection;
-
- if (self->reader != NULL)
- {
- g_clear_pointer (&self->reader, sysprof_capture_reader_unref);
- sysprof_callgraph_view_set_profile (self->callgraph_view, NULL);
- sysprof_visualizer_view_set_reader (self->visualizers, NULL);
- gtk_stack_set_visible_child_name (self->stack, "empty");
- }
-
- selection = sysprof_visualizer_view_get_selection (self->visualizers);
- sysprof_selection_unselect_all (selection);
-
- if (reader != NULL)
- {
- self->reader = sysprof_capture_reader_ref (reader);
- gbp_sysprof_surface_reload (self);
- }
- }
-}
-
-static void
-gbp_sysprof_surface_profiler_failed (GbpSysprofSurface *self,
- const GError *error,
- SysprofProfiler *profiler)
-{
- IDE_ENTRY;
-
- g_assert (GBP_IS_SYSPROF_SURFACE (self));
- g_assert (error != NULL);
- g_assert (SYSPROF_IS_PROFILER (profiler));
-
- gtk_stack_set_visible_child_name (self->stack, "failed");
-
- gtk_label_set_label (self->info_bar_label, error->message);
- gtk_revealer_set_reveal_child (self->info_bar_revealer, TRUE);
-
- IDE_EXIT;
+ sysprof_notebook_open (self->notebook, file);
}
void
-gbp_sysprof_surface_set_profiler (GbpSysprofSurface *self,
- SysprofProfiler *profiler)
+gbp_sysprof_surface_add_profiler (GbpSysprofSurface *self,
+ SysprofProfiler *profiler)
{
g_return_if_fail (GBP_IS_SYSPROF_SURFACE (self));
- g_return_if_fail (!profiler || SYSPROF_IS_PROFILER (profiler));
-
- sysprof_recording_state_view_set_profiler (self->recording_view, profiler);
-
- if (profiler != NULL)
- {
- gtk_stack_set_visible_child_name (self->stack, "recording");
-
- g_signal_connect_object (profiler,
- "failed",
- G_CALLBACK (gbp_sysprof_surface_profiler_failed),
- self,
- G_CONNECT_SWAPPED);
- }
- else
- {
- gtk_stack_set_visible_child_name (self->stack, "empty");
- }
-}
-
-SysprofZoomManager *
-gbp_sysprof_surface_get_zoom_manager (GbpSysprofSurface *self)
-{
- g_return_val_if_fail (GBP_IS_SYSPROF_SURFACE (self), NULL);
+ g_return_if_fail (SYSPROF_IS_PROFILER (profiler));
- return self->zoom_manager;
+ sysprof_notebook_add_profiler (self->notebook, profiler);
}
diff --git a/src/plugins/sysprof/gbp-sysprof-surface.h b/src/plugins/sysprof/gbp-sysprof-surface.h
index 1137dd4a4..8d293a94a 100644
--- a/src/plugins/sysprof/gbp-sysprof-surface.h
+++ b/src/plugins/sysprof/gbp-sysprof-surface.h
@@ -21,7 +21,7 @@
#pragma once
#include <libide-gui.h>
-#include <sysprof-ui.h>
+#include <sysprof.h>
G_BEGIN_DECLS
@@ -29,11 +29,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpSysprofSurface, gbp_sysprof_surface, GBP, SYSPROF_SURFACE, IdeSurface)
-SysprofZoomManager *gbp_sysprof_surface_get_zoom_manager (GbpSysprofSurface *self);
-void gbp_sysprof_surface_set_profiler (GbpSysprofSurface *self,
- SysprofProfiler *profiler);
-SysprofCaptureReader *gbp_sysprof_surface_get_reader (GbpSysprofSurface *self);
-void gbp_sysprof_surface_set_reader (GbpSysprofSurface *self,
- SysprofCaptureReader *reader);
+void gbp_sysprof_surface_add_profiler (GbpSysprofSurface *self,
+ SysprofProfiler *profiler);
+void gbp_sysprof_surface_open (GbpSysprofSurface *self,
+ GFile *file);
G_END_DECLS
diff --git a/src/plugins/sysprof/gbp-sysprof-surface.ui b/src/plugins/sysprof/gbp-sysprof-surface.ui
index 83598a9b8..ba5e090e6 100644
--- a/src/plugins/sysprof/gbp-sysprof-surface.ui
+++ b/src/plugins/sysprof/gbp-sysprof-surface.ui
@@ -2,98 +2,9 @@
<interface>
<template class="GbpSysprofSurface" parent="IdeSurface">
<child>
- <object class="GtkBox">
- <property name="orientation">vertical</property>
+ <object class="SysprofNotebook" id="notebook">
<property name="visible">true</property>
- <child>
- <object class="GtkRevealer" id="info_bar_revealer">
- <property name="visible">true</property>
- <property name="reveal-child">false</property>
- <child>
- <object class="GtkInfoBar" id="info_bar">
- <property name="visible">true</property>
- <child internal-child="content_area">
- <object class="GtkBox">
- <child>
- <object class="GtkLabel" id="info_bar_label">
- <property name="hexpand">true</property>
- <property name="label" translatable="yes">Failure</property>
- <property name="visible">true</property>
- <property name="wrap">true</property>
- <property name="xalign">0</property>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="info_bar_close">
- <property name="label" translatable="yes">_Close</property>
- <property name="use-underline">true</property>
- <property name="visible">true</property>
- <property name="width-request">100</property>
- </object>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="0">info_bar_close</action-widget>
- </action-widgets>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkStack" id="stack">
- <property name="homogeneous">false</property>
- <property name="visible">true</property>
- <child>
- <object class="SysprofEmptyStateView">
- <property name="subtitle" translatable="yes" comments="the action:// link is used to run the
project">Select <a href="action://run-manager.run-with-handler::profiler">Run with profiler</a>
from the run menu to begin</property>
- <property name="visible">true</property>
- </object>
- <packing>
- <property name="name">empty</property>
- </packing>
- </child>
- <child>
- <object class="SysprofRecordingStateView" id="recording_view">
- <property name="visible">true</property>
- </object>
- <packing>
- <property name="name">recording</property>
- </packing>
- </child>
- <child>
- <object class="SysprofFailedStateView" id="failed_view">
- <property name="visible">true</property>
- </object>
- <packing>
- <property name="name">failed</property>
- </packing>
- </child>
- <child>
- <object class="DzlMultiPaned">
- <property name="visible">true</property>
- <child>
- <object class="SysprofVisualizerView" id="visualizers">
- <property name="visible">true</property>
- <property name="zoom-manager">zoom_manager</property>
- </object>
- </child>
- <child>
- <object class="SysprofCallgraphView" id="callgraph_view">
- <property name="vexpand">true</property>
- <property name="visible">true</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">results</property>
- </packing>
- </child>
- </object>
- </child>
</object>
</child>
</template>
- <object class="SysprofZoomManager" id="zoom_manager">
- </object>
</interface>
diff --git a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
index 85e2df6c4..7f8a825a9 100644
--- a/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
+++ b/src/plugins/sysprof/gbp-sysprof-workspace-addin.c
@@ -29,12 +29,9 @@ struct _GbpSysprofWorkspaceAddin
GObject parent_instance;
GSimpleActionGroup *actions;
- SysprofProfiler *profiler;
GbpSysprofSurface *surface;
IdeWorkspace *workspace;
-
- GtkBox *zoom_controls;
};
static void workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface);
@@ -42,85 +39,49 @@ static void workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GbpSysprofWorkspaceAddin, gbp_sysprof_workspace_addin, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN, workspace_addin_iface_init))
-static void
-gbp_sysprof_workspace_addin_update_controls (GbpSysprofWorkspaceAddin *self)
-{
- IdeSurface *surface;
- gboolean visible;
-
- g_assert (IDE_IS_MAIN_THREAD ());
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
-
- if (self->workspace == NULL)
- return;
-
- surface = ide_workspace_get_visible_surface (self->workspace);
- visible = GBP_IS_SYSPROF_SURFACE (surface) &&
- !!gbp_sysprof_surface_get_reader (GBP_SYSPROF_SURFACE (surface));
-
- if (self->zoom_controls)
- gtk_widget_set_visible (GTK_WIDGET (self->zoom_controls), visible);
-}
-
-static void
-profiler_stopped (GbpSysprofWorkspaceAddin *self,
- SysprofProfiler *profiler)
+static gchar *
+get_runtime_sysroot (IdeContext *context,
+ const gchar *path)
{
- g_autoptr(SysprofCaptureReader) reader = NULL;
- g_autoptr(GError) error = NULL;
- SysprofCaptureWriter *writer;
-
- IDE_ENTRY;
+ IdeConfigManager *config_manager;
+ IdeConfig *config;
+ IdeRuntime *runtime;
g_assert (IDE_IS_MAIN_THREAD ());
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
- g_assert (SYSPROF_IS_PROFILER (profiler));
-
- if (self->profiler != profiler)
- IDE_EXIT;
-
- if (self->workspace == NULL)
- IDE_EXIT;
+ g_assert (IDE_IS_CONTEXT (context));
- writer = sysprof_profiler_get_writer (profiler);
- reader = sysprof_capture_writer_create_reader (writer, &error);
+ config_manager = ide_config_manager_from_context (context);
+ config = ide_config_manager_get_current (config_manager);
+ runtime = ide_config_get_runtime (config);
- if (reader == NULL)
+ if (runtime != NULL)
{
- /* TODO: Propagate error to an infobar or similar */
- g_warning ("%s", error->message);
- IDE_EXIT;
- }
-
- gbp_sysprof_surface_set_reader (self->surface, reader);
-
- ide_workspace_set_visible_surface_name (self->workspace, "profiler");
+ g_autoptr(GFile) base = g_file_new_for_path (path);
+ g_autoptr(GFile) translated = ide_runtime_translate_file (runtime, base);
- gbp_sysprof_workspace_addin_update_controls (self);
+ if (translated != NULL)
+ return g_file_get_path (translated);
+ }
- IDE_EXIT;
+ return NULL;
}
static void
-profiler_child_spawned (GbpSysprofWorkspaceAddin *self,
- const gchar *identifier,
- IdeRunner *runner)
+profiler_child_spawned (IdeRunner *runner,
+ const gchar *identifier,
+ SysprofProfiler *profiler)
{
+#ifdef G_OS_UNIX
GPid pid = 0;
g_assert (IDE_IS_MAIN_THREAD ());
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
+ g_assert (SYSPROF_IS_PROFILER (profiler));
g_assert (identifier != NULL);
g_assert (IDE_IS_RUNNER (runner));
- if (!SYSPROF_IS_PROFILER (self->profiler))
- return;
-
-#ifdef G_OS_UNIX
pid = g_ascii_strtoll (identifier, NULL, 10);
-#endif
- if G_UNLIKELY (pid == 0)
+ if (pid == 0)
{
g_warning ("Failed to parse integer value from %s", identifier);
return;
@@ -128,35 +89,21 @@ profiler_child_spawned (GbpSysprofWorkspaceAddin *self,
IDE_TRACE_MSG ("Adding pid %s to profiler", identifier);
- sysprof_profiler_add_pid (self->profiler, pid);
- sysprof_profiler_start (self->profiler);
+ sysprof_profiler_add_pid (profiler, pid);
+ sysprof_profiler_start (profiler);
+#endif
}
-static gchar *
-get_runtime_sysroot (IdeContext *context,
- const gchar *path)
+static void
+runner_exited_cb (IdeRunner *runner,
+ SysprofProfiler *profiler)
{
- IdeConfigManager *config_manager;
- IdeConfig *config;
- IdeRuntime *runtime;
-
g_assert (IDE_IS_MAIN_THREAD ());
- g_assert (IDE_IS_CONTEXT (context));
-
- config_manager = ide_config_manager_from_context (context);
- config = ide_config_manager_get_current (config_manager);
- runtime = ide_config_get_runtime (config);
-
- if (runtime != NULL)
- {
- g_autoptr(GFile) base = g_file_new_for_path (path);
- g_autoptr(GFile) translated = ide_runtime_translate_file (runtime, base);
-
- if (translated != NULL)
- return g_file_get_path (translated);
- }
+ g_assert (IDE_IS_RUNNER (runner));
+ g_assert (SYSPROF_IS_PROFILER (profiler));
- return NULL;
+ if (sysprof_profiler_get_is_running (profiler))
+ sysprof_profiler_stop (profiler);
}
static void
@@ -165,10 +112,14 @@ profiler_run_handler (IdeRunManager *run_manager,
gpointer user_data)
{
GbpSysprofWorkspaceAddin *self = user_data;
+ g_autoptr(SysprofProfiler) profiler = NULL;
g_autoptr(SysprofSource) proc_source = NULL;
g_autoptr(SysprofSource) perf_source = NULL;
g_autoptr(SysprofSource) hostinfo_source = NULL;
g_autoptr(SysprofSource) memory_source = NULL;
+ g_autoptr(SysprofSource) app_source = NULL;
+ g_autoptr(SysprofSource) gjs_source = NULL;
+ g_autoptr(SysprofSource) symbols_source = NULL;
IdeContext *context;
g_assert (IDE_IS_MAIN_THREAD ());
@@ -176,13 +127,6 @@ profiler_run_handler (IdeRunManager *run_manager,
g_assert (IDE_IS_RUNNER (runner));
g_assert (IDE_IS_RUN_MANAGER (run_manager));
- if (SYSPROF_IS_PROFILER (self->profiler))
- {
- if (sysprof_profiler_get_is_running (self->profiler))
- sysprof_profiler_stop (self->profiler);
- g_clear_object (&self->profiler);
- }
-
/*
* First get a copy of the active runtime and find the root of it's
* translation path. That way we can adjust for the sysroot when
@@ -206,6 +150,11 @@ profiler_run_handler (IdeRunManager *run_manager,
context = ide_object_get_context (IDE_OBJECT (run_manager));
+ /*
+ * TODO: We should really be adding symbol directories to the
+ * ELF symbol resolver rather than here.
+ */
+
for (guint i = 0; dirs[i]; i++)
{
g_autofree gchar *path = get_runtime_sysroot (context, dirs[i]);
@@ -215,15 +164,7 @@ profiler_run_handler (IdeRunManager *run_manager,
}
}
- self->profiler = sysprof_local_profiler_new ();
-
- g_signal_connect_object (self->profiler,
- "stopped",
- G_CALLBACK (gbp_sysprof_workspace_addin_update_controls),
- self,
- G_CONNECT_SWAPPED);
-
- gtk_widget_hide (GTK_WIDGET (self->zoom_controls));
+ profiler = sysprof_local_profiler_new ();
/*
* Currently we require whole-system because otherwise we can get a situation
@@ -231,19 +172,33 @@ profiler_run_handler (IdeRunManager *run_manager,
* Longer term we either need a way to follow-children and/or limit to a
* cgroup/process-group.
*/
- sysprof_profiler_set_whole_system (SYSPROF_PROFILER (self->profiler), TRUE);
+ sysprof_profiler_set_whole_system (profiler, TRUE);
proc_source = sysprof_proc_source_new ();
- sysprof_profiler_add_source (self->profiler, proc_source);
+ sysprof_profiler_add_source (profiler, proc_source);
+ /* TODO: Make this source non-fatal since we have other data collectors */
perf_source = sysprof_perf_source_new ();
- sysprof_profiler_add_source (self->profiler, perf_source);
+ sysprof_profiler_add_source (profiler, perf_source);
hostinfo_source = sysprof_hostinfo_source_new ();
- sysprof_profiler_add_source (self->profiler, hostinfo_source);
+ sysprof_profiler_add_source (profiler, hostinfo_source);
memory_source = sysprof_memory_source_new ();
- sysprof_profiler_add_source (self->profiler, memory_source);
+ sysprof_profiler_add_source (profiler, memory_source);
+
+ /* TODO: Only add this when a GJS-based app is run */
+ gjs_source = sysprof_tracefd_source_new ();
+ sysprof_tracefd_source_set_envvar (SYSPROF_TRACEFD_SOURCE (gjs_source), "GJS_TRACE_FD");
+ sysprof_profiler_add_source (profiler, gjs_source);
+
+ /* Allow the app to submit us data if it supports "SYSPROF_TRACE_FD" */
+ app_source = sysprof_tracefd_source_new ();
+ sysprof_tracefd_source_set_envvar (SYSPROF_TRACEFD_SOURCE (app_source), "SYSPROF_TRACE_FD");
+ sysprof_profiler_add_source (profiler, app_source);
+
+ symbols_source = sysprof_symbols_source_new ();
+ sysprof_profiler_add_source (profiler, symbols_source);
/*
* TODO:
@@ -259,90 +214,31 @@ profiler_run_handler (IdeRunManager *run_manager,
g_signal_connect_object (runner,
"spawned",
G_CALLBACK (profiler_child_spawned),
- self,
- G_CONNECT_SWAPPED);
+ profiler,
+ 0);
- g_signal_connect_object (self->profiler,
- "stopped",
- G_CALLBACK (profiler_stopped),
- self,
- G_CONNECT_SWAPPED);
+ g_signal_connect_object (runner,
+ "exited",
+ G_CALLBACK (runner_exited_cb),
+ profiler,
+ 0);
- gbp_sysprof_surface_set_profiler (self->surface, self->profiler);
+ gbp_sysprof_surface_add_profiler (self->surface, profiler);
ide_workspace_set_visible_surface (self->workspace, IDE_SURFACE (self->surface));
}
-static void
-gbp_sysprof_workspace_addin_open_cb (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
-{
- GbpSysprofWorkspaceAddin *self = (GbpSysprofWorkspaceAddin *)object;
- g_autoptr(SysprofCaptureReader) reader = NULL;
- g_autoptr(GError) error = NULL;
-
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
- g_assert (IDE_IS_TASK (result));
-
- reader = ide_task_propagate_pointer (IDE_TASK (result), &error);
-
- g_assert (reader || error != NULL);
-
- if (reader == NULL)
- {
- g_message ("%s", error->message);
- return;
- }
-
- gbp_sysprof_surface_set_profiler (self->surface, NULL);
- gbp_sysprof_surface_set_reader (self->surface, reader);
-
- gbp_sysprof_workspace_addin_update_controls (self);
-}
-
-static void
-gbp_sysprof_workspace_addin_open_worker (IdeTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- g_autofree gchar *path = NULL;
- g_autoptr(GError) error = NULL;
- SysprofCaptureReader *reader;
- GFile *file = task_data;
-
- g_assert (IDE_IS_TASK (task));
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (source_object));
- g_assert (G_IS_FILE (file));
- g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
-
- path = g_file_get_path (file);
-
- if (!(reader = sysprof_capture_reader_new (path, &error)))
- ide_task_return_error (task, g_steal_pointer (&error));
- else
- ide_task_return_pointer (task, reader, sysprof_capture_reader_unref);
-}
-
static void
gbp_sysprof_workspace_addin_open (GbpSysprofWorkspaceAddin *self,
GFile *file)
{
- g_autoptr(IdeTask) task = NULL;
-
g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
g_assert (G_IS_FILE (file));
if (!g_file_is_native (file))
- {
- g_warning ("Can only open local sysprof capture files.");
- return;
- }
-
- task = ide_task_new (self, NULL, gbp_sysprof_workspace_addin_open_cb, NULL);
- ide_task_set_task_data (task, g_object_ref (file), g_object_unref);
- ide_task_run_in_thread (task, gbp_sysprof_workspace_addin_open_worker);
+ g_warning ("Can only open local sysprof capture files.");
+ else
+ gbp_sysprof_surface_open (self->surface, file);
}
static void
@@ -441,39 +337,13 @@ gbp_sysprof_workspace_addin_init (GbpSysprofWorkspaceAddin *self)
self);
}
-static void
-run_manager_stopped (GbpSysprofWorkspaceAddin *self,
- IdeRunManager *run_manager)
-{
- g_assert (IDE_IS_MAIN_THREAD ());
- g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
- g_assert (IDE_IS_RUN_MANAGER (run_manager));
-
- if (self->profiler != NULL && sysprof_profiler_get_is_running (self->profiler))
- sysprof_profiler_stop (self->profiler);
-}
-
-static gboolean
-zoom_level_to_string (GBinding *binding,
- const GValue *from_value,
- GValue *to_value,
- gpointer user_data)
-{
- gdouble level = g_value_get_double (from_value);
- g_value_take_string (to_value, g_strdup_printf ("%d%%", (gint)(level * 100.0)));
- return TRUE;
-}
-
static void
gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
IdeWorkspace *workspace)
{
GbpSysprofWorkspaceAddin *self = (GbpSysprofWorkspaceAddin *)addin;
- SysprofZoomManager *zoom_manager;
IdeRunManager *run_manager;
- IdeHeaderBar *header;
IdeContext *context;
- GtkLabel *label;
g_assert (IDE_IS_MAIN_THREAD ());
g_assert (GBP_IS_SYSPROF_WORKSPACE_ADDIN (self));
@@ -481,11 +351,13 @@ gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
self->workspace = workspace;
+ gtk_widget_insert_action_group (GTK_WIDGET (workspace),
+ "profiler",
+ G_ACTION_GROUP (self->actions));
+
context = ide_workspace_get_context (workspace);
- /*
- * Register our custom run handler to activate the profiler.
- */
+ /* Register our custom run handler to activate the profiler. */
run_manager = ide_run_manager_from_context (context);
ide_run_manager_add_handler (run_manager,
"profiler",
@@ -495,11 +367,6 @@ gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
profiler_run_handler,
self,
NULL);
- g_signal_connect_object (run_manager,
- "stopped",
- G_CALLBACK (run_manager_stopped),
- self,
- G_CONNECT_SWAPPED);
/* Add the surface to the workspace. */
self->surface = g_object_new (GBP_TYPE_SYSPROF_SURFACE,
@@ -510,60 +377,6 @@ gbp_sysprof_workspace_addin_load (IdeWorkspaceAddin *addin,
G_CALLBACK (gtk_widget_destroyed),
&self->surface);
ide_workspace_add_surface (workspace, IDE_SURFACE (self->surface));
-
- zoom_manager = gbp_sysprof_surface_get_zoom_manager (self->surface);
-
- /*
- * Add our actions to the workspace so they can be activated via the
- * headerbar or the surface.
- */
- gtk_widget_insert_action_group (GTK_WIDGET (workspace), "profiler", G_ACTION_GROUP (self->actions));
- gtk_widget_insert_action_group (GTK_WIDGET (workspace), "profiler-zoom", G_ACTION_GROUP (zoom_manager));
-
- /* Add our buttons to the header. */
- header = ide_workspace_get_header_bar (workspace);
- self->zoom_controls = g_object_new (GTK_TYPE_BOX,
- "orientation", GTK_ORIENTATION_HORIZONTAL,
- NULL);
- g_signal_connect (self->zoom_controls,
- "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &self->zoom_controls);
- dzl_gtk_widget_add_style_class (GTK_WIDGET (self->zoom_controls), "linked");
- gtk_container_add (GTK_CONTAINER (self->zoom_controls),
- g_object_new (GTK_TYPE_BUTTON,
- "action-name", "profiler-zoom.zoom-out",
- "can-focus", FALSE,
- "child", g_object_new (GTK_TYPE_IMAGE,
- "icon-name", "zoom-out-symbolic",
- "visible", TRUE,
- NULL),
- "visible", TRUE,
- NULL));
- label = g_object_new (GTK_TYPE_LABEL,
- "width-chars", 5,
- "visible", TRUE,
- NULL);
- g_object_bind_property_full (zoom_manager, "zoom", label, "label", G_BINDING_SYNC_CREATE,
- zoom_level_to_string, NULL, NULL, NULL);
- gtk_container_add (GTK_CONTAINER (self->zoom_controls),
- g_object_new (GTK_TYPE_BUTTON,
- "action-name", "profiler-zoom.zoom-one",
- "can-focus", FALSE,
- "child", label,
- "visible", TRUE,
- NULL));
- gtk_container_add (GTK_CONTAINER (self->zoom_controls),
- g_object_new (GTK_TYPE_BUTTON,
- "action-name", "profiler-zoom.zoom-in",
- "can-focus", FALSE,
- "child", g_object_new (GTK_TYPE_IMAGE,
- "icon-name", "zoom-in-symbolic",
- "visible", TRUE,
- NULL),
- "visible", TRUE,
- NULL));
- ide_header_bar_add_primary (header, GTK_WIDGET (self->zoom_controls));
}
static void
@@ -580,38 +393,20 @@ gbp_sysprof_workspace_addin_unload (IdeWorkspaceAddin *addin,
context = ide_workspace_get_context (workspace);
gtk_widget_insert_action_group (GTK_WIDGET (workspace), "profiler", NULL);
- gtk_widget_insert_action_group (GTK_WIDGET (workspace), "profiler-zoom", NULL);
run_manager = ide_run_manager_from_context (context);
ide_run_manager_remove_handler (run_manager, "profiler");
- if (self->surface)
+ if (self->surface != NULL)
gtk_widget_destroy (GTK_WIDGET (self->surface));
- if (self->zoom_controls)
- gtk_widget_destroy (GTK_WIDGET (self->zoom_controls));
-
- self->zoom_controls = NULL;
self->surface = NULL;
self->workspace = NULL;
}
-static void
-gbp_sysprof_workspace_addin_surface_set (IdeWorkspaceAddin *addin,
- IdeSurface *surface)
-{
- GbpSysprofWorkspaceAddin *self = (GbpSysprofWorkspaceAddin *)addin;
-
- g_assert (IDE_IS_WORKSPACE_ADDIN (addin));
- g_assert (!surface || IDE_IS_SURFACE (surface));
-
- gbp_sysprof_workspace_addin_update_controls (self);
-}
-
static void
workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
{
iface->load = gbp_sysprof_workspace_addin_load;
iface->unload = gbp_sysprof_workspace_addin_unload;
- iface->surface_set = gbp_sysprof_workspace_addin_surface_set;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]