diff options
Diffstat (limited to 'lld/Common/Timer.cpp')
-rw-r--r-- | lld/Common/Timer.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lld/Common/Timer.cpp b/lld/Common/Timer.cpp index 4b7d11003b2c..ea221fd86f3e 100644 --- a/lld/Common/Timer.cpp +++ b/lld/Common/Timer.cpp @@ -13,29 +13,22 @@ using namespace lld; using namespace llvm; -ScopedTimer::ScopedTimer(Timer &t) : t(&t) { t.start(); } +ScopedTimer::ScopedTimer(Timer &t) : t(&t) { + startTime = std::chrono::high_resolution_clock::now(); +} void ScopedTimer::stop() { if (!t) return; - t->stop(); + t->addToTotal(std::chrono::high_resolution_clock::now() - startTime); t = nullptr; } ScopedTimer::~ScopedTimer() { stop(); } -Timer::Timer(llvm::StringRef name) : name(name), parent(nullptr) {} -Timer::Timer(llvm::StringRef name, Timer &parent) - : name(name), parent(&parent) {} - -void Timer::start() { - if (parent && total.count() == 0) - parent->children.push_back(this); - startTime = std::chrono::high_resolution_clock::now(); -} - -void Timer::stop() { - total += (std::chrono::high_resolution_clock::now() - startTime); +Timer::Timer(llvm::StringRef name) : name(std::string(name)) {} +Timer::Timer(llvm::StringRef name, Timer &parent) : name(std::string(name)) { + parent.children.push_back(this); } Timer &Timer::root() { @@ -49,7 +42,8 @@ void Timer::print() { // We want to print the grand total under all the intermediate phases, so we // print all children first, then print the total under that. for (const auto &child : children) - child->print(1, totalDuration); + if (child->total > 0) + child->print(1, totalDuration); message(std::string(49, '-')); @@ -58,7 +52,7 @@ void Timer::print() { double Timer::millis() const { return std::chrono::duration_cast<std::chrono::duration<double, std::milli>>( - total) + std::chrono::nanoseconds(total)) .count(); } @@ -74,6 +68,7 @@ void Timer::print(int depth, double totalDuration, bool recurse) const { if (recurse) { for (const auto &child : children) - child->print(depth + 1, totalDuration); + if (child->total > 0) + child->print(depth + 1, totalDuration); } } |