Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::profile::TraceRecorder Class Reference

Class for recording frame events. More...

#include "tracerecorder.h"

Inheritance diagram for ion::profile::TraceRecorder:
Collaboration diagram for ion::profile::TraceRecorder:

Classes

struct  TraceHeader
 

Public Types

typedef base::CircularBuffer
< uint32 > 
TraceBuffer
 
typedef std::unordered_map
< uint32, std::string > 
IndexToStringMap
 

Public Member Functions

 TraceRecorder (CallTraceManager *manager)
 
 TraceRecorder (CallTraceManager *manager, size_t buffer_size)
 Explicitly specify the capacity of this recorder in bytes. More...
 
void EnterScope (int event_id)
 Queries and records the event corresponding to the provided event_id. More...
 
void AnnotateCurrentScope (const std::string &name, const std::string &value)
 Attaches data to the current scope, which will be visible on mouse-over. More...
 
void LeaveScope ()
 Leaves the current (most recent) scope. More...
 
void EnterScopeAtTime (uint32 timestamp, int event_id)
 Same as EnterScope, but with specified timestamp. More...
 
void AnnotateCurrentScopeAtTime (uint32 timestamp, const std::string &name, const std::string &value)
 Same as AnnotateCurrentScope, but with specified timestamp. More...
 
void LeaveScopeAtTime (uint32 timestamp)
 Same as LeaveScope, but with specified timestamp. More...
 
void EnterFrame (uint32 frame_number)
 Records a frame enter event with a specified frame index. More...
 
void LeaveFrame ()
 Records a frame exit event for the current frame index. More...
 
void EnterTimeRange (uint32 unique_id, const char *name, const char *value)
 Records the start of a time range event. More...
 
uint32 EnterTimeRange (const char *name, const char *value)
 Records the start of a time range event. More...
 
void LeaveTimeRange (uint32 id)
 Records the end of a time range event for the specified unique id. More...
 
void CreateTimeStamp (const char *name, const char *value)
 Records a timeStamp event. More...
 
void CreateTimeStampAtTime (uint32 timestamp, const char *name, const char *value)
 Same as CreateTimeStamp, but with specified timestamp. More...
 
size_t GetNumTraces () const
 Returns the total number of recorded trace events. More...
 
const ion::port::ThreadIdGetThreadId () const
 Returns the ID of the thread that this recorder is tracing. More...
 
void SetThreadName (const std::string &name)
 Sets a name for the thread that this recorder is tracing. More...
 
std::string GetThreadName () const
 Returns the name for the thread that this recorder is tracing. More...
 
void DumpStrings (std::vector< std::string > *table) const
 Dumps the strings one by one to a string table. More...
 
void DumpTrace (std::string *output, uint32 string_index_offset) const
 Appends a binary dump of the trace to the output string. More...
 
void AddTraceToTimelineNode (TimelineNode *root) const
 Adds all events in the trace as a sub-tree under the passed in root node. More...
 
uint32 GetCurrentFrameNumber () const
 Returns the frame number of the current frame scope, or 0 (and a warning message) if TraceRecorder is not in a frame scope. More...
 
bool IsInFrameScope () const
 Returns if the TraceRecorder is currently in a frame scope. More...
 
const AllocatorPtr & GetAllocator () const
 Returns the Allocator that was used for the instance. More...
 
const AllocatorPtr & GetNonNullAllocator () const
 Return our allocator, or the default allocator if the instance was declared on the stack. More...
 
const AllocatorPtr & GetAllocatorForLifetime (AllocationLifetime lifetime) const
 Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More...
 
void * operator new (size_t size)
 The standard no-parameter new operator uses the default Allocator. More...
 
void * operator new (size_t size, AllocationLifetime lifetime)
 This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator)
 This overloaded version of the new operator takes the Allocator to use directly as a parameter. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator, void *ptr)
 Special operator new for using placement new with Allocatables. More...
 
void * operator new (size_t size, void *ptr)
 The placement new operator is defined conventionally. More...
 
void operator delete (void *ptr)
 Define the delete operator to use specialized functions dealing with an Allocator. More...
 
void operator delete (void *ptr, AllocationLifetime lifetime)
 Windows requires these (or it issues C4291 warnings). More...
 
void operator delete (void *ptr, const AllocatorPtr &allocator)
 
void operator delete (void *ptr, void *ptr2)
 The placement delete operator does nothing, as usual. More...
 

Static Public Member Functions

