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

Manages call trace recording for visualization in Web Tracing Framework (WTF) format. More...

#include "calltracemanager.h"

Inheritance diagram for ion::profile::CallTraceManager:
Collaboration diagram for ion::profile::CallTraceManager:

Public Types

enum  EventArgType {
  kArgNone,
  kArgNumeric,
  kArgString
}
 Defines argument types for WTF events. More...
 
enum  BuiltinEventType {
  kDefineEvent = 1,
  kCreateZoneEvent = 3,
  kDeleteZoneEvent = 4,
  kSetZoneEvent = 5,
  kScopeLeaveEvent = 8,
  kScopeAppendDataEvent = 9,
  kMarkEvent = 10,
  kTimeStampEvent = 11,
  kTimeRangeStartEvent = 12,
  kTimeRangeEndEvent = 13,
  kFrameStartEvent = 14,
  kFrameEndEvent = 15,
  kCustomScopeEvent = 100
}
 Defines the built-in WTF events that we use. More...
 
enum  NamedTraceRecorderType {
  kRecorderGpu = 0,
  kRecorderVSync,
  kNumNamedTraceRecorders
}
 Defines name trace recorders. More...
 
typedef
base::AllocUnorderedMap< const
void *, uint32 > 
ScopeEventMap
 Custom scope event mapping from name (as a pointer to a literal string) to uint32 id. More...
 
typedef
base::AllocUnorderedMap
< uint32, const char * > 
ReverseScopeEventMap
 Reversed mapping from custom scope event id to name. More...
 
typedef base::AllocVector
< TraceRecorder * > 
TraceList
 List of TraceRecorders, one created for each thread of execution. More...
 

Public Member Functions

 CallTraceManager ()
 
 CallTraceManager (size_t buffer_size)
 Construct using the specified trace capacity in bytes. More...
 
 ~CallTraceManager () override
 
TraceRecorderGetTraceRecorder ()
 Gets the TraceRecorder instance specific to the current thread. More...
 
TraceRecorderGetNamedTraceRecorder (NamedTraceRecorderType name)
 Gets the TraceRecorder instance specific to the current thread of the given name. More...
 
const TraceListGetAllTraceRecorders () const
 Gets the list of all trace recorders for all threads. More...
 
int GetScopeEnterEvent (const char *string_id)
 Queries the event id of a scope enter event, based on string_id. More...
 
const char * GetScopeEnterEventName (uint32 event_id) const
 Returns the name of the scope enter event with the given id. More...
 
size_t GetNumScopeEvents () const
 Returns the number of unique custom scope events recorded. More...
 
std::string SnapshotCallTraces () const
 Returns a snapshot of traces to a string in binary .wtf-trace format. More...
 
virtual uint32 GetTimeInUs () const
 Returns the time in microseconds, relative to the timebase. More...
 
uint64 GetTimeInNs () const
 Returns the time in nanoseconds, relative to the timebase. More...
 
void WriteFile (const std::string &filename) const
 Writes the current WTF trace to a file, which usually ends in the extension ".wtf-trace". More...
 
Timeline BuildTimeline () const
 Convert the current WTF trace into a timeline. More...
 
void RegisterTimelineMetric (std::unique_ptr< TimelineMetric > metric)
 Registers a timeline metric. More...
 
analytics::Benchmark RunTimelineMetrics () const
 Runs all registered metrics on the current timeline and returns a benchmark object containing the collected statistics. 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 int GetNumArgsForEvent (uint32 event_id)
 Gets the number of arguments for a particular event. More...
 
static EventArgType GetArgType (uint32 event_id, int arg_index)
 Gets the argument types for a particular event. More...
 

Detailed Description

Manages call trace recording for visualization in Web Tracing Framework (WTF) format.

This class maintains a separate recording buffer for each thread.

Definition at line 44 of file calltracemanager.h.

Member Typedef Documentation

Reversed mapping from custom scope event id to name.

Definition at line 102 of file calltracemanager.h.

Custom scope event mapping from name (as a pointer to a literal string) to uint32 id.

Note we explicitly cast the pointer to const void* since we do want to hash the pointer instead of the string; std::hash<const char*> would return error here.

Definition at line 99 of file calltracemanager.h.

List of TraceRecorders, one created for each thread of execution.

Definition at line 105 of file calltracemanager.h.

Member Enumeration Documentation

Defines the built-in WTF events that we use.

Enumerator
kDefineEvent 

The event for defining new WTF events, both custom and built-in events.

kCreateZoneEvent 

Events for managing zones.

kDeleteZoneEvent 
kSetZoneEvent 
kScopeLeaveEvent 

Leaving the current scope.

kScopeAppendDataEvent 

Attaching data to the current scope.

kMarkEvent 

Mark events.

kTimeStampEvent 

TimeStamp events.

kTimeRangeStartEvent 

Time range start and end events.

kTimeRangeEndEvent 
kFrameStartEvent 

The frame start and end events.

kFrameEndEvent 
kCustomScopeEvent 

