Skip to content

Commit

Permalink
Squashed sampling commits. (#143)
Browse files Browse the repository at this point in the history
* Add event for level zero sampling.

* Fix issue with ze event sampling.

* Add example of argument to first heartbeat.

* added gpu energy sampling. do_tracepoint not working

* Domain Power Tracer

* Added babeltrace_energy

* Frequency Tracing

* Added support for frequency in the timeline?

* Allow deprecated for protobuf/perfetto.

* Use interval to process frequency, and define new interval frequency …

* Try using FTrace suport and lttng clock for now.

* Frequency Multi-device Timeline

* Power and frequency Timeline 

* Update xprof/xprof.sh.erb.in

* Cleaned up power-tracer and perfetto proto

* Apply suggestions from code review

* Style formatting.

* Renamed global variables.

* Fix build system.

* Enable sampling energy with --sample.

---------

Co-authored-by: Solomon Bekele <[email protected]>
Co-authored-by: Thomas Applencourt <[email protected]>
Co-authored-by: sbekele <[email protected]>
Co-authored-by: Kazutomo Yoshii <[email protected]>
Co-authored-by: Swann Perarnau <[email protected]>
  • Loading branch information
6 people authored Sep 8, 2023
1 parent 6d30d7a commit cf3cffa
Show file tree
Hide file tree
Showing 38 changed files with 1,618 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = utils opencl ze xprof cuda omp hip
SUBDIRS = utils xprof sampling opencl ze cuda omp hip

EXTRA_DIST = autogen.sh README.md
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ AC_CHECK_FUNCS([atexit clock_gettime ftruncate memmove memset strdup strstr strt

AC_CONFIG_FILES([Makefile
utils/Makefile
sampling/Makefile
xprof/xprof.sh.erb
opencl/Makefile
ze/Makefile
Expand All @@ -113,6 +114,7 @@ AC_CONFIG_FILES([ze/test_wrapper.sh], [chmod +x ze/test_wrapper.sh])
AC_CONFIG_FILES([cuda/tracer_cuda.sh], [chmod +x cuda/tracer_cuda.sh])
AC_CONFIG_FILES([cuda/test_wrapper.sh], [chmod +x cuda/test_wrapper.sh])
AC_CONFIG_FILES([xprof/test_wrapper.sh], [chmod +x xprof/test_wrapper.sh])
AC_CONFIG_FILES([utils/babeltrace_energy], [chmod +x utils/babeltrace_energy])
AC_CONFIG_FILES([utils/babeltrace_thapi], [chmod +x utils/babeltrace_thapi])
AC_CONFIG_FILES([omp/tracer_omp.sh], [chmod +x omp/tracer_omp.sh])
AC_CONFIG_FILES([hip/tracer_hip.sh], [chmod +x hip/tracer_hip.sh])
Expand Down
8 changes: 4 additions & 4 deletions cuda/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,19 @@ nodist_libTracerCUDA_la_SOURCES = \
$(CUDA_PROBES_INCL) \
tracer_cuda.c

libTracerCUDA_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I../utils -I./
libTracerCUDA_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(srcdir)/include -I../utils -I./
libTracerCUDA_la_CFLAGS = -Wall -Wextra $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS)
libTracerCUDA_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS)
libTracerCUDA_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS) ../sampling/libThapiSampling.la
libTracerCUDA_la_LDFLAGS += -version-info 1:0:0
libTracerCUDA_la_LIBADD = libcudatracepoints.la

nodist_libTracerCUDART_la_SOURCES = \
$(CUDART_PROBES_INCL) \
tracer_cudart.c

libTracerCUDART_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I../utils -I./
libTracerCUDART_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(srcdir)/include -I../utils -I./
libTracerCUDART_la_CFLAGS = -Wall -Wextra $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS)
libTracerCUDART_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS)
libTracerCUDART_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS) ../sampling/libThapiSampling.la
libTracerCUDART_la_LDFLAGS += -version-number 12:1:55 -Wl,--version-script,tracer_cudart.map
libTracerCUDART_la_LIBADD = libcudarttracepoints.la

