mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof: allow specifying phase for subprocess output
This is helpful in that you can specify which phase of the capture the process should be run so that it's less likely to show up on profiles.
This commit is contained in:
@ -160,6 +160,7 @@ endif
|
|||||||
|
|
||||||
libsysprof_enum_headers = [
|
libsysprof_enum_headers = [
|
||||||
'sysprof-callgraph.h',
|
'sysprof-callgraph.h',
|
||||||
|
'sysprof-recording.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
libsysprof_enums = gnome.mkenums_simple('sysprof-enums',
|
libsysprof_enums = gnome.mkenums_simple('sysprof-enums',
|
||||||
|
|||||||
@ -28,6 +28,13 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
#define SYSPROF_TYPE_RECORDING (sysprof_recording_get_type())
|
#define SYSPROF_TYPE_RECORDING (sysprof_recording_get_type())
|
||||||
|
|
||||||
|
typedef enum _SysprofRecordingPhase
|
||||||
|
{
|
||||||
|
SYSPROF_RECORDING_PHASE_PREPARE = 1,
|
||||||
|
SYSPROF_RECORDING_PHASE_RECORD,
|
||||||
|
SYSPROF_RECORDING_PHASE_AUGMENT,
|
||||||
|
} SysprofRecordingPhase;
|
||||||
|
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
G_DECLARE_FINAL_TYPE (SysprofRecording, sysprof_recording, SYSPROF, RECORDING, GObject)
|
G_DECLARE_FINAL_TYPE (SysprofRecording, sysprof_recording, SYSPROF, RECORDING, GObject)
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "sysprof-enums.h"
|
||||||
#include "sysprof-instrument-private.h"
|
#include "sysprof-instrument-private.h"
|
||||||
#include "sysprof-recording-private.h"
|
#include "sysprof-recording-private.h"
|
||||||
#include "sysprof-subprocess-output.h"
|
#include "sysprof-subprocess-output.h"
|
||||||
@ -35,6 +36,8 @@ struct _SysprofSubprocessOutput
|
|||||||
|
|
||||||
SysprofRecording *recording;
|
SysprofRecording *recording;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
|
|
||||||
|
SysprofRecordingPhase phase;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _SysprofSubprocessOutputClass
|
struct _SysprofSubprocessOutputClass
|
||||||
@ -47,6 +50,7 @@ enum {
|
|||||||
PROP_COMMAND_ARGV,
|
PROP_COMMAND_ARGV,
|
||||||
PROP_COMMAND_ENVIRON,
|
PROP_COMMAND_ENVIRON,
|
||||||
PROP_COMMAND_CWD,
|
PROP_COMMAND_CWD,
|
||||||
|
PROP_PHASE,
|
||||||
PROP_STDOUT_PATH,
|
PROP_STDOUT_PATH,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
@ -146,6 +150,9 @@ sysprof_subprocess_output_record (SysprofInstrument *instrument,
|
|||||||
g_assert (SYSPROF_IS_RECORDING (recording));
|
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||||
g_assert (G_IS_CANCELLABLE (cancellable));
|
g_assert (G_IS_CANCELLABLE (cancellable));
|
||||||
|
|
||||||
|
if (self->phase != SYSPROF_RECORDING_PHASE_RECORD)
|
||||||
|
return dex_future_new_for_boolean (TRUE);
|
||||||
|
|
||||||
g_set_object (&self->recording, recording);
|
g_set_object (&self->recording, recording);
|
||||||
g_set_object (&self->cancellable, cancellable);
|
g_set_object (&self->cancellable, cancellable);
|
||||||
|
|
||||||
@ -155,6 +162,46 @@ sysprof_subprocess_output_record (SysprofInstrument *instrument,
|
|||||||
g_object_unref);
|
g_object_unref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DexFuture *
|
||||||
|
sysprof_subprocess_output_prepare (SysprofInstrument *instrument,
|
||||||
|
SysprofRecording *recording)
|
||||||
|
{
|
||||||
|
SysprofSubprocessOutput *self = (SysprofSubprocessOutput *)instrument;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_IS_SUBPROCESS_OUTPUT (self));
|
||||||
|
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||||
|
|
||||||
|
if (self->phase != SYSPROF_RECORDING_PHASE_PREPARE)
|
||||||
|
return dex_future_new_for_boolean (TRUE);
|
||||||
|
|
||||||
|
g_set_object (&self->recording, recording);
|
||||||
|
|
||||||
|
return dex_scheduler_spawn (NULL, 0,
|
||||||
|
sysprof_subprocess_output_record_fiber,
|
||||||
|
g_object_ref (self),
|
||||||
|
g_object_unref);
|
||||||
|
}
|
||||||
|
|
||||||
|
static DexFuture *
|
||||||
|
sysprof_subprocess_output_augment (SysprofInstrument *instrument,
|
||||||
|
SysprofRecording *recording)
|
||||||
|
{
|
||||||
|
SysprofSubprocessOutput *self = (SysprofSubprocessOutput *)instrument;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_IS_SUBPROCESS_OUTPUT (self));
|
||||||
|
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||||
|
|
||||||
|
if (self->phase != SYSPROF_RECORDING_PHASE_AUGMENT)
|
||||||
|
return dex_future_new_for_boolean (TRUE);
|
||||||
|
|
||||||
|
g_set_object (&self->recording, recording);
|
||||||
|
|
||||||
|
return dex_scheduler_spawn (NULL, 0,
|
||||||
|
sysprof_subprocess_output_record_fiber,
|
||||||
|
g_object_ref (self),
|
||||||
|
g_object_unref);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sysprof_subprocess_output_dispose (GObject *object)
|
sysprof_subprocess_output_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
@ -192,6 +239,10 @@ sysprof_subprocess_output_get_property (GObject *object,
|
|||||||
g_value_set_boxed (value, sysprof_subprocess_output_get_command_environ (self));
|
g_value_set_boxed (value, sysprof_subprocess_output_get_command_environ (self));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_PHASE:
|
||||||
|
g_value_set_enum (value, sysprof_subprocess_output_get_phase (self));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_STDOUT_PATH:
|
case PROP_STDOUT_PATH:
|
||||||
g_value_set_string (value, sysprof_subprocess_output_get_stdout_path (self));
|
g_value_set_string (value, sysprof_subprocess_output_get_stdout_path (self));
|
||||||
break;
|
break;
|
||||||
@ -223,6 +274,10 @@ sysprof_subprocess_output_set_property (GObject *object,
|
|||||||
sysprof_subprocess_output_set_command_environ (self, g_value_get_boxed (value));
|
sysprof_subprocess_output_set_command_environ (self, g_value_get_boxed (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_PHASE:
|
||||||
|
sysprof_subprocess_output_set_phase (self, g_value_get_enum (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_STDOUT_PATH:
|
case PROP_STDOUT_PATH:
|
||||||
sysprof_subprocess_output_set_stdout_path (self, g_value_get_string (value));
|
sysprof_subprocess_output_set_stdout_path (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
@ -242,7 +297,9 @@ sysprof_subprocess_output_class_init (SysprofSubprocessOutputClass *klass)
|
|||||||
object_class->get_property = sysprof_subprocess_output_get_property;
|
object_class->get_property = sysprof_subprocess_output_get_property;
|
||||||
object_class->set_property = sysprof_subprocess_output_set_property;
|
object_class->set_property = sysprof_subprocess_output_set_property;
|
||||||
|
|
||||||
|
instrument_class->prepare = sysprof_subprocess_output_prepare;
|
||||||
instrument_class->record = sysprof_subprocess_output_record;
|
instrument_class->record = sysprof_subprocess_output_record;
|
||||||
|
instrument_class->augment = sysprof_subprocess_output_augment;
|
||||||
|
|
||||||
properties[PROP_COMMAND_CWD] =
|
properties[PROP_COMMAND_CWD] =
|
||||||
g_param_spec_string ("command-cwd", NULL, NULL,
|
g_param_spec_string ("command-cwd", NULL, NULL,
|
||||||
@ -259,6 +316,12 @@ sysprof_subprocess_output_class_init (SysprofSubprocessOutputClass *klass)
|
|||||||
G_TYPE_STRV,
|
G_TYPE_STRV,
|
||||||
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
properties[PROP_PHASE] =
|
||||||
|
g_param_spec_enum ("phase", NULL, NULL,
|
||||||
|
SYSPROF_TYPE_RECORDING_PHASE,
|
||||||
|
SYSPROF_RECORDING_PHASE_PREPARE,
|
||||||
|
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
properties[PROP_STDOUT_PATH] =
|
properties[PROP_STDOUT_PATH] =
|
||||||
g_param_spec_string ("stdout-path", NULL, NULL,
|
g_param_spec_string ("stdout-path", NULL, NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@ -270,6 +333,7 @@ sysprof_subprocess_output_class_init (SysprofSubprocessOutputClass *klass)
|
|||||||
static void
|
static void
|
||||||
sysprof_subprocess_output_init (SysprofSubprocessOutput *self)
|
sysprof_subprocess_output_init (SysprofSubprocessOutput *self)
|
||||||
{
|
{
|
||||||
|
self->phase = SYSPROF_RECORDING_PHASE_PREPARE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
@ -365,3 +429,25 @@ sysprof_subprocess_output_set_stdout_path (SysprofSubprocessOutput *self,
|
|||||||
if (g_set_str (&self->stdout_path, stdout_path))
|
if (g_set_str (&self->stdout_path, stdout_path))
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STDOUT_PATH]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STDOUT_PATH]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SysprofRecordingPhase
|
||||||
|
sysprof_subprocess_output_get_phase (SysprofSubprocessOutput *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (SYSPROF_IS_SUBPROCESS_OUTPUT (self), 0);
|
||||||
|
|
||||||
|
return self->phase;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysprof_subprocess_output_set_phase (SysprofSubprocessOutput *self,
|
||||||
|
SysprofRecordingPhase phase)
|
||||||
|
{
|
||||||
|
g_return_if_fail (phase > 0);
|
||||||
|
g_return_if_fail (phase <= SYSPROF_RECORDING_PHASE_AUGMENT);
|
||||||
|
|
||||||
|
if (phase == self->phase)
|
||||||
|
return;
|
||||||
|
|
||||||
|
self->phase = phase;
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PHASE]);
|
||||||
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sysprof-instrument.h"
|
#include "sysprof-instrument.h"
|
||||||
|
#include "sysprof-recording.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -35,6 +36,11 @@ typedef struct _SysprofSubprocessOutputClass SysprofSubprocessOutputClass;
|
|||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
GType sysprof_subprocess_output_get_type (void) G_GNUC_CONST;
|
GType sysprof_subprocess_output_get_type (void) G_GNUC_CONST;
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
SysprofRecordingPhase sysprof_subprocess_output_get_phase (SysprofSubprocessOutput *self);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
void sysprof_subprocess_output_set_phase (SysprofSubprocessOutput *self,
|
||||||
|
SysprofRecordingPhase phase);
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
SysprofInstrument *sysprof_subprocess_output_new (void);
|
SysprofInstrument *sysprof_subprocess_output_new (void);
|
||||||
SYSPROF_AVAILABLE_IN_ALL
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
const char *sysprof_subprocess_output_get_stdout_path (SysprofSubprocessOutput *self);
|
const char *sysprof_subprocess_output_get_stdout_path (SysprofSubprocessOutput *self);
|
||||||
|
|||||||
Reference in New Issue
Block a user