Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m

Issue 1289623005: Add stats overlay to iOS AppRTCDemo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m
diff --git a/webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m b/webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m
index 257b6a6a5c9e6ed6d61b5654990ac50a1a269b92..6b5358c66f4202e21e4481a9d11d51df7c8c4736 100644
--- a/webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m
+++ b/webrtc/examples/objc/AppRTCDemo/common/ARDUtilities.m
@@ -10,6 +10,8 @@
#import "ARDUtilities.h"
+#import <mach/mach.h>
+
#import "RTCLogging.h"
@implementation NSDictionary (ARDUtilites)
@@ -93,3 +95,34 @@
}
@end
+
+NSInteger ARDGetCpuUsagePercentage() {
+ // Create an array of thread ports for the current task
jiayl2 2015/08/13 22:21:50 nit: '.' at the end of a comment. here and other p
tkchin_webrtc 2015/08/13 23:55:31 Done.
+ const task_t task = mach_task_self();
+ thread_act_array_t thread_array;
+ mach_msg_type_number_t thread_count;
+ if (task_threads(task, &thread_array, &thread_count) != KERN_SUCCESS) {
+ return -1;
+ }
+
+ // Sum cpu usage from all threads
+ float cpu_usage_percentage = 0;
+ thread_basic_info_data_t thread_info_data = {};
+ mach_msg_type_number_t thread_info_count;
+ for (size_t i = 0; i < thread_count; ++i) {
+ thread_info_count = THREAD_BASIC_INFO_COUNT;
+ kern_return_t ret = thread_info(thread_array[i],
+ THREAD_BASIC_INFO,
+ (thread_info_t)&thread_info_data,
+ &thread_info_count);
+ if (ret == KERN_SUCCESS) {
+ cpu_usage_percentage +=
+ 100.f * (float)thread_info_data.cpu_usage / TH_USAGE_SCALE;
+ }
+ }
+
+ // Dealloc the created array
+ vm_deallocate(task, (vm_address_t)thread_array,
+ sizeof(thread_act_t) * thread_count);
+ return lroundf(cpu_usage_percentage);
+}

Powered by Google App Engine
This is Rietveld 408576698