timeUtil.cpp
Go to the documentation of this file.
00001 #include <fstream>
00002 #include "hrpsys/util/Hrpsys.h"
00003 #include "timeUtil.h"
00004 #include <stdint.h>
00005 
00006 
00007 tick_t get_tick()
00008 {
00009 #ifdef _WIN32
00010     LARGE_INTEGER t;
00011     QueryPerformanceCounter(&t);
00012     return t.QuadPart;
00013 #elif defined(__ARM_ARCH_7A__)
00014     uint32_t r = 0;
00015     asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) );
00016     return r;
00017 #elif defined(__AARCH64EL__)
00018     uint64_t b;
00019     asm volatile( "mrs %0, pmccntr_el0" : "=r"(b) :: "memory" );
00020     return b;
00021 #else
00022     unsigned int l=0,h=0;
00023     __asm__ __volatile__("rdtsc" : "=a" (l), "=d" (h));
00024     return (unsigned long long)h<<32|l;
00025 #endif
00026 }
00027 
00028 double get_cpu_frequency()
00029 {
00030     static double freq = -1;
00031     if (freq != -1) return freq;
00032 #ifdef _WIN32
00033     LARGE_INTEGER li;
00034     QueryPerformanceFrequency(&li);
00035     freq = (double)li.QuadPart;
00036 #else
00037 # ifdef __QNX__
00038     freq = SYSPAGE_ENTRY( qtime )->cycles_per_sec;
00039 # else
00040     std::ifstream ifs("/proc/cpuinfo");
00041     std::string token;
00042     while(!ifs.eof()){
00043         ifs >> token;
00044         if (token == "cpu"){
00045             ifs >> token;
00046             if (token == "MHz"){
00047                 ifs >> token;
00048                 ifs >> freq;
00049                 freq *= 1e6;
00050                 break;
00051             }
00052         }
00053     }
00054     ifs.close();
00055 # endif
00056 #endif
00057     return freq;
00058 }


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:19