summaryrefslogtreecommitdiff
path: root/platform/ios/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/src')
-rw-r--r--platform/ios/src/MGLMapView.mm32
-rw-r--r--platform/ios/src/MGLMapView_Experimental.h32
2 files changed, 64 insertions, 0 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 7423c23c7b..2a231838a4 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -244,6 +244,12 @@ public:
@property (nonatomic) MGLUserLocation *userLocation;
@property (nonatomic) NSMutableDictionary<NSString *, NSMutableArray<MGLAnnotationView *> *> *annotationViewReuseQueueByIdentifier;
+/// Experimental rendering performance measurement.
+@property (nonatomic) BOOL experimental_enableFrameRateMeasurement;
+@property (nonatomic) CGFloat averageFrameRate;
+@property (nonatomic) CFTimeInterval frameTime;
+@property (nonatomic) CFTimeInterval averageFrameTime;
+
@end
@implementation MGLMapView
@@ -300,6 +306,11 @@ public:
BOOL _accessibilityValueAnnouncementIsPending;
MGLReachability *_reachability;
+
+ /// Experimental rendering performance measurement.
+ CFTimeInterval _frameCounterStartTime;
+ NSInteger _frameCount;
+ CFTimeInterval _frameDurations;
}
#pragma mark - Setup & Teardown -
@@ -1108,6 +1119,27 @@ public:
[self.glView display];
}
+
+ if (self.experimental_enableFrameRateMeasurement)
+ {
+ CFTimeInterval now = CACurrentMediaTime();
+
+ self.frameTime = now - _displayLink.timestamp;
+ _frameDurations += self.frameTime;
+
+ _frameCount++;
+
+ CFTimeInterval elapsed = now - _frameCounterStartTime;
+
+ if (elapsed >= 1.0) {
+ self.averageFrameRate = _frameCount / elapsed;
+ self.averageFrameTime = (_frameDurations / _frameCount) * 1000;
+
+ _frameCount = 0;
+ _frameDurations = 0;
+ _frameCounterStartTime = now;
+ }
+ }
}
- (void)setNeedsGLDisplay
diff --git a/platform/ios/src/MGLMapView_Experimental.h b/platform/ios/src/MGLMapView_Experimental.h
new file mode 100644
index 0000000000..94f8d67fb0
--- /dev/null
+++ b/platform/ios/src/MGLMapView_Experimental.h
@@ -0,0 +1,32 @@
+#import <Mapbox/Mapbox.h>
+
+@interface MGLMapView (Experimental)
+
+#pragma mark Rendering Performance Measurement
+
+/** Enable rendering performance measurement. */
+@property (nonatomic) BOOL experimental_enableFrameRateMeasurement;
+
+/**
+ Average frames per second over the previous second, updated once per second.
+
+ Requires `experimental_enableFrameRateMeasurement`.
+ */
+@property (nonatomic, readonly) CGFloat averageFrameRate;
+
+/**
+ Frame render duration for the previous frame, updated instantaneously.
+
+ Requires `experimental_enableFrameRateMeasurement`.
+ */
+@property (nonatomic, readonly) CFTimeInterval frameTime;
+
+/**
+ Average frame render duration over the previous second, updated once per
+ second.
+
+ Requires `experimental_enableFrameRateMeasurement`.
+ */
+@property (nonatomic, readonly) CFTimeInterval averageFrameTime;
+
+@end