From e8531ebe58bab16b09d2b312609668016834f908 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 4 May 2023 10:02:53 -0700 Subject: [PATCH] libsysprof-analyze: add batch getter for stack addresses This allows caching the interface vfunc to reduce the overhead of accessing each instruction pointer in the array. --- .../sysprof-document-traceable.c | 21 +++++++++++++++++++ .../sysprof-document-traceable.h | 10 ++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-document-traceable.c b/src/libsysprof-analyze/sysprof-document-traceable.c index 6525be20..8bf4f250 100644 --- a/src/libsysprof-analyze/sysprof-document-traceable.c +++ b/src/libsysprof-analyze/sysprof-document-traceable.c @@ -57,3 +57,24 @@ sysprof_document_traceable_get_stack_address (SysprofDocumentTraceable *self, { return SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_stack_address (self, position); } + +guint +sysprof_document_traceable_get_stack_addresses (SysprofDocumentTraceable *self, + guint64 *addresses, + guint n_addresses) +{ + guint64 (*decoder) (SysprofDocumentTraceable *, guint); + + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_TRACEABLE (self), 0); + + if (addresses == NULL || n_addresses == 0) + return 0; + + decoder = SYSPROF_DOCUMENT_TRACEABLE_GET_IFACE (self)->get_stack_address; + n_addresses = MIN (n_addresses, sysprof_document_traceable_get_stack_depth (self)); + + for (guint i = 0; i < n_addresses; i++) + addresses[i] = decoder (self, i); + + return n_addresses; +} diff --git a/src/libsysprof-analyze/sysprof-document-traceable.h b/src/libsysprof-analyze/sysprof-document-traceable.h index ad77117e..904ac65e 100644 --- a/src/libsysprof-analyze/sysprof-document-traceable.h +++ b/src/libsysprof-analyze/sysprof-document-traceable.h @@ -40,9 +40,13 @@ struct _SysprofDocumentTraceableInterface }; SYSPROF_AVAILABLE_IN_ALL -guint sysprof_document_traceable_get_stack_depth (SysprofDocumentTraceable *self); +guint sysprof_document_traceable_get_stack_depth (SysprofDocumentTraceable *self); SYSPROF_AVAILABLE_IN_ALL -guint64 sysprof_document_traceable_get_stack_address (SysprofDocumentTraceable *self, - guint position); +guint64 sysprof_document_traceable_get_stack_address (SysprofDocumentTraceable *self, + guint position); +SYSPROF_AVAILABLE_IN_ALL +guint sysprof_document_traceable_get_stack_addresses (SysprofDocumentTraceable *self, + guint64 *addresses, + guint n_addresses); G_END_DECLS