-
Notifications
You must be signed in to change notification settings - Fork 334
/
FooHook.h
53 lines (44 loc) · 917 Bytes
/
FooHook.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
#pragma once
#include "utils/Header.h"
#include "iOssAttr.h"
//inline void OssAttrInc(int iKey, int iID, int iCnt)
//{
//
//}
inline uint64_t _GetTickCount()
{
register uint32_t lo, hi;
register uint64_t o;
__asm__ __volatile__("rdtscp" : "=a"(lo), "=d"(hi) :: "%rcx");
o = hi;
o <<= 32;
return (o | lo);
}
inline uint64_t getCpuKhz()
{
FILE* fp = fopen("/proc/cpuinfo", "r");
if (!fp)
return 1;
char buf[4096] = {0};
fread(buf, 1, sizeof(buf), fp);
fclose(fp);
char* lp = strstr(buf, "cpu MHz");
if (!lp)
return 1;
lp += strlen("cpu MHz");
while (*lp == ' ' || *lp == '\t' || *lp == ':')
{
++lp;
}
double mhz = atof(lp);
uint64_t u = (uint64_t)(mhz * 1000);
return u;
}
inline uint64_t _GetCpuHz()
{
static uint64_t u = getCpuKhz() * 1000;
return u;
}
inline void SetRoutineID(uint32_t iID)
{
}