Minor fixes (#113)
- Improved error handling in getenv
- write_perfetto_counter_track
[ROCm/rocprofiler-systems commit: 80a9039239]
This commit is contained in:
committed by
GitHub
parent
2123e661d5
commit
ae7b931672
@@ -22,8 +22,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<set_env_s>() };
|
||||
|
||||
static auto _set_envs = std::set<std::string_view>{};
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <timemory/utility/procfs/cpuinfo.hpp>
|
||||
#include <timemory/utility/type_list.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sys/resource.h>
|
||||
@@ -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<Types...>, std::array<const char*, N> _
|
||||
(_config(Types{}), ...);
|
||||
}
|
||||
|
||||
struct index
|
||||
{
|
||||
size_t value = 0;
|
||||
};
|
||||
|
||||
template <typename Tp, typename... Args>
|
||||
void
|
||||
write_perfetto_counter_track(Args... _args)
|
||||
@@ -256,6 +260,14 @@ write_perfetto_counter_track(Args... _args)
|
||||
using track = perfetto_counter_track<Tp>;
|
||||
TRACE_COUNTER(trait::name<Tp>::value, track::at(0, 0), _args...);
|
||||
}
|
||||
|
||||
template <typename Tp, typename... Args>
|
||||
void
|
||||
write_perfetto_counter_track(index&& _idx, Args... _args)
|
||||
{
|
||||
using track = perfetto_counter_track<Tp>;
|
||||
TRACE_COUNTER(trait::name<Tp>::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<cpu_freq>(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<cpu_freq>(index{ _idx }, _end_ts, 0);
|
||||
};
|
||||
|
||||
auto _process_cpu_rusage = []() {
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <timemory/runtime.hpp>
|
||||
#include <timemory/settings.hpp>
|
||||
#include <timemory/storage.hpp>
|
||||
#include <timemory/utility/signals.hpp>
|
||||
#include <timemory/variadic.hpp>
|
||||
|
||||
namespace omnitrace
|
||||
|
||||
Reference in New Issue
Block a user