From 6ba408f073a236244c1743277ab3ea9694ade630 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 8 May 2019 09:57:30 -0700 Subject: [PATCH] shared: remove use of libshared This moves everything into other places and simple includes the files in the cases that it is necessary. In the future, we can rewrite sysprofd to use GDBus and add GetProcFile() to allow for client-side processing of kallsyms. --- src/libsysprof-capture/meson.build | 9 ++++-- .../sp-address-fallback.h | 0 .../sp-address.c | 0 .../sp-address.h | 4 ++- src/{shared => libsysprof-capture}/sp-clock.c | 0 src/{shared => libsysprof-capture}/sp-clock.h | 6 +++- .../sp-platform.c | 0 .../sp-platform.h | 0 src/libsysprof-capture/sysprof-capture.h | 1 - .../sysprof-version-macros.h | 4 --- src/libsysprof-capture/sysprof-version.h.in | 4 --- src/libsysprof/meson.build | 3 ++ src/{shared => libsysprof}/sp-kallsyms.c | 0 src/{shared => libsysprof}/sp-kallsyms.h | 7 ++-- src/libsysprof/sp-kernel-symbol.c | 1 - src/{shared => libsysprof}/sp-line-reader.c | 0 src/{shared => libsysprof}/sp-line-reader.h | 3 ++ src/libsysprof/sysprof.h | 1 + src/meson.build | 1 - src/shared/meson.build | 31 ------------------ src/shared/sp-error.c | 32 ------------------- src/shared/sp-error.h | 31 ------------------ src/sysprof/meson.build | 1 - src/sysprofd/meson.build | 11 ++++--- src/tests/test-kallsyms.c | 4 +-- src/tools/meson.build | 1 - 26 files changed, 33 insertions(+), 122 deletions(-) rename src/{shared => libsysprof-capture}/sp-address-fallback.h (100%) rename src/{shared => libsysprof-capture}/sp-address.c (100%) rename src/{shared => libsysprof-capture}/sp-address.h (94%) rename src/{shared => libsysprof-capture}/sp-clock.c (100%) rename src/{shared => libsysprof-capture}/sp-clock.h (92%) rename src/{shared => libsysprof-capture}/sp-platform.c (100%) rename src/{shared => libsysprof-capture}/sp-platform.h (100%) rename src/{shared => libsysprof}/sp-kallsyms.c (100%) rename src/{shared => libsysprof}/sp-kallsyms.h (91%) rename src/{shared => libsysprof}/sp-line-reader.c (100%) rename src/{shared => libsysprof}/sp-line-reader.h (96%) delete mode 100644 src/shared/meson.build delete mode 100644 src/shared/sp-error.c delete mode 100644 src/shared/sp-error.h diff --git a/src/libsysprof-capture/meson.build b/src/libsysprof-capture/meson.build index e2c9cae3..529440d5 100644 --- a/src/libsysprof-capture/meson.build +++ b/src/libsysprof-capture/meson.build @@ -1,19 +1,25 @@ libsysprof_capture_headers = [ + 'sp-address.h', + 'sp-clock.h', 'sp-capture-condition.h', 'sp-capture-cursor.h', 'sp-capture-reader.h', 'sp-capture-types.h', 'sp-capture-writer.h', + 'sp-platform.h', 'sysprof-capture.h', 'sysprof-version-macros.h', ] libsysprof_capture_sources = [ + 'sp-address.c', 'sp-capture-condition.c', 'sp-capture-cursor.c', 'sp-capture-reader.c', - 'sp-capture-writer.c', 'sp-capture-util.c', + 'sp-capture-writer.c', + 'sp-clock.c', + 'sp-platform.c', ] configure_file( @@ -25,7 +31,6 @@ configure_file( libsysprof_capture_deps = [ dependency('glib-2.0', version: glib_req_version), - libshared_dep, ] install_headers(libsysprof_capture_headers, subdir: sysprof_header_subdir) diff --git a/src/shared/sp-address-fallback.h b/src/libsysprof-capture/sp-address-fallback.h similarity index 100% rename from src/shared/sp-address-fallback.h rename to src/libsysprof-capture/sp-address-fallback.h diff --git a/src/shared/sp-address.c b/src/libsysprof-capture/sp-address.c similarity index 100% rename from src/shared/sp-address.c rename to src/libsysprof-capture/sp-address.c diff --git a/src/shared/sp-address.h b/src/libsysprof-capture/sp-address.h similarity index 94% rename from src/shared/sp-address.h rename to src/libsysprof-capture/sp-address.h index af8b3025..858de171 100644 --- a/src/shared/sp-address.h +++ b/src/libsysprof-capture/sp-address.h @@ -20,7 +20,7 @@ #pragma once -#include +#include "sysprof-version-macros.h" G_BEGIN_DECLS @@ -39,8 +39,10 @@ typedef enum SP_ADDRESS_CONTEXT_GUEST_USER, } SpAddressContext; +SYSPROF_AVAILABLE_IN_ALL gboolean sp_address_is_context_switch (SpAddress address, SpAddressContext *context); +SYSPROF_AVAILABLE_IN_ALL const gchar *sp_address_context_to_string (SpAddressContext context); static inline gint diff --git a/src/shared/sp-clock.c b/src/libsysprof-capture/sp-clock.c similarity index 100% rename from src/shared/sp-clock.c rename to src/libsysprof-capture/sp-clock.c diff --git a/src/shared/sp-clock.h b/src/libsysprof-capture/sp-clock.h similarity index 92% rename from src/shared/sp-clock.h rename to src/libsysprof-capture/sp-clock.h index 9edeb743..e53773c8 100644 --- a/src/shared/sp-clock.h +++ b/src/libsysprof-capture/sp-clock.h @@ -23,13 +23,16 @@ #include #include +#include "sysprof-version-macros.h" + G_BEGIN_DECLS typedef gint SpClock; typedef gint64 SpTimeStamp; typedef gint32 SpTimeSpan; -extern SpClock sp_clock; +SYSPROF_AVAILABLE_IN_ALL +SpClock sp_clock; static inline SpTimeStamp sp_clock_get_current_time (void) @@ -50,6 +53,7 @@ sp_clock_get_relative_time (SpTimeStamp epoch) return sp_clock_get_current_time () - epoch; } +SYSPROF_AVAILABLE_IN_ALL void sp_clock_init (void); G_END_DECLS diff --git a/src/shared/sp-platform.c b/src/libsysprof-capture/sp-platform.c similarity index 100% rename from src/shared/sp-platform.c rename to src/libsysprof-capture/sp-platform.c diff --git a/src/shared/sp-platform.h b/src/libsysprof-capture/sp-platform.h similarity index 100% rename from src/shared/sp-platform.h rename to src/libsysprof-capture/sp-platform.h diff --git a/src/libsysprof-capture/sysprof-capture.h b/src/libsysprof-capture/sysprof-capture.h index 5e866313..d949b929 100644 --- a/src/libsysprof-capture/sysprof-capture.h +++ b/src/libsysprof-capture/sysprof-capture.h @@ -32,7 +32,6 @@ G_BEGIN_DECLS # include "sp-capture-reader.h" # include "sp-capture-writer.h" # include "sp-clock.h" -# include "sp-error.h" # include "sysprof-version.h" # include "sysprof-version-macros.h" diff --git a/src/libsysprof-capture/sysprof-version-macros.h b/src/libsysprof-capture/sysprof-version-macros.h index 5224d3e5..f7878737 100644 --- a/src/libsysprof-capture/sysprof-version-macros.h +++ b/src/libsysprof-capture/sysprof-version-macros.h @@ -20,10 +20,6 @@ #pragma once -#if !defined (SYSPROF_CAPTURE_INSIDE) && !defined (SYSPROF_CAPTURE_COMPILATION) -# error "Only can be included directly." -#endif - #include #include "sysprof-version.h" diff --git a/src/libsysprof-capture/sysprof-version.h.in b/src/libsysprof-capture/sysprof-version.h.in index d511c72c..811725ad 100644 --- a/src/libsysprof-capture/sysprof-version.h.in +++ b/src/libsysprof-capture/sysprof-version.h.in @@ -20,10 +20,6 @@ #pragma once -#if !defined(SYSPROF_CAPTURE_INSIDE) && !defined(SYSPROF_CAPTURE_COMPILATION) -# error "Only can be included directly." -#endif - /** * SECTION:sysprof-version * @short_description: sysprof version checking diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build index c86aa5ea..2186d099 100644 --- a/src/libsysprof/meson.build +++ b/src/libsysprof/meson.build @@ -6,6 +6,7 @@ libsysprof_public_sources = [ 'sp-elf-symbol-resolver.c', 'sp-hostinfo-source.c', 'sp-jitmap-symbol-resolver.c', + 'sp-kallsyms.c', 'sp-kernel-symbol.c', 'sp-kernel-symbol-resolver.c', 'sp-local-profiler.c', @@ -27,6 +28,7 @@ libsysprof_public_headers = [ 'sp-elf-symbol-resolver.h', 'sp-hostinfo-source.h', 'sp-jitmap-symbol-resolver.h', + 'sp-kallsyms.h', 'sp-kernel-symbol.h', 'sp-kernel-symbol-resolver.h', 'sp-local-profiler.h', @@ -48,6 +50,7 @@ libsysprof_private_sources = [ 'elfparser.c', 'stackstash.c', 'sp-source-util.c', + 'sp-line-reader.c', ] libsysprof_deps = [ diff --git a/src/shared/sp-kallsyms.c b/src/libsysprof/sp-kallsyms.c similarity index 100% rename from src/shared/sp-kallsyms.c rename to src/libsysprof/sp-kallsyms.c diff --git a/src/shared/sp-kallsyms.h b/src/libsysprof/sp-kallsyms.h similarity index 91% rename from src/shared/sp-kallsyms.h rename to src/libsysprof/sp-kallsyms.h index 70cee2d5..2357d0b7 100644 --- a/src/shared/sp-kallsyms.h +++ b/src/libsysprof/sp-kallsyms.h @@ -20,19 +20,20 @@ #pragma once -#include - -#include "sp-kallsyms.h" +#include "sysprof-version-macros.h" G_BEGIN_DECLS typedef struct _SpKallsyms SpKallsyms; +SYSPROF_AVAILABLE_IN_ALL SpKallsyms *sp_kallsyms_new (const gchar *path); +SYSPROF_AVAILABLE_IN_ALL gboolean sp_kallsyms_next (SpKallsyms *self, const gchar **name, guint64 *address, guint8 *type); +SYSPROF_AVAILABLE_IN_ALL void sp_kallsyms_free (SpKallsyms *self); G_DEFINE_AUTOPTR_CLEANUP_FUNC (SpKallsyms, sp_kallsyms_free) diff --git a/src/libsysprof/sp-kernel-symbol.c b/src/libsysprof/sp-kernel-symbol.c index c45fd72a..37f8c699 100644 --- a/src/libsysprof/sp-kernel-symbol.c +++ b/src/libsysprof/sp-kernel-symbol.c @@ -27,7 +27,6 @@ #include #include "sp-kallsyms.h" -#include "sp-line-reader.h" #include "sp-kernel-symbol.h" static GArray *kernel_symbols; diff --git a/src/shared/sp-line-reader.c b/src/libsysprof/sp-line-reader.c similarity index 100% rename from src/shared/sp-line-reader.c rename to src/libsysprof/sp-line-reader.c diff --git a/src/shared/sp-line-reader.h b/src/libsysprof/sp-line-reader.h similarity index 96% rename from src/shared/sp-line-reader.h rename to src/libsysprof/sp-line-reader.h index fd2fcfbf..9fa02c2e 100644 --- a/src/shared/sp-line-reader.h +++ b/src/libsysprof/sp-line-reader.h @@ -26,9 +26,12 @@ G_BEGIN_DECLS typedef struct _SpLineReader SpLineReader; +G_GNUC_INTERNAL SpLineReader *sp_line_reader_new (const gchar *contents, gssize length); +G_GNUC_INTERNAL void sp_line_reader_free (SpLineReader *self); +G_GNUC_INTERNAL const gchar *sp_line_reader_next (SpLineReader *self, gsize *length); diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h index 3c4030d4..1b762dfb 100644 --- a/src/libsysprof/sysprof.h +++ b/src/libsysprof/sysprof.h @@ -27,6 +27,7 @@ G_BEGIN_DECLS # include "sp-callgraph-profile.h" # include "sp-capture-gobject.h" # include "sp-local-profiler.h" +# include "sp-kallsyms.h" # include "sp-profile.h" # include "sp-profiler.h" # include "sp-map-lookaside.h" diff --git a/src/meson.build b/src/meson.build index 4e913226..8b59c281 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,7 +7,6 @@ sysprof_version_conf.set('MINOR_VERSION', sysprof_version[1]) sysprof_version_conf.set('MICRO_VERSION', sysprof_version[2]) sysprof_version_conf.set('VERSION', meson.project_version()) -subdir('shared') subdir('libsysprof-capture') subdir('sysprofd') subdir('libsysprof') diff --git a/src/shared/meson.build b/src/shared/meson.build deleted file mode 100644 index a3afb304..00000000 --- a/src/shared/meson.build +++ /dev/null @@ -1,31 +0,0 @@ -shared_sources = [ - 'sp-address.c', - 'sp-clock.c', - 'sp-error.c', - 'sp-line-reader.c', - 'sp-platform.c', - 'sp-kallsyms.c', -] - -shared_public_headers = [ - 'sp-address.h', - 'sp-clock.h', - 'sp-error.h', - 'sp-platform.h', - 'sp-kallsyms.h', -] - -install_headers(shared_public_headers, subdir: sysprof_header_subdir) - -libshared_deps = [ - dependency('glib-2.0'), -] - -libshared = static_library('shared', shared_sources, - dependencies: libshared_deps, -) - -libshared_dep = declare_dependency( - link_whole: libshared, - include_directories: include_directories('.'), -) diff --git a/src/shared/sp-error.c b/src/shared/sp-error.c deleted file mode 100644 index dd9cf4e0..00000000 --- a/src/shared/sp-error.c +++ /dev/null @@ -1,32 +0,0 @@ -/* sp-error.c - * - * Copyright 2016-2019 Christian Hergert - * - * 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 2 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 . - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -#include "sp-error.h" - -GQuark -sp_error_quark (void) -{ - static GQuark quark; - - if (G_UNLIKELY (!quark)) - quark = g_quark_from_static_string ("sp-error-quark"); - - return quark; -} diff --git a/src/shared/sp-error.h b/src/shared/sp-error.h deleted file mode 100644 index c4fb8d18..00000000 --- a/src/shared/sp-error.h +++ /dev/null @@ -1,31 +0,0 @@ -/* sp-error.h - * - * Copyright 2016-2019 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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 . - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -#pragma once - -#include - -G_BEGIN_DECLS - -#define SP_ERROR (sp_error_quark()) - -GQuark sp_error_quark (void); - -G_END_DECLS diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index f64a2333..df9febae 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -14,7 +14,6 @@ sysprof_resources = gnome.compile_resources('sysprof-resources', 'sysprof.gresou sysprof_deps = [ cc.find_library('m', required: false), - libshared_dep, libsysprof_capture_dep, libsysprof_dep, libsysprof_ui_dep, diff --git a/src/sysprofd/meson.build b/src/sysprofd/meson.build index c3a95347..097c2d65 100644 --- a/src/sysprofd/meson.build +++ b/src/sysprofd/meson.build @@ -4,6 +4,7 @@ sysprofd_sources = [ 'sysprofd.c', 'sd-bus-helper.c', 'sd-bus-helper.h', + '../libsysprof/sp-kallsyms.c', ] pkglibexecdir = join_paths(get_option('prefix'), get_option('libexecdir')) @@ -11,14 +12,14 @@ pkglibexecdir = join_paths(get_option('prefix'), get_option('libexecdir')) sysprofd_deps = [ dependency('libsystemd', version: '>=222'), dependency('glib-2.0', version: glib_req_version), - libshared_dep, ] sysprofd = executable('sysprofd', sysprofd_sources, - dependencies: sysprofd_deps, - install: true, - install_dir: pkglibexecdir, - pie: true, + dependencies: sysprofd_deps, + install: true, + install_dir: pkglibexecdir, + pie: true, + include_directories: [include_directories('.'), '../libsysprof'], ) sysprofdconf = configuration_data() diff --git a/src/tests/test-kallsyms.c b/src/tests/test-kallsyms.c index be141128..417bf563 100644 --- a/src/tests/test-kallsyms.c +++ b/src/tests/test-kallsyms.c @@ -1,8 +1,6 @@ -#include "../shared/sp-address.h" -#include "../shared/sp-kallsyms.h" - #include #include +#include int main (gint argc, diff --git a/src/tools/meson.build b/src/tools/meson.build index d896e6e7..1c7a0e49 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -1,5 +1,4 @@ tools_deps = [ - libshared_dep, libsysprof_capture_dep, ]