X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FTimer.h;h=a7418827ca3239cfe2564188c090b1bb3637c84e;hb=5df15c692b944b6c46ec6d532fc286b7e0000d5d;hp=59bab1d4741b775f1e93db51b787b32c0cb25108;hpb=9fa0eff30a0d4fcbc84ac3ada4c47620b5449043;p=oota-llvm.git diff --git a/include/llvm/Support/Timer.h b/include/llvm/Support/Timer.h index 59bab1d4741..a7418827ca3 100644 --- a/include/llvm/Support/Timer.h +++ b/include/llvm/Support/Timer.h @@ -15,7 +15,9 @@ #ifndef LLVM_SUPPORT_TIMER_H #define LLVM_SUPPORT_TIMER_H -#include "llvm/System/DataTypes.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/DataTypes.h" +#include "llvm/ADT/StringRef.h" #include #include #include @@ -85,9 +87,11 @@ class Timer { std::string Name; // The name of this time variable. bool Started; // Has this time variable ever been started? TimerGroup *TG; // The TimerGroup this Timer is in. + + Timer **Prev, *Next; // Doubly linked list of timers in the group. public: - explicit Timer(const std::string &N) : TG(0) { init(N); } - Timer(const std::string &N, TimerGroup &tg) : TG(0) { init(N, tg); } + explicit Timer(StringRef N) : TG(0) { init(N); } + Timer(StringRef N, TimerGroup &tg) : TG(0) { init(N, tg); } Timer(const Timer &RHS) : TG(0) { assert(RHS.TG == 0 && "Can only copy uninitialized timers"); } @@ -99,8 +103,8 @@ public: // Create an uninitialized timer, client must use 'init'. explicit Timer() : TG(0) {} - void init(const std::string &N); - void init(const std::string &N, TimerGroup &tg); + void init(StringRef N); + void init(StringRef N, TimerGroup &tg); const std::string &getName() const { return Name; } bool isInitialized() const { return TG != 0; } @@ -127,18 +131,16 @@ private: /// class TimeRegion { Timer *T; - TimeRegion(const TimeRegion &); // DO NOT IMPLEMENT + TimeRegion(const TimeRegion &) LLVM_DELETED_FUNCTION; public: explicit TimeRegion(Timer &t) : T(&t) { T->startTimer(); } explicit TimeRegion(Timer *t) : T(t) { - if (T) - T->startTimer(); + if (T) T->startTimer(); } ~TimeRegion() { - if (T) - T->stopTimer(); + if (T) T->stopTimer(); } }; @@ -149,9 +151,10 @@ public: /// is primarily used for debugging and for hunting performance problems. /// struct NamedRegionTimer : public TimeRegion { - explicit NamedRegionTimer(const std::string &Name); - explicit NamedRegionTimer(const std::string &Name, - const std::string &GroupName); + explicit NamedRegionTimer(StringRef Name, + bool Enabled = true); + explicit NamedRegionTimer(StringRef Name, StringRef GroupName, + bool Enabled = true); }; @@ -162,24 +165,29 @@ struct NamedRegionTimer : public TimeRegion { /// class TimerGroup { std::string Name; - unsigned NumTimers; + Timer *FirstTimer; // First timer in the group. std::vector > TimersToPrint; + + TimerGroup **Prev, *Next; // Doubly linked list of TimerGroup's. + TimerGroup(const TimerGroup &TG) LLVM_DELETED_FUNCTION; + void operator=(const TimerGroup &TG) LLVM_DELETED_FUNCTION; public: - explicit TimerGroup(const std::string &name) : Name(name), NumTimers(0) {} - explicit TimerGroup() : NumTimers(0) {} + explicit TimerGroup(StringRef name); + ~TimerGroup(); + + void setName(StringRef name) { Name.assign(name.begin(), name.end()); } + + /// print - Print any started timers in this group and zero them. + void print(raw_ostream &OS); - void setName(const std::string &name) { Name = name; } + /// printAll - This static method prints all timers and clears them all out. + static void printAll(raw_ostream &OS); - ~TimerGroup() { - assert(NumTimers == 0 && - "TimerGroup destroyed before all contained timers!"); - } - private: friend class Timer; - void addTimer(); - void removeTimer(); - void addTimerToPrint(const TimeRecord &T, const std::string &Name); + void addTimer(Timer &T); + void removeTimer(Timer &T); + void PrintQueuedTimers(raw_ostream &OS); }; } // End llvm namespace