forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvprof_telemetry.h
148 lines (126 loc) · 4.19 KB
/
vprof_telemetry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Real-Time Hierarchical Telemetry Profiling
//
// $NoKeywords: $
//=============================================================================//
#ifndef VPROF_TELEMETRY_H
#define VPROF_TELEMETRY_H
#if !defined( MAKE_VPC )
#if !defined( RAD_TELEMETRY_DISABLED ) && ( defined( IS_WINDOWS_PC ) || defined( _LINUX ) )
// Rad Telemetry profiling is enabled on Win32 and Win64.
#define RAD_TELEMETRY_ENABLED
#endif
#endif // !MAKE_VPC
#if !defined( RAD_TELEMETRY_ENABLED )
//
// Kill all tmZone() macros, etc.
//
#include "tmapi_dummy.h"
inline void TelemetryTick() {}
inline void TelemetrySetLevel( unsigned int Level ) {}
#define TelemetrySetLockName( _ctx, _location, _description )
class CTelemetryLock
{
public:
CTelemetryLock(void *plocation, const char *description) {}
~CTelemetryLock() {}
void Locked() {}
void Unlocked() {}
};
class CTelemetrySpikeDetector
{
public:
CTelemetrySpikeDetector( const char *msg, uint32 threshold = 50 ) {}
~CTelemetrySpikeDetector() { }
};
#else
//
// Telemetry is enabled. Include the telemetry header.
//
#include "../../thirdparty/telemetry/include/telemetry.h"
// Different versions of radbase.h define RADCOPYRIGHT to different values. So undef that here.
#undef RADCOPYRIGHT
struct TelemetryData
{
HTELEMETRY tmContext[32];
float flRDTSCToMilliSeconds; // Conversion from tmFastTime() (rdtsc) to milliseconds.
uint32 FrameCount; // Count of frames to capture before turning off.
char ServerAddress[128]; // Server name to connect to.
int playbacktick; // GetPlaybackTick() value from demo file (or 0 if not playing a demo).
uint32 DemoTickStart; // Start telemetry on demo tick #
uint32 DemoTickEnd; // End telemetry on demo tick #
uint32 Level; // Current Telemetry level (Use TelemetrySetLevel to modify)
};
PLATFORM_INTERFACE TelemetryData g_Telemetry;
PLATFORM_INTERFACE void TelemetryTick();
PLATFORM_INTERFACE void TelemetrySetLevel( unsigned int Level );
#define TELEMETRY_LEVEL0 g_Telemetry.tmContext[0] // high level tmZone()
#define TELEMETRY_LEVEL1 g_Telemetry.tmContext[1] // lower level tmZone(), tmZoneFiltered()
#define TELEMETRY_LEVEL2 g_Telemetry.tmContext[2] // VPROF_0
#define TELEMETRY_LEVEL3 g_Telemetry.tmContext[3] // VPROF_1
#define TELEMETRY_LEVEL4 g_Telemetry.tmContext[4] // VPROF_2
#define TELEMETRY_LEVEL5 g_Telemetry.tmContext[5] // VPROF_3
#define TELEMETRY_LEVEL6 g_Telemetry.tmContext[6] // VPROF_4
#define TelemetrySetLockName( _ctx, _location, _description ) \
do \
{ \
static bool s_bNameSet = false; \
if( _ctx && !s_bNameSet ) \
{ \
tmLockName( _ctx, _location, _description ); \
s_bNameSet = true; \
} \
} while( 0 )
class CTelemetryLock
{
public:
CTelemetryLock(void *plocation, const char *description)
{
m_plocation = (const char *)plocation;
m_description = description;
TelemetrySetLockName( TELEMETRY_LEVEL1, m_plocation, m_description );
tmTryLock( TELEMETRY_LEVEL1, m_plocation, "%s", m_description );
}
~CTelemetryLock()
{
Unlocked();
}
void Locked()
{
tmEndTryLock( TELEMETRY_LEVEL1, m_plocation, TMLR_SUCCESS );
tmSetLockState( TELEMETRY_LEVEL1, m_plocation, TMLS_LOCKED, "%s Locked", m_description );
}
void Unlocked()
{
if( m_plocation )
{
tmSetLockState( TELEMETRY_LEVEL1, m_plocation, TMLS_RELEASED, "%s Released", m_description );
m_plocation = NULL;
}
}
public:
const char *m_plocation;
const char *m_description;
};
class CTelemetrySpikeDetector
{
public:
// Spews Telemetry message when threshold hit (in milliseconds.)
CTelemetrySpikeDetector( const char *msg, float threshold = 5 ) :
m_message( msg ), m_threshold( threshold ), time0( tmFastTime() ) {}
~CTelemetrySpikeDetector()
{
float time = ( tmFastTime() - time0 ) * g_Telemetry.flRDTSCToMilliSeconds;
if( time >= m_threshold )
{
tmMessage( TELEMETRY_LEVEL0, TMMF_ICON_NOTE | TMMF_SEVERITY_WARNING, "(source/spike)%s %.2fms %t", m_message, time, tmSendCallStack( TELEMETRY_LEVEL0, 0 ) );
}
}
private:
TmU64 time0;
float m_threshold;
const char *m_message;
};
#endif // RAD_TELEMETRY_ENABLED
#endif // VPROF_TELEMETRY_H