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"
47 using EntryType = llvm::StringMapEntry<llvm::EmptyStringSetTag>;
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; }
212 tm->startTimer(handle);
219 tm->stopTimer(handle);
232 return tm ?
Timer(*tm, tm->nestTimer(handle,
id, nameBuilder)) :
Timer();
249 tm->hideTimer(handle);
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);
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;
478std::unique_ptr<OutputStrategy>
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.
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.
DefaultTimingManager & operator=(const DefaultTimingManager &rhs)=delete
void hideTimer(void *handle) override
Hide the timer in timing reports and directly show its children.
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.
void stop()
Stop the timer.
friend class TimingManager
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 & operator=(Timer &&other)
Timer(const Timer &other)=default
This class represesents a uniqued string owned by a TimingManager.
StringRef strref() const
Return a StringRef for the string.
std::string str() const
Return an std::string.
const void * getAsOpaquePointer() const
Return the opaque pointer that corresponds to this identifier.
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.
virtual std::optional< void * > rootTimer()=0
Return the root timer.
TimingScope getRootScope()
Get the root timer of this timing manager wrapped in a TimingScope for convenience.
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.
friend class TimingIdentifier
virtual void startTimer(void *handle)=0
Start the timer with the given handle.
Timer getRootTimer()
Get the root timer of this timing manager.
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=(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 & operator=(TimingScope &&other)
TimingScope(const Timer &other)
Implementation details of the DefaultTimingManager.
Private implementation details of the TimingManager.
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...
std::unique_ptr< OutputStrategy > createOutputStrategy(DefaultTimingManager::OutputFormat fmt, raw_ostream &os)
Create an output strategy for the specified format, to be passed to DefaultTimingManager::setOutput()...
llvm::function_ref< Fn > function_ref
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)