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

[ROCm/rocprofiler-systems commit: 808ea7dfa7]
此提交包含在:
Jonathan R. Madsen
2022-08-31 01:24:31 -05:00
提交者 GitHub
父節點 f642813ad1
當前提交 473f452d39
共有 113 個檔案被更改,包括 4284 行新增2880 行删除
+1 -3
查看文件
@@ -24,15 +24,13 @@
#include "enumerated_list.hpp"
#include "get_availability.hpp"
#include "library/api.hpp"
#include "api.hpp"
#include "library/components/backtrace.hpp"
#include "library/components/fork_gotcha.hpp"
#include "library/components/mpi_gotcha.hpp"
#include "library/components/omnitrace.hpp"
#include "library/components/pthread_gotcha.hpp"
#include "library/components/rocprofiler.hpp"
#include "library/components/roctracer.hpp"
#include "library/components/user_region.hpp"
#include <timemory/components/definition.hpp>
#include <timemory/enum.h>
+3 -4
查看文件
@@ -22,7 +22,7 @@
#include "critical-trace.hpp"
#include "library/api.hpp"
#include "api.hpp"
#include "library/config.hpp"
#include "library/perfetto.hpp"
@@ -54,7 +54,7 @@ main(int argc, char** argv)
// config::set_setting_value("OMNITRACE_CRITICAL_TRACE_DEBUG", true);
config::set_setting_value<int64_t>("OMNITRACE_CRITICAL_TRACE_COUNT", 500);
config::set_setting_value<int64_t>("OMNITRACE_CRITICAL_TRACE_PER_ROW", 100);
config::set_setting_value<int64_t>("OMNITRACE_CRITICAL_TRACE_NUM_THREADS",
config::set_setting_value<int64_t>("OMNITRACE_THREAD_POOL_SIZE",
std::thread::hardware_concurrency());
config::set_setting_value("OMNITRACE_CRITICAL_TRACE_SERIALIZE_NAMES", true);
@@ -856,8 +856,7 @@ compute_critical_trace()
try
{
PTL::ThreadPool _tp{ get_critical_trace_num_threads(), []() { copy_hash_ids(); },
[]() {} };
PTL::ThreadPool _tp{ get_thread_pool_size(), []() { copy_hash_ids(); }, []() {} };
_tp.set_verbose(-1);
PTL::TaskGroup<void> _tg{ &_tp };
+7 -3
查看文件
@@ -22,9 +22,13 @@ target_sources(
target_link_libraries(
omnitrace-exe
PRIVATE omnitrace::omnitrace-headers omnitrace::omnitrace-dyninst
omnitrace::omnitrace-compile-options omnitrace::omnitrace-compile-definitions
omnitrace::omnitrace-sanitizer timemory::timemory-headers)
PRIVATE omnitrace::omnitrace-headers
omnitrace::omnitrace-dyninst
omnitrace::omnitrace-compile-options
omnitrace::omnitrace-compile-definitions
omnitrace::omnitrace-sanitizer
timemory::timemory-headers
timemory::timemory-extensions)
set_target_properties(
omnitrace-exe
+4 -1
查看文件
@@ -27,6 +27,7 @@
#include <timemory/mpl/policy.hpp>
#include <timemory/settings.hpp>
#include <timemory/settings/types.hpp>
#include <timemory/tpls/cereal/cereal.hpp>
#include <timemory/utility/delimit.hpp>
#include <timemory/utility/filepath.hpp>
@@ -60,7 +61,9 @@ dump_info(const string_t& _label, string_t _oname, const string_t& _ext,
namespace cereal = tim::cereal;
namespace policy = tim::policy;
_oname = tim::settings::compose_output_filename(_oname, _ext);
auto _cfg = tim::settings::compose_filename_config{};
_cfg.subdirectory = "instrumentation";
_oname = tim::settings::compose_output_filename(_oname, _ext, _cfg);
auto _handle_error = [&]() {
std::stringstream _msg{};
_msg << "[dump_info] Error opening '" << _oname << " for output";
+12 -12
查看文件
@@ -195,7 +195,7 @@ main(int argc, char** argv)
};
std::set<std::string> dyninst_defs = { "TypeChecking", "SaveFPR", "DelayedParsing",
"MergeTramp" };
"DebugParsing", "MergeTramp" };
int _argc = argc;
int _cmdc = 0;
@@ -302,7 +302,7 @@ main(int argc, char** argv)
.add_argument({ "--simulate" },
"Exit after outputting diagnostic "
"{available,instrumented,excluded,overlapping} module "
"function lists, e.g. available-instr.txt")
"function lists, e.g. available.txt")
.max_count(1)
.dtype("bool")
.action([](parser_t& p) { simulate = p.get<bool>("simulate"); });
@@ -310,7 +310,7 @@ main(int argc, char** argv)
.add_argument({ "--print-format" },
"Output format for diagnostic "
"{available,instrumented,excluded,overlapping} module "
"function lists, e.g. {print-dir}/available-instr.txt")
"function lists, e.g. {print-dir}/available.txt")
.min_count(1)
.max_count(3)
.dtype("string")
@@ -320,7 +320,7 @@ main(int argc, char** argv)
.add_argument({ "--print-dir" },
"Output directory for diagnostic "
"{available,instrumented,excluded,overlapping} module "
"function lists, e.g. {print-dir}/available-instr.txt")
"function lists, e.g. {print-dir}/available.txt")
.count(1)
.dtype("string")
.action([](parser_t& p) {
@@ -1040,7 +1040,7 @@ main(int argc, char** argv)
bpatch->setTypeChecking(true);
bpatch->setSaveFPR(true);
bpatch->setDelayedParsing(true);
bpatch->setDebugParsing(false);
bpatch->setDebugParsing(true);
bpatch->setInstrStackFrames(false);
bpatch->setLivenessAnalysis(false);
bpatch->setBaseTrampDeletion(false);
@@ -1276,9 +1276,9 @@ main(int argc, char** argv)
std::cout << '\n' << std::endl;
}
dump_info("available-instr", available_module_functions, 1, werror, "available-instr",
dump_info("available", available_module_functions, 1, werror, "available",
print_formats);
dump_info("overlapping-instr", overlapping_module_functions, 1, werror,
dump_info("overlapping", overlapping_module_functions, 1, werror,
"overlapping_module_functions", print_formats);
//----------------------------------------------------------------------------------//
@@ -1943,16 +1943,16 @@ main(int argc, char** argv)
//
//----------------------------------------------------------------------------------//
dump_info("available-instr", available_module_functions, 0, werror,
dump_info("available", available_module_functions, 0, werror,
"available_module_functions", print_formats);
dump_info("instrumented-instr", instrumented_module_functions, 0, werror,
dump_info("instrumented", instrumented_module_functions, 0, werror,
"instrumented_module_functions", print_formats);
dump_info("excluded-instr", excluded_module_functions, 0, werror,
dump_info("excluded", excluded_module_functions, 0, werror,
"excluded_module_functions", print_formats);
if(coverage_mode != CODECOV_NONE)
dump_info("coverage-instr", coverage_module_functions, 0, werror,
dump_info("coverage", coverage_module_functions, 0, werror,
"coverage_module_functions", print_formats);
dump_info("overlapping-instr", overlapping_module_functions, 0, werror,
dump_info("overlapping", overlapping_module_functions, 0, werror,
"overlapping_module_functions", print_formats);
auto _dump_info = [](const std::string& _label, const string_t& _mode,
+4 -3
查看文件
@@ -174,10 +174,10 @@ omnitrace_add_bin_test(
omnitrace_add_bin_test(
NAME omnitrace-exe-simulate-ls-check
DEPENDS omnitrace-exe-simulate-ls
COMMAND ls omnitrace-tests-output/omnitrace-exe-simulate-ls
COMMAND ls omnitrace-tests-output/omnitrace-exe-simulate-ls/instrumentation
TIMEOUT 60
PASS_REGEX
".*available-instr.json.*available-instr.txt.*available-instr.xml.*excluded-instr.json.*excluded-instr.txt.*excluded-instr.xml.*instrumented-instr.json.*instrumented-instr.txt.*instrumented-instr.xml.*overlapping-instr.json.*overlapping-instr.txt.*overlapping-instr.xml.*"
".*available.json.*available.txt.*available.xml.*excluded.json.*excluded.txt.*excluded.xml.*instrumented.json.*instrumented.txt.*instrumented.xml.*overlapping.json.*overlapping.txt.*overlapping.xml.*"
)
omnitrace_add_bin_test(
@@ -265,7 +265,8 @@ omnitrace_add_bin_test(
--advanced
LABELS "omnitrace-avail"
TIMEOUT 45
PASS_REGEX "ENVIRONMENT VARIABLE,[ \n]+OMNITRACE_USE_PID,[ \n]+"
PASS_REGEX
"ENVIRONMENT VARIABLE,[ \n]+OMNITRACE_THREAD_POOL_SIZE,[ \n]+OMNITRACE_USE_PID,[ \n]+"
FAIL_REGEX "OMNITRACE_USE_PERFETTO")
string(REPLACE "+" "\\\+" _AVAIL_CFG_PATH