You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by ma...@apache.org on 2024/12/17 01:14:32 UTC

(incubator-gluten) branch main updated: [MINOR] [VL] Enhance the gluten timer to support seconds, milliseconds, and microseconds (#8231)

This is an automated email from the ASF dual-hosted git repository.

marong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 059854575b [MINOR] [VL] Enhance the gluten timer to support seconds, milliseconds, and microseconds (#8231)
059854575b is described below

commit 059854575bafd34a03bf422b4c93c31b2a814f7a
Author: zhaokuo <zh...@163.com>
AuthorDate: Tue Dec 17 09:14:28 2024 +0800

    [MINOR] [VL] Enhance the gluten timer to support seconds, milliseconds, and microseconds (#8231)
---
 cpp/core/utils/Timer.h | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/cpp/core/utils/Timer.h b/cpp/core/utils/Timer.h
index b6dec29b1a..4fe39068bb 100644
--- a/cpp/core/utils/Timer.h
+++ b/cpp/core/utils/Timer.h
@@ -19,11 +19,11 @@
 
 #include <chrono>
 
-using TimePoint = std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds>;
-
 namespace gluten {
+template <typename T = std::chrono::nanoseconds>
 class Timer {
  public:
+  using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
   explicit Timer() = default;
 
   void start() {
@@ -36,8 +36,7 @@ class Timer {
       return;
     }
     running_ = false;
-    realTimeUsed_ +=
-        std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - startTime_).count();
+    realTimeUsed_ += std::chrono::duration_cast<T>(std::chrono::steady_clock::now() - startTime_).count();
   }
 
   void reset() {
@@ -62,13 +61,14 @@ class Timer {
   int64_t realTimeUsed_ = 0;
 };
 
-class ScopedTimer {
+template <typename T = std::chrono::nanoseconds>
+class ScopedTimerImpl {
  public:
-  explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) {
+  explicit ScopedTimerImpl(int64_t* toAdd) : toAdd_(toAdd) {
     startInternal();
   }
 
-  ~ScopedTimer() {
+  ~ScopedTimerImpl() {
     stopInternal();
   }
 
@@ -79,7 +79,7 @@ class ScopedTimer {
   }
 
  private:
-  Timer timer_{};
+  Timer<T> timer_{};
   int64_t* toAdd_;
 
   void stopInternal() {
@@ -92,4 +92,10 @@ class ScopedTimer {
     timer_.start();
   }
 };
+
+using ScopedTimer = ScopedTimerImpl<std::chrono::nanoseconds>;
+using ScopedSecondsTimer = ScopedTimerImpl<std::chrono::seconds>;
+using ScopedMillisecondsTimer = ScopedTimerImpl<std::chrono::milliseconds>;
+using ScopedMicrosecondsTimer = ScopedTimerImpl<std::chrono::microseconds>;
+
 } // namespace gluten


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org