Merge remote-tracking branch 'github/main'
commit
0bbcb8eeef
|
@ -375,18 +375,22 @@ namespace blt
|
|||
{
|
||||
if constexpr (std::is_same_v<T, arg_data_vec_t>)
|
||||
return std::get<arg_data_vec_t>(v);
|
||||
else
|
||||
{
|
||||
auto t = std::get<arg_data_internal_t>(v);
|
||||
// user is requesting an int, but holds a string, we are going to make the assumption the data can be converted
|
||||
// it is up to the user to deal with the variant if they do not want this behaviour!
|
||||
if constexpr (std::is_same_v<int32_t, T>)
|
||||
{
|
||||
if (std::holds_alternative<std::string>(t))
|
||||
return std::stoi(std::get<std::string>(t));
|
||||
}
|
||||
auto t = std::get<arg_data_internal_t>(v);
|
||||
// user is requesting an int, but holds a string, we are going to make the assumption the data can be converted
|
||||
// it is up to the user to deal with the variant if they do not want this behaviour!
|
||||
if constexpr (!std::is_arithmetic_v<T>)
|
||||
return std::get<T>(t);
|
||||
}
|
||||
// ugly!
|
||||
if (std::holds_alternative<int32_t>(t))
|
||||
return static_cast<T>(std::get<int32_t>(t));
|
||||
if (std::holds_alternative<bool>(t))
|
||||
return static_cast<T>(std::get<bool>(t));
|
||||
auto s = std::get<std::string>(t);
|
||||
if constexpr (std::is_floating_point_v<T>)
|
||||
return static_cast<T>(std::stod(s));
|
||||
if constexpr (std::is_signed_v<T>)
|
||||
return static_cast<T>(std::stoll(s));
|
||||
return static_cast<T>(std::stoull(s));
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -43,23 +43,23 @@ namespace blt::system
|
|||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
static inline auto getCPUThreadTime()
|
||||
static inline int64_t getCPUThreadTime()
|
||||
{
|
||||
#ifdef unix
|
||||
timespec time{};
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time);
|
||||
return time.tv_nsec;
|
||||
return time.tv_sec * static_cast<int64_t>(1e9) + time.tv_nsec;
|
||||
#else
|
||||
return std::clock();
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto getCPUTime()
|
||||
static inline int64_t getCPUTime()
|
||||
{
|
||||
#ifdef unix
|
||||
timespec time{};
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
|
||||
return time.tv_nsec;
|
||||
return time.tv_sec * static_cast<int64_t>(1e9) + time.tv_nsec;
|
||||
#else
|
||||
return std::clock();
|
||||
#endif
|
||||
|
@ -70,7 +70,7 @@ namespace blt::system
|
|||
#ifdef unix
|
||||
timespec res{};
|
||||
clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res);
|
||||
return res.tv_nsec;
|
||||
return res.tv_sec * static_cast<int64_t>(1e9) + res.tv_nsec;
|
||||
#else
|
||||
return CLOCKS_PER_SECOND;
|
||||
#endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3
|
||||
Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8
|
|
@ -12,6 +12,8 @@
|
|||
#include <algorithm>
|
||||
#include <blt/std/format.h>
|
||||
|
||||
#define TIME_FUNCTION blt::system::getCPUThreadTime()
|
||||
|
||||
namespace blt::profiling {
|
||||
|
||||
// TODO: a better way
|
||||
|
@ -148,7 +150,7 @@ namespace blt::profiling {
|
|||
void startInterval(const std::string& profileName, const std::string& intervalName) {
|
||||
std::scoped_lock lock(profileLock);
|
||||
capture_interval interval{};
|
||||
interval.start = system::getCurrentTimeNanoseconds();
|
||||
interval.start = TIME_FUNCTION;
|
||||
profiles[profileName].intervals[intervalName] = interval;
|
||||
}
|
||||
|
||||
|
@ -157,9 +159,10 @@ namespace blt::profiling {
|
|||
auto& prof = profiles[profileName];
|
||||
auto& ref = prof.intervals[intervalName];
|
||||
|
||||
ref.end = system::getCurrentTimeNanoseconds();
|
||||
ref.end = TIME_FUNCTION;
|
||||
|
||||
auto difference = ref.end - ref.start;
|
||||
|
||||
auto& href = prof.intervals_total[intervalName];
|
||||
|
||||
href.total += difference;
|
||||
|
@ -169,7 +172,7 @@ namespace blt::profiling {
|
|||
void point(const std::string& profileName, const std::string& pointName) {
|
||||
std::scoped_lock lock(profileLock);
|
||||
capture_point point{};
|
||||
point.point = system::getCurrentTimeNanoseconds();
|
||||
point.point = TIME_FUNCTION;
|
||||
point.name = pointName;
|
||||
profiles[profileName].points.push(point);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue