libsysprof-profile: add recording helper to capture file data

We might have the file data from the peer and can specify the data in the
capture writer directly.

It may be useful to allow compressing these too, but we can deal with that
at a later time.
This commit is contained in:
Christian Hergert
2023-05-30 17:00:53 -07:00
parent df7da9bb41
commit 81317bc1ca
2 changed files with 36 additions and 0 deletions

View File

@ -37,5 +37,9 @@ SysprofSpawnable *_sysprof_recording_get_spawnable (SysprofRecording *s
DexFuture *_sysprof_recording_add_file (SysprofRecording *self,
const char *path,
gboolean compress);
void _sysprof_recording_add_file_data (SysprofRecording *self,
const char *path,
const char *contents,
gssize length);
G_END_DECLS

View File

@ -454,3 +454,35 @@ _sysprof_recording_add_file (SysprofRecording *self,
g_steal_pointer (&add_file),
(GDestroyNotify)add_file_free);
}
void
_sysprof_recording_add_file_data (SysprofRecording *self,
const char *path,
const char *contents,
gssize length)
{
g_return_if_fail (SYSPROF_IS_RECORDING (self));
g_return_if_fail (path != NULL);
g_return_if_fail (contents != NULL);
if (length < 0)
length = strlen (contents);
while (length > 0)
{
gsize to_write = MIN (length, ((4096*8)-sizeof (SysprofCaptureFileChunk)));
if (!sysprof_capture_writer_add_file (self->writer,
SYSPROF_CAPTURE_CURRENT_TIME,
-1,
-1,
path,
to_write == length,
(const guint8 *)contents,
to_write))
break;
length -= to_write;
contents += to_write;
}
}