-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.h
74 lines (59 loc) · 1.93 KB
/
Debug.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
//------------------------------------------------------------------------------------------------
//
// Written by Lucky K.
//
//------------------------------------------------------------------------------------------------
#include <tchar.h>
#include <stdio.h>
#include <Windows.h>
#ifdef _DEBUG
#define DMESG( msg, ... ) Debug::Error( _T(msg), ##__VA_ARGS__ )
#define FNT( functionName ) Debug::FT asdfasdhyg8665gkhg8gh8gf( _T(functionName) )
#else
#define DMESG( msg, ... )
#define FNT( functionName )
#endif
namespace Debug
{
//------------------------------------------------------------------------------------------------
//
// Exposed Methods
//
//------------------------------------------------------------------------------------------------
bool Initialize();
void _cdecl Error( const TCHAR *str, ... );
void _cdecl TMSG( const TCHAR *str, ... );
void StartTime();
void StopTime();
//------------------------------------------------------------------------------------------------
//
// Exposed Types
//
//------------------------------------------------------------------------------------------------
static const int depthLimit = 5;
static int t = 0;
static const TCHAR tabs[] = _T("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
struct FT
{
LARGE_INTEGER timeStart;
LARGE_INTEGER timeStop;
LARGE_INTEGER timeFreq;
TCHAR strName[32];
FT( TCHAR *functionName )
{
_tcscpy( strName, functionName );
QueryPerformanceFrequency( &timeFreq );
QueryPerformanceCounter( &timeStart );
if ( t < depthLimit )
TMSG( _T("%.*s<%s t=\"%f\">\r\n"), t, tabs, strName, (float)timeStart.QuadPart / (float)timeFreq.QuadPart );
t++;
}
~FT()
{
QueryPerformanceCounter( &timeStop );
t--;
if ( t < depthLimit )
TMSG( _T("%.*s</%s>\r\n%.*s<%f/>\r\n"), t, tabs, strName, t, tabs, (float)(timeStop.QuadPart - timeStart.QuadPart) / (float)timeFreq.QuadPart );
}
};
}