From 3c7b76c6ba96f1d1ff109d58f8e0b0b7d67a5e01 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Jul 2020 20:00:10 +0100 Subject: [PATCH 1/6] =?UTF-8?q?build:=20Move=20Meson=20dependency()=20call?= =?UTF-8?q?s=20to=20where=20they=E2=80=99re=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids making the project depend on all its dependencies, some of which are optional, when being built as a Meson subproject. Signed-off-by: Philip Withnall --- meson.build | 24 ------------------------ src/libsysprof-ui/meson.build | 6 +++--- src/libsysprof/meson.build | 13 +++++++++++-- src/sysprof/meson.build | 2 +- src/sysprofd/meson.build | 8 ++++---- src/tests/meson.build | 6 +++--- src/tools/meson.build | 3 ++- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/meson.build b/meson.build index 6550126a..57cffa7e 100644 --- a/meson.build +++ b/meson.build @@ -52,30 +52,6 @@ if get_option('default_library') != 'static' endif endif -glib_dep = dependency('glib-2.0', version: glib_req_version) -gio_dep = dependency('gio-2.0', version: glib_req_version) -gio_unix_dep = dependency('gio-unix-2.0', version: glib_req_version) -pangoft2_dep = dependency('pangoft2', required: false) - -if get_option('enable_gtk') - gtk_dep = dependency('gtk+-3.0', version: gtk_req_version) - dazzle_dep = dependency('libdazzle-1.0', version: dazzle_req_version, fallback: ['libdazzle', 'libdazzle_dep']) -endif - -polkit_dep = dependency('polkit-gobject-1', version: '>= 0.114', required: false) -if polkit_dep.found() - config_h.set10('HAVE_POLKIT_AUTOPTR', true) -endif -polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false) - -if polkit_dep.found() - config_h.set10('HAVE_POLKIT', true) -else - if get_option('with_sysprofd') == 'bundled' - error('sysprofd requires polkit @0@'.format(polkit_req_version)) - endif -endif - debugdir = get_option('debugdir') if debugdir == '' debugdir = join_paths(get_option('prefix'), get_option('libdir'), 'debug') diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build index 1151f391..bb3655f8 100644 --- a/src/libsysprof-ui/meson.build +++ b/src/libsysprof-ui/meson.build @@ -85,9 +85,9 @@ libsysprof_ui_resources = gnome.compile_resources( ) libsysprof_ui_deps = [ - gio_dep, - gtk_dep, - dazzle_dep, + dependency('gio-2.0', version: glib_req_version), + dependency('gtk+-3.0', version: gtk_req_version), + dependency('libdazzle-1.0', version: dazzle_req_version, fallback: ['libdazzle', 'libdazzle_dep']), libsysprof_dep, ] diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build index cc5f96ff..a8ecaae1 100644 --- a/src/libsysprof/meson.build +++ b/src/libsysprof/meson.build @@ -100,10 +100,19 @@ librax_dep = declare_dependency( include_directories: include_directories('.'), ) +polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false) +if polkit_dep.found() + libsysprof_c_args += ['-DHAVE_POLKIT'] +endif + +if dependency('polkit-gobject-1', version: '>= 0.114', required: false).found() + libsysprof_c_args += ['-DHAVE_POLKIT_AUTOPTR'] +endif + libsysprof_deps = [ libsysprof_capture_deps, - gio_dep, - gio_unix_dep, + dependency('gio-2.0', version: glib_req_version), + dependency('gio-unix-2.0', version: glib_req_version), polkit_dep, librax_dep, ] diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 7fb58f11..b4e5ea51 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -17,7 +17,7 @@ sysprof_deps = [ libsysprof_capture_dep, libsysprof_dep, libsysprof_ui_dep, - pangoft2_dep, + dependency('pangoft2', required: false), ] sysprof = executable('sysprof', sysprof_resources + sysprof_sources, diff --git a/src/sysprofd/meson.build b/src/sysprofd/meson.build index bf1a652d..719d3af9 100644 --- a/src/sysprofd/meson.build +++ b/src/sysprofd/meson.build @@ -16,10 +16,10 @@ sysprofd_sources = [ pkglibexecdir = join_paths(get_option('prefix'), get_option('libexecdir')) sysprofd_deps = [ - glib_dep, - gio_dep, - gio_unix_dep, - polkit_dep, + dependency('glib-2.0', version: glib_req_version), + dependency('gio-2.0', version: glib_req_version), + dependency('gio-unix-2.0', version: glib_req_version), + dependency('polkit-gobject-1', version: polkit_req_version), libsysprof_capture_dep, ] diff --git a/src/tests/meson.build b/src/tests/meson.build index 1a450aef..b46d6eb1 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -116,9 +116,9 @@ if get_option('enable_gtk') test_ui_deps = [ libsysprof_dep, libsysprof_ui_dep, - gtk_dep, - dazzle_dep, - pangoft2_dep, + dependency('gtk+-3.0', version: gtk_req_version), + dependency('libdazzle-1.0', version: dazzle_req_version, fallback: ['libdazzle', 'libdazzle_dep']), + dependency('pangoft2', required: false), ] test_model_filter = executable('test-model-filter', 'test-model-filter.c', diff --git a/src/tools/meson.build b/src/tools/meson.build index 7cd69279..397f62f0 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -7,6 +7,7 @@ tools_cflags = [ '-DSYSPROF_COMPILATION '] if get_option('libsysprof') and host_machine.system() == 'linux' polkit_agent_dep = dependency('polkit-agent-1') + polkit_dep = dependency('polkit-gobject-1', version: polkit_req_version, required: false) sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c', dependencies: tools_deps + [libsysprof_dep, polkit_dep, polkit_agent_dep], c_args: tools_cflags, @@ -29,7 +30,7 @@ sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c', sysprof_profiler_ctl = executable('sysprof-profiler-ctl', [ 'sysprof-profiler-ctl.c', ipc_profiler_src ], - dependencies: [ tools_deps, gio_unix_dep ], + dependencies: [ tools_deps, dependency('gio-unix-2.0', version: glib_req_version) ], c_args: tools_cflags, install: false, ) From 5d1678974a20b70dff6145901ba95e11ee25cece Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 25 Jun 2020 15:27:37 +0100 Subject: [PATCH 2/6] build: Simplify config file setup This introduces no functional changes, just simplifies the code. As described in the meson manual (https://mesonbuild.com/Configuration.html#configuring-without-an-input-file), passing `false` to `configuration_data.set()` will cause the specified value to be `#undef`fed. Passing `true` will cause it to be defined to 1. Signed-off-by: Philip Withnall --- meson.build | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 57cffa7e..92c49ee5 100644 --- a/meson.build +++ b/meson.build @@ -62,21 +62,14 @@ config_h.set_quoted('GETTEXT_PACKAGE', 'sysprof') config_h.set10('ENABLE_NLS', true) config_h.set_quoted('PACKAGE_LOCALE_DIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale')) config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR') - -if cc.has_header('execinfo.h') - config_h.set10('HAVE_EXECINFO_H', true) -endif +config_h.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h')) config_h.set('HAVE_STRLCPY', cc.has_function('strlcpy')) if get_option('libunwind') libunwind_dep = dependency('libunwind-generic', required: false) - if libunwind_dep.found() - config_h.set10('ENABLE_LIBUNWIND', libunwind_dep.found()) - if cc.has_header_symbol('libunwind.h', 'unw_set_cache_size', dependencies: [libunwind_dep]) - config_h.set10('HAVE_UNW_SET_CACHE_SIZE', 1) - endif - endif + config_h.set('ENABLE_LIBUNWIND', libunwind_dep.found()) + config_h.set('HAVE_UNW_SET_CACHE_SIZE', libunwind_dep.found() and cc.has_header_symbol('libunwind.h', 'unw_set_cache_size', dependencies: [libunwind_dep])) endif # Development build setup @@ -84,9 +77,7 @@ config_h.set('DEVELOPMENT_BUILD', version_split[1].to_int().is_odd()) has_use_clockid = cc.has_member('struct perf_event_attr', 'use_clockid', prefix: '#include ') has_clockid = cc.has_member('struct perf_event_attr', 'clockid', prefix: '#include ') -if has_use_clockid and has_clockid - config_h.set10('HAVE_PERF_CLOCKID', true) -endif +config_h.set('HAVE_PERF_CLOCKID', has_use_clockid and has_clockid) add_project_arguments([ '-I' + meson.build_root(), # config.h From e03b54fca541c51473970ff98b356873ac94c247 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 25 Jun 2020 15:31:16 +0100 Subject: [PATCH 3/6] build: Only run gdbus-codegen if building components which need it This is to avoid running `gdbus-codegen` when building sysprof as a subproject underneath libglib, as by that point in the GLib build process, `gdbus-codegen` is not yet available. The interfaces generated by these `gdbus-codegen` invocations are only needed for `sysprofd` and libsysprof, not for the libraries like `libsysprof-capture`. Signed-off-by: Philip Withnall --- src/meson.build | 32 ++++++++++++++++---------------- src/tools/meson.build | 14 ++++++++------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/meson.build b/src/meson.build index f464cbba..65ab3bae 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,25 +7,25 @@ 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()) -ipc_profiler_src = gnome.gdbus_codegen('ipc-profiler', - sources: 'org.gnome.Sysprof3.Profiler.xml', - interface_prefix: 'org.gnome.Sysprof3.', - namespace: 'Ipc', -) +if get_option('with_sysprofd') == 'bundled' or get_option('libsysprof') + ipc_profiler_src = gnome.gdbus_codegen('ipc-profiler', + sources: 'org.gnome.Sysprof3.Profiler.xml', + interface_prefix: 'org.gnome.Sysprof3.', + namespace: 'Ipc', + ) -ipc_service_src = gnome.gdbus_codegen('ipc-service', - sources: 'org.gnome.Sysprof3.Service.xml', - interface_prefix: 'org.gnome.Sysprof3.', - namespace: 'Ipc', -) + ipc_service_src = gnome.gdbus_codegen('ipc-service', + sources: 'org.gnome.Sysprof3.Service.xml', + interface_prefix: 'org.gnome.Sysprof3.', + namespace: 'Ipc', + ) -ipc_legacy_src = gnome.gdbus_codegen('ipc-legacy', - sources: 'org.gnome.Sysprof2.xml', - interface_prefix: 'org.gnome.', - namespace: 'IpcLegacy', -) + ipc_legacy_src = gnome.gdbus_codegen('ipc-legacy', + sources: 'org.gnome.Sysprof2.xml', + interface_prefix: 'org.gnome.', + namespace: 'IpcLegacy', + ) -if get_option('with_sysprofd') == 'bundled' install_data(['org.gnome.Sysprof3.Service.xml', 'org.gnome.Sysprof2.xml'], install_dir: join_paths(datadir, 'dbus-1/interfaces'), diff --git a/src/tools/meson.build b/src/tools/meson.build index 397f62f0..97a242dd 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -28,12 +28,14 @@ sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c', install: false, ) -sysprof_profiler_ctl = executable('sysprof-profiler-ctl', - [ 'sysprof-profiler-ctl.c', ipc_profiler_src ], - dependencies: [ tools_deps, dependency('gio-unix-2.0', version: glib_req_version) ], - c_args: tools_cflags, - install: false, -) +if get_option('with_sysprofd') == 'bundled' or get_option('libsysprof') + sysprof_profiler_ctl = executable('sysprof-profiler-ctl', + [ 'sysprof-profiler-ctl.c', ipc_profiler_src ], + dependencies: [ tools_deps, dependency('gio-unix-2.0', version: glib_req_version) ], + c_args: tools_cflags, + install: false, + ) +endif list_threads = executable('list-threads', ['list-threads.c'], dependencies: [ tools_deps ], From d6e8d39292143755e5b19e96422e239442fd0e92 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 25 Jun 2020 15:38:42 +0100 Subject: [PATCH 4/6] build: Add subproject support for libsysprof-capture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used to build libsysprof-capture as a subproject within libglib, with the symbols from libglib being left unresolved until the static libsysprof-capture is linked into libglib. When built as a subproject, libsysprof-capture won’t install anything. Signed-off-by: Philip Withnall --- src/libsysprof-capture/meson.build | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libsysprof-capture/meson.build b/src/libsysprof-capture/meson.build index c8cd6895..5f5b7ca2 100644 --- a/src/libsysprof-capture/meson.build +++ b/src/libsysprof-capture/meson.build @@ -13,7 +13,9 @@ libsysprof_capture_headers = files([ 'sysprof-version-macros.h', ]) -install_headers(libsysprof_capture_headers, subdir: sysprof_header_subdir) +if not meson.is_subproject() + install_headers(libsysprof_capture_headers, subdir: sysprof_header_subdir) +endif libsysprof_capture_sources = files([ 'mapped-ring-buffer.c', @@ -34,6 +36,7 @@ configure_file( output: 'sysprof-version.h', configuration: sysprof_version_conf, install_dir: join_paths(get_option('includedir'), sysprof_header_subdir), + install: not meson.is_subproject(), ) libsysprof_capture_deps = [ @@ -47,7 +50,7 @@ libsysprof_capture = static_library( dependencies: libsysprof_capture_deps, c_args: [ '-DSYSPROF_CAPTURE_COMPILATION' ], install_dir: get_option('libdir'), - install: true, + install: not meson.is_subproject(), gnu_symbol_visibility: 'hidden', ) @@ -59,15 +62,17 @@ libsysprof_capture_dep = declare_dependency( include_directories: libsysprof_capture_include_dirs, ) -pkgconfig.generate( - libraries: [libsysprof_capture], - subdirs: [ sysprof_header_subdir ], - version: meson.project_version(), - name: 'sysprof-capture-@0@'.format(libsysprof_api_version), - filebase: 'sysprof-capture-@0@'.format(libsysprof_api_version), - description: 'The static capture library for tools that generate profiling capture data', - install_dir: join_paths(get_option('libdir'), 'pkgconfig'), - variables: [ - 'datadir=' + datadir_for_pc_file, - ], -) +if not meson.is_subproject() + pkgconfig.generate( + libraries: [libsysprof_capture], + subdirs: [ sysprof_header_subdir ], + version: meson.project_version(), + name: 'sysprof-capture-@0@'.format(libsysprof_api_version), + filebase: 'sysprof-capture-@0@'.format(libsysprof_api_version), + description: 'The static capture library for tools that generate profiling capture data', + install_dir: join_paths(get_option('libdir'), 'pkgconfig'), + variables: [ + 'datadir=' + datadir_for_pc_file, + ], + ) +endif From e8790bc3d63e4d5235930f82c41c6febefc935ca Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Jul 2020 20:05:47 +0100 Subject: [PATCH 5/6] build: Add more Meson options for disabling parts of the build This is all aimed at making it so that sysprof can be built as a subproject within GLib, with only `libsysprof-capture-4.a` being produced as output. Signed-off-by: Philip Withnall --- examples/meson.build | 4 ++++ meson_options.txt | 12 ++++++++++++ src/tests/meson.build | 3 +++ src/tools/meson.build | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/examples/meson.build b/examples/meson.build index 71a036a4..4cef7d15 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1,3 +1,7 @@ +if get_option('enable_examples') + app = executable('example-app', 'app.c', dependencies: [dependency('glib-2.0'), libsysprof_capture_dep], ) + +endif diff --git a/meson_options.txt b/meson_options.txt index 623945c7..10f90fb1 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -32,3 +32,15 @@ option('help', type: 'boolean') # Disable use of libunwind option('libunwind', type: 'boolean') + +# Optionally disable the tools (this is mostly only useful for building only +# libsysprof-capture as a subproject) +option('enable_tools', type: 'boolean') + +# Optionally disable the tests (this is mostly only useful for building only +# libsysprof-capture as a subproject) +option('enable_tests', type: 'boolean') + +# Optionally disable the examples (this is mostly only useful for building only +# libsysprof-capture as a subproject) +option('enable_examples', type: 'boolean') diff --git a/src/tests/meson.build b/src/tests/meson.build index b46d6eb1..e2c1d65a 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -1,3 +1,5 @@ +if get_option('enable_tests') + test_env = [ 'G_TEST_SRCDIR="@0@"'.format(meson.current_source_dir()), 'G_TEST_BUILDDIR="@0@"'.format(meson.current_build_dir()), @@ -147,3 +149,4 @@ if get_option('enable_gtk') endif endif +endif diff --git a/src/tools/meson.build b/src/tools/meson.build index 97a242dd..6b49511d 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -1,3 +1,5 @@ +if get_option('enable_tools') + tools_deps = [ dependency('glib-2.0'), libsysprof_capture_dep, @@ -42,3 +44,5 @@ list_threads = executable('list-threads', ['list-threads.c'], c_args: tools_cflags, install: false, ) + +endif From 6fde9c5ce6f76dee44d9a76480eb364a3593676c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 Jul 2020 20:30:41 +0100 Subject: [PATCH 6/6] libsysprof-capture: Add sysprof_collector_mark_{v,}printf() methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are just like `sysprof_collector_mark()`, but do the printf formatting of the message internally, and only once the collector has been fetched — so there is no overhead from the printf if sysprof is not enabled at runtime. Signed-off-by: Philip Withnall --- src/libsysprof-capture/sysprof-collector.c | 67 ++++++++++++++++++++++ src/libsysprof-capture/sysprof-collector.h | 16 ++++++ 2 files changed, 83 insertions(+) diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c index d95aee8c..6d9e6b1c 100644 --- a/src/libsysprof-capture/sysprof-collector.c +++ b/src/libsysprof-capture/sysprof-collector.c @@ -621,6 +621,73 @@ sysprof_collector_mark (int64_t time, } COLLECTOR_END; } +void +sysprof_collector_mark_printf (int64_t time, + int64_t duration, + const char *group, + const char *mark, + const char *message_format, + ...) +{ + va_list args; + + va_start (args, message_format); + sysprof_collector_mark_vprintf (time, duration, group, mark, message_format, args); + va_end (args); +} + +void +sysprof_collector_mark_vprintf (int64_t time, + int64_t duration, + const char *group, + const char *mark, + const char *message_format, + va_list args) +{ + COLLECTOR_BEGIN { + SysprofCaptureMark *ev; + size_t len; + size_t sl; + va_list args2; + + /* Need to take a copy of @args since we iterate through it twice, once to + * work out the formatted string length, and once to format it. */ + va_copy (args2, args); + + if (group == NULL) + group = ""; + + if (mark == NULL) + mark = ""; + + if (message_format == NULL) + message_format = ""; + + /* Work out the formatted message length */ + sl = vsnprintf (NULL, 0, message_format, args); + + len = realign (sizeof *ev + sl + 1); + + if ((ev = mapped_ring_buffer_allocate (collector->buffer, len))) + { + ev->frame.len = len; + ev->frame.type = SYSPROF_CAPTURE_FRAME_MARK; + ev->frame.cpu = _do_getcpu (); + ev->frame.pid = collector->pid; + ev->frame.time = time; + ev->duration = duration; + _sysprof_strlcpy (ev->group, group, sizeof ev->group); + _sysprof_strlcpy (ev->name, mark, sizeof ev->name); + vsnprintf (ev->message, sl + 1, message_format, args2); + ev->message[sl] = 0; + + mapped_ring_buffer_advance (collector->buffer, ev->frame.len); + } + + va_end (args2); + } COLLECTOR_END; +} + void sysprof_collector_log (int severity, const char *domain, diff --git a/src/libsysprof-capture/sysprof-collector.h b/src/libsysprof-capture/sysprof-collector.h index b91a5a7c..577c3bf7 100644 --- a/src/libsysprof-capture/sysprof-collector.h +++ b/src/libsysprof-capture/sysprof-collector.h @@ -56,6 +56,8 @@ #pragma once +#include + #include "sysprof-capture-types.h" #include "sysprof-macros.h" @@ -77,6 +79,20 @@ void sysprof_collector_mark (int64_t time, const char *group, const char *mark, const char *message); +SYSPROF_AVAILABLE_IN_3_38 +void sysprof_collector_mark_printf (int64_t time, + int64_t duration, + const char *group, + const char *mark, + const char *message_format, + ...) SYSPROF_PRINTF(5, 6); +SYSPROF_AVAILABLE_IN_3_38 +void sysprof_collector_mark_vprintf (int64_t time, + int64_t duration, + const char *group, + const char *mark, + const char *message_format, + va_list args) SYSPROF_PRINTF(5, 0); SYSPROF_AVAILABLE_IN_3_36 void sysprof_collector_log (int severity, const char *domain,