mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
libyssprof-analyze: add document type for allocations
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
libsysprof_analyze_public_sources = [
|
||||
'sysprof-document.c',
|
||||
'sysprof-document-allocation.c',
|
||||
'sysprof-document-exit.c',
|
||||
'sysprof-document-fork.c',
|
||||
'sysprof-document-frame.c',
|
||||
@ -14,6 +15,7 @@ libsysprof_analyze_public_sources = [
|
||||
libsysprof_analyze_public_headers = [
|
||||
'sysprof-analyze.h',
|
||||
'sysprof-document.h',
|
||||
'sysprof-document-allocation.h',
|
||||
'sysprof-document-exit.h',
|
||||
'sysprof-document-fork.h',
|
||||
'sysprof-document-frame.h',
|
||||
|
||||
@ -26,6 +26,7 @@ G_BEGIN_DECLS
|
||||
|
||||
#define SYSPROF_ANALYZE_INSIDE
|
||||
# include "sysprof-document.h"
|
||||
# include "sysprof-document-allocation.h"
|
||||
# include "sysprof-document-exit.h"
|
||||
# include "sysprof-document-fork.h"
|
||||
# include "sysprof-document-frame.h"
|
||||
|
||||
172
src/libsysprof-analyze/sysprof-document-allocation.c
Normal file
172
src/libsysprof-analyze/sysprof-document-allocation.c
Normal file
@ -0,0 +1,172 @@
|
||||
/* sysprof-document-allocation.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-allocation.h"
|
||||
|
||||
struct _SysprofDocumentAllocation
|
||||
{
|
||||
SysprofDocumentFrame parent_instance;
|
||||
};
|
||||
|
||||
struct _SysprofDocumentAllocationClass
|
||||
{
|
||||
SysprofDocumentFrameClass parent_class;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ADDRESS,
|
||||
PROP_SIZE,
|
||||
PROP_TID,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_FINAL_TYPE (SysprofDocumentAllocation, sysprof_document_allocation, SYSPROF_TYPE_DOCUMENT_FRAME)
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
sysprof_document_allocation_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SysprofDocumentAllocation *self = SYSPROF_DOCUMENT_ALLOCATION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ADDRESS:
|
||||
g_value_set_uint64 (value, sysprof_document_allocation_get_address (self));
|
||||
break;
|
||||
|
||||
case PROP_SIZE:
|
||||
g_value_set_int64 (value, sysprof_document_allocation_get_size (self));
|
||||
break;
|
||||
|
||||
case PROP_TID:
|
||||
g_value_set_int (value, sysprof_document_allocation_get_tid (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_document_allocation_class_init (SysprofDocumentAllocationClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = sysprof_document_allocation_get_property;
|
||||
|
||||
/**
|
||||
* SysprofDocumentAllocation:tid:
|
||||
*
|
||||
* The task-id or thread-id of the thread which was sampled.
|
||||
*
|
||||
* On Linux, this is generally set to the value of the gettid() syscall.
|
||||
*
|
||||
* Since: 45
|
||||
*/
|
||||
properties [PROP_TID] =
|
||||
g_param_spec_int ("tid", NULL, NULL,
|
||||
G_MININT32, G_MAXINT32, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* SysprofDocumentAllocation:address:
|
||||
*
|
||||
* The address that was allocated or freed.
|
||||
*
|
||||
* Since: 45
|
||||
*/
|
||||
properties [PROP_ADDRESS] =
|
||||
g_param_spec_uint64 ("address", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* SysprofDocumentAllocation:size:
|
||||
*
|
||||
* The size of the memory that was allocated or freed.
|
||||
*/
|
||||
properties [PROP_SIZE] =
|
||||
g_param_spec_int64 ("size", NULL, NULL,
|
||||
G_MININT64, G_MAXINT64, 0,
|
||||
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sysprof_document_allocation_init (SysprofDocumentAllocation *self)
|
||||
{
|
||||
}
|
||||
|
||||
guint64
|
||||
sysprof_document_allocation_get_address (SysprofDocumentAllocation *self)
|
||||
{
|
||||
const SysprofCaptureAllocation *allocation;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_ALLOCATION (self), 0);
|
||||
|
||||
allocation = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureAllocation);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_UINT64 (self, allocation->alloc_addr);
|
||||
}
|
||||
|
||||
gint64
|
||||
sysprof_document_allocation_get_size (SysprofDocumentAllocation *self)
|
||||
{
|
||||
const SysprofCaptureAllocation *allocation;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_ALLOCATION (self), 0);
|
||||
|
||||
allocation = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureAllocation);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_INT64 (self, allocation->alloc_size);
|
||||
}
|
||||
|
||||
int
|
||||
sysprof_document_allocation_get_tid (SysprofDocumentAllocation *self)
|
||||
{
|
||||
const SysprofCaptureAllocation *allocation;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_ALLOCATION (self), 0);
|
||||
|
||||
allocation = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureAllocation);
|
||||
|
||||
return SYSPROF_DOCUMENT_FRAME_INT32 (self, allocation->tid);
|
||||
}
|
||||
|
||||
gboolean
|
||||
sysprof_document_allocation_is_free (SysprofDocumentAllocation *self)
|
||||
{
|
||||
const SysprofCaptureAllocation *allocation;
|
||||
|
||||
g_return_val_if_fail (SYSPROF_IS_DOCUMENT_ALLOCATION (self), 0);
|
||||
|
||||
allocation = SYSPROF_DOCUMENT_FRAME_GET (self, SysprofCaptureAllocation);
|
||||
|
||||
return allocation->alloc_size == 0;
|
||||
}
|
||||
46
src/libsysprof-analyze/sysprof-document-allocation.h
Normal file
46
src/libsysprof-analyze/sysprof-document-allocation.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* sysprof-document-allocation.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_ALLOCATION (sysprof_document_allocation_get_type())
|
||||
#define SYSPROF_IS_DOCUMENT_ALLOCATION(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_DOCUMENT_ALLOCATION)
|
||||
#define SYSPROF_DOCUMENT_ALLOCATION(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_DOCUMENT_ALLOCATION, SysprofDocumentAllocation)
|
||||
#define SYSPROF_DOCUMENT_ALLOCATION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_DOCUMENT_ALLOCATION, SysprofDocumentAllocationClass)
|
||||
|
||||
typedef struct _SysprofDocumentAllocation SysprofDocumentAllocation;
|
||||
typedef struct _SysprofDocumentAllocationClass SysprofDocumentAllocationClass;
|
||||
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
GType sysprof_document_allocation_get_type (void) G_GNUC_CONST;
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
guint64 sysprof_document_allocation_get_address (SysprofDocumentAllocation *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gint64 sysprof_document_allocation_get_size (SysprofDocumentAllocation *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
int sysprof_document_allocation_get_tid (SysprofDocumentAllocation *self);
|
||||
SYSPROF_AVAILABLE_IN_ALL
|
||||
gboolean sysprof_document_allocation_is_free (SysprofDocumentAllocation *self);
|
||||
|
||||
G_END_DECLS
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "sysprof-document-frame-private.h"
|
||||
|
||||
#include "sysprof-document-allocation.h"
|
||||
#include "sysprof-document-exit.h"
|
||||
#include "sysprof-document-fork.h"
|
||||
#include "sysprof-document-log.h"
|
||||
@ -158,6 +159,10 @@ _sysprof_document_frame_new (GMappedFile *mapped_file,
|
||||
gtype = SYSPROF_TYPE_DOCUMENT_FORK;
|
||||
break;
|
||||
|
||||
case SYSPROF_CAPTURE_FRAME_ALLOCATION:
|
||||
gtype = SYSPROF_TYPE_DOCUMENT_ALLOCATION;
|
||||
break;
|
||||
|
||||
default:
|
||||
gtype = SYSPROF_TYPE_DOCUMENT_FRAME;
|
||||
break;
|
||||
|
||||
@ -61,6 +61,16 @@ 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_ALLOCATION (frame))
|
||||
{
|
||||
if (sysprof_document_allocation_is_free (SYSPROF_DOCUMENT_ALLOCATION (frame)))
|
||||
g_print (" 0x%016"G_GINT64_MODIFIER"x: free",
|
||||
sysprof_document_allocation_get_address (SYSPROF_DOCUMENT_ALLOCATION (frame)));
|
||||
else
|
||||
g_print (" 0x%016"G_GINT64_MODIFIER"x: allocate %"G_GUINT64_FORMAT" at ",
|
||||
sysprof_document_allocation_get_address (SYSPROF_DOCUMENT_ALLOCATION (frame)),
|
||||
sysprof_document_allocation_get_size (SYSPROF_DOCUMENT_ALLOCATION (frame)));
|
||||
}
|
||||
|
||||
g_print ("\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user