static size_t GetDefaultBufferSize ()
 Manipulate the default buffer size in bytes used for future instantiations. More...
 
static void SetDefaultBufferSize (size_t s)
 
static bool GetReserveBuffer ()
 Maniupulate whether or not to reserve the full buffer size immediately for future instantiations. More...
 
static void SetReserveBuffer (bool reserve)
 

Detailed Description

Class for recording frame events.

This class tracks events based on pointers to raw string literals. It hashes the pointer value of the literal to a unique frame event id to keep track of events.

Definition at line 42 of file tracerecorder.h.

Member Typedef Documentation

typedef std::unordered_map<uint32, std::string> ion::profile::TraceRecorder::IndexToStringMap

Definition at line 52 of file tracerecorder.h.

Constructor & Destructor Documentation

ion::profile::TraceRecorder::TraceRecorder ( CallTraceManager manager)
explicit

Definition at line 61 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem().

ion::profile::TraceRecorder::TraceRecorder ( CallTraceManager manager,
size_t  buffer_size 
)

Explicitly specify the capacity of this recorder in bytes.

Definition at line 74 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem().

Member Function Documentation

void ion::profile::TraceRecorder::AnnotateCurrentScope ( const std::string &  name,
const std::string &  value 
)

Attaches data to the current scope, which will be visible on mouse-over.

The string value must be in JSON format, e.g. "\"my_string"" for a string value, "18" for the integer value 18, "{ "name": "my_name", "count": 17 }" for an object with two key value pairs.

Note
value must not be a string representation of NaN or infinity, because these values are not supported by JSON.

Definition at line 90 of file tracerecorder.cc.

References AnnotateCurrentScopeAtTime(), ion::profile::CallTraceManager::GetTimeInUs(), name, and value.

void ion::profile::TraceRecorder::AnnotateCurrentScopeAtTime ( uint32  timestamp,
const std::string &  name,
const std::string &  value 
)
void ion::profile::TraceRecorder::CreateTimeStamp ( const char *  name,
const char *  value 
)

Records a timeStamp event.

Definition at line 204 of file tracerecorder.cc.

References CreateTimeStampAtTime(), ion::profile::CallTraceManager::GetTimeInUs(), name, and value.

void ion::profile::TraceRecorder::CreateTimeStampAtTime ( uint32  timestamp,
const char *  name,
const char *  value 
)
void ion::profile::TraceRecorder::DumpStrings ( std::vector< std::string > *  table) const

Dumps the strings one by one to a string table.

Definition at line 254 of file tracerecorder.cc.

References DCHECK_LT.

Referenced by ion::profile::CallTraceManager::SnapshotCallTraces().

void ion::profile::TraceRecorder::DumpTrace ( std::string *  output,
uint32  string_index_offset 
) const
void ion::profile::TraceRecorder::EnterFrame ( uint32  frame_number)
void ion::profile::TraceRecorder::EnterScope ( int  event_id)

Queries and records the event corresponding to the provided event_id.

Definition at line 86 of file tracerecorder.cc.

References EnterScopeAtTime(), and ion::profile::CallTraceManager::GetTimeInUs().

Referenced by ion::profile::ScopedTracer::ScopedTracer().

void ion::profile::TraceRecorder::EnterScopeAtTime ( uint32  timestamp,
int  event_id 
)

Same as EnterScope, but with specified timestamp.

Definition at line 99 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem().

Referenced by EnterScope(), and ion::gfxprofile::GpuProfiler::PollGlTimerQueries().

void ion::profile::TraceRecorder::EnterTimeRange ( uint32  unique_id,
const char *  name,
const char *  value 
)

Records the start of a time range event.

The event is uniquely specified by some 32-bit integer id, with a given name and optional string value in JSON format. The name must be given, but the value is optional and can be NULL.

Definition at line 160 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem(), DCHECK, ion::profile::CallTraceManager::GetTimeInUs(), ion::profile::CallTraceManager::kTimeRangeStartEvent, and ion::base::TrimEndWhitespace().

uint32 ion::profile::TraceRecorder::EnterTimeRange ( const char *  name,
const char *  value 
)

Records the start of a time range event.

This method will automatically assign and return a unique uint32 "id" used to identify the time range event. Note the name must be given; however the parameter string value (JSON format) is an optional value and can be NULL.

Definition at line 177 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem(), DCHECK, ion::profile::CallTraceManager::GetTimeInUs(), ion::profile::CallTraceManager::kTimeRangeStartEvent, and ion::base::TrimEndWhitespace().

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
inlineinherited

