diff --git a/projects/rocprofiler-systems/source/lib/common/environment.hpp b/projects/rocprofiler-systems/source/lib/common/environment.hpp index c43637e7c4..4aecc58396 100644 --- a/projects/rocprofiler-systems/source/lib/common/environment.hpp +++ b/projects/rocprofiler-systems/source/lib/common/environment.hpp @@ -22,8 +22,10 @@ #pragma once +#include #include #include +#include #include #include @@ -53,7 +55,20 @@ get_env(std::string_view env_id, int _default) { if(env_id.empty()) return _default; char* env_var = ::std::getenv(env_id.data()); - if(env_var) return std::stoi(env_var); + if(env_var) + { + try + { + return std::stoi(env_var); + } catch(std::exception& _e) + { + fprintf(stderr, + "[omnitrace][get_env] Exception thrown converting getenv(\"%s\") = " + "%s to integer :: %s. Using default value of %i\n", + env_id.data(), env_var, _e.what(), _default); + } + return _default; + } return _default; } diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library.cpp index 7d12bf4d39..c512e09775 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library.cpp @@ -282,11 +282,15 @@ omnitrace_pop_region_hidden(const char* name) /// //======================================================================================// +namespace +{ +struct set_env_s // NOLINT +{}; +} // namespace + extern "C" void omnitrace_set_env_hidden(const char* env_name, const char* env_val) { - struct set_env_s // NOLINT - {}; tim::auto_lock_t _lk{ tim::type_mutex() }; static auto _set_envs = std::set{}; diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/cpu_freq.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/cpu_freq.cpp index 2f577513a9..319ece31c7 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/cpu_freq.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/cpu_freq.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -176,8 +177,6 @@ config() { OMNITRACE_VERBOSE( 0, "[cpu_freq::config] Warning! Removing invalid cpu %zu...\n", itr); - OMNITRACE_CI_FAIL(true, "[cpu_freq::config] CPU frequencies are disabled " - ":: unable to open /proc/cpuinfo"); } } @@ -249,6 +248,11 @@ config_perfetto_counter_tracks(type_list, std::array _ (_config(Types{}), ...); } +struct index +{ + size_t value = 0; +}; + template void write_perfetto_counter_track(Args... _args) @@ -256,6 +260,14 @@ write_perfetto_counter_track(Args... _args) using track = perfetto_counter_track; TRACE_COUNTER(trait::name::value, track::at(0, 0), _args...); } + +template +void +write_perfetto_counter_track(index&& _idx, Args... _args) +{ + using track = perfetto_counter_track; + TRACE_COUNTER(trait::name::value, track::at(_idx.value, 0), _args...); +} } // namespace void @@ -278,11 +290,11 @@ post_process() uint64_t _ts = std::get<0>(itr); double _freq = std::get<8>(itr).at(_offset); if(!pthread_create_gotcha::is_valid_execution_time(0, _ts)) continue; - TRACE_COUNTER("cpu_freq", freq_track::at(_idx, 0), _ts, _freq); + write_perfetto_counter_track(index{ _idx }, _ts, _freq); } auto _end_ts = pthread_create_gotcha::get_execution_time(0)->second; - TRACE_COUNTER("cpu_freq", freq_track::at(_idx, 0), _end_ts, 0); + write_perfetto_counter_track(index{ _idx }, _end_ts, 0); }; auto _process_cpu_rusage = []() { diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/timemory.hpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/timemory.hpp index b6d4028146..886467b64b 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/timemory.hpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/timemory.hpp @@ -40,6 +40,7 @@ #include #include #include +#include #include namespace omnitrace