Files
rocm-systems/cmake/Formatting.cmake
T
Jonathan R. Madsen 808ea7dfa7 Rework sampling and colorized logs (#140)
## Overview

This is a significant PR which has 3 very notable characteristics:

1. Omnitrace colorizes most of it's logging
2. Completely reworked the sampling 
  - Samples now record the current instruction pointers instead of strings
    - This _dramatically_ decreases the overhead of taking a sample
  - The collection of metrics during a sample are split out into another component, enabling that data collection to be disabled -- which decreases the sampling overhead even further
  - When both `OMNITRACE_SAMPLING_CPUTIME` and `OMNITRACE_SAMPLING_REALTIME` are ON:
    - `OMNITRACE_SAMPLING_CPUTIME_FREQ` and `OMNITRACE_SAMPLING_REALTIME_FREQ` can be used to individually control the sampling frequency 
  - `OMNITRACE_SAMPLING_CPUTIME_DELAY` and `OMNITRACE_SAMPLING_REALTIME_DELAY` can be used to individually control the delay time before starting
  - Now, omnitrace does not start a real-time sampler on the main thread unless `OMNITRACE_SAMPLING_REALTIME` is ON
    - In the future, an `OMNITRACE_SAMPLING_TIDS` (and real-time, cpu-time variants) configuration variable(s) will allow you to select which threads will be sampled
3. Files produced by `omnitrace` exe -- `available-instr.txt`, `instrumented-instr.txt`, etc. -- now no longer has `-instr` suffix and are placed in `instrumentation/` subfolder, i.e. `available-instr.txt` -> instrumentation/available.txt`
  - This helped de-clutter the output folder

Most of the other edits were reorganization (e.g. internal namespace changes), cleanup, and splitting up functionality.

## Bug Fixes

There is a bug fix with respect to the HSA callbacks which disabled sampling on child threads when an HSA API call was made

## Details

- created thread_info struct for mapping different thread IDs
- reorganized file structure significantly
- added categories.hpp, concepts.hpp
- moved around name trait definitions
- moved all omnitrace components into `omnitrace::component` namespace
  - there was a lot of inconsistency b/t using `tim::component` in some places and `omnitrace::component`
  - added macros like OMNITRACE_DECLARE_COMPONENT in lieu of TIMEMORY_DECLARE_COMPONENT
- OMNITRACE_CRITICAL_TRACE_NUM_THREADS -> OMNITRACE_THREAD_POOL_SIZE
- roctracer and critical_trace use same thread pool
- critical_trace functions do not lock anymore bc of thread-local TaskGroup
- added `component::local_category_region` to support using `component::category_region` without explicitly passing in name
- removed `component::omnitrace` (unused)
- migrated KokkosP and OMPT to use `component::local_category_region`
  - removed `component::user_region` as a result
- migrated omnitrace_{push,pop}_{trace,region}_hidden to use component::category_region
  - removed `component::functors` as a result
- migrated some ppdefs
- `api::omnitrace` -> `project::omnitrace`
- `api::(...)` -> `category::(...)`
- improved recording the execution time of threads
  - migrated this functionality out of pthread_create_gotcha and into thread_info
- moved mpi_gotcha, fork_gotcha, exit_gotcha, rcclp into omnitrace::component namespace
- split backtrace up into backtrace, backtrace_metrics, backtrace_timestamp components
- sampling.cpp handles setup and post-processing that was formerly in backtrace
- updated logging to use colors
- `OMNITRACE_COLORIZED_LOG` config variable
- updated docs on JSON output from timemory
- instrumentation info in instrumentation subfolder
- added testing for KokkosP entries
- added testing for ompt entries
- add_critical_trace function defined in critical_trace.hpp
- disable push_thread_state and pop_thread_state when thread state is Disabled or Completed
- add comp::page_rss to main bundle
- thread_data supports std::optional instead of std::unique_ptr
- thread_data supports tim::identity<T> to avoid unique_ptr or optional
- tracing::record_thread_start_time()
- tracing::push_timemory and tracing::pop_timemory are templated on CategoryT
- removed anonymous namespace from omnitrace::utility
- sampling backtrace stores instruction pointers instead of strings
- component::category_region updates
  - handle disabled thread state
  - handle finalized state
  - fewer debug messages
  - invoke thread_init()
  - invoke thread_init_sampling()
  - handle push/pop count based on category
  - push/pop count only modified when used
- component::cpu_freq
- components/ensure_storage.hpp
- reworked the pthread_create replacement function
- updated parallel-overhead example to report # of times locked
- OMNITRACE_MAX_UNWIND_DEPTH build option
- update timemory submodule
2022-08-31 01:24:31 -05:00

124 rivejä
4.6 KiB
CMake

include_guard(DIRECTORY)
# ----------------------------------------------------------------------------------------#
#
# Clang Tidy
#
# ----------------------------------------------------------------------------------------#
# clang-tidy
macro(OMNITRACE_ACTIVATE_CLANG_TIDY)
if(OMNITRACE_USE_CLANG_TIDY)
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
omnitrace_add_feature(CLANG_TIDY_COMMAND "Path to clang-tidy command")
if(NOT CLANG_TIDY_COMMAND)
timemory_message(
WARNING "OMNITRACE_USE_CLANG_TIDY is ON but clang-tidy is not found!")
set(OMNITRACE_USE_CLANG_TIDY OFF)
else()
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND})
# Create a preprocessor definition that depends on .clang-tidy content so the
# compile command will change when .clang-tidy changes. This ensures that a
# subsequent build re-runs clang-tidy on all sources even if they do not
# otherwise need to be recompiled. Nothing actually uses this definition. We
# add it to targets on which we run clang-tidy just to get the build
# dependency on the .clang-tidy file.
file(SHA1 ${CMAKE_CURRENT_LIST_DIR}/.clang-tidy clang_tidy_sha1)
set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
unset(clang_tidy_sha1)
endif()
endif()
endmacro()
# ------------------------------------------------------------------------------#
#
# clang-format target
#
# ------------------------------------------------------------------------------#
find_program(OMNITRACE_CLANG_FORMAT_EXE NAMES clang-format-11 clang-format-mp-11
clang-format)
find_program(OMNITRACE_CMAKE_FORMAT_EXE NAMES cmake-format)
find_program(OMNITRACE_BLACK_FORMAT_EXE NAMES black)
add_custom_target(format-omnitrace)
if(NOT TARGET format)
add_custom_target(format)
endif()
foreach(_TYPE source python cmake)
if(NOT TARGET format-${_TYPE})
add_custom_target(format-${_TYPE})
endif()
endforeach()
if(OMNITRACE_CLANG_FORMAT_EXE
OR OMNITRACE_BLACK_FORMAT_EXE
OR OMNITRACE_CMAKE_FORMAT_EXE)
file(GLOB_RECURSE sources ${PROJECT_SOURCE_DIR}/source/*.cpp)
file(GLOB_RECURSE headers ${PROJECT_SOURCE_DIR}/source/*.hpp
${PROJECT_SOURCE_DIR}/source/*.hpp.in ${PROJECT_SOURCE_DIR}/source/*.h
${PROJECT_SOURCE_DIR}/source/*.h.in)
file(GLOB_RECURSE examples ${PROJECT_SOURCE_DIR}/examples/*.cpp
${PROJECT_SOURCE_DIR}/examples/*.hpp)
file(GLOB_RECURSE external ${PROJECT_SOURCE_DIR}/examples/lulesh/external/kokkos/*)
file(
GLOB_RECURSE
cmake_files
${PROJECT_SOURCE_DIR}/source/*CMakeLists.txt
${PROJECT_SOURCE_DIR}/examples/*CMakeLists.txt
${PROJECT_SOURCE_DIR}/tests/*CMakeLists.txt
${PROJECT_SOURCE_DIR}/cmake/*.cmake
${PROJECT_SOURCE_DIR}/source/*.cmake)
list(APPEND cmake_files ${PROJECT_SOURCE_DIR}/CMakeLists.txt)
if(external)
list(REMOVE_ITEM examples ${external})
list(REMOVE_ITEM cmake_files ${external})
endif()
if(OMNITRACE_CLANG_FORMAT_EXE)
add_custom_target(
format-omnitrace-source
${OMNITRACE_CLANG_FORMAT_EXE} -i ${sources} ${headers} ${examples}
COMMENT "[omnitrace] Running C++ formatter ${OMNITRACE_CLANG_FORMAT_EXE}...")
endif()
if(OMNITRACE_BLACK_FORMAT_EXE)
add_custom_target(
format-omnitrace-python
${OMNITRACE_BLACK_FORMAT_EXE} -q ${PROJECT_SOURCE_DIR}
COMMENT
"[omnitrace] Running Python formatter ${OMNITRACE_BLACK_FORMAT_EXE}...")
if(NOT TARGET format-python)
add_custom_target(format-python)
endif()
endif()
if(OMNITRACE_CMAKE_FORMAT_EXE)
add_custom_target(
format-omnitrace-cmake
${OMNITRACE_CMAKE_FORMAT_EXE} -i ${cmake_files}
COMMENT "[omnitrace] Running CMake formatter ${OMNITRACE_CMAKE_FORMAT_EXE}..."
)
if(NOT TARGET format-cmake)
add_custom_target(format-cmake)
endif()
endif()
foreach(_TYPE source python cmake)
if(TARGET format-omnitrace-${_TYPE})
add_dependencies(format-omnitrace format-omnitrace-${_TYPE})
add_dependencies(format-${_TYPE} format-omnitrace-${_TYPE})
endif()
endforeach()
foreach(_TYPE source python)
if(TARGET format-omnitrace-${_TYPE})
add_dependencies(format format-omnitrace-${_TYPE})
endif()
endforeach()
else()
message(STATUS "clang-format could not be found. format build target not available.")
endif()