From 5746add9c65d7049bebb72dcc1d97ce33eb25091 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 2 Jun 2023 16:15:27 -0700 Subject: [PATCH] libsysprof-profile: give Profiler a spawnable And pass it along to the recording so that it can manage spawning the subprocess during the record loop. --- src/libsysprof-profile/sysprof-profiler.c | 60 ++++++++++++++++++- src/libsysprof-profile/sysprof-profiler.h | 6 ++ .../sysprof-recording-private.h | 1 + src/libsysprof-profile/sysprof-recording.c | 32 ++-------- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/libsysprof-profile/sysprof-profiler.c b/src/libsysprof-profile/sysprof-profiler.c index 0a93432d..ab3c133e 100644 --- a/src/libsysprof-profile/sysprof-profiler.c +++ b/src/libsysprof-profile/sysprof-profiler.c @@ -30,20 +30,29 @@ struct _SysprofProfiler { - GObject parent_instance; - GPtrArray *instruments; + GObject parent_instance; + GPtrArray *instruments; + SysprofSpawnable *spawnable; }; enum { PROP_0, + PROP_SPAWNABLE, N_PROPS }; +static GParamSpec *properties [N_PROPS]; + G_DEFINE_FINAL_TYPE (SysprofProfiler, sysprof_profiler, G_TYPE_OBJECT) static void sysprof_profiler_finalize (GObject *object) { + SysprofProfiler *self = (SysprofProfiler *)object; + + g_clear_pointer (&self->instruments, g_ptr_array_unref); + g_clear_object (&self->spawnable); + G_OBJECT_CLASS (sysprof_profiler_parent_class)->finalize (object); } @@ -53,8 +62,14 @@ sysprof_profiler_get_property (GObject *object, GValue *value, GParamSpec *pspec) { + SysprofProfiler *self = SYSPROF_PROFILER (object); + switch (prop_id) { + case PROP_SPAWNABLE: + g_value_set_object (value, sysprof_profiler_get_spawnable (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -66,8 +81,14 @@ sysprof_profiler_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { + SysprofProfiler *self = SYSPROF_PROFILER (object); + switch (prop_id) { + case PROP_SPAWNABLE: + sysprof_profiler_set_spawnable (self, g_value_get_object (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -81,6 +102,13 @@ sysprof_profiler_class_init (SysprofProfilerClass *klass) object_class->finalize = sysprof_profiler_finalize; object_class->get_property = sysprof_profiler_get_property; object_class->set_property = sysprof_profiler_set_property; + + properties [PROP_SPAWNABLE] = + g_param_spec_object ("spawnable", NULL, NULL, + SYSPROF_TYPE_SPAWNABLE, + (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, N_PROPS, properties); } static void @@ -139,6 +167,7 @@ sysprof_profiler_record_async (SysprofProfiler *self, g_task_set_source_tag (task, sysprof_profiler_record_async); recording = _sysprof_recording_new (writer, + self->spawnable, (SysprofInstrument **)self->instruments->pdata, self->instruments->len); @@ -169,3 +198,30 @@ sysprof_profiler_record_finish (SysprofProfiler *self, return g_task_propagate_pointer (G_TASK (result), error); } + +/** + * sysprof_profiler_get_spawnable: + * @self: a #SysprofProfiler + * + * Gets the #SysprofProfiler:spawnable property. + * + * Returns: (nullable) (transfer none): a #SysprofSpawnable or %NULL + */ +SysprofSpawnable * +sysprof_profiler_get_spawnable (SysprofProfiler *self) +{ + g_return_val_if_fail (SYSPROF_IS_PROFILER (self), NULL); + + return self->spawnable; +} + +void +sysprof_profiler_set_spawnable (SysprofProfiler *self, + SysprofSpawnable *spawnable) +{ + g_return_if_fail (SYSPROF_IS_PROFILER (self)); + g_return_if_fail (!spawnable || SYSPROF_IS_SPAWNABLE (spawnable)); + + if (g_set_object (&self->spawnable, spawnable)) + g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SPAWNABLE]); +} diff --git a/src/libsysprof-profile/sysprof-profiler.h b/src/libsysprof-profile/sysprof-profiler.h index a8be07f5..42fec019 100644 --- a/src/libsysprof-profile/sysprof-profiler.h +++ b/src/libsysprof-profile/sysprof-profiler.h @@ -26,6 +26,7 @@ #include "sysprof-instrument.h" #include "sysprof-recording.h" +#include "sysprof-spawnable.h" G_BEGIN_DECLS @@ -37,6 +38,11 @@ G_DECLARE_FINAL_TYPE (SysprofProfiler, sysprof_profiler, SYSPROF, PROFILER, GObj SYSPROF_AVAILABLE_IN_ALL SysprofProfiler *sysprof_profiler_new (void); SYSPROF_AVAILABLE_IN_ALL +SysprofSpawnable *sysprof_profiler_get_spawnable (SysprofProfiler *self); +SYSPROF_AVAILABLE_IN_ALL +void sysprof_profiler_set_spawnable (SysprofProfiler *self, + SysprofSpawnable *spawnable); +SYSPROF_AVAILABLE_IN_ALL void sysprof_profiler_add_instrument (SysprofProfiler *self, SysprofInstrument *instrument); SYSPROF_AVAILABLE_IN_ALL diff --git a/src/libsysprof-profile/sysprof-recording-private.h b/src/libsysprof-profile/sysprof-recording-private.h index 9e553ec0..88a54626 100644 --- a/src/libsysprof-profile/sysprof-recording-private.h +++ b/src/libsysprof-profile/sysprof-recording-private.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS SysprofRecording *_sysprof_recording_new (SysprofCaptureWriter *writer, + SysprofSpawnable *spawnable, SysprofInstrument **instruments, guint n_instruments); void _sysprof_recording_start (SysprofRecording *self); diff --git a/src/libsysprof-profile/sysprof-recording.c b/src/libsysprof-profile/sysprof-recording.c index 8ed6a816..1cfc94c7 100644 --- a/src/libsysprof-profile/sysprof-recording.c +++ b/src/libsysprof-profile/sysprof-recording.c @@ -164,45 +164,18 @@ sysprof_recording_finalize (GObject *object) g_clear_pointer (&self->writer, sysprof_capture_writer_unref); g_clear_pointer (&self->instruments, g_ptr_array_unref); + g_clear_object (&self->spawnable); dex_clear (&self->fiber); G_OBJECT_CLASS (sysprof_recording_parent_class)->finalize (object); } -static void -sysprof_recording_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_recording_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - static void sysprof_recording_class_init (SysprofRecordingClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = sysprof_recording_finalize; - object_class->get_property = sysprof_recording_get_property; - object_class->set_property = sysprof_recording_set_property; } static void @@ -214,6 +187,7 @@ sysprof_recording_init (SysprofRecording *self) SysprofRecording * _sysprof_recording_new (SysprofCaptureWriter *writer, + SysprofSpawnable *spawnable, SysprofInstrument **instruments, guint n_instruments) { @@ -224,6 +198,8 @@ _sysprof_recording_new (SysprofCaptureWriter *writer, self = g_object_new (SYSPROF_TYPE_RECORDING, NULL); self->writer = sysprof_capture_writer_ref (writer); + g_set_object (&self->spawnable, spawnable); + for (guint i = 0; i < n_instruments; i++) g_ptr_array_add (self->instruments, g_object_ref (instruments[i]));