Skip to content

Commit

Permalink
Make function tracing optional. (#185)
Browse files Browse the repository at this point in the history
1. Disable function tracing by default.
2. Store the cmake option in dftracer_config.h
3. Compile out ftracing when disabled.
4. Add documentations.
  • Loading branch information
hariharan-devarajan authored Sep 8, 2024
1 parent 7696c9e commit 7ab8a88
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 27 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ if (NOT DFTRACER_DISABLE_HWLOC)
set(DFTRACER_HWLOC_ENABLE 1)
endif()

# Options
option (DFTRACER_ENABLE_FTRACING "Enable Function Tracing" OFF)
if (DFTRACER_ENABLE_FTRACING)
set(DFTRACER_FTRACING_ENABLE 1)
set(DFTRACER_FUNCTION_FLAGS "-g" "-finstrument-functions" "-Wl,-E" "-fvisibility=default")
else()
set(DFTRACER_FUNCTION_FLAGS )
endif()

option (DFTRACER_ENABLE_MPI "Enable MPI" On)
if (DFTRACER_ENABLE_MPI)
set(DFTRACER_MPI_ENABLE 1)
Expand Down Expand Up @@ -584,6 +593,8 @@ string(APPEND _str
append_str_tf(_str
DFTRACER_GNU_LINUX
DFTRACER_LIBDIR_AS_LIB
DFTRACER_ENABLE_FTRACING
DFTRACER_ENABLE_MPI
DFTRACER_USE_CLANG_LIBCXX
DFTRACER_WARNINGS_AS_ERRORS
DFTRACER_BUILD_PYTHON_BINDINGS
Expand Down
6 changes: 5 additions & 1 deletion cmake/configure_files/dftracer-config.cmake.build.in
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ if (DFTRACER_INCLUDE_MPI)
message(FATAL_ERROR "-- [DFTRACER] mpi is needed for ${PROJECT_NAME} build")
endif ()
endif()

set(DFTRACER_ENABLE_FTRACING @DFTRACER_ENABLE_FTRACING@)
if (DFTRACER_ENABLE_FTRACING)
set(DFTRACER_FUNCTION_FLAGS "-g" "-finstrument-functions" "-Wl,-E" "-fvisibility=default")
else()
set(DFTRACER_FUNCTION_FLAGS )
endif()
check_required_components(dftracer)

set(DFTRACER_LIBRARIES dftracer)
6 changes: 5 additions & 1 deletion cmake/configure_files/dftracer-config.cmake.install.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ if (DFTRACER_INCLUDE_MPI)
message(FATAL_ERROR "-- [DFTRACER] mpi is needed for ${PROJECT_NAME} build")
endif ()
endif()
set(DFTRACER_ENABLE_FTRACING @DFTRACER_ENABLE_FTRACING@)
if (DFTRACER_ENABLE_FTRACING)
set(DFTRACER_FUNCTION_FLAGS "-g" "-finstrument-functions" "-Wl,-E" "-fvisibility=default")

else()
set(DFTRACER_FUNCTION_FLAGS )
endif()
check_required_components(dftracer)

set(DFTRACER_LIBRARIES dftracer)
1 change: 1 addition & 0 deletions cmake/configure_files/dftracer_config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/* Macro flags */
#cmakedefine DFTRACER_GNU_LINUX 1
#cmakedefine DFTRACER_MPI_ENABLE 1
#cmakedefine DFTRACER_FTRACING_ENABLE 1

//==========================
// Common macro definitions
Expand Down
6 changes: 3 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ ENV Variables supported
DFTRACER_INC_METADATA needs to be enabled.
DFTRACER_GOTCHA_PRIORITY INT PRIORITY of DFTracer in GOTCHA (default: 1).
DFTRACER_LOG_LEVEL STRING Logging level within DFTracer ERROR/WARN/INFO/DEBUG (default ERROR).
DFTRACER_DISABLE_IO STRING Disable automatic binding of all I/O calls.
DFTRACER_DISABLE_POSIX STRING Disable automatic binding of POSIX I/O calls.
DFTRACER_DISABLE_STDIO STRING Disable automatic binding of STDIO I/O calls.
DFTRACER_DISABLE_IO INT Disable automatic binding of all I/O calls (default: 1).
DFTRACER_DISABLE_POSIX INT Disable automatic binding of POSIX I/O calls (default: 1).
DFTRACER_DISABLE_STDIO INT Disable automatic binding of STDIO I/O calls (default: 1).
DFTRACER_TRACE_COMPRESSION INT Enable trace compression (default 1)
DFTRACER_DISABLE_TIDS INT Disable tracing of thread ids (default 0).
DFTRACER_WRITE_BUFFER_SIZE INT Setup the buffering size for write optimization (default 0). Disabled as
Expand Down
36 changes: 19 additions & 17 deletions docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,25 @@ Download the latest DFTracer release from the Releases_ page or clone the develo
branch ('develop') from the DFTracer repository
`https://github.com/hariharan-devarajan/dftracer <https://github.com/hariharan-devarajan/dftracer>`_.

------------------------------------------
Build ENV Variables
------------------------------------------
For pip based installations we can enable HWLOC using
.. code-block:: Bash
export DFTRACER_DISABLE_HWLOC=Off
------------------------------------------
Build CMAKE Variables
------------------------------------------
For Cmake based build, we can enable HWLOC using
.. code-block:: Bash
cmake -DDISABLE_HWLOC=Off <source dir>
---------------
Build Variables
---------------

.. table:: section - main build settings using env variables or cmake flags
:widths: auto

================================ ====== ===========================================================================
Environment Variable Type Description
================================ ====== ===========================================================================
DFTRACER_BUILD_TYPE STRING Sets the build type for DFTRACER (default Release). Values are Debug or Release
DFTRACER_ENABLE_FTRACING BOOL Enables function tracing (default OFF).
DFTRACER_ENABLE_MPI BOOL Enables MPI Rank (default ON).
DFTRACER_DISABLE_HWLOC BOOL Disables HWLOC (default ON).
DFTRACER_PYTHON_EXE STRING Sets path to python executable. Only Cmake.
DFTRACER_PYTHON_SITE STRING Sets path to python site-packages. Only Cmake.
DFTRACER_BUILD_PYTHON_BINDINGS STRING Enable python bindings for DFTracer. Only Cmake.

These build variables can be set with cmake as ``-DDISABLE_HWLOC=OFF`` or as environment variables ``export DFTRACER_DISABLE_HWLOC=OFF``

Build DFTracer Dependencies
********************************
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def build_extension(self, ext: CMakeExtension) -> None:
# auxiliary "native" libs
build_type = os.environ.get("DFTRACER_BUILD_TYPE", "Release")
cmake_args += [f"-DCMAKE_BUILD_TYPE={build_type}"]
enable_ftracing = os.environ.get("DFTRACER_ENABLE_FTRACING", "OFF")
cmake_args += [f"-DDFTRACER_ENABLE_FTRACING={enable_ftracing}"]
enable_mpi = os.environ.get("DFTRACER_ENABLE_MPI", "ON")
cmake_args += [f"-DDFTRACER_ENABLE_MPI={enable_mpi}"]
disable_hwloc = os.environ.get("DFTRACER_DISABLE_HWLOC", "ON")
Expand Down
6 changes: 6 additions & 0 deletions src/dftracer/core/dftracer_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ bool dftracer::DFTracerCore::finalize() {
if (stdio_instance != nullptr) {
stdio_instance->finalize();
}
#ifdef DFTRACER_FTRACING_ENABLE
auto function_instance = dftracer::Function::get_instance();
if (function_instance != nullptr) {
function_instance->finalize();
}
#endif
}
if (logger != nullptr) {
logger->finalize();
Expand Down Expand Up @@ -239,10 +241,14 @@ void dftracer::DFTracerCore::initialize(bool _bind, const char *_log_file,
brahma::STDIODFTracer::get_instance(conf->trace_all_files);
}
}
#ifdef DFTRACER_FTRACING_ENABLE
dftracer::Function::get_instance();
#endif
}
} else {
#ifdef DFTRACER_FTRACING_ENABLE
dftracer::Function::get_instance()->finalize();
#endif
}
is_initialized = true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/dftracer/finstrument/functions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <dftracer/finstrument/functions.h>
#ifdef DFTRACER_FTRACING_ENABLE
#include <link.h>
std::shared_ptr<dftracer::Function> dftracer::Function::instance = nullptr;

Expand Down Expand Up @@ -71,4 +72,5 @@ void __cyg_profile_func_exit(void *func, void *caller) {
end_time - start_time, metadata);
function->logger->exit_event();
}
}
}
#endif
6 changes: 4 additions & 2 deletions src/dftracer/finstrument/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#ifndef DFTRACER_FUNCTION_H
#define DFTRACER_FUNCTION_H

