mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
reader: add sp_capture_reader_copy()
This function allows copying a capture so that we can do additional reads. This does, however, copy the buffers which might be more memory than we want for large usage. We can tweak things as we go to figure out the cursors.
This commit is contained in:
@ -812,3 +812,38 @@ sp_capture_reader_get_start_time (SpCaptureReader *self)
|
||||
|
||||
return self->header.time;
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_capture_reader_copy:
|
||||
*
|
||||
* This function makes a copy of the reader. Since readers use
|
||||
* positioned reads with pread(), this allows you to have multiple
|
||||
* readers with the shared file descriptor. This uses dup() to create
|
||||
* another file descriptor.
|
||||
*
|
||||
* Returns: (transfer full): A copy of @self with a new file-descriptor.
|
||||
*/
|
||||
SpCaptureReader *
|
||||
sp_capture_reader_copy (SpCaptureReader *self)
|
||||
{
|
||||
SpCaptureReader *copy;
|
||||
int fd;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
if (-1 == (fd = dup (self->fd)))
|
||||
return NULL;
|
||||
|
||||
copy = g_new0 (SpCaptureReader, 1);
|
||||
|
||||
*copy = *self;
|
||||
|
||||
copy->ref_count = 1;
|
||||
copy->filename = g_strdup (self->filename);
|
||||
copy->fd = fd;
|
||||
|
||||
copy->buf = g_malloc (self->bufsz);
|
||||
memcpy (copy->buf, self->buf, self->bufsz);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ SpCaptureReader *sp_capture_reader_new (const
|
||||
GError **error);
|
||||
SpCaptureReader *sp_capture_reader_new_from_fd (int fd,
|
||||
GError **error);
|
||||
SpCaptureReader *sp_capture_reader_copy (SpCaptureReader *self);
|
||||
SpCaptureReader *sp_capture_reader_ref (SpCaptureReader *self);
|
||||
void sp_capture_reader_unref (SpCaptureReader *self);
|
||||
const gchar *sp_capture_reader_get_filename (SpCaptureReader *self);
|
||||
|
||||
Reference in New Issue
Block a user