[libcxx-commits] [libcxx] debug chrono (PR #181407)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Feb 14 08:29:51 PST 2026


https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/181407

>From 9936e05c1679dec142db979a93482a6ee5a72277 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Fri, 13 Feb 2026 19:52:15 +0000
Subject: [PATCH 1/3] debug chrono

---
 .../time.clock.steady/debug.pass.cpp          | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp

diff --git a/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
new file mode 100644
index 0000000000000..b198bbccc071b
--- /dev/null
+++ b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: no-monotonic-clock
+
+// <chrono>
+#include <chrono>
+#include <cassert>
+
+#include "test_macros.h"
+
+#if defined(_LIBCPP_WIN32API)
+#  define WIN32_LEAN_AND_MEAN
+#  define VC_EXTRA_LEAN
+#  include <windows.h>
+#  if _WIN32_WINNT >= _WIN32_WINNT_WIN8
+#    include <winapifamily.h>
+#  endif
+#endif // defined(_LIBCPP_WIN32API)
+
+#if defined(_LIBCPP_WIN32API)
+
+#  include <iostream>
+
+// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says:
+//    If the function fails, the return value is zero. <snip>
+//    On systems that run Windows XP or later, the function will always succeed
+//      and will thus never return zero.
+
+static LARGE_INTEGER __QueryPerformanceFrequency() {
+  LARGE_INTEGER val;
+  (void)QueryPerformanceFrequency(&val);
+  return val;
+}
+
+static steady_clock::time_point __libcpp_steady_clock_now() {
+  static const LARGE_INTEGER freq = __QueryPerformanceFrequency();
+
+  LARGE_INTEGER counter;
+  (void)QueryPerformanceCounter(&counter);
+  auto seconds   = counter.QuadPart / freq.QuadPart;
+  auto fractions = counter.QuadPart % freq.QuadPart;
+  auto dur       = seconds * nano::den + fractions * nano::den / freq.QuadPart;
+  std::cout << "counter.QuadPart: " << counter.QuadPart << ", freq.QuadPart: " << freq.QuadPart
+            << "\n seconds: " << seconds << ", fractions: " << fractions << "\n nano::den: " << nano::den
+            << ", dur: " << dur << std::endl;
+  return steady_clock::time_point(steady_clock::duration(dur));
+}
+
+int main(int, char**) {
+  int iteration = 100;
+  for (int i = 0; i < iteration; ++i) {
+    std::cout << "Iteration: " << i << std::endl;
+    auto t1 = __libcpp_steady_clock_now();
+    auto t2 = __libcpp_steady_clock_now();
+    assert(t2 >= t1);
+    // make sure t2 didn't wrap around
+  }
+
+  return 1;
+}
+
+#else
+
+int main(int, char**) { return 0; }
+
+#endif

>From 9f1f302fd368592b6ce6b6cb7c0a48bb909559d4 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 14 Feb 2026 08:47:31 +0000
Subject: [PATCH 2/3] debug print

---
 .../std/time/time.clock/time.clock.steady/debug.pass.cpp    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
index b198bbccc071b..5121ca54071c4 100644
--- a/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
+++ b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
@@ -46,16 +46,16 @@ static steady_clock::time_point __libcpp_steady_clock_now() {
   auto seconds   = counter.QuadPart / freq.QuadPart;
   auto fractions = counter.QuadPart % freq.QuadPart;
   auto dur       = seconds * nano::den + fractions * nano::den / freq.QuadPart;
-  std::cout << "counter.QuadPart: " << counter.QuadPart << ", freq.QuadPart: " << freq.QuadPart
+  std::cerr << "counter.QuadPart: " << counter.QuadPart << ", freq.QuadPart: " << freq.QuadPart
             << "\n seconds: " << seconds << ", fractions: " << fractions << "\n nano::den: " << nano::den
             << ", dur: " << dur << std::endl;
-  return steady_clock::time_point(steady_clock::duration(dur));
+  return std::steady_clock::time_point(steady_clock::duration(dur));
 }
 
 int main(int, char**) {
   int iteration = 100;
   for (int i = 0; i < iteration; ++i) {
-    std::cout << "Iteration: " << i << std::endl;
+    std::cerr << "Iteration: " << i << std::endl;
     auto t1 = __libcpp_steady_clock_now();
     auto t2 = __libcpp_steady_clock_now();
     assert(t2 >= t1);

>From e298c9d37df37e59e0188c6ff511f1405549ab23 Mon Sep 17 00:00:00 2001
From: Hui Xie <hui.xie1990 at gmail.com>
Date: Sat, 14 Feb 2026 16:29:39 +0000
Subject: [PATCH 3/3] debug print

---
 .../std/time/time.clock/time.clock.steady/debug.pass.cpp  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
index 5121ca54071c4..a5a230a774f94 100644
--- a/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
+++ b/libcxx/test/std/time/time.clock/time.clock.steady/debug.pass.cpp
@@ -38,18 +38,18 @@ static LARGE_INTEGER __QueryPerformanceFrequency() {
   return val;
 }
 
-static steady_clock::time_point __libcpp_steady_clock_now() {
+static std::chrono::steady_clock::time_point __libcpp_steady_clock_now() {
   static const LARGE_INTEGER freq = __QueryPerformanceFrequency();
 
   LARGE_INTEGER counter;
   (void)QueryPerformanceCounter(&counter);
   auto seconds   = counter.QuadPart / freq.QuadPart;
   auto fractions = counter.QuadPart % freq.QuadPart;
-  auto dur       = seconds * nano::den + fractions * nano::den / freq.QuadPart;
+  auto dur       = seconds * std::nano::den + fractions * std::nano::den / freq.QuadPart;
   std::cerr << "counter.QuadPart: " << counter.QuadPart << ", freq.QuadPart: " << freq.QuadPart
-            << "\n seconds: " << seconds << ", fractions: " << fractions << "\n nano::den: " << nano::den
+            << "\n seconds: " << seconds << ", fractions: " << fractions << "\n nano::den: " << std::nano::den
             << ", dur: " << dur << std::endl;
-  return std::steady_clock::time_point(steady_clock::duration(dur));
+  return std::chrono::steady_clock::time_point(std::chrono::steady_clock::duration(dur));
 }
 
 int main(int, char**) {



More information about the libcxx-commits mailing list