From 8feeec782fe4d5c3b2143c7ded2f23a8746a9363 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 17 May 2019 11:11:39 -0700 Subject: [PATCH] libsysprof-capture: discover the end time if necessary If we get a capture file without a valid end-time, we should just go discover that up-front instead of dealing with it all over the place. --- .../sysprof-capture-reader.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c index f81607fb..c22d3bbf 100644 --- a/src/libsysprof-capture/sysprof-capture-reader.c +++ b/src/libsysprof-capture/sysprof-capture-reader.c @@ -109,6 +109,35 @@ sysprof_capture_reader_get_filename (SysprofCaptureReader *self) return self->filename; } +static void +sysprof_capture_reader_discover_end_time (SysprofCaptureReader *self) +{ + SysprofCaptureFrame frame; + + g_assert (self != NULL); + + while (sysprof_capture_reader_peek_frame (self, &frame)) + { + gint64 end_time = frame.time; + + if (frame.type == SYSPROF_CAPTURE_FRAME_MARK) + { + const SysprofCaptureMark *mark = NULL; + + if ((mark = sysprof_capture_reader_read_mark (self))) + end_time = frame.time + MAX (0, mark->duration); + } + + if (end_time > self->end_time) + self->end_time = end_time; + + if (!sysprof_capture_reader_skip (self)) + break; + } + + sysprof_capture_reader_reset (self); +} + /** * sysprof_capture_reader_new_from_fd: * @fd: an fd to take ownership from @@ -148,6 +177,13 @@ sysprof_capture_reader_new_from_fd (int fd, else self->endian = G_BIG_ENDIAN; + /* If we detect a capture file that did not get an end time, or an erroneous + * end time, then we need to take a performance hit here and scan the file + * and discover the end time with frame timings. + */ + if (self->header.end_time < self->header.time) + sysprof_capture_reader_discover_end_time (self); + return self; }