Global trace delay and duration (#235)

- The primary feature of this PR is the **addition of support for scoping the collection of tracing/profiling data into one or more time-based windows**
  - Closes #222 
  - Closes #207
  - Support for a real-clock time delay and/or a duration for tracing/profiling was added, *resembling the support for this feature during sampling and process-sampling*
  - However, above paradigm was enhanced for tracing 
    - Instead of one delay and/or one duration based on real time, ***tracing supports periodic and varying delays and durations and these delay+duration sets can be controlled with different clocks***  
    - At some point, this capability will be extended to sampling and process-sampling
- A secondary feature of this PR are the improvements to the handling of categories (by-product of the primary feature)
  - For example, previously setting `OMNITRACE_ENABLE_CATEGORIES` to a specific set of categories only eliminated the disabled categories from the perfetto trace, now these are applied to timemory profiles too
  - A new configuration variable `OMNITRACE_DISABLE_CATEGORIES` was added for when disabling only a handful of categories is easier
- There are quite a few miscellaneous modifications which pollute this PR a bit

## Multiple Tracing Windows

As noted above, tracing now supports specifying multiple delays and durations _and_ with different clocks. Consider the configuration below with two entries in the format `<DELAY>:<DURATION>:<REPEAT>:<CLOCK_TYPE>`:

```console
OMNITRACE_TRACE_PERIODS = 0.5:1.0:2:realtime    10.0:5.0:3:cputime
```

The above configuration defines:
1. `0.5:1.0:2:realtime`
  - A delay of 0.5 seconds (real-time)
  - Followed by a data collection duration of 1 second (real-time)
  - This delay + duration is repeated 2x
  - Summary: tracing data is collected for 2 out of the first 3 seconds of the application's execution
2. `10.0:5.0:3:cputime`
  - A delay of 10 seconds (process _CPU-time_)
  - Followed by a data collection duration of 5 seconds (process _CPU-time_)
  - This delay + duration is repeated 3x
  - Summary: tracing data is collected for a total of 15 seconds of process CPU-time in the ensuing 75 seconds of CPU-time during the application execution. 
    - Note: the elapsed CPU-time is the aggregate of the CPU-time consumed by all the threads in the process and should be scaled accordingly, e.g., 4 threads running constantly for 1 second of real-time is ~4 seconds of CPU time. 

## `omnitrace-sample` Changes

Formerly, `--wait` and `--duration` command-line options only applied to sampling delay and duration. The value of these options are now applied to the tracing delay and duration. To retain the ability to control sampling delay/duration without setting tracing delay/duration or vice versa, `--sampling-wait`, `--sampling-duration`, `--trace-wait`, and `--trace-duration` options were added. `omnitrace-sample` also has new options for most of the new configuration options detailed below.

## New configuration options

| Option | Description |
| ------- | ----------- |
| `OMNITRACE_DISABLE_CATEGORIES` | inverse behavior from `OMNITRACE_ENABLE_CATEGORIES` -- populates list of all available categories and then removes the specified ones. |
| `OMNITRACE_TRACE_DELAY` | Single floating-point number specifying time to wait before starting data collection. Analagous to `OMNITRACE_SAMPLING_DELAY` and `OMNITRACE_PROCESS_SAMPLING_DELAY` |
| `OMNITRACE_TRACE_DURATION` | Single floating-point number specifying data collection duration. Analagous to `OMNITRACE_SAMPLING_DURATION` and `OMNITRACE_PROCESS_SAMPLING_DURATION` |
| `OMNITRACE_TRACE_PERIOD_CLOCK_ID` | Sets the default clock-type for tracing delay/duration. Always applied to above two options, can be overridden in below option. Accepts `CLOCK_REALTIME`, `CLOCK_MONOTONIC`, `CLOCK_PROCESS_CPUTIME_ID`, `CLOCK_MONOTONIC_RAW`, `CLOCK_REALTIME_COARSE`, `CLOCK_MONOTONIC_COARSE`, `CLOCK_BOOTTIME`. See `man 2 clock_gettime` for details on differences. |
| `OMNITRACE_TRACE_PERIODS` | More powerful version for specifying delay + duration. Supports formats: `<DELAY>`, `<DELAY>:<DURATION>`, `<DELAY>:<DURATION>:<REPEAT>`, and `<DELAY>:<DURATION>:<REPEAT>:<CLOCK_ID>`.  |

 ## Miscellaneous Changes

- Expanded `critical_trace_categories_t` to include tracing data from MPI, pthread, HIP, HSA, RCCL, NUMA, and Python.
- Added categories `thread_wall_time` and `thread_cpu_time` (derived from sampling)
- Read DWARF info for breakpoints
- Relocated some source code
  - Reason: necessary to make `libomnitrace` a bit more modular. Eventually, a large chunk will be separated into `libomnitrace-core`, `libomnitrace-binary`, etc. in order to facilitate re-usability
  - Relocated some functionality from `runtime.cpp` to `config.cpp`
  - Relocated code using rocm-smi library to query number of devices to `gpu.cpp` (where the code for using HIP to query number of devices is)
  - Relocated code for perfetto config and perfetto session out of tracing namespace to reside with other perfetto code
- `OMNITRACE_COLORIZED_LOG` configuration option renamed to `OMNITRACE_MONOCHROME`
  - Backwards compatibility via a deprecated option was not retained here since the logic changed (i.e. true in former means false in latter)
- Replaced `TIMEMORY_DEFAULT_OBJECT` macro with `OMNITRACE_DEFAULT_OBJECT` macro 
- Updated some code in roctracer to use `component::category_region` instead of explicitly using `tracing::` functions
- Updated `backtrace_metrics` to better support controlling their presence in the traces/profiles via categories
- Added support for `--print` in `validate-timemory-json.py`
- Generic `OMNITRACE_ADD_VALIDATION_TEST` CMake function

## Git Log

* OMNITRACE_DEFAULT_OBJECT

- replace TIMEMORY_DEFAULT_OBJECT with TIMEMORY_DEFAULT_OBJECT

* trace-time-window example + tests

- adds cmake OMNITRACE_ADD_VALIDATION_TEST function for testing
- validate-timemory-json.py now supports printing (-p)
- update to OMNITRACE_STRIP_TARGET

* Update timemory submodule

- detailed backtrace print /proc/<PID>/maps
- operation::push_node verbosity change
- storage::insert_hierarchy use emplace + at instead of operator[]
- concepts::is_type_listing
- argparse updates for start/end group
- argparse color fixes

* perfetto updates

- Remove OMNITRACE_CUSTOM_DATA_SOURCE CMake option
- move tracing::get_perfetto_config and tracing::get_perfetto_session to perfetto.cpp

* config and runtime updates

- OMNITRACE_DISABLE_CATEGORIES option
  - get_enabled_categories() + get_disabled_categories()
  - config impl handles populating them
- OMNITRACE_TRACE_DELAY option
- OMNITRACE_TRACE_DURATION option
- OMNITRACE_TRACE_PERIODS option
- {get,set}_signal_handler
  - removes config.cpp link dependency for omnitrace_finalize
- get_realtime_signal() + get_cputime_signal() + get_sampling_signals()
  - moved from runtime.cpp to config.cpp

* utility::convert

- helper function for converting string to a type

* pthread_create_gotcha + thread_info updates

- thread_index_data::as_string()
- tweak printing info about new thread / exited thread

* binary updates

- get_binary_info has arg to disable dwarf parsing
- binary_info contains vector of breakpoint addresses
- binary_info:filename() function
- binary::get_linked_path
- binary::get_link_map has args for dlopen mode
- symbol::read_dwarf -> symbol::read_dwarf_entries
- symbol::read_dwarf_breakpoints

* library updates + categories impl

- implement config::set_signal_handler
- categories.cpp for handling trace delays
  - implement trace delay/duration/periods

* concepts + debug + defines

- tuple_element in concepts
- removed runtime header from debug header
- OMNITRACE_DEFAULT_COPY_MOVE

* gpu + rocm_smi

- moved rsmi_num_monitor_devices call to gpu.cpp
  - gpu::rsmi_device_count()

* roctracer updates

- roctracer_bundle_t -> roctracer_hip_bundle_t
- use category_region instead of explicit tracing push/pop calls

* sampling + backtrace_metrics

- rework backtrace_metrics to support categories

* tracing updates

- category stack counters (i.e. push vs. pop counter) for profiling and tracing
- push_timemory and pop_timemory accept string_view instead of const char*
- tweaked the pop_timemory hash search
- {push,pop}_perfetto theoretically supports same invocations as for {push,pop}_perfetto_ts and {push,pop}_perfetto_track
- mark_perfetto, mark_perfetto_ts, mark_perfetto_track

* category_region update

- expanded the critical trace categories
- use category_push_disabled
- use category_pop_disabled
- use category_mark_disabled

* constraint implementation

- This provides generic functionality for constraining data collection within a windows of time.
 - E.g., delay, delay + duration, (delay + duration) * nrepeat

* COLORIZED_LOG -> MONOCHROME

* constraint + omnitrace-causal + omnitrace-sample updates

- support for using different clock IDs for constraints
- OMNITRACE_TRACE_PERIOD_CLOCK_ID option
- tweak to trace-time-window example
- tweak to trace-time-window tests

* Fix formatting

* Update time-window tests

- Fix detection of validation support for perfetto
- Using the --caller-include feature + runtime instrumentation on Ubuntu 18.04 and OpenSUSE 15.2 results in a segfault in the internals of Dyninst.
  - For now, mark that these tests will fail
  - Later, determine if updating Dyninst submodule fixes this problem

* Fix OMNITRACE_OUTPUT_PATH for all tests

- Provide absolute path instead of relative

* Tweak lambda for checking whether HW counters are enabled

- causing strange build errors on older GCC compilers

* Update dyninst submodule

- fix issues with using --caller-include for Ubuntu 18.04, OpenSUSE 15.x

* cmake formatting

* fix sampling compiler issue for GCC 8

* Tweak thread create message

* Increase causal validation iterations
Этот коммит содержится в:
Jonathan R. Madsen
2023-02-03 14:10:42 -06:00
коммит произвёл GitHub
родитель 2fb67c394b
Коммит 8feb6bf8b6
82 изменённых файлов: 2538 добавлений и 632 удалений
+138 -33
Просмотреть файл
@@ -54,14 +54,47 @@
namespace color = tim::log::color;
using namespace timemory::join;
using tim::get_env;
using tim::log::colorized;
using tim::log::monochrome;
using tim::log::stream;
namespace
{
int verbose = 0;
auto updated_envs = std::set<std::string_view>{};
auto original_envs = std::set<std::string>{};
int verbose = 0;
auto updated_envs = std::set<std::string_view>{};
auto original_envs = std::set<std::string>{};
auto clock_id_choices = []() {
auto clock_name = [](std::string _v) {
constexpr auto _clock_prefix = std::string_view{ "clock_" };
for(auto& itr : _v)
itr = tolower(itr);
auto _pos = _v.find(_clock_prefix);
if(_pos == 0) _v = _v.substr(_pos + _clock_prefix.length());
if(_v == "process_cputime_id") _v = "cputime";
return _v;
};
#define OMNITRACE_CLOCK_IDENTIFIER(VAL) \
std::make_tuple(clock_name(#VAL), VAL, std::string_view{ #VAL })
auto _choices = std::vector<std::string>{};
auto _aliases = std::map<std::string, std::vector<std::string>>{};
for(auto itr : { OMNITRACE_CLOCK_IDENTIFIER(CLOCK_REALTIME),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_MONOTONIC),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_PROCESS_CPUTIME_ID),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_MONOTONIC_RAW),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_REALTIME_COARSE),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_MONOTONIC_COARSE),
OMNITRACE_CLOCK_IDENTIFIER(CLOCK_BOOTTIME) })
{
auto _choice = std::to_string(std::get<1>(itr));
_choices.emplace_back(_choice);
_aliases[_choice] = { std::get<0>(itr), std::string{ std::get<2>(itr) } };
}
#undef OMNITRACE_CLOCK_IDENTIFIER
return std::make_pair(_choices, _aliases);
}();
} // namespace
std::string
@@ -329,15 +362,7 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
%{INDENT}%- discard : new data is ignored
%{INDENT}%- ring_buffer : new data overwrites oldest data)";
auto _add_separator = [&](std::string _v, const std::string& _desc) {
parser.add_argument({ "" }, "");
parser
.add_argument({ join("", "[", _v, "]") },
(_desc.empty()) ? _desc : join({ "", "(", ")" }, _desc))
.color(tim::log::color::info());
parser.add_argument({ "" }, "");
};
parser.set_use_color(true);
parser.enable_help();
parser.enable_version("omnitrace-sample", "v" OMNITRACE_VERSION_STRING,
OMNITRACE_GIT_DESCRIBE, OMNITRACE_GIT_REVISION);
@@ -347,16 +372,16 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
parser.set_description_width(
std::min<int>(_cols - parser.get_help_width() - 8, 120));
_add_separator("DEBUG OPTIONS", "");
parser.start_group("DEBUG OPTIONS", "");
parser.add_argument({ "--monochrome" }, "Disable colorized output")
.max_count(1)
.dtype("bool")
.action([&](parser_t& p) {
auto _colorized = !p.get<bool>("monochrome");
colorized() = _colorized;
p.set_use_color(_colorized);
update_env(_env, "OMNITRACE_COLORIZED_LOG", (_colorized) ? "1" : "0");
update_env(_env, "COLORIZED_LOG", (_colorized) ? "1" : "0");
auto _monochrome = p.get<bool>("monochrome");
monochrome() = _monochrome;
p.set_use_color(!_monochrome);
update_env(_env, "OMNITRACE_MONOCHROME", (_monochrome) ? "1" : "0");
update_env(_env, "MONOCHROME", (_monochrome) ? "1" : "0");
});
parser.add_argument({ "--debug" }, "Debug output")
.max_count(1)
@@ -371,7 +396,8 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
update_env(_env, "OMNITRACE_VERBOSE", _v);
});
_add_separator("GENERAL OPTIONS", "");
parser.start_group("GENERAL OPTIONS",
"These are options which are ubiquitously applied");
parser.add_argument({ "-c", "--config" }, "Configuration file")
.min_count(0)
.dtype("filepath")
@@ -437,8 +463,28 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
update_env(_env, "OMNITRACE_USE_PROCESS_SAMPLING", _h || _d);
update_env(_env, "OMNITRACE_USE_ROCM_SMI", _d);
});
parser
.add_argument({ "-w", "--wait" },
"This option is a combination of '--trace-wait' and "
"'--sampling-wait'. See the descriptions for those two options.")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_DELAY", p.get<double>("wait"));
update_env(_env, "OMNITRACE_SAMPLING_DELAY", p.get<double>("wait"));
});
parser
.add_argument(
{ "-d", "--duration" },
"This option is a combination of '--trace-duration' and "
"'--sampling-duration'. See the descriptions for those two options.")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_DURATION", p.get<double>("duration"));
update_env(_env, "OMNITRACE_SAMPLING_DURATION", p.get<double>("duration"));
});
_add_separator("TRACING OPTIONS", "");
parser.start_group("TRACING OPTIONS", "Specific options controlling tracing (i.e. "
"deterministic measurements of every event)");
parser
.add_argument({ "--trace-file" },
"Specify the trace output filename. Relative filepath will be with "
@@ -464,8 +510,57 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
update_env(_env, "OMNITRACE_PERFETTO_FILL_POLICY",
p.get<std::string>("trace-fill-policy"));
});
parser
.add_argument({ "--trace-wait" },
"Set the wait time (in seconds) "
"before collecting trace and/or profiling data"
"(in seconds). By default, the duration is in seconds of realtime "
"but that can changed via --trace-clock-id.")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_DELAY", p.get<double>("trace-wait"));
});
parser
.add_argument({ "--trace-duration" },
"Set the duration of the trace and/or profile data collection (in "
"seconds). By default, the duration is in seconds of realtime but "
"that can changed via --trace-clock-id.")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_DURATION", p.get<double>("trace-duration"));
});
parser
.add_argument(
{ "--trace-periods" },
"More powerful version of specifying trace delay and/or duration. Format is "
"one or more groups of: <DELAY>:<DURATION>, <DELAY>:<DURATION>:<REPEAT>, "
"and/or <DELAY>:<DURATION>:<REPEAT>:<CLOCK_ID>.")
.min_count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_PERIODS",
join(array_config{ ",", "", "" },
p.get<std::vector<std::string>>("trace-periods")));
});
parser
.add_argument(
{ "--trace-clock-id" },
"Set the default clock ID for for trace delay/duration. Note: \"cputime\" is "
"the *process* CPU time and might need to be scaled based on the number of "
"threads, i.e. 4 seconds of CPU-time for an application with 4 fully active "
"threads would equate to ~1 second of realtime. If this proves to be "
"difficult to handle in practice, please file a feature request for "
"omnitrace to auto-scale based on the number of threads.")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_TRACE_PERIOD_CLOCK_ID",
p.get<double>("trace-clock-id"));
})
.choices(clock_id_choices.first)
.choice_aliases(clock_id_choices.second);
_add_separator("PROFILE OPTIONS", "");
parser.start_group("PROFILE OPTIONS",
"Specific options controlling profiling (i.e. deterministic "
"measurements which are aggregated into a summary)");
parser.add_argument({ "--profile-format" }, "Data formats for profiling results")
.min_count(1)
.max_count(3)
@@ -496,7 +591,10 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
if(_v.size() > 1) update_env(_env, "OMNITRACE_INPUT_PREFIX", _v.at(1));
});
_add_separator("HOST/DEVICE (PROCESS SAMPLING) OPTIONS", "");
parser.start_group(
"HOST/DEVICE (PROCESS SAMPLING) OPTIONS",
"Process sampling is background measurements for resources available to the "
"entire process. These samples are not tied to specific lines/regions of code");
parser
.add_argument({ "--process-freq" },
"Set the default host/device sampling frequency "
@@ -545,7 +643,8 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
join(array_config{ "," }, p.get<std::vector<std::string>>("gpus")));
});
_add_separator("GENERAL SAMPLING OPTIONS", "");
parser.start_group("GENERAL SAMPLING OPTIONS",
"General options for timer-based sampling per-thread");
parser
.add_argument({ "-f", "--freq" }, "Set the default sampling frequency "
"(number of interrupts per second)")
@@ -555,23 +654,24 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
});
parser
.add_argument(
{ "-w", "--wait" },
{ "--sampling-wait" },
"Set the default wait time (i.e. delay) before taking first sample "
"(in seconds). This delay time is based on the clock of the sampler, i.e., a "
"delay of 1 second for CPU-clock sampler may not equal 1 second of realtime")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_SAMPLING_DELAY", p.get<double>("wait"));
update_env(_env, "OMNITRACE_SAMPLING_DELAY", p.get<double>("sampling-wait"));
});
parser
.add_argument(
{ "-d", "--duration" },
{ "--sampling-duration" },
"Set the duration of the sampling (in seconds of realtime). I.e., it is "
"possible (currently) to set a CPU-clock time delay that exceeds the "
"real-time duration... resulting in zero samples being taken")
.count(1)
.action([&](parser_t& p) {
update_env(_env, "OMNITRACE_SAMPLING_DURATION", p.get<double>("duration"));
update_env(_env, "OMNITRACE_SAMPLING_DURATION",
p.get<double>("sampling-duration"));
});
parser
.add_argument({ "-t", "--tids" },
@@ -584,7 +684,9 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
join(array_config{ ", " }, p.get<std::vector<int64_t>>("tids")));
});
_add_separator("SAMPLING TIMER OPTIONS", "");
parser.start_group(
"SAMPLING TIMER OPTIONS",
"These options determine the heuristic for deciding when to take a sample");
parser.add_argument({ "--cputime" }, _cputime_desc)
.min_count(0)
.action([&](parser_t& p) {
@@ -660,8 +762,9 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
_backend_choices.erase("rocprofiler");
#endif
_add_separator("BACKEND OPTIONS", "These options control region information captured "
"w/o sampling or instrumentation");
parser.start_group("BACKEND OPTIONS",
"These options control region information captured "
"w/o sampling or instrumentation");
parser.add_argument({ "-I", "--include" }, "Include data from these backends")
.choices(_backend_choices)
.action([&](parser_t& p) {
@@ -727,7 +830,7 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
remove_env(_env, "KOKKOS_PROFILE_LIBRARY");
});
_add_separator("HARDWARE COUNTER OPTIONS", "");
parser.start_group("HARDWARE COUNTER OPTIONS", "See also: omnitrace-avail -H");
parser
.add_argument({ "-C", "--cpu-events" },
"Set the CPU hardware counter events to record (ref: "
@@ -750,7 +853,7 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
});
#endif
_add_separator("MISCELLANEOUS OPTIONS", "");
parser.start_group("MISCELLANEOUS OPTIONS", "");
parser
.add_argument({ "-i", "--inlines" },
"Include inline info in output when available")
@@ -768,6 +871,8 @@ parse_args(int argc, char** argv, std::vector<char*>& _env)
update_env(_env, "HSA_ENABLE_INTERRUPT", p.get<int>("hsa-interrupt"));
});
parser.end_group();
auto _inpv = std::vector<char*>{};
auto _outv = std::vector<char*>{};
bool _hash = false;