camcom 1.0.0-pre2
 
Loading...
Searching...
No Matches
tools.hpp
Go to the documentation of this file.
1
8
9#ifndef CAMCOM_COMMON_TOOLS_HPP
10#define CAMCOM_COMMON_TOOLS_HPP
11
12#include <ifaddrs.h>
13#include <sys/types.h>
14#include <sys/socket.h>
15#include <netinet/in.h>
16#include <arpa/inet.h>
17#include <net/if.h>
18#include <string>
19#include <chrono>
20#include <execinfo.h>
21#include <unistd.h>
22#include <algorithm>
23
24namespace camcom::common {
25
26 std::chrono::time_point<std::chrono::system_clock> TimeNow();
27
28 std::string IsoTimestampNow(
29 std::chrono::system_clock::time_point time = std::chrono::system_clock::now());
30
31 std::string ProcName();
32
33 std::string TrimString(const std::string& str);
34
35 std::string ResolveHostAddress();
36
37 // Minimal inline call stack printer.
38 inline void PrintCallStack(int skip = 1, int max_frames = 64) {
39 void* buf[256];
40 const int n = ::backtrace(buf, std::min(max_frames, 256));
41 if (n > skip) {
42 ::backtrace_symbols_fd(buf + skip, n - skip, STDOUT_FILENO);
43 }
44 }
45
46}
47
48#endif
Definition adapterBase.cpp:18
std::string IsoTimestampNow(std::chrono::system_clock::time_point time=std::chrono::system_clock::now())
Definition tools.cpp:24
void PrintCallStack(int skip=1, int max_frames=64)
Definition tools.hpp:38
std::string TrimString(const std::string &str)
Definition tools.cpp:46
std::chrono::time_point< std::chrono::system_clock > TimeNow()
Definition tools.cpp:19
std::string ResolveHostAddress()
Definition tools.cpp:58
std::string ProcName()
Definition tools.cpp:39