timeUtil.cpp
Go to the documentation of this file.
1 #include <fstream>
2 #include "hrpsys/util/Hrpsys.h"
3 #include "timeUtil.h"
4 #include <stdint.h>
5 
6 
8 {
9 #ifdef _WIN32
10  LARGE_INTEGER t;
11  QueryPerformanceCounter(&t);
12  return t.QuadPart;
13 #elif defined(__ARM_ARCH_7A__)
14  uint32_t r = 0;
15  asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) );
16  return r;
17 #elif defined(__AARCH64EL__)
18  uint64_t b;
19  asm volatile( "mrs %0, pmccntr_el0" : "=r"(b) :: "memory" );
20  return b;
21 #else
22  unsigned int l=0,h=0;
23  __asm__ __volatile__("rdtsc" : "=a" (l), "=d" (h));
24  return (unsigned long long)h<<32|l;
25 #endif
26 }
27 
29 {
30  static double freq = -1;
31  if (freq != -1) return freq;
32 #ifdef _WIN32
33  LARGE_INTEGER li;
34  QueryPerformanceFrequency(&li);
35  freq = (double)li.QuadPart;
36 #else
37 # ifdef __QNX__
38  freq = SYSPAGE_ENTRY( qtime )->cycles_per_sec;
39 # else
40  std::ifstream ifs("/proc/cpuinfo");
41  std::string token;
42  while(!ifs.eof()){
43  ifs >> token;
44  if (token == "cpu"){
45  ifs >> token;
46  if (token == "MHz"){
47  ifs >> token;
48  ifs >> freq;
49  freq *= 1e6;
50  break;
51  }
52  }
53  }
54  ifs.close();
55 # endif
56 #endif
57  return freq;
58 }
unsigned long long tick_t
double get_cpu_frequency()
get CPU frequency
Definition: timeUtil.cpp:28
ifs
JHUFF_TBL long freq[]
t
tick_t get_tick()
get time stamp counter
Definition: timeUtil.cpp:7


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51