Skip to content

Commit

Permalink
[profiling] Handle thread_info to account for killed threads
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Oct 28, 2020
1 parent 53d5d68 commit 40c0e2e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,26 @@ void DeleteIO(io_object_t value) {
kernel_return_code =
thread_info(mach_threads.threads[i], THREAD_BASIC_INFO,
reinterpret_cast<thread_info_t>(&basic_thread_info), &thread_info_count);
if (kernel_return_code != KERN_SUCCESS) {
FML_LOG(ERROR) << "Error retrieving thread information: "
<< mach_error_string(kernel_return_code);
return std::nullopt;
switch (kernel_return_code) {
case KERN_SUCCESS: {
const double current_thread_cpu_usage =
basic_thread_info.cpu_usage / static_cast<float>(TH_USAGE_SCALE);
total_cpu_usage += current_thread_cpu_usage;
break;
}
case MACH_SEND_TIMEOUT:
case MACH_SEND_TIMED_OUT:
case MACH_SEND_INVALID_DEST:
// Ignore as this thread been destroyed. The possible return codes are not really well
// documented. This handling is inspired from the following sources:
// - https://opensource.apple.com/source/xnu/xnu-4903.221.2/tests/task_inspect.c.auto.html
// - https://github.com/apple/swift-corelibs-libdispatch/blob/main/src/queue.c#L6617
break;
default:
FML_LOG(ERROR) << "Error retrieving thread information: "
<< mach_error_string(kernel_return_code);
return std::nullopt;
}
const double current_thread_cpu_usage =
basic_thread_info.cpu_usage / static_cast<float>(TH_USAGE_SCALE);
total_cpu_usage += current_thread_cpu_usage;
}

flutter::CpuUsageInfo cpu_usage_info = {.num_threads = mach_threads.thread_count,
Expand Down

0 comments on commit 40c0e2e

Please sign in to comment.