mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libsysprof-analyze: add document type for memory maps
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
libsysprof_analyze_public_sources = [
|
||||
'sysprof-document.c',
|
||||
'sysprof-document-frame.c',
|
||||
'sysprof-document-mmap.c',
|
||||
'sysprof-document-sample.c',
|
||||
]
|
||||
|
||||
@ -8,6 +9,7 @@ libsysprof_analyze_public_headers = [
|
||||
'sysprof-analyze.h',
|
||||
'sysprof-document.h',
|
||||
'sysprof-document-frame.h',
|
||||
'sysprof-document-mmap.h',
|
||||
'sysprof-document-sample.h',
|
||||
]
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ G_BEGIN_DECLS
|
||||
#define SYSPROF_ANALYZE_INSIDE
|
||||
# include "sysprof-document.h"
|
||||
# include "sysprof-document-frame.h"
|
||||
# include "sysprof-document-mmap.h"
|
||||
# include "sysprof-document-sample.h"
|
||||
#undef SYSPROF_ANALYZE_INSIDE
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "sysprof-document-frame-private.h"
|
||||
#include "sysprof-document-mmap.h"
|
||||
#include "sysprof-document-sample.h"
|
||||
|
||||
G_DEFINE_TYPE (SysprofDocumentFrame, sysprof_document_frame, G_TYPE_OBJECT)
|
||||
@ -121,7 +122,10 @@ _sysprof_document_frame_new (GMappedFile *mapped_file,
|
||||
GType gtype = SYSPROF_TYPE_DOCUMENT_FRAME;
|
||||
SysprofDocumentFrame *self;
|
||||
|
||||
if (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE)
|
||||
if (0) {}
|
||||
else if (frame->type == SYSPROF_CAPTURE_FRAME_MAP)
|
||||
gtype = SYSPROF_TYPE_DOCUMENT_MMAP;
|
||||
else if (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE)
|
||||
gtype = SYSPROF_TYPE_DOCUMENT_SAMPLE;
|
||||
|
||||
self = g_object_new (gtype, NULL);
|
||||
|
||||
184
src/libsysprof-analyze/sysprof-document-mmap.c
Normal file
184
src/libsysprof-analyze/sysprof-document-mmap.c
Normal file
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* sysprof-document-mmap.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-mmap.h"
|
||||
|
||||
struct _SysprofDocumentMmap
|
||||
{
|
||||
SysprofDocumentFrame parent_instance;
|
||||
};
|
||||
|
||||
struct _SysprofDocumentMmapClass
|
||||
{
|
||||
SysprofDocumentFrameClass parent_class;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_END_ADDRESS,
|
||||
PROP_FILE,
|
||||
PROP_FILE_INODE,
|
||||
PROP_FILE_OFFSET,
|
||||
PROP_START_ADDRESS,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofDocumentMmap, sysprof_document_mmap, SYSPROF_TYPE_DOCUMENT_FRAME)
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
sysprof_document_mmap_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofDocumentMmap *self = SYSPROF_DOCUMENT_MMAP (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_START_ADDRESS:
|
||||
g_value_set_uint64 (value, sysprof_document_mmap_get_start_address (self));
|
||||
break;
|
||||
|
||||
case PROP_END_ADDRESS:
|
||||
g_value_set_uint64 (value, sysprof_document_mmap_get_end_address (self));
|
||||
break;
|
||||
|
||||
case PROP_FILE:
|
||||
g_value_set_string (value, sysprof_document_mmap_get_file (self));
|
||||
break;
|
||||
|
||||
case PROP_FILE_OFFSET:
|
||||
g_value_set_uint64 (value, sysprof_document_mmap_get_file_offset (self));
|
||||
break;
|
||||
|
||||
case PROP_FILE_INODE:
|
||||
g_value_set_uint64 (value, sysprof_document_mmap_get_file_inode (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_document_mmap_class_init (SysprofDocumentMmapClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = sysprof_document_mmap_get_property;
|
||||
|
||||
properties [PROP_START_ADDRESS] =
|
||||
g_param_spec_uint64 ("start-address", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_END_ADDRESS] =
|
||||
g_param_spec_uint64 ("end-address", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_FILE] =
|
||||
g_param_spec_string ("file", NULL, NULL,
|
||||
NULL,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_FILE_INODE] =
|
||||
g_param_spec_uint64 ("file-inode", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_FILE_OFFSET] =
|
||||
g_param_spec_uint64 ("file-offset", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_document_mmap_init (SysprofDocumentMmap *self)
|
||||
{
|
||||
}
|
||||
|
||||
guint64
|
||||
sysprof_document_mmap_get_start_address (SysprofDocumentMmap *self)
|
||||
{
|
||||
const SysprofCaptureMap *mmap;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
|
||||
|
||||
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_UINT64 (self, mmap->start);
|
||||
}
|
||||
|
||||
guint64
|
||||
sysprof_document_mmap_get_end_address (SysprofDocumentMmap *self)
|
||||
{
|
||||
const SysprofCaptureMap *mmap;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
|
||||
|
||||
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_UINT64 (self, mmap->end);
|
||||
}
|
||||
|
||||
guint64
|
||||
sysprof_document_mmap_get_file_inode (SysprofDocumentMmap *self)
|
||||
{
|
||||
const SysprofCaptureMap *mmap;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
|
||||
|
||||
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_UINT64 (self, mmap->inode);
|
||||
}
|
||||
|
||||
guint64
|
||||
sysprof_document_mmap_get_file_offset (SysprofDocumentMmap *self)
|
||||
{
|
||||
const SysprofCaptureMap *mmap;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
|
||||
|
||||
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_UINT64 (self, mmap->offset);
|
||||
}
|
||||
|
||||
const char *
|
||||
sysprof_document_mmap_get_file (SysprofDocumentMmap *self)
|
||||
{
|
||||
const SysprofCaptureMap *mmap;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_MMAP (self), 0);
|
||||
|
||||
mmap = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureMap);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_CSTRING (SYSPROF_DOCUMENT_FRAME (self), mmap->filename);
|
||||
}
|
||||
49
src/libsysprof-analyze/sysprof-document-mmap.h
Normal file
49
src/libsysprof-analyze/sysprof-document-mmap.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* sysprof-document-mmap.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_MMAP (sysprof_document_mmap_get_type())
|
||||
#define SYSPROF_IS_DOCUMENT_MMAP(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_MMAP)
|
||||
#define SYSPROF_DOCUMENT_MMAP(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_MMAP, SysprofDocumentMmap)
|
||||
#define SYSPROF_DOCUMENT_MMAP_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_MMAP, SysprofDocumentMmapClass)
|
||||
|
||||
typedef struct _SysprofDocumentMmap SysprofDocumentMmap;
|
||||
typedef struct _SysprofDocumentMmapClass SysprofDocumentMmapClass;
|
||||
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GType sysprof_document_mmap_get_type (void) G_GNUC_CONST;
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
guint64 sysprof_document_mmap_get_start_address (SysprofDocumentMmap *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
guint64 sysprof_document_mmap_get_end_address (SysprofDocumentMmap *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
guint64 sysprof_document_mmap_get_file_inode (SysprofDocumentMmap *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
guint64 sysprof_document_mmap_get_file_offset (SysprofDocumentMmap *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
const char *sysprof_document_mmap_get_file (SysprofDocumentMmap *self);
|
||||
|
||||
G_END_DECLS
|
||||
Reference in New Issue
Block a user