/* Config Header */
#include <dftracer/dftracer_config.hpp>
#ifdef DFTRACER_FTRACING_ENABLE
/* Internal Header */
#include <dftracer/core/logging.h>
#include <dftracer/core/typedef.h>
Expand Down Expand Up @@ -57,5 +59,5 @@ class Function {
};

} // namespace dftracer

#endif
#endif // DFTRACER_FUNCTION_H
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ add_dependencies(test_cpp ${PROJECT_NAME})
add_dependencies(test_cpp ${PROJECT_NAME}_preload)

add_library(testlib SHARED c/testlib.c)
target_compile_options(testlib PRIVATE "-g" "-finstrument-functions" "-Wl,-E" "-fvisibility=default")
target_compile_options(testlib PRIVATE ${DFTRACER_FUNCTION_FLAGS})
add_executable(test_c c/test.c)
target_compile_options(test_c PRIVATE "-g" "-finstrument-functions" "-Wl,-E" "-fvisibility=default")
target_compile_options(test_c PRIVATE ${DFTRACER_FUNCTION_FLAGS})
target_link_libraries(test_c ${PROJECT_NAME} testlib)
add_dependencies(test_c ${PROJECT_NAME})
add_dependencies(test_c ${PROJECT_NAME}_preload)
Expand Down

0 comments on commit 7ab8a88

Please sign in to comment.