WSF
profiling::ProfilingRegion Class Reference

Scope guard that marks a region of code for profiling. More...

#include <ProfilingRegion.hpp>

Public Member Functions

 ProfilingRegion (const char aRegionLabel[])
 Begin a profiling region.
 ~ProfilingRegion ()
 End the current profiling region.
 ProfilingRegion ()=delete
 ProfilingRegion (const ProfilingRegion &)=delete
ProfilingRegionoperator= (const ProfilingRegion &)=delete
 ProfilingRegion (ProfilingRegion &&)=delete
ProfilingRegionoperator= (ProfilingRegion &&)=delete

Detailed Description

Scope guard that marks a region of code for profiling.

This class' constructor begins the profiling region. Its destructor ends the profiling region.

Profiling regions must be nested. This implies that ProfilingRegion instances should never be handled by pointer or passed as arguments to functions.

Always name the variable representing the ProfilingRegion instance. Don't just invoke the constructor without giving the variable a name. If you forget to name the variable, then the region will close right away, since the unnamed temporary object's destructor will be invoked at the end of the statement.

Exactly one ProfilingSystem instance must exist before constructing or destroying a ProfilingRegion instance. That is, the lifetime of any ProfilingRegion must fit within the lifetime of exactly one ProfilingSystem instance.

Warning
Do NOT use this at main scope! Always make sure the region is closed before main returns.
ProfilingRegion should only be used by one thread at a time. It's safe to have thread parallelism happening inside of a ProfilingRegion, but it's not safe to have multiple threads creating ProfilingRegion instances concurrently.

Here is an example of how to use this class in a function, assuming that the function is only ever called within the lifetime of a ProfilingSystem object.

void InnerFunction() {
ProfilingRegion r("name of my choice");
ComputeStuff();
}
void MiddleFunction() {
ProfilingRegion r2("another name of my choice");
ComputeOtherStuff();
for(int i = 0; i < 3; ++i) {
InnerFunction();
}
ComputeEvenMoreStuff();
}
void OuterFunction() {
ComputeSomething();
MiddleFunction();
MiddleFunction();
ComputeSomeMoreStuff();
}
Scope guard that marks a region of code for profiling.
Definition ProfilingRegion.hpp:97
ProfilingRegion(const char aRegionLabel[])
Begin a profiling region.
Definition ProfilingRegion.cpp:26

This results in the following nested regions:

  1. First instance of "another name of my choice" region, containing:
    1. First instance of "name of my choice" region
    2. Second instance of "name of my choice" region
    3. Third instance of "name of my choice" region
  2. Second instance of "another name of my choice" region, containing:
    1. Fourth instance of "name of my choice" region
    2. Fifth instance of "name of my choice" region
    3. Sixth instance of "name of my choice" region

Constructor & Destructor Documentation

◆ ProfilingRegion() [1/4]

profiling::ProfilingRegion::ProfilingRegion ( const char aRegionLabel[])

Begin a profiling region.

Parameters
aRegionLabelString label for the region

References profiling::detail::GetGlobalProfilingHooks(), and profiling::ProfilingHooks::mBeginRegion.

Referenced by operator=(), operator=(), ProfilingRegion(), and ProfilingRegion().

◆ ~ProfilingRegion()

profiling::ProfilingRegion::~ProfilingRegion ( )

End the current profiling region.

References profiling::detail::GetGlobalProfilingHooks(), and profiling::ProfilingHooks::mEndRegion.

◆ ProfilingRegion() [2/4]

profiling::ProfilingRegion::ProfilingRegion ( )
delete

◆ ProfilingRegion() [3/4]

profiling::ProfilingRegion::ProfilingRegion ( const ProfilingRegion & )
delete

References ProfilingRegion().

◆ ProfilingRegion() [4/4]

profiling::ProfilingRegion::ProfilingRegion ( ProfilingRegion && )
delete

References ProfilingRegion().

Member Function Documentation

◆ operator=() [1/2]

ProfilingRegion & profiling::ProfilingRegion::operator= ( const ProfilingRegion & )
delete

References ProfilingRegion().

◆ operator=() [2/2]

ProfilingRegion & profiling::ProfilingRegion::operator= ( ProfilingRegion && )
delete

References ProfilingRegion().


The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved