From dbd16441b8b64da7d52e51daa79357e5abeb259a Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Fri, 13 Dec 2024 16:03:23 +0800 Subject: [PATCH 1/4] Reinforce gluten timer to support seconds/millseconds/microseconds --- cpp/core/utils/Timer.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cpp/core/utils/Timer.h b/cpp/core/utils/Timer.h index b6dec29b1a6a..40b5110599b8 100644 --- a/cpp/core/utils/Timer.h +++ b/cpp/core/utils/Timer.h @@ -19,11 +19,11 @@ #include -using TimePoint = std::chrono::time_point; - namespace gluten { +template class Timer { public: + using TimePoint = std::chrono::time_point; explicit Timer() = default; void start() { @@ -36,8 +36,7 @@ class Timer { return; } running_ = false; - realTimeUsed_ += - std::chrono::duration_cast(std::chrono::steady_clock::now() - startTime_).count(); + realTimeUsed_ += std::chrono::duration_cast(std::chrono::steady_clock::now() - startTime_).count(); } void reset() { @@ -62,6 +61,7 @@ class Timer { int64_t realTimeUsed_ = 0; }; +template class ScopedTimer { public: explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) { @@ -79,7 +79,7 @@ class ScopedTimer { } private: - Timer timer_{}; + Timer timer_{}; int64_t* toAdd_; void stopInternal() { @@ -92,4 +92,9 @@ class ScopedTimer { timer_.start(); } }; + +using ScopedSecondsTimer = ScopedTimer; +using ScopedMillisecondsTimer = ScopedTimer; +using ScopedMicrosecondsTimer = ScopedTimer; + } // namespace gluten From 99da8d04e79cba30ea1794982e1b5cb894b66e19 Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Fri, 13 Dec 2024 16:15:07 +0800 Subject: [PATCH 2/4] fix compile --- cpp/core/shuffle/Payload.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/core/shuffle/Payload.cc b/cpp/core/shuffle/Payload.cc index ddf4a409661e..52756c711dc4 100644 --- a/cpp/core/shuffle/Payload.cc +++ b/cpp/core/shuffle/Payload.cc @@ -300,7 +300,7 @@ arrow::Result>> BlockPayload::deseria uint32_t& numRows, int64_t& deserializeTime, int64_t& decompressTime) { - auto timer = std::make_unique(&deserializeTime); + Timer timer; static const std::vector> kEmptyBuffers{}; ARROW_ASSIGN_OR_RAISE(auto type, readType(inputStream)); if (type == 0) { @@ -310,7 +310,7 @@ arrow::Result>> BlockPayload::deseria RETURN_NOT_OK(inputStream->Read(sizeof(uint32_t), &numRows)); uint32_t numBuffers; RETURN_NOT_OK(inputStream->Read(sizeof(uint32_t), &numBuffers)); - timer.reset(); + deserializeTime += timer.realTimeUsed(); bool isCompressionEnabled = type == Type::kCompressed; std::vector> buffers; From 8ae70e5b93d724882b10e3c8660d8ab63820afc8 Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Sat, 14 Dec 2024 08:33:10 +0800 Subject: [PATCH 3/4] Revert "fix compile" This reverts commit 99da8d04e79cba30ea1794982e1b5cb894b66e19. --- cpp/core/shuffle/Payload.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/core/shuffle/Payload.cc b/cpp/core/shuffle/Payload.cc index 52756c711dc4..ddf4a409661e 100644 --- a/cpp/core/shuffle/Payload.cc +++ b/cpp/core/shuffle/Payload.cc @@ -300,7 +300,7 @@ arrow::Result>> BlockPayload::deseria uint32_t& numRows, int64_t& deserializeTime, int64_t& decompressTime) { - Timer timer; + auto timer = std::make_unique(&deserializeTime); static const std::vector> kEmptyBuffers{}; ARROW_ASSIGN_OR_RAISE(auto type, readType(inputStream)); if (type == 0) { @@ -310,7 +310,7 @@ arrow::Result>> BlockPayload::deseria RETURN_NOT_OK(inputStream->Read(sizeof(uint32_t), &numRows)); uint32_t numBuffers; RETURN_NOT_OK(inputStream->Read(sizeof(uint32_t), &numBuffers)); - deserializeTime += timer.realTimeUsed(); + timer.reset(); bool isCompressionEnabled = type == Type::kCompressed; std::vector> buffers; From d900ae8eeda7a3fbc4448030986902f76cbf3c60 Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Sat, 14 Dec 2024 08:34:02 +0800 Subject: [PATCH 4/4] fix --- cpp/core/utils/Timer.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cpp/core/utils/Timer.h b/cpp/core/utils/Timer.h index 40b5110599b8..4fe39068bb77 100644 --- a/cpp/core/utils/Timer.h +++ b/cpp/core/utils/Timer.h @@ -62,13 +62,13 @@ class Timer { }; template -class ScopedTimer { +class ScopedTimerImpl { public: - explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) { + explicit ScopedTimerImpl(int64_t* toAdd) : toAdd_(toAdd) { startInternal(); } - ~ScopedTimer() { + ~ScopedTimerImpl() { stopInternal(); } @@ -93,8 +93,9 @@ class ScopedTimer { } }; -using ScopedSecondsTimer = ScopedTimer; -using ScopedMillisecondsTimer = ScopedTimer; -using ScopedMicrosecondsTimer = ScopedTimer; +using ScopedTimer = ScopedTimerImpl; +using ScopedSecondsTimer = ScopedTimerImpl; +using ScopedMillisecondsTimer = ScopedTimerImpl; +using ScopedMicrosecondsTimer = ScopedTimerImpl; } // namespace gluten