mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-10 07:00:53 +00:00
libsysprof-profile: add malloc tracing instrument
This commit is contained in:
@ -5,6 +5,7 @@ libsysprof_profile_public_sources = [
|
|||||||
'sysprof-energy-usage.c',
|
'sysprof-energy-usage.c',
|
||||||
'sysprof-instrument.c',
|
'sysprof-instrument.c',
|
||||||
'sysprof-memory-usage.c',
|
'sysprof-memory-usage.c',
|
||||||
|
'sysprof-malloc-tracing.c',
|
||||||
'sysprof-network-usage.c',
|
'sysprof-network-usage.c',
|
||||||
'sysprof-profiler.c',
|
'sysprof-profiler.c',
|
||||||
'sysprof-proxied-instrument.c',
|
'sysprof-proxied-instrument.c',
|
||||||
@ -30,6 +31,7 @@ libsysprof_profile_public_headers = [
|
|||||||
'sysprof-energy-usage.h',
|
'sysprof-energy-usage.h',
|
||||||
'sysprof-instrument.h',
|
'sysprof-instrument.h',
|
||||||
'sysprof-memory-usage.h',
|
'sysprof-memory-usage.h',
|
||||||
|
'sysprof-malloc-tracing.h',
|
||||||
'sysprof-network-usage.h',
|
'sysprof-network-usage.h',
|
||||||
'sysprof-profiler.h',
|
'sysprof-profiler.h',
|
||||||
'sysprof-proxied-instrument.h',
|
'sysprof-proxied-instrument.h',
|
||||||
|
|||||||
73
src/libsysprof-profile/sysprof-malloc-tracing.c
Normal file
73
src/libsysprof-profile/sysprof-malloc-tracing.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* sysprof-malloc-tracing.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-malloc-tracing.h"
|
||||||
|
#include "sysprof-instrument-private.h"
|
||||||
|
#include "sysprof-recording-private.h"
|
||||||
|
#include "sysprof-spawnable.h"
|
||||||
|
|
||||||
|
struct _SysprofMallocTracing
|
||||||
|
{
|
||||||
|
SysprofInstrument parent_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _SysprofMallocTracingClass
|
||||||
|
{
|
||||||
|
SysprofInstrumentClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_FINAL_TYPE (SysprofMallocTracing, sysprof_malloc_tracing, SYSPROF_TYPE_INSTRUMENT)
|
||||||
|
|
||||||
|
static DexFuture *
|
||||||
|
sysprof_malloc_tracing_prepare (SysprofInstrument *instrument,
|
||||||
|
SysprofRecording *recording)
|
||||||
|
{
|
||||||
|
SysprofSpawnable *spawnable;
|
||||||
|
|
||||||
|
g_assert (SYSPROF_IS_MALLOC_TRACING (instrument));
|
||||||
|
g_assert (SYSPROF_IS_RECORDING (recording));
|
||||||
|
|
||||||
|
if ((spawnable = _sysprof_recording_get_spawnable (recording)))
|
||||||
|
sysprof_spawnable_add_ld_preload (spawnable,
|
||||||
|
PACKAGE_LIBDIR"/libsysprof-memory-" API_VERSION_S ".so");
|
||||||
|
|
||||||
|
return dex_future_new_for_boolean (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_malloc_tracing_class_init (SysprofMallocTracingClass *klass)
|
||||||
|
{
|
||||||
|
SysprofInstrumentClass *instrument_class = SYSPROF_INSTRUMENT_CLASS (klass);
|
||||||
|
|
||||||
|
instrument_class->prepare = sysprof_malloc_tracing_prepare;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysprof_malloc_tracing_init (SysprofMallocTracing *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SysprofInstrument *
|
||||||
|
sysprof_malloc_tracing_new (void)
|
||||||
|
{
|
||||||
|
return g_object_new (SYSPROF_TYPE_MALLOC_TRACING, NULL);
|
||||||
|
}
|
||||||
42
src/libsysprof-profile/sysprof-malloc-tracing.h
Normal file
42
src/libsysprof-profile/sysprof-malloc-tracing.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* sysprof-malloc-tracing.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-instrument.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define SYSPROF_TYPE_MALLOC_TRACING (sysprof_malloc_tracing_get_type())
|
||||||
|
#define SYSPROF_IS_MALLOC_TRACING(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_MALLOC_TRACING)
|
||||||
|
#define SYSPROF_MALLOC_TRACING(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_MALLOC_TRACING, SysprofMallocTracing)
|
||||||
|
#define SYSPROF_MALLOC_TRACING_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_MALLOC_TRACING, SysprofMallocTracingClass)
|
||||||
|
|
||||||
|
typedef struct _SysprofMallocTracing SysprofMallocTracing;
|
||||||
|
typedef struct _SysprofMallocTracingClass SysprofMallocTracingClass;
|
||||||
|
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
GType sysprof_malloc_tracing_get_type (void) G_GNUC_CONST;
|
||||||
|
SYSPROF_AVAILABLE_IN_ALL
|
||||||
|
SysprofInstrument *sysprof_malloc_tracing_new (void);
|
||||||
|
|
||||||
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofMallocTracing, g_object_unref)
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
@ -30,6 +30,7 @@ G_BEGIN_DECLS
|
|||||||
# include "sysprof-disk-usage.h"
|
# include "sysprof-disk-usage.h"
|
||||||
# include "sysprof-energy-usage.h"
|
# include "sysprof-energy-usage.h"
|
||||||
# include "sysprof-instrument.h"
|
# include "sysprof-instrument.h"
|
||||||
|
# include "sysprof-malloc-tracing.h"
|
||||||
# include "sysprof-memory-usage.h"
|
# include "sysprof-memory-usage.h"
|
||||||
# include "sysprof-network-usage.h"
|
# include "sysprof-network-usage.h"
|
||||||
# include "sysprof-profiler.h"
|
# include "sysprof-profiler.h"
|
||||||
|
|||||||
@ -143,6 +143,9 @@ main (int argc,
|
|||||||
sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ());
|
sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ());
|
||||||
sysprof_profiler_add_instrument (profiler, sysprof_sampler_new ());
|
sysprof_profiler_add_instrument (profiler, sysprof_sampler_new ());
|
||||||
|
|
||||||
|
if (memprof)
|
||||||
|
sysprof_profiler_add_instrument (profiler, sysprof_malloc_tracing_new ());
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (strcmp (argv[i], "--") == 0 && i+1 < argc)
|
if (strcmp (argv[i], "--") == 0 && i+1 < argc)
|
||||||
@ -152,11 +155,9 @@ main (int argc,
|
|||||||
sysprof_spawnable_append_args (spawnable, (const char * const *)&argv[i+1]);
|
sysprof_spawnable_append_args (spawnable, (const char * const *)&argv[i+1]);
|
||||||
sysprof_profiler_set_spawnable (profiler, spawnable);
|
sysprof_profiler_set_spawnable (profiler, spawnable);
|
||||||
|
|
||||||
if (memprof)
|
|
||||||
sysprof_spawnable_add_ld_preload (spawnable,
|
|
||||||
PACKAGE_LIBDIR "/libsysprof-memory-" API_VERSION_S ".so");
|
|
||||||
|
|
||||||
trace_fd = sysprof_spawnable_add_trace_fd (spawnable, NULL);
|
trace_fd = sysprof_spawnable_add_trace_fd (spawnable, NULL);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user