[sysprof/wip/chergert/mem-preload] libsysprof-ui: start on memory profile loading
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof/wip/chergert/mem-preload] libsysprof-ui: start on memory profile loading
- Date: Tue, 4 Feb 2020 20:44:28 +0000 (UTC)
commit dc50aed5ab48a7ce429d96c34669fd03b6b12c2d
Author: Christian Hergert <chergert redhat com>
Date: Mon Feb 3 20:51:07 2020 -0800
libsysprof-ui: start on memory profile loading
Still a lot to do here since this crashes (as we've not yet decoded the
actual strings for the instructions).
src/libsysprof-ui/libsysprof-ui.gresource.xml | 1 +
src/libsysprof-ui/sysprof-display.c | 2 +
src/libsysprof-ui/sysprof-memory-aid.c | 150 +++++++++++++++++++++++++-
3 files changed, 152 insertions(+), 1 deletion(-)
---
diff --git a/src/libsysprof-ui/libsysprof-ui.gresource.xml b/src/libsysprof-ui/libsysprof-ui.gresource.xml
index fd6a597..db75cd3 100644
--- a/src/libsysprof-ui/libsysprof-ui.gresource.xml
+++ b/src/libsysprof-ui/libsysprof-ui.gresource.xml
@@ -19,6 +19,7 @@
<file preprocess="xml-stripblanks">sysprof-failed-state-view.ui</file>
<file preprocess="xml-stripblanks">sysprof-logs-page.ui</file>
<file preprocess="xml-stripblanks">sysprof-marks-page.ui</file>
+ <file preprocess="xml-stripblanks">sysprof-memory-page.ui</file>
<file preprocess="xml-stripblanks">sysprof-process-model-row.ui</file>
<file preprocess="xml-stripblanks">sysprof-profiler-assistant.ui</file>
<file preprocess="xml-stripblanks">sysprof-recording-state-view.ui</file>
diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c
index e7ea00f..6d082a2 100644
--- a/src/libsysprof-ui/sysprof-display.c
+++ b/src/libsysprof-ui/sysprof-display.c
@@ -42,6 +42,7 @@
#include "sysprof-diskstat-aid.h"
#include "sysprof-logs-aid.h"
#include "sysprof-marks-aid.h"
+#include "sysprof-memory-aid.h"
#include "sysprof-netdev-aid.h"
#include "sysprof-rapl-aid.h"
@@ -654,6 +655,7 @@ sysprof_display_present_async (SysprofDisplay *self,
g_ptr_array_add (aids, sysprof_diskstat_aid_new ());
g_ptr_array_add (aids, sysprof_logs_aid_new ());
g_ptr_array_add (aids, sysprof_marks_aid_new ());
+ g_ptr_array_add (aids, sysprof_memory_aid_new ());
g_ptr_array_add (aids, sysprof_netdev_aid_new ());
g_ptr_array_add (aids, sysprof_rapl_aid_new ());
diff --git a/src/libsysprof-ui/sysprof-memory-aid.c b/src/libsysprof-ui/sysprof-memory-aid.c
index 7280dc3..90d8958 100644
--- a/src/libsysprof-ui/sysprof-memory-aid.c
+++ b/src/libsysprof-ui/sysprof-memory-aid.c
@@ -24,7 +24,9 @@
#include <glib/gi18n.h>
+#include "sysprof-depth-visualizer.h"
#include "sysprof-memory-aid.h"
+#include "sysprof-memory-page.h"
struct _SysprofMemoryAid
{
@@ -33,6 +35,36 @@ struct _SysprofMemoryAid
G_DEFINE_TYPE (SysprofMemoryAid, sysprof_memory_aid, SYSPROF_TYPE_AID)
+typedef struct
+{
+ SysprofCaptureCursor *cursor;
+ SysprofDisplay *display;
+ guint has_allocs : 1;
+} Present;
+
+static void
+present_free (gpointer data)
+{
+ Present *p = data;
+
+ g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref);
+ g_clear_object (&p->display);
+ g_slice_free (Present, p);
+}
+
+static void
+on_group_activated_cb (SysprofVisualizerGroup *group,
+ SysprofPage *page)
+{
+ SysprofDisplay *display;
+
+ g_assert (SYSPROF_IS_VISUALIZER_GROUP (group));
+ g_assert (SYSPROF_IS_PAGE (page));
+
+ display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY));
+ sysprof_display_set_visible_page (display, page);
+}
+
/**
* sysprof_memory_aid_new:
*
@@ -50,7 +82,7 @@ sysprof_memory_aid_new (void)
static void
sysprof_memory_aid_prepare (SysprofAid *self,
- SysprofProfiler *profiler)
+ SysprofProfiler *profiler)
{
#ifdef __linux__
g_autoptr(SysprofSource) source = NULL;
@@ -63,12 +95,128 @@ sysprof_memory_aid_prepare (SysprofAid *self,
#endif
}
+static gboolean
+discover_samples_cb (const SysprofCaptureFrame *frame,
+ gpointer user_data)
+{
+ Present *p = user_data;
+
+ g_assert (frame != NULL);
+ g_assert (p != NULL);
+
+ if (frame->type == SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC)
+ {
+ p->has_allocs = TRUE;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+sysprof_memory_aid_present_worker (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ Present *p = task_data;
+
+ g_assert (G_IS_TASK (task));
+ g_assert (SYSPROF_IS_MEMORY_AID (source_object));
+ g_assert (p != NULL);
+ g_assert (p->cursor != NULL);
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ sysprof_capture_cursor_foreach (p->cursor, discover_samples_cb, p);
+ g_task_return_boolean (task, TRUE);
+}
+
+static void
+sysprof_memory_aid_present_async (SysprofAid *aid,
+ SysprofCaptureReader *reader,
+ SysprofDisplay *display,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_MEMORY_ALLOC };
+ g_autoptr(SysprofCaptureCondition) condition = NULL;
+ g_autoptr(SysprofCaptureCursor) cursor = NULL;
+ g_autoptr(GTask) task = NULL;
+ Present present;
+
+ g_assert (SYSPROF_IS_MEMORY_AID (aid));
+ g_assert (reader != NULL);
+ g_assert (SYSPROF_IS_DISPLAY (display));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ condition = sysprof_capture_condition_new_where_type_in (1, types);
+ cursor = sysprof_capture_cursor_new (reader);
+ sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition));
+
+ present.cursor = g_steal_pointer (&cursor);
+ present.display = g_object_ref (display);
+
+ task = g_task_new (aid, cancellable, callback, user_data);
+ g_task_set_source_tag (task, sysprof_memory_aid_present_async);
+ g_task_set_task_data (task,
+ g_slice_dup (Present, &present),
+ present_free);
+ g_task_run_in_thread (task, sysprof_memory_aid_present_worker);
+}
+
+static gboolean
+sysprof_memory_aid_present_finish (SysprofAid *aid,
+ GAsyncResult *result,
+ GError **error)
+{
+ Present *p;
+
+ g_assert (SYSPROF_IS_MEMORY_AID (aid));
+ g_assert (G_IS_TASK (result));
+
+ p = g_task_get_task_data (G_TASK (result));
+
+ if (p->has_allocs)
+ {
+ SysprofVisualizerGroup *group;
+ SysprofPage *page;
+
+ group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP,
+ "can-focus", TRUE,
+ "has-page", TRUE,
+ "priority", -300,
+ "title", _("Memory"),
+ "visible", TRUE,
+ NULL);
+ sysprof_display_add_group (p->display, group);
+
+ page = g_object_new (SYSPROF_TYPE_MEMORY_PAGE,
+ "title", _("Memory"),
+ "vexpand", TRUE,
+ "visible", TRUE,
+ NULL);
+ sysprof_display_add_page (p->display, page);
+ sysprof_display_set_visible_page (p->display, page);
+
+ g_signal_connect_object (group,
+ "group-activated",
+ G_CALLBACK (on_group_activated_cb),
+ page,
+ 0);
+ }
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
static void
sysprof_memory_aid_class_init (SysprofMemoryAidClass *klass)
{
SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass);
aid_class->prepare = sysprof_memory_aid_prepare;
+ aid_class->present_async = sysprof_memory_aid_present_async;
+ aid_class->present_finish = sysprof_memory_aid_present_finish;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]