32 #include <src/crow_config.hpp> 33 #include <src/crow_utilities.hpp> 35 #ifndef NLOHMANN_CROW_MINGW 42 #ifdef NLOHMANN_CROW_HAVE_CXXABI_H 46 #ifdef NLOHMANN_CROW_HAVE_EXECINFO_H 50 #ifdef NLOHMANN_CROW_HAVE_DLFCN_H 57 namespace crow_utilities
64 json result = json::array();
66 #if defined(NLOHMANN_CROW_HAVE_DLFCN_H) && defined(NLOHMANN_CROW_HAVE_EXECINFO_H) 68 const int nMaxFrames =
sizeof(callstack) /
sizeof(callstack[0]);
70 int nFrames = backtrace(callstack, nMaxFrames);
71 char** symbols = backtrace_symbols(callstack, nFrames);
73 for (
int i = skip; i < nFrames; i++)
76 if (dladdr(callstack[i], &info) && info.dli_sname)
78 char* demangled =
nullptr;
80 if (info.dli_sname[0] ==
'_')
82 #ifdef NLOHMANN_CROW_HAVE_CXXABI_H 83 demangled = abi::__cxa_demangle(info.dli_sname,
nullptr,
nullptr, &status);
87 const std::string function_name = (status == 0 ? demangled : info.dli_sname ==
nullptr ? symbols[i] : info.dli_sname);
89 snprintf(buf,
sizeof(buf),
"%-3d %*p %s + %zd\n",
90 i,
int(2 +
sizeof(
void*) * 2), callstack[i],
91 function_name.c_str(),
92 (
char*) callstack[i] - (
char*) info.dli_saddr);
96 entry[
"function"] = function_name;
98 if (not function_name.empty())
100 if (function_name.substr(0, 5) ==
"std::" or function_name.substr(0, 2) ==
"__")
102 entry[
"in_app"] =
false;
106 result.push_back(entry);
112 snprintf(buf,
sizeof(buf),
"%-3d %*p %s\n",
113 i,
int(2 +
sizeof(
void*) * 2), callstack[i], symbols[i]);
123 const bool only_module)
125 #ifdef NLOHMANN_CROW_HAVE_CXXABI_H 127 std::string result = abi::__cxa_demangle(type_id_name,
nullptr,
nullptr, &status);
129 std::string result = type_id_name;
133 ? result.substr(0, result.find_first_of(
':'))
139 const auto tp = std::chrono::system_clock::now();
140 const auto dur = tp.time_since_epoch();
141 return std::chrono::duration_cast<std::chrono::seconds>(dur).count();
148 char buf[
sizeof "2011-10-08T07:07:09Z"];
149 std::strftime(buf,
sizeof buf,
"%Y-%m-%dT%H:%M:%SZ", std::gmtime(&now));
163 #ifdef NLOHMANN_CROW_MINGW 164 static bool init =
false;
168 std::srand(std::time(
nullptr));
170 return std::rand() % upper + lower;
172 static std::random_device random_device;
173 static std::default_random_engine random_engine(random_device());
174 static std::uniform_int_distribution<int> uniform_dist(lower, upper);
175 return uniform_dist(random_engine);
181 std::string result(32,
' ');
183 for (std::size_t i = 0; i < result.size(); ++i)
200 result[i] =
'a' + r -
static_cast<char>(10);
int get_random_number(int lower, int upper)
return a random integer
std::string get_iso8601()
get the current date and time as ISO 8601 string
json get_backtrace(int skip)
namespace for Niels Lohmann
std::int64_t get_timestamp()
get the seconds since epoch
std::string pretty_name(const char *type_id_name, const bool only_module)
return pretty type name
std::string generate_uuid()
generate a UUID4 without dashes