diff options
author | Philip Chimento <philip.chimento@gmail.com> | 2020-09-20 04:34:36 +0000 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2020-09-20 04:34:36 +0000 |
commit | 051a841bdc72481e5f877f76316601cd8f704796 (patch) | |
tree | 871ddc4228ffb912a5d1b7988b45366ad25f12f2 | |
parent | 9f0268a0f88f4553cc05d3432a09b9c9273e61df (diff) | |
parent | 607f9aa66192d4955f7daf5906b5053c30ce8ff2 (diff) | |
download | gjs-051a841bdc72481e5f877f76316601cd8f704796.tar.gz |
Merge branch 'gbsneto/external-capture-writer' into 'master'
profiler: Support external SysprofCaptureWriters
See merge request GNOME/gjs!489
-rw-r--r-- | gjs/profiler.cpp | 31 | ||||
-rw-r--r-- | gjs/profiler.h | 3 |
2 files changed, 33 insertions, 1 deletions
diff --git a/gjs/profiler.cpp b/gjs/profiler.cpp index c5113bec..d7c90ef5 100644 --- a/gjs/profiler.cpp +++ b/gjs/profiler.cpp @@ -105,6 +105,8 @@ struct _GjsProfiler { /* Buffers and writes our sampled stacks */ SysprofCaptureWriter* capture; GSource* periodic_flush; + + SysprofCaptureWriter* target_capture; #endif /* ENABLE_PROFILER */ /* The filename to write to */ @@ -259,6 +261,7 @@ _gjs_profiler_free(GjsProfiler *self) #ifdef ENABLE_PROFILER g_clear_pointer(&self->capture, sysprof_capture_writer_unref); g_clear_pointer(&self->periodic_flush, g_source_destroy); + g_clear_pointer(&self->target_capture, sysprof_capture_writer_unref); if (self->fd != -1) close(self->fd); @@ -429,7 +432,9 @@ gjs_profiler_start(GjsProfiler *self) struct itimerspec its = { 0 }; struct itimerspec old_its; - if (self->fd != -1) { + if (self->target_capture) { + self->capture = sysprof_capture_writer_ref(self->target_capture); + } else if (self->fd != -1) { self->capture = sysprof_capture_writer_new_from_fd(self->fd, 0); self->fd = -1; } else { @@ -673,6 +678,30 @@ gjs_profiler_chain_signal(GjsContext *context, } /** + * gjs_profiler_set_capture_writer: + * @self: A #GjsProfiler + * @capture: (nullable): A #SysprofCaptureWriter + * + * Set the capture writer to which profiling data is written when the @self + * is stopped. + */ +void gjs_profiler_set_capture_writer(GjsProfiler* self, gpointer capture) { + g_return_if_fail(self); + g_return_if_fail(!self->running); + +#ifdef ENABLE_PROFILER + g_clear_pointer(&self->target_capture, sysprof_capture_writer_unref); + self->target_capture = + capture ? sysprof_capture_writer_ref( + reinterpret_cast<SysprofCaptureWriter*>(capture)) + : NULL; +#else + // Unused in the no-profiler case + (void)capture; +#endif +} + +/** * gjs_profiler_set_filename: * @self: A #GjsProfiler * @filename: string containing a filename diff --git a/gjs/profiler.h b/gjs/profiler.h index d3518b87..fe8bc509 100644 --- a/gjs/profiler.h +++ b/gjs/profiler.h @@ -43,6 +43,9 @@ GJS_EXPORT GType gjs_profiler_get_type(void); GJS_EXPORT +void gjs_profiler_set_capture_writer(GjsProfiler* self, void* capture); + +GJS_EXPORT void gjs_profiler_set_filename(GjsProfiler *self, const char *filename); GJS_EXPORT |