aboutsummaryrefslogtreecommitdiffhomepage
path: root/tdutils/td
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-05-17 23:26:30 +0300
committerlevlam <levlam@telegram.org>2026-05-17 23:26:30 +0300
commit5bcae9125fc0be88b1d07f621faad31242512a54 (patch)
tree4c10a692c9f7c01ea6d2845a87e5ef6aac270da8 /tdutils/td
parent156ce4c37a5e36c7bbee86ae177240b2212e1082 (diff)
Add Clocks::get_debug().
Diffstat (limited to 'tdutils/td')
-rw-r--r--tdutils/td/utils/port/Clocks.cpp57
-rw-r--r--tdutils/td/utils/port/Clocks.h4
2 files changed, 60 insertions, 1 deletions
diff --git a/tdutils/td/utils/port/Clocks.cpp b/tdutils/td/utils/port/Clocks.cpp
index 775ec5f89..6f86e1161 100644
--- a/tdutils/td/utils/port/Clocks.cpp
+++ b/tdutils/td/utils/port/Clocks.cpp
@@ -6,7 +6,9 @@
//
#include "td/utils/port/Clocks.h"
-#include "td/utils/port/platform.h"
+#include "td/utils/port/config.h"
+#include "td/utils/Slice.h"
+#include "td/utils/SliceBuilder.h"
#include <chrono>
#include <ctime>
@@ -57,6 +59,59 @@ double Clocks::system() {
return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9;
}
+string Clocks::get_debug() {
+ string result;
+#if TD_PORT_POSIX
+ auto add_clock = [&](Slice clock_name, clockid_t clock_id) {
+ struct timespec spec;
+ if (clock_gettime(clock_id, &spec) == 0) {
+ result += PSTRING() << '[' << clock_name << " = "
+ << static_cast<double>(spec.tv_nsec) * 1e-9 + static_cast<double>(spec.tv_sec) << ']';
+ } else {
+ result += PSTRING() << '[' << clock_name << " failed]";
+ }
+ };
+
+#ifdef CLOCK_REALTIME
+ add_clock("REALTIME", CLOCK_REALTIME);
+#endif
+#ifdef CLOCK_REALTIME_COARSE
+ add_clock("REALTIME_COARSE", CLOCK_REALTIME_COARSE);
+#endif
+#ifdef CLOCK_TAI
+ add_clock("TAI", CLOCK_TAI);
+#endif
+#ifdef CLOCK_MONOTONIC
+ add_clock("MONOTONIC", CLOCK_MONOTONIC);
+#endif
+#ifdef CLOCK_MONOTONIC_COARSE
+ add_clock("MONOTONIC_COARSE", CLOCK_MONOTONIC_COARSE);
+#endif
+#ifdef CLOCK_MONOTONIC_RAW
+ add_clock("MONOTONIC_RAW", CLOCK_MONOTONIC_RAW);
+#endif
+#ifdef CLOCK_BOOTTIME
+ add_clock("BOOTTIME", CLOCK_BOOTTIME);
+#endif
+#ifdef CLOCK_BOOTTIME_ALARM
+ add_clock("BOOTTIME_ALARM", CLOCK_BOOTTIME_ALARM);
+#endif
+#ifdef CLOCK_PROCESS_CPUTIME_ID
+ add_clock("PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID);
+#endif
+#ifdef CLOCK_THREAD_CPUTIME_ID
+ add_clock("THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID);
+#endif
+#endif
+
+ auto duration = std::chrono::steady_clock::now().time_since_epoch();
+ result +=
+ PSTRING() << "[chrono::steady = "
+ << static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count()) * 1e-9
+ << ']';
+ return result;
+}
+
int Clocks::tz_offset() {
// not thread-safe on POSIX, so calculate the offset only once
static int offset = [] {
diff --git a/tdutils/td/utils/port/Clocks.h b/tdutils/td/utils/port/Clocks.h
index 67de1d542..b349fb860 100644
--- a/tdutils/td/utils/port/Clocks.h
+++ b/tdutils/td/utils/port/Clocks.h
@@ -6,6 +6,8 @@
//
#pragma once
+#include "td/utils/common.h"
+
namespace td {
struct Clocks {
@@ -13,6 +15,8 @@ struct Clocks {
static double system();
+ static string get_debug();
+
static int tz_offset();
};