From 63b42c2319e659a304402167dbfbf4e446018e79 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 12 Jun 2023 15:41:29 -0700 Subject: [PATCH] libsysprof-analyze: track relative offset for frame This is handy so that we don't have to keep multiple objects around to handle this request. Otherwise we'd need to keep references to the document and that is a bit annoying. This of course has a limit of about an hour (in tv_nsec), but that is far longer than we can realistically record anyway. --- .../sysprof-document-frame-private.h | 4 +++- .../sysprof-document-frame.c | 24 ++++++++++++++++++- .../sysprof-document-frame.h | 10 ++++---- src/libsysprof-analyze/sysprof-document.c | 3 ++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-document-frame-private.h b/src/libsysprof-analyze/sysprof-document-frame-private.h index 50326fe9..3755009e 100644 --- a/src/libsysprof-analyze/sysprof-document-frame-private.h +++ b/src/libsysprof-analyze/sysprof-document-frame-private.h @@ -34,6 +34,7 @@ struct _SysprofDocumentFrame guint32 frame_len : 16; guint32 needs_swap : 1; guint32 padding : 15; + guint32 time_offset; }; struct _SysprofDocumentFrameClass @@ -44,7 +45,8 @@ struct _SysprofDocumentFrameClass SysprofDocumentFrame *_sysprof_document_frame_new (GMappedFile *mapped, const SysprofCaptureFrame *frame, guint16 frame_len, - gboolean needs_swap); + gboolean needs_swap, + gint64 clock_at_start); #define SYSPROF_DOCUMENT_FRAME_ENDPTR(obj) \ (&((const guint8 *)SYSPROF_DOCUMENT_FRAME(obj)->frame)[SYSPROF_DOCUMENT_FRAME(obj)->frame_len]) diff --git a/src/libsysprof-analyze/sysprof-document-frame.c b/src/libsysprof-analyze/sysprof-document-frame.c index f52022d5..d7259c5b 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.c +++ b/src/libsysprof-analyze/sysprof-document-frame.c @@ -43,6 +43,7 @@ enum { PROP_CPU, PROP_PID, PROP_TIME, + PROP_TIME_OFFSET, N_PROPS }; @@ -83,6 +84,10 @@ sysprof_document_frame_get_property (GObject *object, g_value_set_int64 (value, sysprof_document_frame_get_time (self)); break; + case PROP_TIME_OFFSET: + g_value_set_int64 (value, sysprof_document_frame_get_time_offset (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -117,6 +122,13 @@ sysprof_document_frame_class_init (SysprofDocumentFrameClass *klass) 0, (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + properties[PROP_TIME_OFFSET] = + g_param_spec_int64 ("time-offset", NULL, NULL, + G_MININT64, + G_MAXINT64, + 0, + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_properties (object_class, N_PROPS, properties); } @@ -129,7 +141,8 @@ SysprofDocumentFrame * _sysprof_document_frame_new (GMappedFile *mapped_file, const SysprofCaptureFrame *frame, guint16 frame_len, - gboolean needs_swap) + gboolean needs_swap, + gint64 begin_time) { SysprofDocumentFrame *self; GType gtype; @@ -198,6 +211,7 @@ _sysprof_document_frame_new (GMappedFile *mapped_file, self->frame = frame; self->frame_len = frame_len; self->needs_swap = !!needs_swap; + self->time_offset = CLAMP (sysprof_document_frame_get_time (self) - begin_time, 0, G_MAXINT64); return self; } @@ -225,3 +239,11 @@ sysprof_document_frame_get_time (SysprofDocumentFrame *self) return SYSPROF_DOCUMENT_FRAME_INT64 (self, self->frame->time); } + +gint64 +sysprof_document_frame_get_time_offset (SysprofDocumentFrame *self) +{ + g_return_val_if_fail (SYSPROF_IS_DOCUMENT_FRAME (self), 0); + + return self->time_offset; +} diff --git a/src/libsysprof-analyze/sysprof-document-frame.h b/src/libsysprof-analyze/sysprof-document-frame.h index 46d98055..c8556fa1 100644 --- a/src/libsysprof-analyze/sysprof-document-frame.h +++ b/src/libsysprof-analyze/sysprof-document-frame.h @@ -35,13 +35,15 @@ typedef struct _SysprofDocumentFrame SysprofDocumentFrame; typedef struct _SysprofDocumentFrameClass SysprofDocumentFrameClass; SYSPROF_AVAILABLE_IN_ALL -GType sysprof_document_frame_get_type (void) G_GNUC_CONST; +GType sysprof_document_frame_get_type (void) G_GNUC_CONST; SYSPROF_AVAILABLE_IN_ALL -int sysprof_document_frame_get_cpu (SysprofDocumentFrame *self); +int sysprof_document_frame_get_cpu (SysprofDocumentFrame *self); SYSPROF_AVAILABLE_IN_ALL -int sysprof_document_frame_get_pid (SysprofDocumentFrame *self); +int sysprof_document_frame_get_pid (SysprofDocumentFrame *self); SYSPROF_AVAILABLE_IN_ALL -gint64 sysprof_document_frame_get_time (SysprofDocumentFrame *self); +gint64 sysprof_document_frame_get_time (SysprofDocumentFrame *self); +SYSPROF_AVAILABLE_IN_ALL +gint64 sysprof_document_frame_get_time_offset (SysprofDocumentFrame *self); G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentFrame, g_object_unref) diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index 47ca0fb2..a18b1134 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -118,7 +118,8 @@ sysprof_document_get_item (GListModel *model, ret = _sysprof_document_frame_new (self->mapped_file, (gconstpointer)&self->base[ptr->offset], ptr->length, - self->needs_swap); + self->needs_swap, + self->header.time); /* Annotate processes with pre-calculated info */ if (SYSPROF_IS_DOCUMENT_PROCESS (ret))