libsysprof-profile: add API to notify of process started

This will be used when we discover a process started like when the Perf
instrument gets PERF_RECORD_COMM.
This commit is contained in:
Christian Hergert
2023-05-30 17:27:33 -07:00
parent ee3a78433f
commit 2ac4ff692d
2 changed files with 43 additions and 7 deletions

View File

@ -44,14 +44,20 @@ struct _SysprofInstrumentClass
DexFuture *(*record) (SysprofInstrument *self,
SysprofRecording *recording,
GCancellable *cancellable);
DexFuture *(*process_started) (SysprofInstrument *self,
SysprofRecording *recording,
int pid);
};
DexFuture *_sysprof_instruments_acquire_policy (GPtrArray *instruments,
SysprofRecording *recording);
DexFuture *_sysprof_instruments_prepare (GPtrArray *instruments,
SysprofRecording *recording);
DexFuture *_sysprof_instruments_record (GPtrArray *instruments,
SysprofRecording *recording,
GCancellable *cancellable);
DexFuture *_sysprof_instruments_acquire_policy (GPtrArray *instruments,
SysprofRecording *recording);
DexFuture *_sysprof_instruments_prepare (GPtrArray *instruments,
SysprofRecording *recording);
DexFuture *_sysprof_instruments_record (GPtrArray *instruments,
SysprofRecording *recording,
GCancellable *cancellable);
DexFuture *_sysprof_instruments_process_started (GPtrArray *instruments,
SysprofRecording *recording,
int pid);
G_END_DECLS

View File

@ -174,6 +174,7 @@ _sysprof_instruments_record (GPtrArray *instruments,
g_return_val_if_fail (instruments != NULL, NULL);
g_return_val_if_fail (SYSPROF_IS_RECORDING (recording), NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
futures = g_ptr_array_new_with_free_func (dex_unref);
@ -190,3 +191,32 @@ _sysprof_instruments_record (GPtrArray *instruments,
return dex_future_allv ((DexFuture **)futures->pdata, futures->len);
}
DexFuture *
_sysprof_instruments_process_started (GPtrArray *instruments,
SysprofRecording *recording,
int pid)
{
g_autoptr(GPtrArray) futures = NULL;
g_return_val_if_fail (instruments != NULL, NULL);
g_return_val_if_fail (SYSPROF_IS_RECORDING (recording), NULL);
futures = g_ptr_array_new_with_free_func (dex_unref);
for (guint i = 0; i < instruments->len; i++)
{
SysprofInstrument *instrument = g_ptr_array_index (instruments, i);
if (SYSPROF_INSTRUMENT_GET_CLASS (instruments)->process_started == NULL)
continue;
g_ptr_array_add (futures,
SYSPROF_INSTRUMENT_GET_CLASS (instrument)->process_started (instrument, recording, pid));
}
if (futures->len == 0)
return dex_future_new_for_boolean (TRUE);
return dex_future_allv ((DexFuture **)futures->pdata, futures->len);
}