VR-Vantage 2.7 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TracyScoped.hpp
Go to the documentation of this file.
1 #ifndef __TRACYSCOPED_HPP__
2 #define __TRACYSCOPED_HPP__
3 
4 #include <limits>
5 #include <stdint.h>
6 #include <string.h>
7 
8 #include "../common/TracySystem.hpp"
9 #include "../common/TracyAlign.hpp"
10 #include "../common/TracyAlloc.hpp"
11 #include "TracyProfiler.hpp"
12 
13 namespace tracy
14 {
15 
17 {
18 public:
19  tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
20 #ifdef TRACY_ON_DEMAND
21  : m_active( is_active && GetProfiler().IsConnected() )
22 #else
23  : m_active( is_active )
24 #endif
25  {
26  if( !m_active ) return;
27 #ifdef TRACY_ON_DEMAND
28  m_connectionId = GetProfiler().ConnectionId();
29 #endif
30  TracyLfqPrepare( QueueType::ZoneBegin );
31  MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
32  MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
34  }
35 
36  tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
37 #ifdef TRACY_ON_DEMAND
38  : m_active( is_active && GetProfiler().IsConnected() )
39 #else
40  : m_active( is_active )
41 #endif
42  {
43  if( !m_active ) return;
44 #ifdef TRACY_ON_DEMAND
45  m_connectionId = GetProfiler().ConnectionId();
46 #endif
47  TracyLfqPrepare( QueueType::ZoneBeginCallstack );
48  MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
49  MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
51 
52  GetProfiler().SendCallstack( depth );
53  }
54 
55  tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, bool is_active = true )
56 #ifdef TRACY_ON_DEMAND
57  : m_active( is_active && GetProfiler().IsConnected() )
58 #else
59  : m_active( is_active )
60 #endif
61  {
62  if( !m_active ) return;
63 #ifdef TRACY_ON_DEMAND
64  m_connectionId = GetProfiler().ConnectionId();
65 #endif
66  TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLoc );
67  const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
68  MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
69  MemWrite( &item->zoneBegin.srcloc, srcloc );
71  }
72 
73  tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, int depth, bool is_active = true )
74 #ifdef TRACY_ON_DEMAND
75  : m_active( is_active && GetProfiler().IsConnected() )
76 #else
77  : m_active( is_active )
78 #endif
79  {
80  if( !m_active ) return;
81 #ifdef TRACY_ON_DEMAND
82  m_connectionId = GetProfiler().ConnectionId();
83 #endif
84  TracyLfqPrepare( QueueType::ZoneBeginAllocSrcLocCallstack );
85  const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
86  MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
87  MemWrite( &item->zoneBegin.srcloc, srcloc );
89 
90  GetProfiler().SendCallstack( depth );
91  }
92 
94  {
95  if( !m_active ) return;
96 #ifdef TRACY_ON_DEMAND
97  if( GetProfiler().ConnectionId() != m_connectionId ) return;
98 #endif
99  TracyLfqPrepare( QueueType::ZoneEnd );
100  MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
102  }
103 
104  tracy_force_inline void Text( const char* txt, size_t size )
105  {
106  assert( size < std::numeric_limits<uint16_t>::max() );
107  if( !m_active ) return;
108 #ifdef TRACY_ON_DEMAND
109  if( GetProfiler().ConnectionId() != m_connectionId ) return;
110 #endif
111  auto ptr = (char*)tracy_malloc( size );
112  memcpy( ptr, txt, size );
114  MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
115  MemWrite( &item->zoneTextFat.size, (uint16_t)size );
117  }
118 
119  tracy_force_inline void Name( const char* txt, size_t size )
120  {
121  assert( size < std::numeric_limits<uint16_t>::max() );
122  if( !m_active ) return;
123 #ifdef TRACY_ON_DEMAND
124  if( GetProfiler().ConnectionId() != m_connectionId ) return;
125 #endif
126  auto ptr = (char*)tracy_malloc( size );
127  memcpy( ptr, txt, size );
129  MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
130  MemWrite( &item->zoneTextFat.size, (uint16_t)size );
132  }
133 
135  {
136  if( !m_active ) return;
137 #ifdef TRACY_ON_DEMAND
138  if( GetProfiler().ConnectionId() != m_connectionId ) return;
139 #endif
141  MemWrite( &item->zoneValue.value, value );
143  }
144 
145 private:
146  const bool m_active;
147 
148 #ifdef TRACY_ON_DEMAND
149  uint64_t m_connectionId;
150 #endif
151 };
152 
153 }
154 
155 #endif


Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)