Returns the Allocator that was used for the instance.

This will be NULL if the instance was declared on the stack or created with normal placement new.

Definition at line 68 of file allocatable.h.

References allocator_.

Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
uint32 ion::profile::TraceRecorder::GetCurrentFrameNumber ( ) const

Returns the frame number of the current frame scope, or 0 (and a warning message) if TraceRecorder is not in a frame scope.

Definition at line 427 of file tracerecorder.cc.

References IsInFrameScope(), LOG_ONCE, and ion::port::WARNING.

static size_t ion::profile::TraceRecorder::GetDefaultBufferSize ( )
inlinestatic

Manipulate the default buffer size in bytes used for future instantiations.

Definition at line 60 of file tracerecorder.h.

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
inlineinherited

Return our allocator, or the default allocator if the instance was declared on the stack.

Definition at line 72 of file allocatable.h.

References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().

size_t ion::profile::TraceRecorder::GetNumTraces ( ) const

Returns the total number of recorded trace events.

Note
this is SLOW, it goes through a linear scan of the trace buffer.

Definition at line 224 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::GetItem(), ion::profile::CallTraceManager::GetNumArgsForEvent(), ion::base::CircularBuffer< T >::GetSize(), and length.

static bool ion::profile::TraceRecorder::GetReserveBuffer ( )
inlinestatic

Maniupulate whether or not to reserve the full buffer size immediately for future instantiations.

Definition at line 65 of file tracerecorder.h.

const ion::port::ThreadId& ion::profile::TraceRecorder::GetThreadId ( ) const
inline

Returns the ID of the thread that this recorder is tracing.

Definition at line 128 of file tracerecorder.h.

Referenced by ion::profile::CallTraceManager::BuildTimeline().

std::string ion::profile::TraceRecorder::GetThreadName ( ) const
inline

Returns the name for the thread that this recorder is tracing.

The name is "UnnamedThread" unless it has been set by a call to SetThreadName.

Definition at line 135 of file tracerecorder.h.

Referenced by ion::profile::CallTraceManager::BuildTimeline().

bool ion::profile::TraceRecorder::IsInFrameScope ( ) const
inline

Returns if the TraceRecorder is currently in a frame scope.

Definition at line 151 of file tracerecorder.h.

Referenced by GetCurrentFrameNumber(), and LeaveFrame().

void ion::profile::TraceRecorder::LeaveFrame ( )
void ion::profile::TraceRecorder::LeaveScope ( )

Leaves the current (most recent) scope.

Scope events must be strictly nested.

Definition at line 95 of file tracerecorder.cc.

References ion::profile::CallTraceManager::GetTimeInUs(), and LeaveScopeAtTime().

Referenced by ion::profile::ScopedTracer::~ScopedTracer().

void ion::profile::TraceRecorder::LeaveScopeAtTime ( uint32  timestamp)

Same as LeaveScope, but with specified timestamp.

Definition at line 124 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem(), DCHECK_GT, and ion::profile::CallTraceManager::kScopeLeaveEvent.

Referenced by LeaveScope(), and ion::gfxprofile::GpuProfiler::PollGlTimerQueries().

void ion::profile::TraceRecorder::LeaveTimeRange ( uint32  id)

Records the end of a time range event for the specified unique id.

Definition at line 198 of file tracerecorder.cc.

References ion::base::CircularBuffer< T >::AddItem(), ion::profile::CallTraceManager::GetTimeInUs(), and ion::profile::CallTraceManager::kTimeRangeEndEvent.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
inlineinherited

This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.

Definition at line 88 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
inlineinherited

This overloaded version of the new operator takes the Allocator to use directly as a parameter.

If the Allocator pointer is NULL, this uses the default Allocator.

Definition at line 95 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

static void ion::profile::TraceRecorder::SetDefaultBufferSize ( size_t  s)
inlinestatic

Definition at line 61 of file tracerecorder.h.

static void ion::profile::TraceRecorder::SetReserveBuffer ( bool  reserve)
inlinestatic

Definition at line 66 of file tracerecorder.h.

void ion::profile::TraceRecorder::SetThreadName ( const std::string &  name)
inline

Sets a name for the thread that this recorder is tracing.

Definition at line 131 of file tracerecorder.h.

References name.

Referenced by ion::profile::CallTraceManager::GetNamedTraceRecorder().


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