The starting offset for scope event ids, purposefully set high to make room for built-in WTF events.

Definition at line 54 of file calltracemanager.h.

Defines argument types for WTF events.

Enumerator
kArgNone 
kArgNumeric 
kArgString 

Definition at line 47 of file calltracemanager.h.

Defines name trace recorders.

Enumerator
kRecorderGpu 
kRecorderVSync 
kNumNamedTraceRecorders 

Definition at line 89 of file calltracemanager.h.

Constructor & Destructor Documentation

ion::profile::CallTraceManager::CallTraceManager ( )

Definition at line 238 of file calltracemanager.cc.

ion::profile::CallTraceManager::CallTraceManager ( size_t  buffer_size)
explicit

Construct using the specified trace capacity in bytes.

Definition at line 247 of file calltracemanager.cc.

ion::profile::CallTraceManager::~CallTraceManager ( )
override

Member Function Documentation

Timeline ion::profile::CallTraceManager::BuildTimeline ( ) const
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
const TraceList& ion::profile::CallTraceManager::GetAllTraceRecorders ( ) const
inline

Gets the list of all trace recorders for all threads.

Definition at line 123 of file calltracemanager.h.

CallTraceManager::EventArgType ion::profile::CallTraceManager::GetArgType ( uint32  event_id,
int  arg_index 
)
static

Gets the argument types for a particular event.

Definition at line 351 of file calltracemanager.cc.

References CHECK, kArgNone, kArgNumeric, kArgString, and kCustomScopeEvent.

Referenced by ion::profile::TraceRecorder::DumpTrace().

TraceRecorder * ion::profile::CallTraceManager::GetNamedTraceRecorder ( NamedTraceRecorderType  name)

Gets the TraceRecorder instance specific to the current thread of the given name.

These are used for non-CPU-thread tracing such as for GPU events.

Definition at line 282 of file calltracemanager.cc.

References DCHECK, ion::base::ThreadLocalObject< T >::Get(), kNumNamedTraceRecorders, kRecorderGpu, kRecorderVSync, LOG, name, ion::profile::TraceRecorder::SetThreadName(), and ion::port::WARNING.

Referenced by ion::gfxprofile::GpuProfiler::PollGlTimerQueries().

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().

int ion::profile::CallTraceManager::GetNumArgsForEvent ( uint32  event_id)
static

Gets the number of arguments for a particular event.

Definition at line 339 of file calltracemanager.cc.

References kCustomScopeEvent.

Referenced by ion::profile::TraceRecorder::AddTraceToTimelineNode(), ion::profile::TraceRecorder::DumpTrace(), and ion::profile::TraceRecorder::GetNumTraces().

size_t ion::profile::CallTraceManager::GetNumScopeEvents ( ) const
inline

Returns the number of unique custom scope events recorded.

Definition at line 139 of file calltracemanager.h.

Referenced by GetScopeEnterEvent().

int ion::profile::CallTraceManager::GetScopeEnterEvent ( const char *  string_id)

Queries the event id of a scope enter event, based on string_id.

Only raw string literals are allowed for the string_id argument.

Definition at line 319 of file calltracemanager.cc.

References GetNumScopeEvents(), and kCustomScopeEvent.

const char * ion::profile::CallTraceManager::GetScopeEnterEventName ( uint32  event_id) const

Returns the name of the scope enter event with the given id.

Definition at line 335 of file calltracemanager.cc.

uint64 ion::profile::CallTraceManager::GetTimeInNs ( ) const
inline

Returns the time in nanoseconds, relative to the timebase.

The timebase is the time when this CallTraceManager instance was created, expressed in nanoseconds since the epoch.

Definition at line 157 of file calltracemanager.h.

References ion::port::Timer::Get().

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

virtual uint32 ion::profile::CallTraceManager::GetTimeInUs ( ) const
inlinevirtual
TraceRecorder * ion::profile::CallTraceManager::GetTraceRecorder ( )

Gets the TraceRecorder instance specific to the current thread.

Definition at line 271 of file calltracemanager.cc.

References ion::port::GetThreadLocalStorage().

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.

void ion::profile::CallTraceManager::RegisterTimelineMetric ( std::unique_ptr< TimelineMetric metric)
inline

Registers a timeline metric.

Definition at line 171 of file calltracemanager.h.

analytics::Benchmark ion::profile::CallTraceManager::RunTimelineMetrics ( ) const

Runs all registered metrics on the current timeline and returns a benchmark object containing the collected statistics.

Definition at line 646 of file calltracemanager.cc.

References BuildTimeline().

Referenced by ~CallTraceManager().

std::string ion::profile::CallTraceManager::SnapshotCallTraces ( ) const
void ion::profile::CallTraceManager::WriteFile ( const std::string &  filename) const

Writes the current WTF trace to a file, which usually ends in the extension ".wtf-trace".

Definition at line 619 of file calltracemanager.cc.

References ion::port::INFO, LOG, SnapshotCallTraces(), and ion::port::WARNING.


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