| 235 | #endif |
| 236 | |
| 237 | double getProcessorTimeThread() { |
| 238 | INJECT_FAULT(platform_error, "getProcessorTimeThread"); // Get Thread CPU Time failed |
| 239 | #if defined(_WIN32) |
| 240 | FILETIME ftCreate, ftExit, ftKernel, ftUser; |
| 241 | if (!GetThreadTimes(GetCurrentThread(), &ftCreate, &ftExit, &ftKernel, &ftUser)) { |
| 242 | TraceEvent(SevError, "GetThreadCPUTime").GetLastError(); |
| 243 | throw platform_error(); |
| 244 | } |
| 245 | return FiletimeAsInt64(ftKernel) / double(1e7) + FiletimeAsInt64(ftUser) / double(1e7); |
| 246 | #elif defined(__linux__) || defined(__FreeBSD__) |
| 247 | return getProcessorTimeGeneric(RUSAGE_THREAD); |
| 248 | #elif defined(__APPLE__) |
| 249 | /* No RUSAGE_THREAD so we use the lower level interface */ |
| 250 | struct thread_basic_info info; |
| 251 | mach_msg_type_number_t info_count = THREAD_BASIC_INFO_COUNT; |
| 252 | if (KERN_SUCCESS != thread_info(mach_thread_self(), THREAD_BASIC_INFO, (thread_info_t)&info, &info_count)) { |
| 253 | TraceEvent(SevError, "GetThreadCPUTime").GetLastError(); |
| 254 | throw platform_error(); |
| 255 | } |
| 256 | return (info.user_time.seconds + (info.user_time.microseconds / double(1e6)) + info.system_time.seconds + |
| 257 | (info.system_time.microseconds / double(1e6))); |
| 258 | #else |
| 259 | #warning getProcessorTimeThread unimplemented on this platform |
| 260 | return 0.0; |
| 261 | #endif |
| 262 | } |
| 263 | |
| 264 | double getProcessorTimeProcess() { |
| 265 | INJECT_FAULT(platform_error, "getProcessorTimeProcess"); // Get CPU Process Time failed |
no test coverage detected