netgen/libsrc/core/utils.cpp

63 lines
1.5 KiB
C++
Raw Normal View History

2019-01-02 22:38:03 +05:00
#include "utils.hpp"
2019-01-03 19:54:50 +05:00
#include "logging.hpp"
2019-01-02 22:38:03 +05:00
#ifndef WIN32
#include <cxxabi.h>
#endif
2019-01-03 19:54:50 +05:00
#include <iostream>
2019-01-02 22:38:03 +05:00
namespace ngcore
{
2019-01-14 17:04:27 +05:00
// parallel netgen
int id = 0, ntasks = 1;
2019-01-02 22:38:03 +05:00
#ifdef WIN32
// windows does demangling in typeid(T).name()
NGCORE_API std::string Demangle(const char* typeinfo) {
std::string name = typeinfo;
// remove "class " and "struct " at beginning of type names to be consistent with demangled names of gcc/clang
if(name.find("class ") == 0)
name.erase(0,6);
if(name.find("struct ") == 0)
name.erase(0,7);
return name;
}
2019-01-02 22:38:03 +05:00
#else
2019-10-14 13:56:27 +05:00
NGCORE_API std::string Demangle(const char* typeinfo)
{
int status=0;
try
{
char *s = abi::__cxa_demangle(typeinfo, nullptr, nullptr, &status);
std::string result{s};
free(s);
return result;
}
catch( const std::exception & e )
{
GetLogger("utils")->warn("{}:{} cannot demangle {}, status: {}, error:{}", __FILE__, __LINE__, typeinfo, status, e.what());
}
return typeinfo;
}
2019-01-08 17:12:12 +05:00
#endif
2019-01-03 19:54:50 +05:00
2019-10-01 16:18:24 +05:00
double seconds_per_tick = [] () noexcept
2019-01-03 19:54:50 +05:00
{
auto tick_start = GetTimeCounter();
double tstart = WallTime();
double tend = WallTime()+0.001;
// wait for 1ms and compare wall time with time counter
while(WallTime()<tend);
auto tick_end = GetTimeCounter();
tend = WallTime();
2019-10-01 16:18:24 +05:00
return (tend-tstart)/static_cast<double>(tick_end-tick_start);
2019-01-03 19:54:50 +05:00
}();
const std::chrono::time_point<TClock> wall_time_start = TClock::now();
2019-01-02 22:38:03 +05:00
} // namespace ngcore