capture: add end time for captures

Update the end time when we flush the buffer to disk. Also add
a way to either incrementally get the end time or rely on the
header when possible.
This commit is contained in:
Christian Hergert
2016-09-27 21:24:33 -07:00
parent 4953731dd7
commit 2197a0c02e
5 changed files with 65 additions and 3 deletions

View File

@ -39,6 +39,7 @@ struct _SpCaptureReader
int fd;
gint endian;
SpCaptureFileHeader header;
gint64 end_time;
};
#ifndef SP_DISABLE_GOBJECT
@ -297,6 +298,9 @@ sp_capture_reader_peek_frame (SpCaptureReader *self,
sp_capture_reader_bswap_frame (self, frame);
if (frame->time > self->end_time)
self->end_time = frame->time;
return TRUE;
}
@ -813,6 +817,36 @@ sp_capture_reader_get_start_time (SpCaptureReader *self)
return self->header.time;
}
/**
* sp_capture_reader_get_end_time:
*
* This function will return the end time for the capture, which is the
* same as the last event added to the capture.
*
* If the end time has been stored in the capture header, that will be used.
* Otherwise, the time is discovered from the last capture frame and therefore
* the caller must have read all frames to ensure this value is accurate.
*
* Captures created by sysprof versions containing this API will have the
* end time set if the output capture file-descriptor supports seeking.
*
* Since: 3.22.1
*/
gint64
sp_capture_reader_get_end_time (SpCaptureReader *self)
{
g_return_val_if_fail (self != NULL, 0);
if (self->header.end_time != 0)
{
if (self->endian != G_BYTE_ORDER)
return GUINT64_SWAP_LE_BE (self->header.end_time);
return self->header.end_time;
}
return self->end_time;
}
/**
* sp_capture_reader_copy:
*