diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c index ea9e0538..fe654626 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.c +++ b/src/libsysprof-capture/sysprof-capture-writer.c @@ -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, diff --git a/src/libsysprof-capture/sysprof-capture-writer.h b/src/libsysprof-capture/sysprof-capture-writer.h index bde8c174..ffbb8edc 100644 --- a/src/libsysprof-capture/sysprof-capture-writer.h +++ b/src/libsysprof-capture/sysprof-capture-writer.h @@ -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, diff --git a/src/libsysprof-capture/tests/test-capture.c b/src/libsysprof-capture/tests/test-capture.c index 470ebf24..522afbff 100644 --- a/src/libsysprof-capture/tests/test-capture.c +++ b/src/libsysprof-capture/tests/test-capture.c @@ -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. */