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]
This commit is contained in:
committed by
GitHub
parent
f642813ad1
commit
473f452d39
@@ -34,6 +34,8 @@
|
||||
#include <timemory/backends/threading.hpp>
|
||||
#include <timemory/environment.hpp>
|
||||
#include <timemory/environment/types.hpp>
|
||||
#include <timemory/log/color.hpp>
|
||||
#include <timemory/log/logger.hpp>
|
||||
#include <timemory/manager.hpp>
|
||||
#include <timemory/sampling/allocator.hpp>
|
||||
#include <timemory/settings.hpp>
|
||||
@@ -174,7 +176,7 @@ configure_settings(bool _init)
|
||||
|
||||
if(get_state() < State::Init)
|
||||
{
|
||||
::tim::print_demangled_backtrace<64>();
|
||||
timemory_print_demangled_backtrace<64>();
|
||||
OMNITRACE_THROW("config::configure_settings() called before "
|
||||
"omnitrace_init_library. state = %s",
|
||||
std::to_string(get_state()).c_str());
|
||||
@@ -220,6 +222,9 @@ configure_settings(bool _init)
|
||||
"for continuous integration)",
|
||||
false, "debugging", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(bool, "OMNITRACE_COLORIZED_LOG", "Enable colorized logging",
|
||||
true, "debugging", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_EXT_SETTING(int, "OMNITRACE_DL_VERBOSE",
|
||||
"Verbosity within the omnitrace-dl library", 0,
|
||||
"debugging", "libomnitrace-dl", "advanced");
|
||||
@@ -300,12 +305,35 @@ configure_settings(bool _init)
|
||||
"Number of software interrupts per second when OMNITTRACE_USE_SAMPLING=ON", 10.0,
|
||||
"sampling", "process_sampling");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(double, "OMNITRACE_SAMPLING_CPUTIME_FREQ",
|
||||
"Number of software interrupts per second of CPU-time. "
|
||||
"Defaults to OMNITRACE_SAMPLING_FREQ when <= 0.0",
|
||||
-1.0, "sampling", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
double, "OMNITRACE_SAMPLING_REALTIME_FREQ",
|
||||
"Number of software interrupts per second of real (wall) time. "
|
||||
"Defaults to OMNITRACE_SAMPLING_FREQ when <= 0.0",
|
||||
-1.0, "sampling", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
double, "OMNITRACE_SAMPLING_DELAY",
|
||||
"Time (in seconds) to wait before the first sampling signal is delivered, "
|
||||
"increasing this value can fix deadlocks during init",
|
||||
0.5, "sampling", "process_sampling");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(double, "OMNITRACE_SAMPLING_CPUTIME_DELAY",
|
||||
"Time (in seconds) to wait before the first CPU-time "
|
||||
"sampling signal is delivered. "
|
||||
"Defaults to OMNITRACE_SAMPLING_DELAY when <= 0.0",
|
||||
-1.0, "sampling", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
double, "OMNITRACE_SAMPLING_REALTIME_DELAY",
|
||||
"Time (in seconds) to wait before the first real (wall) time sampling signal is "
|
||||
"delivered. Defaults to OMNITRACE_SAMPLING_DELAY when <= 0.0",
|
||||
-1.0, "sampling", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
double, "OMNITRACE_PROCESS_SAMPLING_FREQ",
|
||||
"Number of measurements per second when OMNITTRACE_USE_PROCESS_SAMPLING=ON. If "
|
||||
@@ -383,7 +411,7 @@ configure_settings(bool _init)
|
||||
"CPU time used by the current process, "
|
||||
"and CPU time expended on behalf of the process by the "
|
||||
"system. This is recommended.",
|
||||
true, "timemory", "sampling", "advanced");
|
||||
true, "sampling", "advanced");
|
||||
|
||||
auto _sigrt_range = SIGRTMAX - SIGRTMIN;
|
||||
|
||||
@@ -472,6 +500,13 @@ configure_settings(bool _init)
|
||||
"data", "advanced")
|
||||
->set_choices(get_available_perfetto_categories<std::vector<std::string>>());
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
uint64_t, "OMNITRACE_THREAD_POOL_SIZE",
|
||||
"Max number of threads for processing background tasks",
|
||||
std::max<uint64_t>(std::min<uint64_t>(4, std::thread::hardware_concurrency() / 2),
|
||||
1),
|
||||
"parallelism", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_EXT_SETTING(int64_t, "OMNITRACE_CRITICAL_TRACE_COUNT",
|
||||
"Number of critical trace to export (0 == all)",
|
||||
int64_t{ 0 }, "data", "critical_trace",
|
||||
@@ -482,12 +517,6 @@ configure_settings(bool _init)
|
||||
"memory before submitting to shared buffer",
|
||||
uint64_t{ 2000 }, "data", "critical_trace", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_SETTING(
|
||||
uint64_t, "OMNITRACE_CRITICAL_TRACE_NUM_THREADS",
|
||||
"Number of threads to use when generating the critical trace",
|
||||
std::min<uint64_t>(8, std::thread::hardware_concurrency()), "parallelism",
|
||||
"critical_trace", "advanced");
|
||||
|
||||
OMNITRACE_CONFIG_EXT_SETTING(
|
||||
int64_t, "OMNITRACE_CRITICAL_TRACE_PER_ROW",
|
||||
"How many critical traces per row in perfetto (0 == all in one row)",
|
||||
@@ -688,6 +717,9 @@ configure_settings(bool _init)
|
||||
|
||||
settings::suppress_config() = true;
|
||||
|
||||
if(!get_env("OMNITRACE_COLORIZED_LOG", _config->get<bool>("OMNITRACE_COLORIZED_LOG")))
|
||||
tim::log::colorized() = false;
|
||||
|
||||
if(_init)
|
||||
{
|
||||
using argparser_t = tim::argparse::argument_parser;
|
||||
@@ -758,6 +790,7 @@ configure_mode_settings()
|
||||
set_default_setting_value("OMNITRACE_USE_CODE_COVERAGE", true);
|
||||
_set("OMNITRACE_USE_PERFETTO", false);
|
||||
_set("OMNITRACE_USE_TIMEMORY", false);
|
||||
//_set("OMNITRACE_USE_CAUSAL", false);
|
||||
_set("OMNITRACE_USE_ROCM_SMI", false);
|
||||
_set("OMNITRACE_USE_ROCTRACER", false);
|
||||
_set("OMNITRACE_USE_ROCPROFILER", false);
|
||||
@@ -814,6 +847,7 @@ configure_mode_settings()
|
||||
{
|
||||
_set("OMNITRACE_USE_PERFETTO", false);
|
||||
_set("OMNITRACE_USE_TIMEMORY", false);
|
||||
//_set("OMNITRACE_USE_CAUSAL", false);
|
||||
_set("OMNITRACE_USE_ROCM_SMI", false);
|
||||
_set("OMNITRACE_USE_ROCTRACER", false);
|
||||
_set("OMNITRACE_USE_ROCPROFILER", false);
|
||||
@@ -878,7 +912,7 @@ configure_signal_handler()
|
||||
"signal %s (%i) ignored (OMNITRACE_IGNORE_DYNINST_TRAMPOLINE=ON)\n",
|
||||
std::get<0>(_info).c_str(), _v);
|
||||
if(get_verbose_env() > 1 || get_debug_env())
|
||||
::tim::print_demangled_backtrace<64>();
|
||||
timemory_print_demangled_backtrace<64>();
|
||||
if(_old_handler) _old_handler(_v);
|
||||
}
|
||||
};
|
||||
@@ -1071,7 +1105,8 @@ print_banner(std::ostream& _os)
|
||||
\______/ |__| |__| |__| \__| |__| |__| | _| `._____/__/ \__\ \______||_______|
|
||||
|
||||
)banner";
|
||||
_os << _banner << std::endl;
|
||||
tim::log::stream(_os, tim::log::color::info()) << _banner;
|
||||
_os << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1139,7 +1174,6 @@ print_settings(
|
||||
_spacer << "#" << std::setw(tot_width + _spacer_extra) << ""
|
||||
<< "#";
|
||||
_os << _spacer.str() << "\n";
|
||||
// _os << "# api::omnitrace settings:" << std::setw(tot_width - 8) << "#" << "\n";
|
||||
for(const auto& itr : _data)
|
||||
{
|
||||
_os << ((_md) ? "| " : "# ");
|
||||
@@ -1174,9 +1208,11 @@ print_settings(
|
||||
}
|
||||
_os << ((_md) ? "\n" : " #\n");
|
||||
}
|
||||
|
||||
_os << _spacer.str() << "\n";
|
||||
|
||||
_ros << _os.str() << std::flush;
|
||||
tim::log::stream(_ros, tim::log::color::info()) << _os.str();
|
||||
_ros << std::flush;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1191,9 +1227,13 @@ print_settings(bool _include_env)
|
||||
|
||||
if(_include_env)
|
||||
{
|
||||
std::cerr << tim::log::info;
|
||||
tim::print_env(std::cerr, [_is_omnitrace_option](const std::string& _v) {
|
||||
return _is_omnitrace_option(_v, std::set<std::string>{});
|
||||
auto _is_omni_opt = _is_omnitrace_option(_v, std::set<std::string>{});
|
||||
if(settings::verbose() >= 2 || settings::debug()) return _is_omni_opt;
|
||||
return (_is_omni_opt && _v.find("OMNITRACE_SIGNAL_") != 0);
|
||||
});
|
||||
std::cerr << tim::log::flush;
|
||||
}
|
||||
|
||||
print_settings(std::cerr, _is_omnitrace_option);
|
||||
@@ -1607,10 +1647,9 @@ get_critical_trace_update_freq()
|
||||
}
|
||||
|
||||
uint64_t
|
||||
get_critical_trace_num_threads()
|
||||
get_thread_pool_size()
|
||||
{
|
||||
static uint64_t _v =
|
||||
get_config()->get<uint64_t>("OMNITRACE_CRITICAL_TRACE_NUM_THREADS");
|
||||
static uint64_t _v = get_config()->get<uint64_t>("OMNITRACE_THREAD_POOL_SIZE");
|
||||
return _v;
|
||||
}
|
||||
|
||||
@@ -1671,13 +1710,49 @@ get_sampling_freq()
|
||||
return static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
}
|
||||
|
||||
double&
|
||||
double
|
||||
get_sampling_cpu_freq()
|
||||
{
|
||||
static auto _v = get_config()->find("OMNITRACE_SAMPLING_CPUTIME_FREQ");
|
||||
auto& _val = static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
if(_val <= 0.0) _val = get_sampling_freq();
|
||||
return _val;
|
||||
}
|
||||
|
||||
double
|
||||
get_sampling_real_freq()
|
||||
{
|
||||
static auto _v = get_config()->find("OMNITRACE_SAMPLING_REALTIME_FREQ");
|
||||
auto& _val = static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
if(_val <= 0.0) _val = get_sampling_freq();
|
||||
return _val;
|
||||
}
|
||||
|
||||
double
|
||||
get_sampling_delay()
|
||||
{
|
||||
static auto _v = get_config()->find("OMNITRACE_SAMPLING_DELAY");
|
||||
return static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
}
|
||||
|
||||
double
|
||||
get_sampling_cpu_delay()
|
||||
{
|
||||
static auto _v = get_config()->find("OMNITRACE_SAMPLING_CPUTIME_DELAY");
|
||||
auto& _val = static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
if(_val <= 0.0) _val = get_sampling_delay();
|
||||
return _val;
|
||||
}
|
||||
|
||||
double
|
||||
get_sampling_real_delay()
|
||||
{
|
||||
static auto _v = get_config()->find("OMNITRACE_SAMPLING_REALTIME_DELAY");
|
||||
auto& _val = static_cast<tim::tsettings<double>&>(*_v->second).get();
|
||||
if(_val <= 0.0) _val = get_sampling_delay();
|
||||
return _val;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_sampling_cpus()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user