Index: webrtc/sdk/objc/Framework/Classes/RTCMetric.mm |
diff --git a/webrtc/sdk/objc/Framework/Classes/RTCMetric.mm b/webrtc/sdk/objc/Framework/Classes/RTCMetric.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..741847d4b0f8960840f19ef8b04cc09c18ac426a |
--- /dev/null |
+++ b/webrtc/sdk/objc/Framework/Classes/RTCMetric.mm |
@@ -0,0 +1,64 @@ |
+/* |
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#import "RTCMetric+Private.h" |
+ |
+#import "NSString+StdString.h" |
+ |
+@implementation RTCMetric |
+ |
+@synthesize name = _name; |
+@synthesize min = _min; |
+@synthesize max = _max; |
+@synthesize bucketCount = _bucketCount; |
+@synthesize samples = _samples; |
+ |
++ (void)enable { |
+ webrtc::metrics::Enable(); |
tkchin_webrtc
2016/06/03 23:55:44
Are there other metric classes that we are expecti
åsapersson
2016/06/06 10:57:36
Done.
|
+} |
+ |
++ (NSArray<RTCMetric *> *)getAndReset { |
tkchin_webrtc
2016/06/03 23:55:44
the "get" prefix is not used in ObjC style for obj
åsapersson
2016/06/06 10:57:36
Done.
|
+ std::map<std::string, std::unique_ptr<webrtc::metrics::SampleInfo>> |
+ histograms; |
+ webrtc::metrics::GetAndReset(&histograms); |
+ |
+ NSMutableArray* metrics = |
+ [NSMutableArray arrayWithCapacity:histograms.size()]; |
+ for (auto const& histogram : histograms) { |
+ RTCMetric* metric = |
+ [[RTCMetric alloc] initWithNativeSampleInfo:*histogram.second]; |
+ [metrics addObject:metric]; |
+ } |
+ return metrics; |
+} |
+ |
+#pragma mark - Private |
+ |
+- (instancetype)initWithNativeSampleInfo: |
tkchin_webrtc
2016/06/03 23:55:44
This class sounds like the ObjC version of webrtc:
åsapersson
2016/06/06 10:57:36
Moved this to a separate file RTCMetricsSampleInfo
|
+ (const webrtc::metrics::SampleInfo&)info { |
+ if (self = [super init]) { |
+ _name = [NSString stringForStdString:info.name]; |
+ _min = info.min; |
+ _max = info.max; |
+ _bucketCount = info.bucket_count; |
+ |
+ NSMutableDictionary* samples = |
+ [NSMutableDictionary dictionaryWithCapacity:info.samples.size()]; |
+ for (auto const& sample : info.samples) { |
+ NSNumber* key = [NSNumber numberWithInt:sample.first]; |
tkchin_webrtc
2016/06/03 23:55:44
this can be simplified to:
samples[@(sample.first)
åsapersson
2016/06/06 10:57:36
fails to compile on mac bots..
|
+ NSNumber* value = [NSNumber numberWithInt:sample.second]; |
+ [samples setObject:value forKey:key]; |
+ } |
+ _samples = samples; |
+ } |
+ return self; |
+} |
+ |
+@end |