Expand Down
8 changes: 8 additions & 0 deletions cuda/tracer_cuda.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ display_help() {
echo " -e, --exports Trace export functions"
echo " -v, --visualize Visualize trace on thefly"
echo " --properties Dump devices infos"
echo " --sample Sample performance counters"
exit 1
}

Expand All @@ -61,6 +62,7 @@ while true; do
-e | --exports ) shift; exports=1;;
-v | --visualize ) shift; lttng_view=1;;
--properties ) shift; properties=1;;
--sample ) shift; sample=1;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -101,6 +103,12 @@ if [ ! -z "$properties" ]
then
lttng enable-event --channel=blocking-channel --userspace lttng_ust_cuda_properties:*
fi
if [ ! -z "$sample" ]
then
export LTTNG_UST_SAMPLING=1
lttng enable-channel --userspace nonblocking-channel
lttng enable-event --channel=nonblocking-channel --userspace lttng_ust_sampling:*
fi
if [ -z "$LTTNG_UST_CUDA_LIBCUDA" ]
then
LTTNG_UST_CUDA_LIBCUDA=$(whichlib64_head libcuda.so)
Expand Down
4 changes: 4 additions & 0 deletions cuda/tracer_cuda_helpers.include.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "thapi_sampling.h"

//pthread_mutex_t cuda_closures_mutex = PTHREAD_MUTEX_INITIALIZER;
//
//struct cuda_closure {
Expand Down Expand Up @@ -485,6 +487,8 @@ static void _load_tracer(void) {
void *handle = NULL;
int verbose = 0;

thapi_sampling_init();

s = getenv("LTTNG_UST_CUDA_LIBCUDA");
if (s)
handle = dlopen(s, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
Expand Down
4 changes: 4 additions & 0 deletions cuda/tracer_cudart_helpers.include.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "thapi_sampling.h"

static pthread_once_t _init = PTHREAD_ONCE_INIT;
static __thread volatile int in_init = 0;
static volatile int _initialized = 0;
Expand All @@ -7,6 +9,8 @@ static void _load_tracer(void) {
void *handle = NULL;
int verbose = 0;

thapi_sampling_init();

s = getenv("LTTNG_UST_CUDART_LIBCUDART");
if (s)
handle = dlopen(s, RTLD_LAZY | RTLD_LOCAL);
Expand Down
4 changes: 2 additions & 2 deletions hip/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ nodist_libTracerHIP_la_SOURCES = \
$(HIP_PROBES_INCL) \
tracer_hip.c

libTracerHIP_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./utils -I./
libTracerHIP_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(srcdir)/include -I./utils -I./
libTracerHIP_la_CFLAGS = -Wall -Wextra $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS)
libTracerHIP_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS)
libTracerHIP_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS) ../sampling/libThapiSampling.la
libTracerHIP_la_LDFLAGS += -Wl,--version-script,$(srcdir)/hip.map -version-number 5:4:50400
libTracerHIP_la_DEPENDS = $(srcdir)/hip.map
libTracerHIP_la_LIBADD = libhiptracepoints.la
Expand Down
4 changes: 2 additions & 2 deletions omp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ nodist_libTracerOMPT_la_SOURCES = \
$(OMP_PROBES_INCL) \
tracer_ompt.c

libTracerOMPT_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I./modified_include -I../utils -I./
libTracerOMPT_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I./modified_include -I../utils -I./
libTracerOMPT_la_CFLAGS = -Wall -Wextra $(WERROR) $(LTTNG_UST_CFLAGS)
libTracerOMPT_la_LDFLAGS = $(LTTNG_UST_LIBS) -avoid-version -module
libTracerOMPT_la_LDFLAGS = $(LTTNG_UST_LIBS) -avoid-version -module ../sampling/libThapiSampling.la
libTracerOMPT_la_LIBADD = libompttracepoints.la

install-exec-hook:
Expand Down
8 changes: 8 additions & 0 deletions omp/tracer_omp.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ display_help() {
echo " --help Show this screen"
echo " --version Print the version string"
echo " --disable-intel-extensions Disable Intel extensions"
echo " --sample Sample performance counters"
exit 1
}

