NeoPZ
PerfUtil
cycle_timer.h
Go to the documentation of this file.
1
#ifndef CYCLE_TIMER_H
2
3
#include<string.h>
4
5
extern
"C"
{
6
__inline__ uint64_t
rdtsc
(
void
) {
7
uint32_t lo, hi;
8
__asm__ __volatile__ (
// serialize
9
"xorl %%eax,%%eax \n cpuid"
10
:::
"%rax"
,
"%rbx"
,
"%rcx"
,
"%rdx"
);
11
/* We cannot use "=A", since this would use %rax on x86_64 and
12
return only the lower 32bits of the TSC */
13
__asm__ __volatile__ (
"rdtsc"
:
"=a"
(lo),
"=d"
(hi));
14
return
(uint64_t) hi << 32 | lo;
15
}
16
}
17
18
class
CycleTimer
19
{
20
public
:
21
CycleTimer
() {};
22
23
void
start
() {
24
cycles
=
rdtsc
();
25
}
26
27
uint64_t
stop
() {
28
uint64_t aux =
rdtsc
();
29
cycles
=
cycles
- aux;
30
return
cycles
;
31
}
32
33
uint64_t
getCycles
() {
return
cycles
;}
34
35
uint64_t
getUnits
() {
return
cycles
;}
36
37
std::string
getTime
() {
38
std::string str =
uint64_to_string
(
cycles
);
39
str +=
" cycles"
;
40
return
str;
41
}
42
43
private
:
44
45
uint64_t
cycles
;
46
47
std::string
uint64_to_string
(uint64_t value ) {
48
std::ostringstream os;
49
os << value;
50
return
os.str();
51
}
52
53
};
54
55
#endif
CycleTimer::uint64_to_string
std::string uint64_to_string(uint64_t value)
Definition:
cycle_timer.h:47
rdtsc
__inline__ uint64_t rdtsc(void)
Definition:
cycle_timer.h:6
CycleTimer::getTime
std::string getTime()
Definition:
cycle_timer.h:37
CycleTimer::CycleTimer
CycleTimer()
Definition:
cycle_timer.h:21
CycleTimer::stop
uint64_t stop()
Definition:
cycle_timer.h:27
CycleTimer::getCycles
uint64_t getCycles()
Definition:
cycle_timer.h:33
CycleTimer
Definition:
cycle_timer.h:18
CycleTimer::getUnits
uint64_t getUnits()
Definition:
cycle_timer.h:35
CycleTimer::start
void start()
Definition:
cycle_timer.h:23
CycleTimer::cycles
uint64_t cycles
Definition:
cycle_timer.h:45
Generated on Sun Aug 16 2020 11:17:08 for NeoPZ by
1.8.13