MCPcopy Create free account
hub / github.com/apache/kvrocks / ThreadGetCPUTime

Function ThreadGetCPUTime

src/common/thread_util.cc:42–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40
41#ifdef __APPLE__
42double 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
60double ThreadGetCPUTime(std::thread::native_handle_type thread_id) {
61 if (!thread_id) {

Callers 1

GetCpuInfoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected