From 31547de795da44f0c157fdb258b36a3768eca917 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 28 Aug 2023 17:24:27 -0700 Subject: [PATCH] libsysprof: rename follow_fork() to follow_process() This is more of what we want to be doing anyway, we don't care about all the forks in existence. Additionally, include the comm[] with the pid so that instruments can take action based on it. --- src/libsysprof/sysprof-instrument-private.h | 6 ++++-- src/libsysprof/sysprof-instrument.c | 10 ++++++---- src/libsysprof/sysprof-linux-instrument.c | 3 ++- src/libsysprof/sysprof-recording-private.h | 5 +++-- src/libsysprof/sysprof-recording.c | 7 ++++--- src/libsysprof/sysprof-sampler.c | 19 +++++++++++-------- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/libsysprof/sysprof-instrument-private.h b/src/libsysprof/sysprof-instrument-private.h index 9474ab9c..c665f38e 100644 --- a/src/libsysprof/sysprof-instrument-private.h +++ b/src/libsysprof/sysprof-instrument-private.h @@ -48,7 +48,8 @@ struct _SysprofInstrumentClass SysprofRecording *recording); DexFuture *(*process_started) (SysprofInstrument *self, SysprofRecording *recording, - int pid); + int pid, + const char *comm); }; DexFuture *_sysprof_instruments_acquire_policy (GPtrArray *instruments, @@ -62,6 +63,7 @@ DexFuture *_sysprof_instruments_augment (GPtrArray *instruments, SysprofRecording *recording); DexFuture *_sysprof_instruments_process_started (GPtrArray *instruments, SysprofRecording *recording, - int pid); + int pid, + const char *comm); G_END_DECLS diff --git a/src/libsysprof/sysprof-instrument.c b/src/libsysprof/sysprof-instrument.c index e3254c90..404d78ff 100644 --- a/src/libsysprof/sysprof-instrument.c +++ b/src/libsysprof/sysprof-instrument.c @@ -126,13 +126,14 @@ _sysprof_instrument_augment (SysprofInstrument *self, static DexFuture * _sysprof_instrument_process_started (SysprofInstrument *self, SysprofRecording *recording, - int pid) + int pid, + const char *comm) { g_assert (SYSPROF_IS_INSTRUMENT (self)); g_assert (SYSPROF_IS_RECORDING (recording)); if (SYSPROF_INSTRUMENT_GET_CLASS (self)->process_started) - return SYSPROF_INSTRUMENT_GET_CLASS (self)->process_started (self, recording, pid); + return SYSPROF_INSTRUMENT_GET_CLASS (self)->process_started (self, recording, pid, comm); return dex_future_new_for_boolean (TRUE); } @@ -288,7 +289,8 @@ _sysprof_instruments_augment (GPtrArray *instruments, DexFuture * _sysprof_instruments_process_started (GPtrArray *instruments, SysprofRecording *recording, - int pid) + int pid, + const char *comm) { g_autoptr(GPtrArray) futures = NULL; @@ -301,7 +303,7 @@ _sysprof_instruments_process_started (GPtrArray *instruments, { SysprofInstrument *instrument = g_ptr_array_index (instruments, i); - g_ptr_array_add (futures, _sysprof_instrument_process_started (instrument, recording, pid)); + g_ptr_array_add (futures, _sysprof_instrument_process_started (instrument, recording, pid, comm)); } if (futures->len == 0) diff --git a/src/libsysprof/sysprof-linux-instrument.c b/src/libsysprof/sysprof-linux-instrument.c index ef2f3b6a..1225f4b2 100644 --- a/src/libsysprof/sysprof-linux-instrument.c +++ b/src/libsysprof/sysprof-linux-instrument.c @@ -294,7 +294,8 @@ sysprof_linux_instrument_prepare (SysprofInstrument *instrument, static DexFuture * sysprof_linux_instrument_process_started (SysprofInstrument *instrument, SysprofRecording *recording, - int pid) + int pid, + const char *comm) { g_assert (SYSPROF_IS_INSTRUMENT (instrument)); g_assert (SYSPROF_IS_RECORDING (recording)); diff --git a/src/libsysprof/sysprof-recording-private.h b/src/libsysprof/sysprof-recording-private.h index a77f8eee..15fb7f16 100644 --- a/src/libsysprof/sysprof-recording-private.h +++ b/src/libsysprof/sysprof-recording-private.h @@ -95,8 +95,9 @@ void _sysprof_recording_add_file_data (SysprofRecording *s const char *contents, gssize length, gboolean compress); -void _sysprof_recording_follow_fork (SysprofRecording *self, - int pid); +void _sysprof_recording_follow_process(SysprofRecording *self, + int pid, + const char *comm); void _sysprof_recording_diagnostic (SysprofRecording *self, const char *domain, const char *format, diff --git a/src/libsysprof/sysprof-recording.c b/src/libsysprof/sysprof-recording.c index 163085ff..040c2d7a 100644 --- a/src/libsysprof/sysprof-recording.c +++ b/src/libsysprof/sysprof-recording.c @@ -904,11 +904,12 @@ sysprof_recording_get_subprocess (SysprofRecording *self) } void -_sysprof_recording_follow_fork (SysprofRecording *self, - int pid) +_sysprof_recording_follow_process (SysprofRecording *self, + int pid, + const char *comm) { g_return_if_fail (SYSPROF_IS_RECORDING (self)); g_return_if_fail (pid > 0); - dex_future_disown (_sysprof_instruments_process_started (self->instruments, self, pid)); + dex_future_disown (_sysprof_instruments_process_started (self->instruments, self, pid, comm)); } diff --git a/src/libsysprof/sysprof-sampler.c b/src/libsysprof/sysprof-sampler.c index 6948cfa6..d86d7029 100644 --- a/src/libsysprof/sysprof-sampler.c +++ b/src/libsysprof/sysprof-sampler.c @@ -122,11 +122,17 @@ sysprof_sampler_perf_event_stream_cb (const SysprofPerfEvent *event, memcpy (&time, event->comm.comm + offset, sizeof time); if (event->comm.pid == event->comm.tid) - sysprof_capture_writer_add_process (writer, - time, - cpu, - event->comm.pid, - event->comm.comm); + { + sysprof_capture_writer_add_process (writer, + time, + cpu, + event->comm.pid, + event->comm.comm); + + _sysprof_recording_follow_process (recording, + event->comm.pid, + event->comm.comm); + } break; @@ -148,9 +154,6 @@ sysprof_sampler_perf_event_stream_cb (const SysprofPerfEvent *event, cpu, event->fork.ptid, event->fork.tid); - - _sysprof_recording_follow_fork (recording, event->fork.tid); - break; case PERF_RECORD_LOST: