MLIR  20.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
mlir::TimingManager Class Referenceabstract

This class represents facilities to measure execution time. More...

#include "mlir/Support/Timing.h"

+ Inheritance diagram for mlir::TimingManager:

Public Member Functions

 TimingManager ()
 
virtual ~TimingManager ()
 
Timer getRootTimer ()
 Get the root timer of this timing manager. More...
 
TimingScope getRootScope ()
 Get the root timer of this timing manager wrapped in a TimingScope for convenience. More...
 

Protected Member Functions

virtual std::optional< void * > rootTimer ()=0
 Return the root timer. More...
 
virtual void startTimer (void *handle)=0
 Start the timer with the given handle. More...
 
virtual void stopTimer (void *handle)=0
 Stop the timer with the given handle. More...
 
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. More...
 
virtual void hideTimer (void *handle)
 Hide the timer in timing reports and directly show its children. More...
 

Protected Attributes

const std::unique_ptr< detail::TimingManagerImplimpl
 

Friends

class Timer
 
class TimingIdentifier
 

Detailed Description

This class represents facilities to measure execution time.

Libraries and infrastructure code operate on opque Timer handles returned by various functions of this manager. Timers are started and stopped to demarcate regions in the code where execution time is of interest, and they can be nested to provide more detailed timing resolution. Calls to the timer start, stop, and nesting functions must be balanced. To facilitate this, users are encouraged to leverage the TimingScope RAII-style wrapper around Timers.

Users can provide their own implementation of TimingManager, or use the default DefaultTimingManager implementation in MLIR. Implementations override the various protected virtual functions to create, nest, start, and stop timers. A common pattern is for subclasses to provide a custom timer class and simply pass pointers to instances of this class around as the opaque timer handle. The manager itself can then forward callbacks to the this class. Alternatively, external timing libraries may return their own opaque handles for timing scopes.

For example:

void doWork(TimingManager &tm) {
auto root = tm.getRootScope();
{
auto scope = root.nest("First");
doSomeWork();
// <-- "First" timer stops here
}
auto scope = root.nest("Second");
doEvenMoreWork();
scope.stop(); // <-- "Second" timer stops here
// <-- Root timer stops here
}

Definition at line 113 of file Timing.h.

Constructor & Destructor Documentation

◆ TimingManager()

TimingManager::TimingManager ( )
explicit

Definition at line 63 of file Timing.cpp.

◆ ~TimingManager()

TimingManager::~TimingManager ( )
virtualdefault

Member Function Documentation

◆ getRootScope()

TimingScope TimingManager::getRootScope ( )

Get the root timer of this timing manager wrapped in a TimingScope for convenience.

Get the root timer of this timing manager wrapped in a TimingScope.

Automatically starts the timer and stops it as soon as the TimingScope is destroyed, e.g. when it goes out of scope.

Definition at line 74 of file Timing.cpp.

References getRootTimer().

Referenced by performActions().

◆ getRootTimer()

Timer TimingManager::getRootTimer ( )

Get the root timer of this timing manager.

The returned timer must be started and stopped manually. Execution time can be measured by nesting timers within this root timer and starting/stopping them as appropriate. Use this function only if you need access to the timer itself. Otherwise consider the more convenient getRootScope() which offers an RAII-style wrapper around the timer.

Definition at line 68 of file Timing.cpp.

References rootTimer(), and Timer.

Referenced by getRootScope().

◆ hideTimer()

virtual void mlir::TimingManager::hideTimer ( void *  handle)
inlineprotectedvirtual

Hide the timer in timing reports and directly show its children.

This is merely a hint that implementations are free to ignore.

Reimplemented in mlir::DefaultTimingManager.

Definition at line 162 of file Timing.h.

Referenced by mlir::Timer::hide().

◆ nestTimer()

virtual void* mlir::TimingManager::nestTimer ( void *  handle,
const void *  id,
function_ref< std::string()>  nameBuilder 
)
protectedpure virtual

Create a child timer nested within the one with the given handle.

The id parameter is used to uniquely identify the timer within its parent. Multiple calls to this function with the same handle and id should return the same timer, or at least cause the samples of the returned timers to be combined for the final timing results.

Implemented in mlir::DefaultTimingManager.

Referenced by mlir::Timer::nest().

◆ rootTimer()

virtual std::optional<void *> mlir::TimingManager::rootTimer ( )
protectedpure virtual

Return the root timer.

Implementations should return std::nullopt if the collection of timing samples is disabled. This will cause the timers constructed from the manager to be tombstones which can be skipped quickly.

Implemented in mlir::DefaultTimingManager.

Referenced by getRootTimer().

◆ startTimer()

virtual void mlir::TimingManager::startTimer ( void *  handle)
protectedpure virtual

Start the timer with the given handle.

Implemented in mlir::DefaultTimingManager.

Referenced by mlir::Timer::start().

◆ stopTimer()

virtual void mlir::TimingManager::stopTimer ( void *  handle)
protectedpure virtual

Stop the timer with the given handle.

Implemented in mlir::DefaultTimingManager.

Referenced by mlir::Timer::stop().

Friends And Related Function Documentation

◆ Timer

friend class Timer
friend

Definition at line 133 of file Timing.h.

Referenced by getRootTimer().

◆ TimingIdentifier

friend class TimingIdentifier
friend

Definition at line 168 of file Timing.h.

Member Data Documentation

◆ impl

const std::unique_ptr<detail::TimingManagerImpl> mlir::TimingManager::impl
protected

Definition at line 165 of file Timing.h.

Referenced by mlir::TimingIdentifier::get().


The documentation for this class was generated from the following files: