MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ProcessCPUUsage

Function ProcessCPUUsage

deps/google-benchmark/src/timers.cc:114–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112} // end namespace
113
114double ProcessCPUUsage() {
115#if defined(BENCHMARK_OS_WINDOWS)
116 HANDLE proc = GetCurrentProcess();
117 FILETIME creation_time;
118 FILETIME exit_time;
119 FILETIME kernel_time;
120 FILETIME user_time;
121 if (GetProcessTimes(proc, &creation_time, &exit_time, &kernel_time,
122 &user_time))
123 return MakeTime(kernel_time, user_time);
124 DiagnoseAndExit("GetProccessTimes() failed");
125#elif defined(BENCHMARK_OS_QURT)
126 return static_cast<double>(
127 qurt_timer_timetick_to_us(qurt_timer_get_ticks())) *
128 1.0e-6;
129#elif defined(BENCHMARK_OS_EMSCRIPTEN)
130 // clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) returns 0 on Emscripten.
131 // Use Emscripten-specific API. Reported CPU time would be exactly the
132 // same as total time, but this is ok because there aren't long-latency
133 // synchronous system calls in Emscripten.
134 return emscripten_get_now() * 1e-3;
135#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
136 // FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
137 // See https://github.com/google/benchmark/pull/292
138 struct timespec spec;
139 if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0)
140 return MakeTime(spec);
141 DiagnoseAndExit("clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) failed");
142#else
143 struct rusage ru;
144 if (getrusage(RUSAGE_SELF, &ru) == 0) return MakeTime(ru);
145 DiagnoseAndExit("getrusage(RUSAGE_SELF, ...) failed");
146#endif
147}
148
149double ThreadCPUUsage() {
150#if defined(BENCHMARK_OS_WINDOWS)

Callers 2

ThreadCPUUsageFunction · 0.85
ReadCpuTimerOfChoiceMethod · 0.85

Calls 2

MakeTimeFunction · 0.85
DiagnoseAndExitFunction · 0.85

Tested by

no test coverage detected