-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtscplugin.h
More file actions
executable file
·76 lines (64 loc) · 1.62 KB
/
tscplugin.h
File metadata and controls
executable file
·76 lines (64 loc) · 1.62 KB
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
#ifndef tscplugin_h__
#define tscplugin_h__
#include <stdint.h>
#include <string.h>
#include <pthread.h>
#include <stdbool.h>
#define TSCCOMMON_SYMMAX 64
#define SHM_FILEMODE 00777
#define TSCCOMMON_TRACEMAX 1024
static inline uint64_t tscrecord_rdtsc(void)
{
union {
uint64_t tsc_64;
struct {
uint32_t lo_32;
uint32_t hi_32;
};
} tsc;
asm volatile("rdtsc" :
"=a" (tsc.lo_32),
"=d" (tsc.hi_32));
return tsc.tsc_64;
}
struct tracepoint_s
{
bool enable;
char name[TSCCOMMON_SYMMAX];
uint64_t runtime;
uint64_t cycle;
};
struct tracepoint_shm_s
{
struct tracepoint_s tracepoint[TSCCOMMON_TRACEMAX];
};
extern struct tracepoint_shm_s * traceshm;
extern pthread_mutex_t tscplugin_register_mutex;
static inline void __attribute__((always_inline))
TSCRECORD_REGISTER(unsigned int id, const char * name)
{
pthread_mutex_lock(&tscplugin_register_mutex);
if (!traceshm->tracepoint[id].enable)
{
strncpy(traceshm->tracepoint[id].name, name, TSCCOMMON_SYMMAX);
traceshm->tracepoint[id].enable = 1;
}
pthread_mutex_unlock(&tscplugin_register_mutex);
return;
}
static inline void __attribute__((always_inline))
TSCRECORD_START(unsigned int id, uint64_t * counter)
{
* counter = tscrecord_rdtsc();
return;
}
static inline void __attribute__((always_inline))
TSCRECORD_STOP(unsigned int id, uint64_t * counter)
{
uint64_t end = tscrecord_rdtsc();
uint64_t start = *counter;
__sync_fetch_and_add(&(traceshm->tracepoint[id].runtime), end - start);
__sync_fetch_and_add(&(traceshm->tracepoint[id].cycle), 1);
return;
}
#endif // tscplugin_h__