libsysprof-capture: add map variant with build-id

This allows tacking on suplimental data to the capture with a build-id so
that our SysprofDocumentMmap can read it. The format is @build-id\0 after
the trailing \0 of the filename in a SysprofCaptureMap frame.
This commit is contained in:
Christian Hergert
2023-07-24 17:29:59 -07:00
parent dfd81f1ecb
commit a7fe9abb19
3 changed files with 95 additions and 0 deletions

View File

@ -620,6 +620,64 @@ sysprof_capture_writer_add_map (SysprofCaptureWriter *self,
return true;
}
bool
sysprof_capture_writer_add_map_with_build_id (SysprofCaptureWriter *self,
int64_t time,
int cpu,
int32_t pid,
uint64_t start,
uint64_t end,
uint64_t offset,
uint64_t inode,
const char *filename,
const char *build_id)
{
SysprofCaptureMap *ev;
size_t len;
size_t filename_len;
size_t build_id_len;
if (filename == NULL)
filename = "";
if (build_id == NULL)
build_id = "";
assert (self != NULL);
assert (filename != NULL);
assert (build_id != NULL);
filename_len = strlen (filename) + 1;
build_id_len = strlen (build_id) + 1;
len = sizeof *ev + filename_len + strlen("@") + build_id_len;
ev = (SysprofCaptureMap *)sysprof_capture_writer_allocate (self, &len);
if (!ev)
return false;
sysprof_capture_writer_frame_init (&ev->frame,
len,
cpu,
pid,
time,
SYSPROF_CAPTURE_FRAME_MAP);
ev->start = start;
ev->end = end;
ev->offset = offset;
ev->inode = inode;
_sysprof_strlcpy (ev->filename, filename, filename_len);
ev->filename[filename_len] = '@';
_sysprof_strlcpy (&ev->filename[filename_len+1], build_id, build_id_len);
((char*)ev)[len-1] = 0;
self->stat.frame_count[SYSPROF_CAPTURE_FRAME_MAP]++;
return true;
}
bool
sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
int64_t time,

View File

@ -109,6 +109,17 @@ bool sysprof_capture_writer_add_map (Sy
uint64_t inode,
const char *filename);
SYSPROF_AVAILABLE_IN_ALL
bool sysprof_capture_writer_add_map_with_build_id (SysprofCaptureWriter *self,
int64_t time,
int cpu,
int32_t pid,
uint64_t start,
uint64_t end,
uint64_t offset,
uint64_t inode,
const char *filename,
const char *build_id);
SYSPROF_AVAILABLE_IN_ALL
bool sysprof_capture_writer_add_mark (SysprofCaptureWriter *self,
int64_t time,
int cpu,

View File

@ -101,6 +101,32 @@ test_reader_basic (void)
g_assert_cmpstr (map->filename, ==, str);
}
r = sysprof_capture_writer_add_map_with_build_id (writer, t, -1, -1, 0, 0, 0, 0, "map", "build-id");
g_assert_cmpint (r, ==, TRUE);
sysprof_capture_writer_flush (writer);
{
SysprofCaptureFrameType type = -1;
const SysprofCaptureMap *map;
if (!sysprof_capture_reader_peek_type (reader, &type))
g_assert_not_reached ();
g_assert_cmpint (type, ==, SYSPROF_CAPTURE_FRAME_MAP);
map = sysprof_capture_reader_read_map (reader);
g_assert_nonnull (map);
g_assert_cmpint (map->frame.pid, ==, -1);
g_assert_cmpint (map->frame.cpu, ==, -1);
g_assert_cmpint (map->start, ==, 0);
g_assert_cmpint (map->end, ==, 0);
g_assert_cmpint (map->offset, ==, 0);
g_assert_cmpint (map->inode, ==, 0);
g_assert_cmpstr (map->filename, ==, "map");
g_assert_cmpstr (map->filename+strlen("map")+1, ==, "@build-id");
}
/* Now that we have read a frame, we should start having updated
* end times with each incoming frame.
*/