Merge branch 'glib' into 'master'

Add subproject support to libsysprof-capture

Closes #40

See merge request GNOME/sysprof!31
This commit is contained in:
Christian Hergert
2020-07-04 18:29:37 +00:00
13 changed files with 176 additions and 86 deletions

View File

@ -1,3 +1,7 @@
if get_option('enable_examples')
app = executable('example-app', 'app.c', app = executable('example-app', 'app.c',
dependencies: [dependency('glib-2.0'), libsysprof_capture_dep], dependencies: [dependency('glib-2.0'), libsysprof_capture_dep],
) )
endif

View File

@ -52,30 +52,6 @@ if get_option('default_library') != 'static'
endif endif
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') debugdir = get_option('debugdir')
if debugdir == '' if debugdir == ''
debugdir = join_paths(get_option('prefix'), get_option('libdir'), 'debug') 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.set10('ENABLE_NLS', true)
config_h.set_quoted('PACKAGE_LOCALE_DIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale')) config_h.set_quoted('PACKAGE_LOCALE_DIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR') config_h.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
config_h.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h'))
if cc.has_header('execinfo.h')
config_h.set10('HAVE_EXECINFO_H', true)
endif
config_h.set('HAVE_STRLCPY', cc.has_function('strlcpy')) config_h.set('HAVE_STRLCPY', cc.has_function('strlcpy'))
if get_option('libunwind') if get_option('libunwind')
libunwind_dep = dependency('libunwind-generic', required: false) libunwind_dep = dependency('libunwind-generic', required: false)
if libunwind_dep.found() config_h.set('ENABLE_LIBUNWIND', libunwind_dep.found())
config_h.set10('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]))
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
endif endif
# Development build setup # 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 <linux/perf_event.h>') has_use_clockid = cc.has_member('struct perf_event_attr', 'use_clockid', prefix: '#include <linux/perf_event.h>')
has_clockid = cc.has_member('struct perf_event_attr', 'clockid', prefix: '#include <linux/perf_event.h>') has_clockid = cc.has_member('struct perf_event_attr', 'clockid', prefix: '#include <linux/perf_event.h>')
if has_use_clockid and has_clockid config_h.set('HAVE_PERF_CLOCKID', has_use_clockid and has_clockid)
config_h.set10('HAVE_PERF_CLOCKID', true)
endif
add_project_arguments([ add_project_arguments([
'-I' + meson.build_root(), # config.h '-I' + meson.build_root(), # config.h

View File

@ -32,3 +32,15 @@ option('help', type: 'boolean')
# Disable use of libunwind # Disable use of libunwind
option('libunwind', type: 'boolean') 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')

View File

@ -13,7 +13,9 @@ libsysprof_capture_headers = files([
'sysprof-version-macros.h', '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([ libsysprof_capture_sources = files([
'mapped-ring-buffer.c', 'mapped-ring-buffer.c',
@ -34,6 +36,7 @@ configure_file(
output: 'sysprof-version.h', output: 'sysprof-version.h',
configuration: sysprof_version_conf, configuration: sysprof_version_conf,
install_dir: join_paths(get_option('includedir'), sysprof_header_subdir), install_dir: join_paths(get_option('includedir'), sysprof_header_subdir),
install: not meson.is_subproject(),
) )
libsysprof_capture_deps = [ libsysprof_capture_deps = [
@ -47,7 +50,7 @@ libsysprof_capture = static_library(
dependencies: libsysprof_capture_deps, dependencies: libsysprof_capture_deps,
c_args: [ '-DSYSPROF_CAPTURE_COMPILATION' ], c_args: [ '-DSYSPROF_CAPTURE_COMPILATION' ],
install_dir: get_option('libdir'), install_dir: get_option('libdir'),
install: true, install: not meson.is_subproject(),
gnu_symbol_visibility: 'hidden', gnu_symbol_visibility: 'hidden',
) )
@ -59,15 +62,17 @@ libsysprof_capture_dep = declare_dependency(
include_directories: libsysprof_capture_include_dirs, include_directories: libsysprof_capture_include_dirs,
) )
pkgconfig.generate( if not meson.is_subproject()
libraries: [libsysprof_capture], pkgconfig.generate(
subdirs: [ sysprof_header_subdir ], libraries: [libsysprof_capture],
version: meson.project_version(), subdirs: [ sysprof_header_subdir ],
name: 'sysprof-capture-@0@'.format(libsysprof_api_version), version: meson.project_version(),
filebase: 'sysprof-capture-@0@'.format(libsysprof_api_version), name: 'sysprof-capture-@0@'.format(libsysprof_api_version),
description: 'The static capture library for tools that generate profiling capture data', filebase: 'sysprof-capture-@0@'.format(libsysprof_api_version),
install_dir: join_paths(get_option('libdir'), 'pkgconfig'), description: 'The static capture library for tools that generate profiling capture data',
variables: [ install_dir: join_paths(get_option('libdir'), 'pkgconfig'),
'datadir=' + datadir_for_pc_file, variables: [
], 'datadir=' + datadir_for_pc_file,
) ],
)
endif

View File

@ -621,6 +621,73 @@ sysprof_collector_mark (int64_t time,
} COLLECTOR_END; } 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 void
sysprof_collector_log (int severity, sysprof_collector_log (int severity,
const char *domain, const char *domain,

View File

@ -56,6 +56,8 @@
#pragma once #pragma once
#include <stdarg.h>
#include "sysprof-capture-types.h" #include "sysprof-capture-types.h"
#include "sysprof-macros.h" #include "sysprof-macros.h"
@ -77,6 +79,20 @@ void sysprof_collector_mark (int64_t time,
const char *group, const char *group,
const char *mark, const char *mark,
const char *message); 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 SYSPROF_AVAILABLE_IN_3_36
void sysprof_collector_log (int severity, void sysprof_collector_log (int severity,
const char *domain, const char *domain,

View File

@ -85,9 +85,9 @@ libsysprof_ui_resources = gnome.compile_resources(
) )
libsysprof_ui_deps = [ libsysprof_ui_deps = [
gio_dep, dependency('gio-2.0', version: glib_req_version),
gtk_dep, dependency('gtk+-3.0', version: gtk_req_version),
dazzle_dep, dependency('libdazzle-1.0', version: dazzle_req_version, fallback: ['libdazzle', 'libdazzle_dep']),
libsysprof_dep, libsysprof_dep,
] ]

View File

@ -100,10 +100,19 @@ librax_dep = declare_dependency(
include_directories: include_directories('.'), 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_deps = [
libsysprof_capture_deps, libsysprof_capture_deps,
gio_dep, dependency('gio-2.0', version: glib_req_version),
gio_unix_dep, dependency('gio-unix-2.0', version: glib_req_version),
polkit_dep, polkit_dep,
librax_dep, librax_dep,
] ]

View File

@ -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('MICRO_VERSION', sysprof_version[2])
sysprof_version_conf.set('VERSION', meson.project_version()) sysprof_version_conf.set('VERSION', meson.project_version())
ipc_profiler_src = gnome.gdbus_codegen('ipc-profiler', if get_option('with_sysprofd') == 'bundled' or get_option('libsysprof')
sources: 'org.gnome.Sysprof3.Profiler.xml', ipc_profiler_src = gnome.gdbus_codegen('ipc-profiler',
interface_prefix: 'org.gnome.Sysprof3.', sources: 'org.gnome.Sysprof3.Profiler.xml',
namespace: 'Ipc', interface_prefix: 'org.gnome.Sysprof3.',
) namespace: 'Ipc',
)
ipc_service_src = gnome.gdbus_codegen('ipc-service', ipc_service_src = gnome.gdbus_codegen('ipc-service',
sources: 'org.gnome.Sysprof3.Service.xml', sources: 'org.gnome.Sysprof3.Service.xml',
interface_prefix: 'org.gnome.Sysprof3.', interface_prefix: 'org.gnome.Sysprof3.',
namespace: 'Ipc', namespace: 'Ipc',
) )
ipc_legacy_src = gnome.gdbus_codegen('ipc-legacy', ipc_legacy_src = gnome.gdbus_codegen('ipc-legacy',
sources: 'org.gnome.Sysprof2.xml', sources: 'org.gnome.Sysprof2.xml',
interface_prefix: 'org.gnome.', interface_prefix: 'org.gnome.',
namespace: 'IpcLegacy', namespace: 'IpcLegacy',
) )
if get_option('with_sysprofd') == 'bundled'
install_data(['org.gnome.Sysprof3.Service.xml', install_data(['org.gnome.Sysprof3.Service.xml',
'org.gnome.Sysprof2.xml'], 'org.gnome.Sysprof2.xml'],
install_dir: join_paths(datadir, 'dbus-1/interfaces'), install_dir: join_paths(datadir, 'dbus-1/interfaces'),

View File

@ -17,7 +17,7 @@ sysprof_deps = [
libsysprof_capture_dep, libsysprof_capture_dep,
libsysprof_dep, libsysprof_dep,
libsysprof_ui_dep, libsysprof_ui_dep,
pangoft2_dep, dependency('pangoft2', required: false),
] ]
sysprof = executable('sysprof', sysprof_resources + sysprof_sources, sysprof = executable('sysprof', sysprof_resources + sysprof_sources,

View File

@ -16,10 +16,10 @@ sysprofd_sources = [
pkglibexecdir = join_paths(get_option('prefix'), get_option('libexecdir')) pkglibexecdir = join_paths(get_option('prefix'), get_option('libexecdir'))
sysprofd_deps = [ sysprofd_deps = [
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),
polkit_dep, dependency('polkit-gobject-1', version: polkit_req_version),
libsysprof_capture_dep, libsysprof_capture_dep,
] ]

View File

@ -1,3 +1,5 @@
if get_option('enable_tests')
test_env = [ test_env = [
'G_TEST_SRCDIR="@0@"'.format(meson.current_source_dir()), 'G_TEST_SRCDIR="@0@"'.format(meson.current_source_dir()),
'G_TEST_BUILDDIR="@0@"'.format(meson.current_build_dir()), 'G_TEST_BUILDDIR="@0@"'.format(meson.current_build_dir()),
@ -116,9 +118,9 @@ if get_option('enable_gtk')
test_ui_deps = [ test_ui_deps = [
libsysprof_dep, libsysprof_dep,
libsysprof_ui_dep, libsysprof_ui_dep,
gtk_dep, dependency('gtk+-3.0', version: gtk_req_version),
dazzle_dep, dependency('libdazzle-1.0', version: dazzle_req_version, fallback: ['libdazzle', 'libdazzle_dep']),
pangoft2_dep, dependency('pangoft2', required: false),
] ]
test_model_filter = executable('test-model-filter', 'test-model-filter.c', test_model_filter = executable('test-model-filter', 'test-model-filter.c',
@ -147,3 +149,4 @@ if get_option('enable_gtk')
endif endif
endif endif
endif

View File

@ -1,3 +1,5 @@
if get_option('enable_tools')
tools_deps = [ tools_deps = [
dependency('glib-2.0'), dependency('glib-2.0'),
libsysprof_capture_dep, libsysprof_capture_dep,
@ -7,6 +9,7 @@ tools_cflags = [ '-DSYSPROF_COMPILATION ']
if get_option('libsysprof') and host_machine.system() == 'linux' if get_option('libsysprof') and host_machine.system() == 'linux'
polkit_agent_dep = dependency('polkit-agent-1') 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', sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c',
dependencies: tools_deps + [libsysprof_dep, polkit_dep, polkit_agent_dep], dependencies: tools_deps + [libsysprof_dep, polkit_dep, polkit_agent_dep],
c_args: tools_cflags, c_args: tools_cflags,
@ -27,15 +30,19 @@ sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c',
install: false, install: false,
) )
sysprof_profiler_ctl = executable('sysprof-profiler-ctl', if get_option('with_sysprofd') == 'bundled' or get_option('libsysprof')
[ 'sysprof-profiler-ctl.c', ipc_profiler_src ], sysprof_profiler_ctl = executable('sysprof-profiler-ctl',
dependencies: [ tools_deps, gio_unix_dep ], [ 'sysprof-profiler-ctl.c', ipc_profiler_src ],
c_args: tools_cflags, dependencies: [ tools_deps, dependency('gio-unix-2.0', version: glib_req_version) ],
install: false, c_args: tools_cflags,
) install: false,
)
endif
list_threads = executable('list-threads', ['list-threads.c'], list_threads = executable('list-threads', ['list-threads.c'],
dependencies: [ tools_deps ], dependencies: [ tools_deps ],
c_args: tools_cflags, c_args: tools_cflags,
install: false, install: false,
) )
endif