| 40 | |
| 41 | #ifdef __APPLE__ |
| 42 | double ThreadGetCPUTime(std::thread::native_handle_type thread_id) { |
| 43 | if (!thread_id) { |
| 44 | return 0.0; |
| 45 | } |
| 46 | |
| 47 | mach_port_t mach_thread = pthread_mach_thread_np(thread_id); |
| 48 | |
| 49 | thread_basic_info_data_t info; |
| 50 | mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; |
| 51 | |
| 52 | if (thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS) { |
| 53 | return 0.0; |
| 54 | } |
| 55 | |
| 56 | return (static_cast<double>(info.user_time.seconds) + static_cast<double>(info.user_time.microseconds) / 1e6) + |
| 57 | (static_cast<double>(info.system_time.seconds) + static_cast<double>(info.system_time.microseconds) / 1e6); |
| 58 | } |
| 59 | #else |
| 60 | double ThreadGetCPUTime(std::thread::native_handle_type thread_id) { |
| 61 | if (!thread_id) { |