Expand All @@ -26,6 +27,7 @@ while true; do
--help ) display_help; exit;;
--version ) display_version; exit;;
--disable-intel-extensions) intel_extensions=false shift;;
--sample ) shift; sample=1;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -53,6 +55,12 @@ export LTTNG_UST_ALLOW_BLOCKING=1
if [ "$intel_extensions" = true ] ; then
export LTTNG_UST_OMP_INTEL=1
fi
if [ ! -z "$sample" ]
then
export LTTNG_UST_SAMPLING=1
lttng enable-channel --userspace nonblocking-channel
lttng enable-event --channel=nonblocking-channel --userspace lttng_ust_sampling:*
fi

lttng start

Expand Down
4 changes: 4 additions & 0 deletions omp/tracer_ompt_helpers.include.c.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "thapi_sampling.h"

<% require "yaml" %>

#define _OMPT_SET_CALLBACK(value, name) \
Expand Down Expand Up @@ -33,6 +35,8 @@ static int _ompt_initialize(ompt_function_lookup_t lookup,
int do_callbacks_intel = 0;
int verbose = 0;

thapi_sampling_init();

if (getenv("LTTNG_UST_OMP_INTEL"))
do_callbacks_intel = 1;
if (getenv("LTTNG_UST_OMP_VERBOSE"))
Expand Down
4 changes: 2 additions & 2 deletions opencl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ nodist_libTracerOpenCL_la_SOURCES = \
tracer_opencl.h \
tracer_opencl.c

libTracerOpenCL_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I../utils -I./
libTracerOpenCL_la_CPPFLAGS = -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(top_srcdir)/sampling -I$(srcdir)/include -I../utils -I./
libTracerOpenCL_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter $(WERROR) $(LIBFFI_CFLAGS) $(LTTNG_UST_CFLAGS)
libTracerOpenCL_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS)
libTracerOpenCL_la_LDFLAGS = $(LTTNG_UST_LIBS) -ldl -lpthread $(LIBFFI_LIBS) ../sampling/libThapiSampling.la
libTracerOpenCL_la_LDFLAGS += -Wl,--version-script,$(srcdir)/tracer_opencl.map -version-info 1:0:0
libTracerOpenCL_la_DEPENDS = $(srcdir)/tracer_opencl.map
libTracerOpenCL_la_LIBADD = libtracepoints.la
Expand Down
8 changes: 8 additions & 0 deletions opencl/tracer_opencl.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ display_help() {
echo " -e, --iteration-end VALUE Dump inputs and outputs for kernels until enqueue counter VALUE"
echo " -v, --visualize Visualize trace on thefly"
echo " --devices Dump devices information"
echo " --sample Sample performance counters"
exit 1
}

Expand All @@ -73,6 +74,7 @@ while true; do
-e | --iteration-end ) shift; export LTTNG_UST_OPENCL_DUMP=1; export LTTNG_UST_OPENCL_DUMP_END=$1; shift ;;
-v | --visualize) shift; lttng_view=1;;
--devices ) shift; devices=1;;
--sample ) shift; sample=1;;
-- ) shift; break ;;
* ) break ;;
esac
Expand Down Expand Up @@ -117,6 +119,12 @@ if [ ! -z "$build" ]
then
lttng enable-event --channel=blocking-channel --userspace lttng_ust_opencl_build:*
fi
if [ ! -z "$sample" ]
then
export LTTNG_UST_SAMPLING=1
lttng enable-channel --userspace nonblocking-channel
lttng enable-event --channel=nonblocking-channel --userspace lttng_ust_sampling:*
fi
if [ ! -z "$LTTNG_UST_OPENCL_DUMP" ]
then
lttng enable-event --channel=blocking-channel --userspace lttng_ust_opencl_dump:*
Expand Down
4 changes: 4 additions & 0 deletions opencl/tracer_opencl_helpers.include.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "thapi_sampling.h"

