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
This commit is contained in:
1 parent
a1dcd1bc4b
commit
808ea7dfa7
113 files changed
+4284
-2880
No files matched your search
@@ -21,7 +21,6 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "library/components/pthread_mutex_gotcha.hpp"
|
||||
#include "library.hpp"
|
||||
#include "library/components/category_region.hpp"
|
||||
#include "library/components/pthread_gotcha.hpp"
|
||||
#include "library/config.hpp"
|
||||
@@ -41,6 +40,8 @@
|
||||
|
||||
namespace omnitrace
|
||||
{
|
||||
namespace component
|
||||
{
|
||||
using Device = critical_trace::Device;
|
||||
using Phase = critical_trace::Phase;
|
||||
|
||||
@@ -98,7 +99,7 @@ pthread_mutex_gotcha::configure()
|
||||
pthread_mutex_gotcha_t::get_initializer() = []() {
|
||||
if(config::get_trace_thread_locks())
|
||||
{
|
||||
pthread_mutex_gotcha::validate();
|
||||
validate();
|
||||
|
||||
pthread_mutex_gotcha_t::configure(
|
||||
comp::gotcha_config<0, int, pthread_mutex_t*>{ "pthread_mutex_lock" });
|
||||
@@ -186,23 +187,39 @@ pthread_mutex_gotcha::validate()
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_gotcha::pthread_mutex_gotcha(const gotcha_data_t& _data)
|
||||
: m_data{ &_data }
|
||||
{}
|
||||
|
||||
template <typename... Args>
|
||||
auto
|
||||
pthread_mutex_gotcha::operator()(uintptr_t&& _id, const comp::gotcha_data& _data,
|
||||
int (*_callee)(Args...), Args... _args) const
|
||||
pthread_mutex_gotcha::operator()(uintptr_t&& _id, int (*_callee)(Args...),
|
||||
Args... _args) const
|
||||
{
|
||||
using bundle_t = omnitrace::component::category_region<category::pthread>;
|
||||
using bundle_t = category_region<category::pthread>;
|
||||
|
||||
if(is_disabled())
|
||||
{
|
||||
if(!_callee)
|
||||
{
|
||||
OMNITRACE_PRINT("Warning! nullptr to %s\n", _data.tool_id.c_str());
|
||||
if(m_data)
|
||||
{
|
||||
OMNITRACE_PRINT("Warning! nullptr to %s\n", m_data->tool_id.c_str());
|
||||
}
|
||||
return EINVAL;
|
||||
}
|
||||
return (*_callee)(_args...);
|
||||
}
|
||||
|
||||
struct local_dtor
|
||||
{
|
||||
explicit local_dtor(bool& _v)
|
||||
: _protect{ _v }
|
||||
{}
|
||||
~local_dtor() { _protect = false; }
|
||||
bool& _protect;
|
||||
} _dtor{ m_protect = true };
|
||||
|
||||
uint64_t _cid = 0;
|
||||
uint64_t _parent_cid = 0;
|
||||
uint32_t _depth = 0;
|
||||
@@ -216,15 +233,15 @@ pthread_mutex_gotcha::operator()(uintptr_t&& _id, const comp::gotcha_data& _data
|
||||
_ts = comp::wall_clock::record();
|
||||
}
|
||||
|
||||
bundle_t::audit(_data, audit::incoming{}, _args...);
|
||||
bundle_t::audit(std::string_view{ m_data->tool_id }, audit::incoming{}, _args...);
|
||||
auto _ret = (*_callee)(_args...);
|
||||
bundle_t::audit(_data, audit::outgoing{}, _ret);
|
||||
bundle_t::audit(std::string_view{ m_data->tool_id }, audit::outgoing{}, _ret);
|
||||
|
||||
if(_id < std::numeric_limits<uintptr_t>::max() && get_use_critical_trace())
|
||||
{
|
||||
add_critical_trace<Device::CPU, Phase::DELTA>(
|
||||
threading::get_id(), _cid, 0, _parent_cid, _ts, comp::wall_clock::record(), 0,
|
||||
_id, get_hashes().at(_data.index), _depth);
|
||||
_id, get_hashes().at(m_data->index), _depth);
|
||||
}
|
||||
|
||||
tim::consume_parameters(_id, _cid, _parent_cid, _depth, _ts);
|
||||
@@ -232,51 +249,69 @@ pthread_mutex_gotcha::operator()(uintptr_t&& _id, const comp::gotcha_data& _data
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_gotcha::operator()(const gotcha_data_t& _data,
|
||||
int (*_callee)(pthread_mutex_t*),
|
||||
pthread_mutex_gotcha::operator()(int (*_callee)(pthread_mutex_t*),
|
||||
pthread_mutex_t* _mutex) const
|
||||
{
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_mutex), _data, _callee, _mutex);
|
||||
if(m_protect) return (*_callee)(_mutex);
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_mutex), _callee, _mutex);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_gotcha::operator()(const gotcha_data_t& _data,
|
||||
int (*_callee)(pthread_spinlock_t*),
|
||||
pthread_mutex_gotcha::operator()(int (*_callee)(pthread_spinlock_t*),
|
||||
pthread_spinlock_t* _lock) const
|
||||
{
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_lock), _data, _callee, _lock);
|
||||
if(m_protect) return (*_callee)(_lock);
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_lock), _callee, _lock);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_gotcha::operator()(const gotcha_data_t& _data,
|
||||
int (*_callee)(pthread_rwlock_t*),
|
||||
pthread_mutex_gotcha::operator()(int (*_callee)(pthread_rwlock_t*),
|
||||
pthread_rwlock_t* _lock) const
|
||||
{
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_lock), _data, _callee, _lock);
|
||||
if(m_protect) return (*_callee)(_lock);
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_lock), _callee, _lock);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_gotcha::operator()(const gotcha_data_t& _data,
|
||||
int (*_callee)(pthread_barrier_t*),
|
||||
pthread_mutex_gotcha::operator()(int (*_callee)(pthread_barrier_t*),
|
||||
pthread_barrier_t* _barrier) const
|
||||
{
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_barrier), _data, _callee, _barrier);
|
||||
if(m_protect) return (*_callee)(_barrier);
|
||||
return (*this)(reinterpret_cast<uintptr_t>(_barrier), _callee, _barrier);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_gotcha::operator()(const gotcha_data_t& _data,
|
||||
int (*_callee)(pthread_t, void**), pthread_t _thr,
|
||||
pthread_mutex_gotcha::operator()(int (*_callee)(pthread_t, void**), pthread_t _thr,
|
||||
void** _tinfo) const
|
||||
{
|
||||
return (*this)(static_cast<uintptr_t>(threading::get_id()), _data, _callee, _thr,
|
||||
_tinfo);
|
||||
if(m_protect) return (*_callee)(_thr, _tinfo);
|
||||
return (*this)(static_cast<uintptr_t>(threading::get_id()), _callee, _thr, _tinfo);
|
||||
}
|
||||
|
||||
bool
|
||||
pthread_mutex_gotcha::is_disabled()
|
||||
{
|
||||
return (omnitrace::get_state() != omnitrace::State::Active ||
|
||||
omnitrace::get_thread_state() != omnitrace::ThreadState::Enabled ||
|
||||
return (get_state() != ::omnitrace::State::Active ||
|
||||
get_thread_state() != ThreadState::Enabled ||
|
||||
(get_use_sampling() && !pthread_gotcha::sampling_enabled_on_child_threads()));
|
||||
}
|
||||
} // namespace component
|
||||
} // namespace omnitrace
|
||||
|
||||
namespace tim
|
||||
{
|
||||
namespace policy
|
||||
{
|
||||
template <size_t N>
|
||||
pthread_mutex_gotcha&
|
||||
static_data<pthread_mutex_gotcha, pthread_mutex_gotcha_t>::operator()(
|
||||
std::integral_constant<size_t, N>, const component::gotcha_data& _data) const
|
||||
{
|
||||
using thread_data_t =
|
||||
omnitrace::thread_data<pthread_mutex_gotcha, std::integral_constant<size_t, N>>;
|
||||
static thread_local auto& _v =
|
||||
thread_data_t::instance(omnitrace::construct_on_init{}, _data);
|
||||
return *_v;
|
||||
}
|
||||
} // namespace policy
|
||||
} // namespace tim
|
||||
Reference in new issue
Block a user