libsysprof-analyze: add SysprofDocumentOverlay

This maps to the SysprofCaptureOverlay data frames. We need them currently
to be able to locate files from various podman/toolbox rootless containers.
This commit is contained in:
Christian Hergert
2023-05-19 16:51:15 -07:00
parent 61d5187b09
commit 12e497891f
6 changed files with 202 additions and 0 deletions

View File

@ -12,6 +12,7 @@ libsysprof_analyze_public_sources = [
'sysprof-document-mark.c',
'sysprof-document-metadata.c',
'sysprof-document-mmap.c',
'sysprof-document-overlay.c',
'sysprof-document-process.c',
'sysprof-document-sample.c',
'sysprof-document-traceable.c',
@ -55,6 +56,7 @@ libsysprof_analyze_public_headers = [
'sysprof-document-mark.h',
'sysprof-document-metadata.h',
'sysprof-document-mmap.h',
'sysprof-document-overlay.h',
'sysprof-document-process.h',
'sysprof-document-sample.h',
'sysprof-document-traceable.h',

View File

@ -38,6 +38,7 @@ G_BEGIN_DECLS
# include "sysprof-document-mark.h"
# include "sysprof-document-metadata.h"
# include "sysprof-document-mmap.h"
# include "sysprof-document-overlay.h"
# include "sysprof-document-process.h"
# include "sysprof-document-sample.h"
# include "sysprof-document-traceable.h"

View File

@ -29,6 +29,7 @@
#include "sysprof-document-log.h"
#include "sysprof-document-mark.h"
#include "sysprof-document-mmap.h"
#include "sysprof-document-overlay.h"
#include "sysprof-document-process.h"
#include "sysprof-document-sample.h"
@ -168,6 +169,10 @@ _sysprof_document_frame_new (GMappedFile *mapped_file,
gtype = SYSPROF_TYPE_DOCUMENT_FILE_CHUNK;
break;
case SYSPROF_CAPTURE_FRAME_OVERLAY:
gtype = SYSPROF_TYPE_DOCUMENT_OVERLAY;
break;
default:
gtype = SYSPROF_TYPE_DOCUMENT_FRAME;
break;

View File

@ -0,0 +1,142 @@
/* sysprof-document-overlay.c
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include "sysprof-document-frame-private.h"
#include "sysprof-document-overlay.h"
struct _SysprofDocumentOverlay
{
SysprofDocumentFrame parent_instance;
};
struct _SysprofDocumentOverlayClass
{
SysprofDocumentFrameClass parent_class;
};
enum {
PROP_0,
PROP_DESTINATION,
PROP_LAYER,
PROP_SOURCE,
N_PROPS
};
G_DEFINE_FINAL_TYPE (SysprofDocumentOverlay, sysprof_document_overlay, SYSPROF_TYPE_DOCUMENT_FRAME)
static GParamSpec *properties [N_PROPS];
static void
sysprof_document_overlay_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
SysprofDocumentOverlay *self = SYSPROF_DOCUMENT_OVERLAY (object);
switch (prop_id)
{
case PROP_DESTINATION:
g_value_set_string (value, sysprof_document_overlay_get_destination (self));
break;
case PROP_LAYER:
g_value_set_uint (value, sysprof_document_overlay_get_layer (self));
break;
case PROP_SOURCE:
g_value_set_string (value, sysprof_document_overlay_get_source (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
sysprof_document_overlay_class_init (SysprofDocumentOverlayClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = sysprof_document_overlay_get_property;
properties [PROP_LAYER] =
g_param_spec_uint ("layer", NULL, NULL,
0, G_MAXUINT, 0,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_DESTINATION] =
g_param_spec_string ("destination", NULL, NULL,
NULL,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
properties [PROP_SOURCE] =
g_param_spec_string ("source", NULL, NULL,
NULL,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
sysprof_document_overlay_init (SysprofDocumentOverlay *self)
{
}
guint
sysprof_document_overlay_get_layer (SysprofDocumentOverlay *self)
{
const SysprofCaptureOverlay *overlay;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_OVERLAY (self), 0);
overlay = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureOverlay);
return overlay->layer;
}
const char *
sysprof_document_overlay_get_source (SysprofDocumentOverlay *self)
{
const SysprofCaptureOverlay *overlay;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_OVERLAY (self), 0);
overlay = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureOverlay);
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, overlay->data);
}
const char *
sysprof_document_overlay_get_destination (SysprofDocumentOverlay *self)
{
const SysprofCaptureOverlay *overlay;
guint16 offset;
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_OVERLAY (self), 0);
overlay = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureOverlay);
offset = SYSPROF_DOCUMENT_FRAME_UINT16 (self, overlay->src_len);
return SYSPROF_DOCUMENT_FRAME_CSTRING (self, &overlay->data[offset+1]);
}

View File

@ -0,0 +1,47 @@
/* sysprof-document-overlay.h
*
* Copyright 2023 Christian Hergert <chergert@redhat.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include "sysprof-document-frame.h"
G_BEGIN_DECLS
#define SYSPROF_TYPE_DOCUMENT_OVERLAY (sysprof_document_overlay_get_type())
#define SYSPROF_IS_DOCUMENT_OVERLAY(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_OVERLAY)
#define SYSPROF_DOCUMENT_OVERLAY(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_OVERLAY, SysprofDocumentOverlay)
#define SYSPROF_DOCUMENT_OVERLAY_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_OVERLAY, SysprofDocumentOverlayClass)
typedef struct _SysprofDocumentOverlay SysprofDocumentOverlay;
typedef struct _SysprofDocumentOverlayClass SysprofDocumentOverlayClass;
SYSPROF_AVAILABLE_IN_ALL
GType sysprof_document_overlay_get_type (void) G_GNUC_CONST;
SYSPROF_AVAILABLE_IN_ALL
guint sysprof_document_overlay_get_layer (SysprofDocumentOverlay *self);
SYSPROF_AVAILABLE_IN_ALL
const char *sysprof_document_overlay_get_source (SysprofDocumentOverlay *self);
SYSPROF_AVAILABLE_IN_ALL
const char *sysprof_document_overlay_get_destination (SysprofDocumentOverlay *self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofDocumentOverlay, g_object_unref)
G_END_DECLS

View File

@ -70,6 +70,11 @@ main (int argc,
else if (SYSPROF_IS_DOCUMENT_FORK (frame))
g_print (" child-pid=%d",
sysprof_document_fork_get_child_pid (SYSPROF_DOCUMENT_FORK (frame)));
else if (SYSPROF_IS_DOCUMENT_OVERLAY (frame))
g_print (" layer=%u source=%s destination=%s",
sysprof_document_overlay_get_layer (SYSPROF_DOCUMENT_OVERLAY (frame)),
sysprof_document_overlay_get_source (SYSPROF_DOCUMENT_OVERLAY (frame)),
sysprof_document_overlay_get_destination (SYSPROF_DOCUMENT_OVERLAY (frame)));
else if (SYSPROF_IS_DOCUMENT_MMAP (frame))
g_print (" begin=0x%"G_GINT64_MODIFIER"x end=0x%"G_GINT64_MODIFIER"x offset=0x%"G_GINT64_MODIFIER"x path=%s",
sysprof_document_mmap_get_start_address (SYSPROF_DOCUMENT_MMAP (frame)),