void CL_CALLBACK event_notify (cl_event event, cl_int event_command_exec_status, void *user_data) {
(void)user_data;
if (tracepoint_enabled(lttng_ust_opencl_profiling, event_profiling_results)) {
Expand Down Expand Up @@ -1180,6 +1182,8 @@ static void _load_tracer(void) {
void * handle = NULL;
int verbose = 0;

thapi_sampling_init();

s = getenv("LTTNG_UST_OPENCL_LIBOPENCL");
if (s)
handle = dlopen(s, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
Expand Down
59 changes: 59 additions & 0 deletions sampling/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
if STRICT
WERROR = -Werror
else
WERROR =
endif
LTTNG_FLAGS = -fPIC -Wall -Wextra -Wno-unused-parameter -Wno-type-limits -Wno-sign-compare $(WERROR) -I$(top_srcdir)/utils -I$(top_srcdir)/utils/include -I$(srcdir)/include -I../utils -I./


TRACEPOINT_GEN = \
$(srcdir)/sampling_events.yaml

SAMPLING_STATIC_PROBES = \
sampling

SAMPLING_STATIC_PROBES_TP = $(SAMPLING_STATIC_PROBES:=.tp)

SAMPLING_STATIC_PROBES_INCL = $(SAMPLING_STATIC_PROBES:=.h)

SAMPLING_STATIC_PROBES_SRC = $(SAMPLING_STATIC_PROBES:=.c)

$(SAMPLING_STATIC_PROBES_TP): %.tp: $(srcdir)/gen_sampling_custom_probes.rb $(TRACEPOINT_GEN)
SRC_DIR=$(srcdir) $(RUBY) $< lttng_ust_$* > $@

%.h %.c: %.tp
$(LTTNG_GEN_TP) $< -o $*.c -o $*.h

noinst_LTLIBRARIES = libtracepoints.la

nodist_libtracepoints_la_SOURCES = \
$(SAMPLING_STATIC_PROBES_INCL) \
$(SAMPLING_STATIC_PROBES_SRC)

libtracepoints_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS)
libtracepoints_la_LDFLAGS = $(LTTNG_UST_LIBS)

EXTRA_DIST = \
sampling_events.yaml \
gen_sampling_custom_probes.rb

CLEANFILES = \
$(SAMPLING_STATIC_PROBES_INCL) \
$(SAMPLING_STATIC_PROBES_TP) \
$(SAMPLING_STATIC_PROBES_SRC)

BUILT_SOURCES = \
$(SAMPLING_STATIC_PROBES_INCL)

nodist_libThapiSampling_la_SOURCES = \
$(SAMPLING_STATIC_PROBES_INCL)

libThapiSampling_la_SOURCES = \
thapi_sampling.h \
thapi_sampling.c

libThapiSampling_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter $(WERROR) -I$(top_srcdir)/utils/include
libThapiSampling_la_LDFLAGS = -lpthread -version-info 1:0:0
libThapiSampling_la_LIBADD = libtracepoints.la

lib_LTLIBRARIES = libThapiSampling.la
32 changes: 32 additions & 0 deletions sampling/gen_sampling_custom_probes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'yaml'
require_relative '../utils/LTTng'

if ENV["SRC_DIR"]
SRC_DIR = ENV["SRC_DIR"]
else
SRC_DIR = "."
end

namespace = ARGV[0]

raise "No namespace provided!" unless namespace

h = YAML::load_file(File.join(SRC_DIR,"sampling_events.yaml"))[namespace]

raise "Invalid namespace!" unless h

puts <<EOF
#include "lttng/tracepoint_gen.h"
EOF
enums = h["enums"]

if enums
enums.each { |e|
LTTng.print_enum(namespace, e)
}
end

h["events"].each { |e|
LTTng.print_tracepoint(namespace, e)
}
11 changes: 11 additions & 0 deletions sampling/sampling_events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
lttng_ust_sampling:
events:
- name: heartbeat
args:
- [uint64_t, foo]
fields:
- [ctf_integer, uint64_t, foo, foo]
- name: heartbeat2
args: []
fields: []
Loading

0 comments on commit cf3cffa

Please sign in to comment.