Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:41

0001 //===- Timer.h ----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLD_COMMON_TIMER_H
0010 #define LLD_COMMON_TIMER_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include <assert.h>
0015 #include <atomic>
0016 #include <chrono>
0017 #include <map>
0018 #include <memory>
0019 #include <vector>
0020 
0021 namespace lld {
0022 
0023 class Timer;
0024 
0025 struct ScopedTimer {
0026   explicit ScopedTimer(Timer &t);
0027 
0028   ~ScopedTimer();
0029 
0030   void stop();
0031 
0032   std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
0033 
0034   Timer *t = nullptr;
0035 };
0036 
0037 class Timer {
0038 public:
0039   Timer(llvm::StringRef name, Timer &parent);
0040 
0041   // Creates the root timer.
0042   explicit Timer(llvm::StringRef name);
0043 
0044   void addToTotal(std::chrono::nanoseconds time) { total += time.count(); }
0045   void print();
0046 
0047   double millis() const;
0048 
0049 private:
0050   void print(int depth, double totalDuration, bool recurse = true) const;
0051 
0052   std::atomic<std::chrono::nanoseconds::rep> total;
0053   std::vector<Timer *> children;
0054   std::string name;
0055 };
0056 
0057 } // namespace lld
0058 
0059 #endif