| 105 | } |
| 106 | |
| 107 | inline MicrosecondsInt64 GetThreadCpuTimeMicros() { |
| 108 | // See https://www.gnu.org/software/hurd/gnumach-doc/Thread-Information.html |
| 109 | // and Chromium base/time/time_mac.cc. |
| 110 | task_t thread = mach_thread_self(); |
| 111 | if (thread == MACH_PORT_NULL) { |
| 112 | LOG(WARNING) << "Failed to get mach_thread_self()"; |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | mach_msg_type_number_t thread_info_count = THREAD_BASIC_INFO_COUNT; |
| 117 | thread_basic_info_data_t thread_info_data; |
| 118 | |
| 119 | kern_return_t result = thread_info( |
| 120 | thread, |
| 121 | THREAD_BASIC_INFO, |
| 122 | reinterpret_cast<thread_info_t>(&thread_info_data), |
| 123 | &thread_info_count); |
| 124 | |
| 125 | if (result != KERN_SUCCESS) { |
| 126 | LOG(WARNING) << "Failed to get thread_info()"; |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | return thread_info_data.user_time.seconds * MICROS_PER_SEC + |
| 131 | thread_info_data.user_time.microseconds; |
| 132 | } |
| 133 | |
| 134 | #else |
| 135 |
no test coverage detected