13 #ifndef MLIR_SUPPORT_TIMING_H
14 #define MLIR_SUPPORT_TIMING_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringMapEntry.h"
19 #include "llvm/Support/raw_ostream.h"
27 class DefaultTimingManager;
29 class TimingManagerImpl;
30 class DefaultTimingManagerImpl;
47 using EntryType = llvm::StringMapEntry<std::nullopt_t>;
57 StringRef
strref()
const {
return entry->first(); }
64 return static_cast<const void *
>(entry);
68 const EntryType *entry;
165 const std::unique_ptr<detail::TimingManagerImpl>
impl;
192 other.handle =
nullptr;
197 handle = other.handle;
199 other.handle =
nullptr;
206 explicit operator bool()
const {
return tm !=
nullptr; }
263 void *handle =
nullptr;
288 timer = std::move(other.timer);
293 explicit operator bool()
const {
return bool(timer); }
310 template <
typename... Args>
312 return TimingScope(std::move(timer.
nest(std::forward<Args>(args)...)));
361 bool lastEntry =
false) = 0;
431 void setOutput(std::unique_ptr<OutputStrategy> output);
443 void dumpTimers(raw_ostream &os = llvm::errs());
447 void dumpAsList(raw_ostream &os = llvm::errs());
451 void dumpAsTree(raw_ostream &os = llvm::errs());
455 std::optional<void *>
rootTimer()
override;
458 void *
nestTimer(
void *handle,
const void *
id,
463 const std::unique_ptr<detail::DefaultTimingManagerImpl>
impl;
464 std::unique_ptr<OutputStrategy> out;
Facilities for time measurement and report printing to an output stream.
void setDisplayMode(DisplayMode displayMode)
Change the display mode.
void stopTimer(void *handle) override
Stop the timer with the given handle.
std::optional< void * > rootTimer() override
Return the root timer.
DisplayMode
The different display modes for printing the timers.
@ Tree
In this mode the results are displayed in a tree view, with child timers nested under their parents.
@ List
In this mode the results are displayed in a list sorted by total time, with timers aggregated into on...
void setOutput(std::unique_ptr< OutputStrategy > output)
Change the stream where the output will be printed to.
void dumpTimers(raw_ostream &os=llvm::errs())
Debug print the timer data structures to an output stream.
void * nestTimer(void *handle, const void *id, function_ref< std::string()> nameBuilder) override
Create a child timer nested within the one with the given handle.
void startTimer(void *handle) override
Start the timer with the given handle.
DefaultTimingManager & operator=(const DefaultTimingManager &rhs)=delete
DisplayMode getDisplayMode() const
Return the current display mode;.
void dumpAsList(raw_ostream &os=llvm::errs())
Debug print the timers as a list.
void dumpAsTree(raw_ostream &os=llvm::errs())
Debug print the timers as a tree.
DefaultTimingManager(DefaultTimingManager &&rhs)
void clear()
Clear the timing results.
~DefaultTimingManager() override
void print()
Print and clear the timing results.
void setEnabled(bool enabled)
Enable or disable execution time sampling.
OutputFormat
The different output formats for printing the timers.
@ Text
In this format the results are displayed in text format.
@ Json
In this format the results are displayed in JSON format.
DefaultTimingManager(const DefaultTimingManager &rhs)=delete
bool isEnabled() const
Return whether execution time sampling is enabled.
void hideTimer(void *handle) override
Hide the timer in timing reports and directly show its children.
Facilities for printing timing reports to various output formats.
virtual void printListEntry(StringRef name, const TimeRecord &time, const TimeRecord &total, bool lastEntry=false)=0
virtual void printFooter()=0
OutputStrategy(raw_ostream &os)
virtual ~OutputStrategy()=default
virtual void printTime(const TimeRecord &time, const TimeRecord &total)=0
virtual void printTreeEntryEnd(unsigned indent, bool lastEntry=false)=0
virtual void printHeader(const TimeRecord &total)=0
virtual void printTreeEntry(unsigned indent, StringRef name, const TimeRecord &time, const TimeRecord &total)=0
A handle for a timer in a TimingManager.
Timer(TimingManager &tm, void *handle)
Timer nest(TimingIdentifier name)
See above.
void hide()
Hide the timer in timing reports and directly show its children.
Timer & operator=(Timer &&other)
void stop()
Stop the timer.
Timer nest(StringRef name)
See above.
void start()
Start the timer.
Timer nest(const void *id, function_ref< std::string()> nameBuilder)
Create a child timer nested within this one.
Timer(const Timer &other)=default
This class represesents a uniqued string owned by a TimingManager.
const void * getAsOpaquePointer() const
Return the opaque pointer that corresponds to this identifier.
StringRef strref() const
Return a StringRef for the string.
std::string str() const
Return an std::string.
TimingIdentifier(const TimingIdentifier &)=default
TimingIdentifier & operator=(const TimingIdentifier &other)=default
static TimingIdentifier get(StringRef str, TimingManager &tm)
Return an identifier for the specified string.
This class represents facilities to measure execution time.
virtual void hideTimer(void *handle)
Hide the timer in timing reports and directly show its children.
TimingScope getRootScope()
Get the root timer of this timing manager wrapped in a TimingScope for convenience.
virtual void startTimer(void *handle)=0
Start the timer with the given handle.
const std::unique_ptr< detail::TimingManagerImpl > impl
virtual std::optional< void * > rootTimer()=0
Return the root timer.
Timer getRootTimer()
Get the root timer of this timing manager.
virtual void * nestTimer(void *handle, const void *id, function_ref< std::string()> nameBuilder)=0
Create a child timer nested within the one with the given handle.
virtual void stopTimer(void *handle)=0
Stop the timer with the given handle.
An RAII-style wrapper around a timer that ensures the timer is properly started and stopped.
TimingScope & operator=(TimingScope &&other)
TimingScope & operator=(const TimingScope &)=delete
TimingScope nest(Args... args)
Create a nested timing scope.
TimingScope(const TimingScope &)=delete
void hide()
Hide the timer in timing reports and directly show its children.
void stop()
Manually stop the timer early.
TimingScope(TimingScope &&other)
TimingScope(Timer &&other)
TimingScope(const Timer &other)
Include the generated interface declarations.
void registerDefaultTimingManagerCLOptions()
Register a set of useful command-line options that can be used to configure a DefaultTimingManager.
void applyDefaultTimingManagerCLOptions(DefaultTimingManager &tm)
Apply any values that were registered with 'registerDefaultTimingManagerOptions' to a DefaultTimingMa...
Simple record class to record timing information.
TimeRecord & operator-=(const TimeRecord &other)
TimeRecord & operator+=(const TimeRecord &other)
TimeRecord(double wall=0.0, double user=0.0)