Skip to content

Commit

Permalink
PR comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
solo2abera committed Nov 15, 2024
1 parent 5b2246e commit 23bd204
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 70 deletions.
12 changes: 7 additions & 5 deletions xprof/xprof.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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|
Expand All @@ -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
Expand Down
24 changes: 3 additions & 21 deletions ze/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ CLEANFILES += \
$(ZE_STATIC_PROBES_INCL) \
$(ZE_STATIC_PROBES_SRC)



EXTRA_DIST += \
gen_probe_base.rb \
$(ZE_GEN_TRACEPOINTS) \
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
41 changes: 13 additions & 28 deletions ze/sampling_daemon.c
Original file line number Diff line number Diff line change
@@ -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 <dlfcn.h>
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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("<parent_pid>", 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);
Expand All @@ -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;
}
7 changes: 0 additions & 7 deletions ze/sampling_daemon.h

This file was deleted.

9 changes: 0 additions & 9 deletions ze/tracer_ze_helpers.include.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//#include "thapi_sampling.h"
//#include "sampling_daemon.h"

#ifdef THAPI_DEBUG
#define TAHPI_LOG stderr
#define THAPI_DBGLOG(fmt, ...) \
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 23bd204

Please sign in to comment.