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

Function ThreadCPUUsage

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

Source from the content-addressed store, hash-verified

147}
148
149double ThreadCPUUsage() {
150#if defined(BENCHMARK_OS_WINDOWS)
151 HANDLE this_thread = GetCurrentThread();
152 FILETIME creation_time;
153 FILETIME exit_time;
154 FILETIME kernel_time;
155 FILETIME user_time;
156 GetThreadTimes(this_thread, &creation_time, &exit_time, &kernel_time,
157 &user_time);
158 return MakeTime(kernel_time, user_time);
159#elif defined(BENCHMARK_OS_QURT)
160 return static_cast<double>(
161 qurt_timer_timetick_to_us(qurt_timer_get_ticks())) *
162 1.0e-6;
163#elif defined(BENCHMARK_OS_MACOSX)
164 // FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
165 // See https://github.com/google/benchmark/pull/292
166 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
167 thread_basic_info_data_t info;
168 mach_port_t thread = pthread_mach_thread_np(pthread_self());
169 if (thread_info(thread, THREAD_BASIC_INFO,
170 reinterpret_cast<thread_info_t>(&info),
171 &count) == KERN_SUCCESS) {
172 return MakeTime(info);
173 }
174 DiagnoseAndExit("ThreadCPUUsage() failed when evaluating thread_info");
175#elif defined(BENCHMARK_OS_EMSCRIPTEN)
176 // Emscripten doesn't support traditional threads
177 return ProcessCPUUsage();
178#elif defined(BENCHMARK_OS_RTEMS)
179 // RTEMS doesn't support CLOCK_THREAD_CPUTIME_ID. See
180 // https://github.com/RTEMS/rtems/blob/master/cpukit/posix/src/clockgettime.c
181 return ProcessCPUUsage();
182#elif defined(BENCHMARK_OS_SOLARIS)
183 struct rusage ru;
184 if (getrusage(RUSAGE_LWP, &ru) == 0) return MakeTime(ru);
185 DiagnoseAndExit("getrusage(RUSAGE_LWP, ...) failed");
186#elif defined(CLOCK_THREAD_CPUTIME_ID)
187 struct timespec ts;
188 if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == 0) return MakeTime(ts);
189 DiagnoseAndExit("clock_gettime(CLOCK_THREAD_CPUTIME_ID, ...) failed");
190#else
191#error Per-thread timing is not available on your system.
192#endif
193}
194
195std::string LocalDateTimeString() {
196 // Write the local time in RFC3339 format yyyy-mm-ddTHH:MM:SS+/-HH:MM.

Callers 1

ReadCpuTimerOfChoiceMethod · 0.85

Calls 3

MakeTimeFunction · 0.85
DiagnoseAndExitFunction · 0.85
ProcessCPUUsageFunction · 0.85

Tested by

no test coverage detected