SLProject 4.0.000
Instrumentor Class Reference

Basic instrumentation profiler for Google Chrome tracing format. More...

#include <Instrumentor.h>

Public Member Functions

 Instrumentor ()
 
void beginSession (const std::string &name, const bool storeInMemory=false, const std::string &filePath="Profiling-Results.json")
 
void endSession ()
 
void addProfile (const ProfileResult &result)
 
void writeProfile (const ProfileResult &result)
 
void writeHeader ()
 
void writeFooter ()
 
std::string filePath ()
 

Static Public Member Functions

static Instrumentorget ()
 

Private Attributes

InstrumentationSession_currentSession
 
std::string _filePath
 
std::ofstream _outputStream
 
int _profileCount
 
std::mutex _mutex
 
bool _storeInMemory = false
 
std::vector< ProfileResult_profileResults
 

Detailed Description

Basic instrumentation profiler for Google Chrome tracing format.

Usage: include this header file somewhere in your code. In your most outer function (e.g. main) you have to begin profiling session with: Instrumentor::get().beginSession("Session Name"); If you pass storeInMemory=true the profileResults will be stored in memory instead of being written into the file stream which is pretty slow. Of course the in memory storage can quickly use a lot of memory depending how fine grained your profiling is. In app-Demo-SLProject this is done in SLInterface::slCreateAppAndScene.

In between you can add either PROFILE_FUNCTION(); at the beginning of any routine or PROFILE_SCOPE(scopeName) at the beginning of any scope you want to measure.

At the end of your most outer function (e.g. main) you end the session with: Instrumentor::get().endSession();

After the endSession you can drag the Profiling-Results.json file into the chrome://tracing page of the Google Chrome browser. In app-Demo-SLProject this is done in SLInterface::slTerminate.

Constructor & Destructor Documentation

◆ Instrumentor()

Instrumentor::Instrumentor ( )
inline

Member Function Documentation

◆ addProfile()

void Instrumentor::addProfile ( const ProfileResult result)
inline

addProfile should be as fast as possible for not influencing the profiling by the profiler itself. In addition it must be thread safe.

◆ beginSession()

void Instrumentor::beginSession ( const std::string &  name,
const bool  storeInMemory = false,
const std::string &  filePath = "Profiling-Results.json" 
)
inline

◆ endSession()

void Instrumentor::endSession ( )
inline

◆ filePath()

std::string Instrumentor::filePath ( )
inline

◆ get()

static Instrumentor & Instrumentor::get ( )
inlinestatic

◆ writeFooter()

void Instrumentor::writeFooter ( )
inline

◆ writeHeader()

void Instrumentor::writeHeader ( )
inline

◆ writeProfile()

void Instrumentor::writeProfile ( const ProfileResult result)
inline

Member Data Documentation

◆ _currentSession

InstrumentationSession* Instrumentor::_currentSession
private

◆ _filePath

std::string Instrumentor::_filePath
private

◆ _mutex

std::mutex Instrumentor::_mutex
private

◆ _outputStream

std::ofstream Instrumentor::_outputStream
private

◆ _profileCount

int Instrumentor::_profileCount
private

◆ _profileResults

std::vector<ProfileResult> Instrumentor::_profileResults
private

◆ _storeInMemory

bool Instrumentor::_storeInMemory = false
private

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