Compare commits

..

No commits in common. "0c933fc5695ae0048572eafaba5d3f59aa531cdd" and "029132c622f8d371f0d002513fd2a4a633e76137" have entirely different histories.

3 changed files with 19 additions and 26 deletions

View File

@ -375,22 +375,18 @@ 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_arithmetic_v<T>)
if constexpr (std::is_same_v<int32_t, T>)
{
if (std::holds_alternative<std::string>(t))
return std::stoi(std::get<std::string>(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:

View File

@ -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 int64_t getCPUThreadTime()
static inline auto getCPUThreadTime()
{
#ifdef unix
timespec time{};
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time);
return time.tv_sec * static_cast<int64_t>(1e9) + time.tv_nsec;
return time.tv_nsec;
#else
return std::clock();
#endif
}
static inline int64_t getCPUTime()
static inline auto getCPUTime()
{
#ifdef unix
timespec time{};
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time);
return time.tv_sec * static_cast<int64_t>(1e9) + time.tv_nsec;
return 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_sec * static_cast<int64_t>(1e9) + res.tv_nsec;
return res.tv_nsec;
#else
return CLOCKS_PER_SECOND;
#endif

View File

@ -12,8 +12,6 @@
#include <algorithm>
#include <blt/std/format.h>
#define TIME_FUNCTION blt::system::getCPUThreadTime()
namespace blt::profiling {
// TODO: a better way
@ -150,7 +148,7 @@ namespace blt::profiling {
void startInterval(const std::string& profileName, const std::string& intervalName) {
std::scoped_lock lock(profileLock);
capture_interval interval{};
interval.start = TIME_FUNCTION;
interval.start = system::getCurrentTimeNanoseconds();
profiles[profileName].intervals[intervalName] = interval;
}
@ -159,10 +157,9 @@ namespace blt::profiling {
auto& prof = profiles[profileName];
auto& ref = prof.intervals[intervalName];
ref.end = TIME_FUNCTION;
ref.end = system::getCurrentTimeNanoseconds();
auto difference = ref.end - ref.start;
auto& href = prof.intervals_total[intervalName];
href.total += difference;
@ -172,7 +169,7 @@ namespace blt::profiling {
void point(const std::string& profileName, const std::string& pointName) {
std::scoped_lock lock(profileLock);
capture_point point{};
point.point = TIME_FUNCTION;
point.point = system::getCurrentTimeNanoseconds();
point.name = pointName;
profiles[profileName].points.push(point);
}