-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPUTimer.h
77 lines (65 loc) · 981 Bytes
/
GPUTimer.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
#pragma once
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <vector>
#include <epoxy/gl.h>
class GPUTimer
{
public:
GPUTimer()
{
glGenQueries(1, &m_query);
}
~GPUTimer()
{
glDeleteQueries(1, &m_query);
}
void BeginTimer()
{
glBeginQuery(GL_TIME_ELAPSED, m_query);
}
void EndTimer()
{
glEndQuery(GL_TIME_ELAPSED);
}
uint64_t GetTime()
{
uint64_t res = 0;
glGetQueryObjectui64v(m_query, GL_QUERY_RESULT, &res);
return res;
}
static int64_t GetTimestamp()
{
int64_t res = 0;
glGetInteger64v(GL_TIMESTAMP, &res);
return res;
}
private:
GLuint m_query;
};
class CPUTimer
{
public:
CPUTimer()
{
}
void Start()
{
start = GetTime();
}
uint64_t End()
{
end = GetTime();
return end - start;
}
static uint64_t GetTime()
{
struct timespec t;
(void)clock_gettime(CLOCK_MONOTONIC, &t);
return ((uint64_t)(t.tv_sec * 1000000 + t.tv_nsec / 1000));
}
private:
uint64_t start, end;
};