[mutter/gbsneto/tracing] profiler: Support setting output filename
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/tracing] profiler: Support setting output filename
- Date: Fri, 12 Apr 2019 19:33:37 +0000 (UTC)
commit a89f06d247f2b7b034e9a4fd4e3f686e53293493
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Apr 12 15:34:56 2019 -0300
profiler: Support setting output filename
So we can have some control over where the file
will be saved.
cogl/cogl/cogl-trace.c | 89 +++++++++++++++++++++++++++++++++++---------
cogl/cogl/cogl-trace.h | 9 +++--
src/backends/meta-profiler.c | 11 ++++--
tools/mutter-profiler | 7 +++-
4 files changed, 91 insertions(+), 25 deletions(-)
---
diff --git a/cogl/cogl/cogl-trace.c b/cogl/cogl/cogl-trace.c
index 2b88cbe88..78d62e46c 100644
--- a/cogl/cogl/cogl-trace.c
+++ b/cogl/cogl/cogl-trace.c
@@ -29,23 +29,48 @@
#define COGL_TRACE_OUTPUT_FILE "cogl-trace-sp-capture.syscap"
+typedef struct
+{
+ int fd;
+ char *filename;
+} TraceData;
+
+static void
+trace_data_free (gpointer user_data)
+{
+ TraceData *data = user_data;
+
+ data->fd = -1;
+ g_clear_pointer (&data->filename, g_free);
+ g_free (data);
+}
+
__thread CoglTraceThreadContext *cogl_trace_thread_context;
CoglTraceContext *cogl_trace_context;
GMutex cogl_trace_mutex;
static CoglTraceContext *
-cogl_trace_context_new (int fd)
+cogl_trace_context_new (int fd,
+ const gchar *filename)
{
CoglTraceContext *context;
SpCaptureWriter *writer;
- g_debug ("Initializing trace context with fd=%d", fd);
-
- if (fd == -1)
- writer = sp_capture_writer_new (COGL_TRACE_OUTPUT_FILE,
- 4096 * 4);
+ if (fd != -1)
+ {
+ g_debug ("Initializing trace context with fd=%d", fd);
+ writer = sp_capture_writer_new_from_fd (fd, 4096 * 4);
+ }
+ else if (filename != NULL)
+ {
+ g_debug ("Initializing trace context with filename='%s'", filename);
+ writer = sp_capture_writer_new (filename, 4096 * 4);
+ }
else
- writer = sp_capture_writer_new_from_fd (fd, 4096 * 4);
+ {
+ g_debug ("Initializing trace context with default dilename");
+ writer = sp_capture_writer_new (COGL_TRACE_OUTPUT_FILE, 4096 * 4);
+ }
context = g_new0 (CoglTraceContext, 1);
context->writer = writer;
@@ -60,13 +85,13 @@ cogl_trace_context_free (CoglTraceContext *trace_context)
}
static void
-ensure_trace_context (int fd)
+ensure_trace_context (TraceData *data)
{
static GMutex mutex;
g_mutex_lock (&mutex);
if (!cogl_trace_context)
- cogl_trace_context = cogl_trace_context_new (fd);
+ cogl_trace_context = cogl_trace_context_new (data->fd, data->filename);
g_mutex_unlock (&mutex);
}
@@ -95,10 +120,10 @@ cogl_trace_thread_context_new (void)
static gboolean
enable_tracing_idle_callback (gpointer user_data)
{
- int fd = GPOINTER_TO_INT (user_data);
+ TraceData *data = user_data;
ensure_sigpipe_ignored ();
- ensure_trace_context (fd);
+ ensure_trace_context (data);
if (cogl_trace_thread_context)
{
@@ -144,20 +169,43 @@ disable_tracing_idle_callback (gpointer user_data)
return G_SOURCE_REMOVE;
}
-void
-cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
- int fd)
+static void
+set_tracing_enabled_on_thread (GMainContext *main_context,
+ int fd,
+ const char *filename)
{
+ TraceData *data;
GSource *source;
+ data = g_new0 (TraceData, 1);
+ data->fd = fd;
+ data->filename = strdup (filename);
+
source = g_idle_source_new ();
- g_source_set_callback (source, enable_tracing_idle_callback, GINT_TO_POINTER (fd), NULL);
+ g_source_set_callback (source,
+ enable_tracing_idle_callback,
+ data,
+ trace_data_free);
g_source_attach (source, main_context);
g_source_unref (source);
}
+void
+cogl_set_tracing_enabled_on_thread_with_fd (GMainContext *main_context,
+ int fd)
+{
+ set_tracing_enabled_on_thread (main_context, fd, NULL);
+}
+
+void
+cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
+ const char *filename)
+{
+ set_tracing_enabled_on_thread (main_context, -1, filename);
+}
+
void
cogl_set_tracing_disabled_on_thread (GMainContext *main_context)
{
@@ -177,8 +225,15 @@ cogl_set_tracing_disabled_on_thread (GMainContext *main_context)
#include <stdio.h>
void
-cogl_set_tracing_enabled_on_thread (void *data,
- int fd)
+cogl_set_tracing_enabled_on_thread_with_fd (void *data,
+ int fd)
+{
+ fprintf (stderr, "Tracing not enabled");
+}
+
+void
+cogl_set_tracing_enabled_on_thread (void *data,
+ const char *filename)
{
fprintf (stderr, "Tracing not enabled");
}
diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h
index 8b2c1ad95..574926283 100644
--- a/cogl/cogl/cogl-trace.h
+++ b/cogl/cogl/cogl-trace.h
@@ -51,8 +51,11 @@ extern __thread CoglTraceThreadContext *cogl_trace_thread_context;
extern CoglTraceContext *cogl_trace_context;
extern GMutex cogl_trace_mutex;
+void cogl_set_tracing_enabled_on_thread_with_fd (GMainContext *main_context,
+ int fd);
+
void cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
- int fd);
+ const char *filename);
void cogl_set_tracing_disabled_on_thread (GMainContext *main_context);
@@ -129,8 +132,8 @@ cogl_auto_trace_end_helper (CoglTraceHead **head)
#define COGL_TRACE_END(Name) (void) 0
#define COGL_TRACE_BEGIN_SCOPED(Name) (void) 0
-void cogl_set_tracing_enabled_on_thread (void *data, int fd);
-
+void cogl_set_tracing_enabled_on_thread_with_fd (void *data, int fd);
+void cogl_set_tracing_enabled_on_thread (void *data, const char *filename);
void cogl_set_tracing_disabled_on_thread (void *data);
#endif /* HAVE_TRACING */
diff --git a/src/backends/meta-profiler.c b/src/backends/meta-profiler.c
index 73f23449e..b009c1d65 100644
--- a/src/backends/meta-profiler.c
+++ b/src/backends/meta-profiler.c
@@ -112,8 +112,8 @@ handle_capture (MetaDBusSysprofCapturer *capturer,
return TRUE;
}
- cogl_set_tracing_enabled_on_thread (g_main_context_default (),
- capture_pipe[1]);
+ cogl_set_tracing_enabled_on_thread_with_fd (g_main_context_default (),
+ capture_pipe[1]);
fd_list = g_unix_fd_list_new ();
fd_index = g_unix_fd_list_append (fd_list, capture_pipe[0], &error);
@@ -128,7 +128,12 @@ handle_capture (MetaDBusSysprofCapturer *capturer,
}
else if (self->capture_timeout_id == 0)
{
- cogl_set_tracing_enabled_on_thread (g_main_context_default (), -1);
+ g_autofree char *output_filename = NULL;
+
+ g_variant_lookup (parameters, "output-filename", "s", &output_filename);
+
+ cogl_set_tracing_enabled_on_thread (g_main_context_default (),
+ output_filename);
self->capture_timeout_id =
g_timeout_add_seconds (timeout, on_capture_timeout_cb, self);
diff --git a/tools/mutter-profiler b/tools/mutter-profiler
index 397e4e97c..3d67eda88 100755
--- a/tools/mutter-profiler
+++ b/tools/mutter-profiler
@@ -35,7 +35,7 @@ def setup_logging(enable_debug):
log.setLevel(log_level)
-def start_profiler(seconds):
+def start_profiler(seconds, filename):
"""
Calls the D-Bus method for profiling with the passed number
of seconds. The result is printed for debugging purposes but
@@ -53,6 +53,7 @@ def start_profiler(seconds):
None)
params = GLib.Variant('(a{sv})', ({
+ 'output-filename': GLib.Variant('s', filename),
'timeout': GLib.Variant('u', seconds),
}, ))
log.debug('Sending parameters: {}'.format(params))
@@ -73,13 +74,15 @@ def main():
description='Capture Mutter profiling data with Sysprof')
parser.add_argument('seconds', type=int,
help='Timeout (in seconds) to capture data')
+ parser.add_argument('-o', '--output', type=str,
+ help='Output file name')
parser.add_argument('-d', '--debug', action='store_true',
help='Show debug messages')
args = parser.parse_args()
setup_logging(args.debug)
- start_profiler(args.seconds)
+ start_profiler(args.seconds, args.output)
return 0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]