capture: add pid-root frame type

While I'm not thrilled to add new frame types for every sort of thing, I
think having this will be relatively useful so we can improve decoding
operations.

This adds SysprofCapturePidRoot which lets us specify a root directory
on the host system for which is the real root (/) of the PID. This can
be useful when reconstructing overlays for containers and you need to
direct access to alternate roots.

The layer gives us some ability to try to deal with overlayfs, albeit at
a very rudimentary level. In most cases I anticipate we just deal with
the main root and ignore overlays until necessary.
This commit is contained in:
Christian Hergert
2021-02-24 17:50:36 -08:00
parent ff22417de9
commit 4758fb42ce
8 changed files with 138 additions and 2 deletions

View File

@ -353,6 +353,17 @@ sysprof_capture_reader_bswap_mark (SysprofCaptureReader *self,
mark->duration = bswap_64 (mark->duration);
}
static inline void
sysprof_capture_reader_bswap_pid_root (SysprofCaptureReader *self,
SysprofCapturePidRoot *pr)
{
assert (self != NULL);
assert (pr != NULL);
if (SYSPROF_UNLIKELY (self->endian != __BYTE_ORDER))
pr->layer = bswap_32 (pr->layer);
}
static inline void
sysprof_capture_reader_bswap_jitmap (SysprofCaptureReader *self,
SysprofCaptureJitmap *jitmap)
@ -679,6 +690,46 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
return mark;
}
const SysprofCapturePidRoot *
sysprof_capture_reader_read_pid_root (SysprofCaptureReader *self)
{
SysprofCapturePidRoot *pr;
assert (self != NULL);
assert ((self->pos % SYSPROF_CAPTURE_ALIGN) == 0);
assert (self->pos <= self->bufsz);
if (!sysprof_capture_reader_ensure_space_for (self, sizeof *pr + 1))
return NULL;
pr = (SysprofCapturePidRoot *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_frame (self, &pr->frame);
if (pr->frame.type != SYSPROF_CAPTURE_FRAME_PID_ROOT)
return NULL;
if (pr->frame.len < (sizeof *pr + 1))
return NULL;
if (!sysprof_capture_reader_ensure_space_for (self, pr->frame.len))
return NULL;
pr = (SysprofCapturePidRoot *)(void *)&self->buf[self->pos];
sysprof_capture_reader_bswap_pid_root (self, pr);
self->pos += pr->frame.len;
if ((self->pos % SYSPROF_CAPTURE_ALIGN) != 0)
return NULL;
/* Ensure trailing \0 in name and message */
((char *)pr)[pr->frame.len-1] = 0;
return pr;
}
const SysprofCaptureMetadata *
sysprof_capture_reader_read_metadata (SysprofCaptureReader *self)
{