summaryrefslogtreecommitdiff
path: root/engine/dt_instrumentation_server.h
blob: 3617ee2652e09382d4ea2becb21d21da7f4e1ae2 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef DATATABLE_INSTRUMENTATION_SERVER_H
#define DATATABLE_INSTRUMENTATION_SERVER_H
#ifdef _WIN32
#pragma once
#endif

#include "tier0/fasttimer.h"
#include "iservernetworkable.h"


class CDTISendTable;
class SendTable;


// Is instrumentation enabled?
extern bool g_bServerDTIEnabled;


// Types of things it times.
typedef enum
{
	SERVERDTI_CALCDELTA=0,
	SERVERDTI_ENCODE,
	SERVERDTI_SHOULDTRANSMIT,
	SERVERDTI_WRITE_DELTA_PROPS
} ServerDTITimerType;



// ------------------------------------------------------------------------------------------ // 
// Instrumentation functions.
// ------------------------------------------------------------------------------------------ // 

// This is called at startup to enable or disable instrumentation.
// If pFilename is null, no instrumentation is performed.
void ServerDTI_Init( char const *pFilename );

// This calls ServerDTI_Flush and cleans up.
void ServerDTI_Term();

// This writes out the instrumentation file.
void ServerDTI_Flush();

// Setup instrumentation on a CRecvDecoder.
CDTISendTable* ServerDTI_HookTable( SendTable *pTable );

void ServerDTI_AddEntityEncodeEvent( SendTable *pTable, float distToPlayer );

// Used to tell if the entity is using manual or auto mode.
void ServerDTI_RegisterNetworkStateChange( SendTable *pTable, bool bStateChanged );


// ------------------------------------------------------------------------------------------ // 
// Helper class to place timers easily.
// ------------------------------------------------------------------------------------------ // 

class CServerDTITimer
{
public:
				CServerDTITimer( const SendTable *pTable, ServerDTITimerType type );
				~CServerDTITimer();

private:

	const SendTable		*m_pTable;
	ServerDTITimerType	m_Type;
	CFastTimer			m_Timer;
};

inline CServerDTITimer::CServerDTITimer( const SendTable *pTable, ServerDTITimerType type )
{
	if ( g_bServerDTIEnabled )
	{
		m_pTable = pTable;
		m_Type = type;
		m_Timer.Start();
	}
}

inline CServerDTITimer::~CServerDTITimer()
{
	if ( g_bServerDTIEnabled && m_pTable )
	{
		m_Timer.End();
		extern void _ServerDTI_HookTimer( const SendTable *pTable, ServerDTITimerType timerType, CCycleCount const &count );
		_ServerDTI_HookTimer( m_pTable, m_Type, m_Timer.GetDuration() );
	}
}

inline void ServerDTI_RegisterNetworkStateChange( SendTable *pTable, bool bStateChanged )
{
	if ( g_bServerDTIEnabled )
	{
		extern void _ServerDTI_RegisterNetworkStateChange( SendTable *pTable, bool bStateChanged );
		_ServerDTI_RegisterNetworkStateChange( pTable, bStateChanged );
	}
}

#endif // DATATABLE_INSTRUMENTATION_SERVER_H