Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINOR] [VL] Enhance the gluten timer to support seconds, milliseconds, and microseconds #8231

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/core/shuffle/Payload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ arrow::Result<std::vector<std::shared_ptr<arrow::Buffer>>> BlockPayload::deseria
uint32_t& numRows,
int64_t& deserializeTime,
int64_t& decompressTime) {
auto timer = std::make_unique<ScopedTimer>(&deserializeTime);
Timer timer;
static const std::vector<std::shared_ptr<arrow::Buffer>> kEmptyBuffers{};
ARROW_ASSIGN_OR_RAISE(auto type, readType(inputStream));
if (type == 0) {
Expand All @@ -310,7 +310,7 @@ arrow::Result<std::vector<std::shared_ptr<arrow::Buffer>>> 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change? timer.start() and timer.stop() is not called. the realTimeUsed would be zero

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marin-ma Thanks, Um.. I've added this to fix the compile error with std::unique_ptr<ScopedTimer>. It was a typo. Now, I have fixed it in another way.


bool isCompressionEnabled = type == Type::kCompressed;
std::vector<std::shared_ptr<arrow::Buffer>> buffers;
Expand Down
15 changes: 10 additions & 5 deletions cpp/core/utils/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -62,6 +61,7 @@ class Timer {
int64_t realTimeUsed_ = 0;
};

template <typename T = std::chrono::nanoseconds>
class ScopedTimer {
public:
explicit ScopedTimer(int64_t* toAdd) : toAdd_(toAdd) {
Expand All @@ -79,7 +79,7 @@ class ScopedTimer {
}

private:
Timer timer_{};
Timer<T> timer_{};
int64_t* toAdd_;

void stopInternal() {
Expand All @@ -92,4 +92,9 @@ class ScopedTimer {
timer_.start();
}
};

using ScopedSecondsTimer = ScopedTimer<std::chrono::seconds>;
using ScopedMillisecondsTimer = ScopedTimer<std::chrono::milliseconds>;
using ScopedMicrosecondsTimer = ScopedTimer<std::chrono::microseconds>;

} // namespace gluten
Loading