-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreformanceSampler.h
81 lines (66 loc) · 1.76 KB
/
PreformanceSampler.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
/* ======== Basic Admin tool ========
* Copyright (C) 2004-2007 Erling K. Sæterdal
* No warranties of any kind
*
*
* Author(s): Erling K. Sæterdal ( EKS )
* ============================ */
#ifndef _INCLUDE_PREFORMANCESAMLER
#define _INCLUDE_PREFORMANCESAMLER
#define MAX_SAMPLENAME_LEN 40
#define MAX_SAMPLEITEMS 25
#ifdef WIN32
#define PREFORMANCE_SAMPLER 1
#else
#define __int64 long
#define ULONG_MAX 45000
typedef struct
{
long HighPart;
long LowPart;
}LARGE_INTEGER;
#define PREFORMANCE_SAMPLER 0
#endif
struct stPreSample
{
long long TotalTime;
long long LongestTime;
long long ShortestTime;
long CalledTimes;
char Name[MAX_SAMPLENAME_LEN];
};
class PreformanceSampler
{
public:
PreformanceSampler();
~PreformanceSampler();
public:
static int AddPreformaceName(const char *NameOfTimer);
static void SampleStart(int SamplerIndex);
static void SampleEnd(int SamplerIndex);
static void WriteLogFile(const char *FileName);
private:
static long long GetSeconds(__int64 Time);
static long long GetMiliseconds(__int64 Time);
static const char *GetTimeInformationString(__int64 Time);
};
#if PREFORMANCE_SAMPLER == 1
#define PreSamplerStart(SampleName) \
static int iSampleIndex = -1; \
if(iSampleIndex == -1) \
iSampleIndex = PreformanceSampler::AddPreformaceName(SampleName); \
\
PreformanceSampler::SampleStart(iSampleIndex);
#define PreSamplerEnd(SampleName) \
PreformanceSampler::SampleEnd(iSampleIndex);
#define QPF(Sample) \
QueryPerformanceFrequency(Sample);
#define QPC(Sample) \
QueryPerformanceCounter(Sample);
#else
#define PreSamplerStart(SampleIndex)
#define PreSamplerEnd(SampleName)
#define QPF(Sample)
#define QPC(Sample)
#endif
#endif // _INCLUDE_PREFORMANCESAMLER