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.build b/meson.build index 6550126a..92c49ee5 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') @@ -86,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 @@ -108,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 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/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 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, 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/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/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..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()), @@ -116,9 +118,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', @@ -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 7cd69279..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, @@ -7,6 +9,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, @@ -27,15 +30,19 @@ 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, gio_unix_dep ], - 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 ], c_args: tools_cflags, install: false, ) + +endif