2021-10-28 16:47:58 +05:00
|
|
|
#include "ngcore_api.hpp"
|
2019-01-02 22:38:03 +05:00
|
|
|
#include "utils.hpp"
|
2019-01-03 19:54:50 +05:00
|
|
|
#include "logging.hpp"
|
2021-10-28 16:47:58 +05:00
|
|
|
#include "simd_generic.hpp"
|
2019-01-02 22:38:03 +05:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
2021-09-01 19:56:01 +05:00
|
|
|
#include <array>
|
2021-11-04 16:20:56 +05:00
|
|
|
#include <filesystem>
|
2019-01-03 19:54:50 +05:00
|
|
|
#include <iostream>
|
2021-09-01 19:56:01 +05:00
|
|
|
#include <regex>
|
2019-01-02 22:38:03 +05:00
|
|
|
|
2021-09-06 19:59:48 +05:00
|
|
|
#include "ngstream.hpp"
|
|
|
|
|
2019-01-02 22:38:03 +05:00
|
|
|
namespace ngcore
|
|
|
|
{
|
2021-09-01 19:56:01 +05:00
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
// see https://github.com/RobotLocomotion/drake/blob/master/common/nice_type_name.cc
|
|
|
|
static const auto demangle_regexes =
|
|
|
|
std::array<std::pair<std::regex, std::string>, 8>{
|
|
|
|
// Remove unwanted keywords and following space. (\b is word boundary.)
|
|
|
|
std::make_pair(std::regex("\\b(class|struct|enum|union) "), ""),
|
|
|
|
// Tidy up anonymous namespace.
|
|
|
|
{std::regex("[`(]anonymous namespace[')]"), "(anonymous)"},
|
|
|
|
// Replace Microsoft __int64 with long long.
|
|
|
|
{std::regex("\\b__int64\\b"), "long long"},
|
|
|
|
// Temporarily replace spaces we want to keep with "!". (\w is
|
|
|
|
// alphanumeric or underscore.)
|
|
|
|
{std::regex("(\\w) (\\w)"), "$1!$2"},
|
|
|
|
{std::regex(" "), ""}, // Delete unwanted spaces.
|
|
|
|
// Some compilers throw in extra namespaces like "__1" or "__cxx11".
|
|
|
|
// Delete them.
|
|
|
|
{std::regex("\\b__[[:alnum:]_]+::"), ""},
|
|
|
|
{std::regex("!"), " "}, // Restore wanted spaces.
|
|
|
|
|
|
|
|
// Recognize std::string's full name and abbreviate.
|
|
|
|
{std::regex("\\bstd::basic_string<char,std::char_traits<char>,"
|
|
|
|
"std::allocator<char>>"), "std::string"}
|
|
|
|
};
|
|
|
|
std::string CleanupDemangledName( std::string s )
|
|
|
|
{
|
|
|
|
for(const auto & [r, sub] : demangle_regexes)
|
|
|
|
s = std::regex_replace (s,r,sub);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
|
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()
|
2021-04-23 23:06:48 +05:00
|
|
|
NGCORE_API std::string Demangle(const char* typeinfo) {
|
|
|
|
std::string name = typeinfo;
|
2021-09-01 19:56:01 +05:00
|
|
|
return detail::CleanupDemangledName(name);
|
2021-04-23 23:06:48 +05:00
|
|
|
}
|
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);
|
2023-04-28 20:33:07 +05:00
|
|
|
std::string result;
|
|
|
|
if (s == nullptr)
|
|
|
|
result = typeinfo;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = s;
|
|
|
|
free(s);
|
|
|
|
}
|
2021-09-01 19:56:01 +05:00
|
|
|
result = detail::CleanupDemangledName(result);
|
2019-10-14 13:56:27 +05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
catch( const std::exception & e )
|
|
|
|
{
|
|
|
|
GetLogger("utils")->warn("{}:{} cannot demangle {}, status: {}, error:{}", __FILE__, __LINE__, typeinfo, status, e.what());
|
|
|
|
}
|
2021-09-01 19:56:01 +05:00
|
|
|
std::string name = typeinfo;
|
|
|
|
return detail::CleanupDemangledName(name);
|
2019-10-14 13:56:27 +05:00
|
|
|
}
|
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();
|
|
|
|
|
2021-09-06 20:36:53 +05:00
|
|
|
int printmessage_importance = 0;
|
2021-09-06 19:59:48 +05:00
|
|
|
bool NGSOStream :: glob_active = true;
|
|
|
|
|
2021-10-28 16:47:58 +05:00
|
|
|
NGCORE_API int GetCompiledSIMDSize()
|
|
|
|
{
|
|
|
|
return GetDefaultSIMDSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
NGCORE_API bool IsRangeCheckEnabled()
|
|
|
|
{
|
|
|
|
#ifdef NETGEN_ENABLE_CHECK_RANGE
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-02-17 20:52:07 +05:00
|
|
|
NGCORE_API std::filesystem::path GetTempFilename()
|
2021-11-04 16:20:56 +05:00
|
|
|
{
|
|
|
|
static int counter = 0;
|
|
|
|
auto path = std::filesystem::temp_directory_path();
|
2022-02-17 20:52:07 +05:00
|
|
|
path += ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter());
|
|
|
|
return path;
|
2021-11-04 16:20:56 +05:00
|
|
|
}
|
|
|
|
|
2019-01-02 22:38:03 +05:00
|
|
|
} // namespace ngcore
|
|
|
|
|