diff --git a/src/libsysprof-capture/meson.build b/src/libsysprof-capture/meson.build index 54427de8..4aa41b24 100644 --- a/src/libsysprof-capture/meson.build +++ b/src/libsysprof-capture/meson.build @@ -12,6 +12,7 @@ libsysprof_capture_sources = [ 'sp-capture-cursor.c', 'sp-capture-reader.c', 'sp-capture-writer.c', + 'sp-capture-util.c', ] configure_file( diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build index 92c5f618..15efb12a 100644 --- a/src/libsysprof-ui/meson.build +++ b/src/libsysprof-ui/meson.build @@ -56,7 +56,6 @@ libsysprof_ui_deps = [ dependency('gio-2.0', version: glib_req_version), dependency('gtk+-3.0', version: gtk_req_version), libsysprof_dep, - libshared_dep, ] libsysprof_ui = shared_library('sysprof-ui-@0@'.format(libsysprof_api_version), diff --git a/src/libsysprof/elfparser.c b/src/libsysprof/elfparser.c index 881bcc2f..59b78150 100644 --- a/src/libsysprof/elfparser.c +++ b/src/libsysprof/elfparser.c @@ -15,9 +15,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #include #include -#include +#ifdef __APPLE__ +# include +#else +# include +#endif #include #include "demangle.h" diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build index 597597bd..c86aa5ea 100644 --- a/src/libsysprof/meson.build +++ b/src/libsysprof/meson.build @@ -1,20 +1,17 @@ +libsysprof_c_args = [ '-DSYSPROF_COMPILATION' ] + libsysprof_public_sources = [ 'sp-callgraph-profile.c', 'sp-capture-gobject.c', 'sp-elf-symbol-resolver.c', - 'sp-gjs-source.c', 'sp-hostinfo-source.c', 'sp-jitmap-symbol-resolver.c', 'sp-kernel-symbol.c', 'sp-kernel-symbol-resolver.c', 'sp-local-profiler.c', 'sp-map-lookaside.c', - 'sp-memory-source.c', - 'sp-perf-counter.c', - 'sp-perf-source.c', 'sp-process-model.c', 'sp-process-model-item.c', - 'sp-proc-source.c', 'sp-profile.c', 'sp-profiler.c', 'sp-selection.c', @@ -28,19 +25,14 @@ libsysprof_public_headers = [ 'sp-callgraph-profile-private.h', 'sp-capture-gobject.h', 'sp-elf-symbol-resolver.h', - 'sp-gjs-source.h', 'sp-hostinfo-source.h', 'sp-jitmap-symbol-resolver.h', 'sp-kernel-symbol.h', 'sp-kernel-symbol-resolver.h', 'sp-local-profiler.h', 'sp-map-lookaside.h', - 'sp-memory-source.h', - 'sp-perf-counter.h', - 'sp-perf-source.h', 'sp-process-model.h', 'sp-process-model-item.h', - 'sp-proc-source.h', 'sp-profile.h', 'sp-profiler.h', 'sp-selection.h', @@ -59,13 +51,38 @@ libsysprof_private_sources = [ ] libsysprof_deps = [ - cxx.find_library('stdc++'), dependency('gio-2.0', version: glib_req_version), dependency('gio-unix-2.0', version: glib_req_version), libsysprof_capture_dep, - libshared_dep, ] +if host_machine.system() == 'linux' + libsysprof_public_sources += [ + 'sp-gjs-source.c', + 'sp-memory-source.c', + 'sp-perf-counter.c', + 'sp-perf-source.c', + 'sp-proc-source.c', + ] + + libsysprof_public_headers += [ + 'sp-gjs-source.h', + 'sp-memory-source.h', + 'sp-perf-counter.h', + 'sp-perf-source.h', + 'sp-proc-source.h', + ] +endif + +if host_machine.system() == 'darwin' + libsysprof_deps += [ dependency('libelf') ] + libsysprof_c_args = [ '-DNT_GNU_BUILD_ID=3', '-DELF_NOTE_GNU="GNU"', '-D__LIBELF_INTERNAL__' ] +endif + +if host_machine.system() != 'darwin' + libsysprof_deps += [cxx.find_library('stdc++')] +endif + if get_option('with_sysprofd') != 'none' libsysprof_deps += dependency('polkit-gobject-1') endif @@ -73,7 +90,7 @@ endif libsysprof = shared_library('sysprof-@0@'.format(libsysprof_api_version), libsysprof_public_sources + libsysprof_private_sources, dependencies: libsysprof_deps, - c_args: [ '-DSYSPROF_COMPILATION' ], + c_args: libsysprof_c_args, install: true, install_dir: get_option('libdir'), ) diff --git a/src/libsysprof/sp-callgraph-profile.c b/src/libsysprof/sp-callgraph-profile.c index 5bb90b8a..119ebb9f 100644 --- a/src/libsysprof/sp-callgraph-profile.c +++ b/src/libsysprof/sp-callgraph-profile.c @@ -340,7 +340,7 @@ sp_callgraph_profile_generate_worker (GTask *task, last_context = SP_ADDRESS_CONTEXT_NONE; #endif - node = stack_stash_add_trace (stash, sample->addrs, sample->n_addrs, 1); + node = stack_stash_add_trace (stash, (gpointer)sample->addrs, sample->n_addrs, 1); for (iter = node; iter != NULL; iter = iter->parent) len++; @@ -410,7 +410,7 @@ sp_callgraph_profile_generate_worker (GTask *task, g_array_index (resolved, guint64, len++) = POINTER_TO_U64 ("[Everything]"); - stack_stash_add_trace (resolved_stash, (SpAddress *)(gpointer)resolved->data, len, 1); + stack_stash_add_trace (resolved_stash, (gpointer)resolved->data, len, 1); } ret = TRUE; diff --git a/src/libsysprof/sp-process-model-item.c b/src/libsysprof/sp-process-model-item.c index 7d4b62a4..61cbaf55 100644 --- a/src/libsysprof/sp-process-model-item.c +++ b/src/libsysprof/sp-process-model-item.c @@ -19,7 +19,9 @@ #include #include "sp-process-model-item.h" -#include "sp-proc-source.h" +#ifdef __linux__ +# include "sp-proc-source.h" +#endif struct _SpProcessModelItem { @@ -134,11 +136,13 @@ sp_process_model_item_init (SpProcessModelItem *self) SpProcessModelItem * sp_process_model_item_new (GPid pid) { + g_autofree gchar *cmdline = NULL; SpProcessModelItem *ret; - gchar *cmdline; - gboolean is_kernel; + gboolean is_kernel = FALSE; +#ifdef __linux__ cmdline = sp_proc_source_get_command_line (pid, &is_kernel); +#endif ret = g_object_new (SP_TYPE_PROCESS_MODEL_ITEM, "command-line", cmdline, @@ -146,8 +150,6 @@ sp_process_model_item_new (GPid pid) NULL); ret->is_kernel = is_kernel; - g_free (cmdline); - return ret; } diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h index fa50c34b..3c4030d4 100644 --- a/src/libsysprof/sysprof.h +++ b/src/libsysprof/sysprof.h @@ -29,12 +29,7 @@ G_BEGIN_DECLS # include "sp-local-profiler.h" # include "sp-profile.h" # include "sp-profiler.h" -# include "sp-gjs-source.h" -# include "sp-hostinfo-source.h" # include "sp-map-lookaside.h" -# include "sp-memory-source.h" -# include "sp-perf-source.h" -# include "sp-proc-source.h" # include "sp-source.h" # include "sp-elf-symbol-resolver.h" # include "sp-jitmap-symbol-resolver.h" @@ -44,6 +39,15 @@ G_BEGIN_DECLS # include "sp-symbol-resolver.h" # include "sp-map-lookaside.h" # include "sp-selection.h" + +#ifdef __linux__ +# include "sp-gjs-source.h" +# include "sp-hostinfo-source.h" +# include "sp-memory-source.h" +# include "sp-perf-source.h" +# include "sp-proc-source.h" +#endif + #undef SYSPROF_INSIDE G_END_DECLS diff --git a/src/shared/meson.build b/src/shared/meson.build index 980c7b59..a3afb304 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -4,6 +4,7 @@ shared_sources = [ 'sp-error.c', 'sp-line-reader.c', 'sp-platform.c', + 'sp-kallsyms.c', ] shared_public_headers = [ @@ -11,14 +12,11 @@ shared_public_headers = [ 'sp-clock.h', 'sp-error.h', 'sp-platform.h', + 'sp-kallsyms.h', ] install_headers(shared_public_headers, subdir: sysprof_header_subdir) -if host_machine.system() == 'linux' - shared_sources += ['sp-kallsyms.c'] -endif - libshared_deps = [ dependency('glib-2.0'), ] diff --git a/src/shared/sp-address-fallback.h b/src/shared/sp-address-fallback.h new file mode 100644 index 00000000..6dcbf326 --- /dev/null +++ b/src/shared/sp-address-fallback.h @@ -0,0 +1,6 @@ +#define PERF_CONTEXT_GUEST_USER (-2560) +#define PERF_CONTEXT_GUEST_KERNEL (-2176) +#define PERF_CONTEXT_GUEST (-2048) +#define PERF_CONTEXT_USER (-512) +#define PERF_CONTEXT_KERNEL (-128) +#define PERF_CONTEXT_HV (-32) diff --git a/src/shared/sp-address.c b/src/shared/sp-address.c index 4f3415c6..bf9ba65d 100644 --- a/src/shared/sp-address.c +++ b/src/shared/sp-address.c @@ -18,7 +18,11 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include +#ifdef __linux__ +# include +#else +# include "sp-address-fallback.h" +#endif #include "sp-address.h" diff --git a/src/shared/sp-clock.c b/src/shared/sp-clock.c index 4b6a4e7e..24e3793f 100644 --- a/src/shared/sp-clock.c +++ b/src/shared/sp-clock.c @@ -28,8 +28,10 @@ sp_clock_init (void) static const gint clock_ids[] = { CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, +#ifdef __linux__ CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME_COARSE, +#endif CLOCK_REALTIME, }; diff --git a/src/sysprof/meson.build b/src/sysprof/meson.build index 72c11a4d..f64a2333 100644 --- a/src/sysprof/meson.build +++ b/src/sysprof/meson.build @@ -14,6 +14,9 @@ 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, ] @@ -22,7 +25,6 @@ sysprof = executable('sysprof', sysprof_resources + sysprof_sources, gui_app: true, install_dir: get_option('bindir'), install: true, - pie: true, ) endif diff --git a/src/sysprof/sp-window.c b/src/sysprof/sp-window.c index b2655ddf..faf6d70e 100644 --- a/src/sysprof/sp-window.c +++ b/src/sysprof/sp-window.c @@ -400,6 +400,7 @@ static void sp_window_add_sources (SpWindow *window, SpProfiler *profiler) { +#ifdef __linux__ g_autoptr(SpSource) host_source = NULL; g_autoptr(SpSource) proc_source = NULL; g_autoptr(SpSource) perf_source = NULL; @@ -419,6 +420,7 @@ sp_window_add_sources (SpWindow *window, memory_source = sp_memory_source_new (); sp_profiler_add_source (profiler, memory_source); +#endif } static void diff --git a/src/tests/meson.build b/src/tests/meson.build index dde14836..1fdd5e12 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -6,18 +6,22 @@ test_env = [ 'MALLOC_CHECK_=2', ] +test_deps = [ + libsysprof_dep, +] + test_cflags = [ '-DTEST_DATA_DIR="@0@/data/"'.format(meson.current_source_dir()), ] test_capture = executable('test-capture', 'test-capture.c', c_args: test_cflags, - dependencies: libsysprof_capture_dep, + dependencies: test_deps, ) test_capture_cursor = executable('test-capture-cursor', 'test-capture-cursor.c', c_args: test_cflags, - dependencies: libsysprof_capture_dep, + dependencies: test_deps, ) test('test-capture', test_capture, env: test_env) @@ -26,24 +30,29 @@ test('test-capture-cursor', test_capture_cursor, env: test_env) # Use ./tests/test-kallsyms /proc/kallsyms to test (as user or root) test_kallsyms = executable('test-kallsyms', 'test-kallsyms.c', c_args: test_cflags, - dependencies: libsysprof_dep, + dependencies: test_deps, ) if get_option('enable_gtk') + test_ui_deps = [ + libsysprof_dep, + libsysprof_ui_dep, + ] + test_model_filter = executable('test-model-filter', 'test-model-filter.c', c_args: test_cflags, - dependencies: libsysprof_ui_dep, + dependencies: test_ui_deps, ) test_process_model = executable('test-process-model', 'test-process-model.c', c_args: test_cflags, - dependencies: libsysprof_ui_dep, + dependencies: test_ui_deps, ) test_zoom = executable('test-zoom', 'test-zoom.c', c_args: test_cflags, - dependencies: libsysprof_ui_dep, + dependencies: test_ui_deps, ) test('test-model-filter', test_model_filter, env: test_env) diff --git a/src/tools/meson.build b/src/tools/meson.build index 97ad8253..d896e6e7 100644 --- a/src/tools/meson.build +++ b/src/tools/meson.build @@ -1,20 +1,24 @@ +tools_deps = [ + libshared_dep, + libsysprof_capture_dep, +] -sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c', - dependencies: libsysprof_dep, - install_dir: get_option('bindir'), - install: true, -) +if host_machine.system() == 'linux' + sysprof_cli = executable('sysprof-cli', 'sysprof-cli.c', + dependencies: tools_deps + [libsysprof_dep], + install_dir: get_option('bindir'), + install: true, + ) +endif sysprof_cat = executable('sysprof-cat', 'sysprof-cat.c', - dependencies: libsysprof_capture_dep, + dependencies: tools_deps, install_dir: get_option('bindir'), install: true, - pie: true, ) sysprof_dump = executable('sysprof-dump', 'sysprof-dump.c', - dependencies: libsysprof_capture_dep, + dependencies: tools_deps, install_dir: get_option('bindir'), install: true, - pie: true, )