diff --git a/xprof/xprof.rb.in b/xprof/xprof.rb.in index 2bce46c3..161ab2f3 100755 --- a/xprof/xprof.rb.in +++ b/xprof/xprof.rb.in @@ -748,6 +748,7 @@ class SamplingDaemon daemon_path = "#{__dir__}/sampling_daemon" raise "No sampling_daemon binary found at #{daemon_path}" unless File.exist?(daemon_path) + @pid = spawn("#{daemon_path} #{parent_pid}") Process.detach(@pid) @@ -758,7 +759,8 @@ class SamplingDaemon return unless @pid Process.kill(SIG_SAMPLING_FINISH, @pid) - LOGGER.debug("Sent FINISH signal to sampling daemon PID #{@pid}") + + wait_for_ready_signal end private @@ -768,7 +770,7 @@ class SamplingDaemon Signal.trap(SIG_SAMPLING_READY) do received_ready = true end - sleep(0.1) while !received_ready # Wait until READY signal is received + sleep(0.1) until received_ready # Wait until READY signal is received end end @@ -794,7 +796,7 @@ def trace_and_on_node_processing(usr_argv) end # we can kill the session daemon lm_lttng_kill_sessiond - sampling_daemon.finalize if sampling_daemon + sampling_daemon&.finalize end SyncDaemon.open do |syncd| @@ -814,8 +816,8 @@ def trace_and_on_node_processing(usr_argv) syncd.local_barrier('waiting_for_lttng_setup') if sampling? - sampling_daemon = SamplingDaemon.new - sampling_daemon&.start(Process.pid) + sampling_daemon = SamplingDaemon.new + sampling_daemon&.start(Process.pid) end # Launch User Command diff --git a/ze/Makefile.am b/ze/Makefile.am index adf9507d..a38f6ad1 100644 --- a/ze/Makefile.am +++ b/ze/Makefile.am @@ -140,8 +140,6 @@ CLEANFILES += \ $(ZE_STATIC_PROBES_INCL) \ $(ZE_STATIC_PROBES_SRC) - - EXTRA_DIST += \ gen_probe_base.rb \ $(ZE_GEN_TRACEPOINTS) \ @@ -153,22 +151,19 @@ BUILT_SOURCES = \ bin_PROGRAMS = sampling_daemon -sampling_daemon_SOURCES = \ - sampling_daemon.c \ - sampling_daemon.h +sampling_daemon_SOURCES = sampling_daemon.c nodist_sampling_daemon_SOURCES = \ $(ZE_PROBES_INCL) \ $(ZE_STATIC_PROBES_INCL) -sampling_daemon_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/ze/include -I./ +sampling_daemon_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(top_srcdir)/ze/include -I./ sampling_daemon_CFLAGS = -Wall -Wextra $(WERROR) $(LTTNG_UST_CFLAGS) sampling_daemon_LDADD = libzetracepoints.la -ldl -lpthread $(LTTNG_UST_LIBS) ../sampling/libThapiSampling.la tracer_ze.c: $(srcdir)/gen_ze.rb $(srcdir)/tracer_ze_helpers.include.c $(srcdir)/ze.h.include $(ZE_MODEL) $(ZE_PROBES_INCL) $(ZE_STATIC_PROBES_INCL) SRC_DIR=$(srcdir) $(RUBY) $< > $@ - EXTRA_DIST += \ gen_ze.rb \ tracer_ze_helpers.include.c @@ -196,26 +191,13 @@ nodist_libze_loader_la_SOURCES = \ $(ZE_PROBES_INCL) \ $(ZE_STATIC_PROBES_INCL) \ tracer_ze.c - + libze_loader_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(srcdir)/include -I$(top_srcdir)/utils -I./ libze_loader_la_CFLAGS = -Wall -Wextra $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS) libze_loader_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS) ../sampling/libThapiSampling.la libze_loader_la_LDFLAGS += -version-info 1:0:0 libze_loader_la_LIBADD = libzetracepoints.la -install-exec-hook: - $(MKDIR_P) $(DESTDIR)$(pkglibdir)/ze - $(LN_S) -f $(DESTDIR)$(libdir)/libze_loader.so.1.0.0 $(DESTDIR)$(pkglibdir)/ze/libze_loader.so.1 - $(LN_S) -f $(DESTDIR)$(pkglibdir)/ze/libze_loader.so.1 $(DESTDIR)$(pkglibdir)/ze/libze_loader.so - $(MKDIR_P) $(DESTDIR)$(pkglibdir)/bt2 - $(LN) -f $(DESTDIR)$(libdir)/libZEInterval.so $(DESTDIR)$(pkglibdir)/bt2/libZEInterval.so - -uninstall-hook: - $(RM) -f $(DESTDIR)$(pkglibdir)/ze/libze_loader.so.1 $(DESTDIR)$(pkglibdir)/ze/libze_loader.so - -rmdir $(DESTDIR)$(pkglibdir)/ze - $(RM) -f $(DESTDIR)$(pkglibdir)/bt2/libZEInterval.so - -rmdir $(DESTDIR)$(pkglibdir)/bt2 - tmplibdir = $(libdir)/tmp install-data-hook: diff --git a/ze/sampling_daemon.c b/ze/sampling_daemon.c index 2bdd973d..987edf4c 100644 --- a/ze/sampling_daemon.c +++ b/ze/sampling_daemon.c @@ -1,5 +1,4 @@ -#include "sampling_daemon.h" -#include "../sampling/thapi_sampling.h" +#include "thapi_sampling.h" #include "ze_build.h" #include "ze_sampling.h" #include @@ -18,45 +17,25 @@ #define SIG_SAMPLING_FINISH (SIGRTMIN + 1) #define ZES_INIT_PTR zesInit_ptr - #define ZES_DRIVER_GET_PTR zesDriverGet_ptr - #define ZES_DEVICE_GET_PTR zesDeviceGet_ptr - #define ZES_DEVICE_GET_PROPERTIES_PTR zesDeviceGetProperties_ptr - #define ZES_DEVICE_ENUM_POWER_DOMAINS_PTR zesDeviceEnumPowerDomains_ptr - #define ZES_POWER_GET_PROPERTIES_PTR zesPowerGetProperties_ptr - #define ZES_POWER_GET_ENERGY_COUNTER_PTR zesPowerGetEnergyCounter_ptr - #define ZES_DEVICE_ENUM_FREQUENCY_DOMAINS_PTR zesDeviceEnumFrequencyDomains_ptr - #define ZES_FREQUENCY_GET_PROPERTIES_PTR zesFrequencyGetProperties_ptr - #define ZES_FREQUENCY_GET_STATE_PTR zesFrequencyGetState_ptr - #define ZES_DEVICE_ENUM_ENGINE_GROUPS_PTR zesDeviceEnumEngineGroups_ptr - #define ZES_ENGINE_GET_PROPERTIES_PTR zesEngineGetProperties_ptr - #define ZES_ENGINE_GET_ACTIVITY_PTR zesEngineGetActivity_ptr - #define ZES_DEVICE_ENUM_FABRIC_PORTS_PTR zesDeviceEnumFabricPorts_ptr - #define ZES_FABRIC_PORT_GET_PROPERTIES_PTR zesFabricPortGetProperties_ptr - #define ZES_FABRIC_PORT_GET_STATE_PTR zesFabricPortGetState_ptr - #define ZES_FABRIC_PORT_GET_THROUGHPUT_PTR zesFabricPortGetThroughput_ptr - #define ZES_DEVICE_ENUM_MEMORY_MODULES_PTR zesDeviceEnumMemoryModules_ptr - #define ZES_MEMORY_GET_PROPERTIES_PTR zesMemoryGetProperties_ptr - #define ZES_MEMORY_GET_STATE_PTR zesMemoryGetState_ptr - #define ZES_MEMORY_GET_BANDWIDTH_PTR zesMemoryGetBandwidth_ptr typedef ze_result_t (*zesInit_t)(zes_init_flags_t flags); @@ -735,14 +714,15 @@ static void thapi_sampling_energy() { } } } -void process_sampling() { +void process_sampling() { struct timespec interval; interval.tv_sec = 0; interval.tv_nsec = 50000000; // 50ms interval thapi_sampling_energy(); _sampling_handle = thapi_register_sampling(&thapi_sampling_energy, &interval); } + void cleanup_sampling() { if (_sampling_handle) { thapi_unregister_sampling(_sampling_handle); @@ -758,21 +738,23 @@ void signal_handler(int signum) { } int main(int argc, char **argv) { - + + int parent_pid = 0; + int verbose = 0; + void *handle = NULL; if (argc < 2) { _USAGE_MSG("", argv[0]); return 1; } - int parent_pid = atoi(argv[1]); + parent_pid = atoi(argv[1]); if (parent_pid <= 0) { - _ERROR_MSG("Invalid or missing parent PID. A positive integer is required."); + _ERROR_MSG("Invalid or missing parent PID."); return 1; } - int verbose = 0; + thapi_sampling_init();// Initialize sampling // Load necessary libraries - void *handle = NULL; char *s = getenv("LTTNG_UST_ZE_LIBZE_LOADER"); if (s) { handle = dlopen(s, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND); @@ -798,6 +780,9 @@ int main(int argc, char **argv) { while (running) { process_sampling(); } + if (parent_pid != 0) + kill(parent_pid, SIG_SAMPLING_READY); + dlclose(handle); return 0; } diff --git a/ze/sampling_daemon.h b/ze/sampling_daemon.h deleted file mode 100644 index 4f4cd6ed..00000000 --- a/ze/sampling_daemon.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef SAMPLING_DAEMON_H -#define SAMPLING_DAEMON_H - -void initialize_sampling(); -void cleanup_sampling(); - -#endif // SAMPLING_DAEMON_H \ No newline at end of file diff --git a/ze/tracer_ze_helpers.include.c b/ze/tracer_ze_helpers.include.c index ebdc7369..7e5f4a25 100644 --- a/ze/tracer_ze_helpers.include.c +++ b/ze/tracer_ze_helpers.include.c @@ -1,6 +1,3 @@ -//#include "thapi_sampling.h" -//#include "sampling_daemon.h" - #ifdef THAPI_DEBUG #define TAHPI_LOG stderr #define THAPI_DBGLOG(fmt, ...) \ @@ -41,7 +38,6 @@ static int _do_cleanup = 0; static int _do_chained_structs = 0; static int _do_paranoid_drift = 0; static int _do_paranoid_memory_location = 0; -//thapi_sampling_handle_t _sampling_handle = NULL; pthread_mutex_t ze_closures_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -788,15 +784,10 @@ static inline void _dump_memory_info(ze_command_list_handle_t hCommandList, cons {perror((MSG)); fprintf(stderr,"errno=%d at %d(%s)",errno,__LINE__,__FILE__);\ } while (0) - - static void _load_tracer(void) { char *s = NULL; void *handle = NULL; int verbose = 0; - //struct timespec interval; - //thapi_sampling_init(); - s = getenv("LTTNG_UST_ZE_LIBZE_LOADER"); if (s) handle = dlopen(s, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);