summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-07-23 16:48:35 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-08-23 16:22:07 -0400
commitb8f3c9ebc21a436a97d810d7ca4b20c64c942e28 (patch)
tree89d35f372429082058c65de38c19b6f59b50e162
parentd2d77d8e520b2381de44a689d64f6f15d42f9b9f (diff)
downloadqtlocation-mapboxgl-b8f3c9ebc21a436a97d810d7ca4b20c64c942e28.tar.gz
Adds MGLSignpost to replace inline signpost calls
-rw-r--r--platform/darwin/src/MGLSignpost.h55
-rw-r--r--platform/darwin/src/MGLSignpost.m32
-rw-r--r--platform/ios/app/MBXViewController.m34
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj12
-rw-r--r--platform/macos/CHANGELOG.md2
5 files changed, 106 insertions, 29 deletions
diff --git a/platform/darwin/src/MGLSignpost.h b/platform/darwin/src/MGLSignpost.h
new file mode 100644
index 0000000000..01191bbfc1
--- /dev/null
+++ b/platform/darwin/src/MGLSignpost.h
@@ -0,0 +1,55 @@
+#ifndef MGLSignpost_h
+#define MGLSignpost_h
+
+#include <os/log.h>
+#include <os/signpost.h>
+
+#define MGL_EXPORT __attribute__((visibility ("default")))
+
+MGL_EXPORT extern os_log_t MGLDefaultSignpostLog;
+MGL_EXPORT extern os_signpost_id_t MGLDefaultSignpostId;
+
+/**
+ Create an os_log_t (for use with os_signposts) with the "com.mapbox.mapbox" subsystem.
+
+ This method checks `NSUserDefaults` for `MGLSignpostsEnabled`, otherwise will return `OS_LOG_DISABLED`.
+ Typically you should add `-MGLSignpostsEnabled YES` as run arguments to the Xcode scheme when
+ profiling.
+
+ This is only required if you need to add categories other than the default.
+
+ @param name Name for the log category.
+ @return log object.
+ */
+MGL_EXPORT extern os_log_t MGLSignpostLogCreate(const char* name);
+
+#define MGL_NAMED_SIGNPOST_BEGIN(log, signpost, name) \
+ __extension__({ \
+ if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
+ os_signpost_interval_begin(log, signpost, name); \
+ } \
+ })
+
+#define MGL_NAMED_SIGNPOST_END(log, signpost, name, ...) \
+ __extension__({ \
+ if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
+ os_signpost_interval_end(log, signpost, name, ##__VA_ARGS__); \
+ } \
+ })
+
+#define MGL_NAMED_SIGNPOST_EVENT(log, signpost, name, ...) \
+ __extension__({ \
+ if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
+ os_signpost_event_emit(log, signpost, name, ##__VA_ARGS__); \
+ } \
+ })
+
+// Use MGL_SIGNPOST_BEGIN & MGL_SIGNPOST_END around sections of code that you
+// wish to profile.
+// MGL_SIGNPOST_EVENT can be used for single one-off events
+
+#define MGL_SIGNPOST_BEGIN(name) MGL_NAMED_SIGNPOST_BEGIN(MGLDefaultSignpostLog, MGLDefaultSignpostId, name)
+#define MGL_SIGNPOST_END(name, ...) MGL_NAMED_SIGNPOST_END(MGLDefaultSignpostLog, MGLDefaultSignpostId, name, ##__VA_ARGS__)
+#define MGL_SIGNPOST_EVENT(name, ...) MGL_NAMED_SIGNPOST_EVENT(MGLDefaultSignpostLog, MGLDefaultSignpostId, name, ##__VA_ARGS__)
+
+#endif /* MGLSignpost_h */
diff --git a/platform/darwin/src/MGLSignpost.m b/platform/darwin/src/MGLSignpost.m
new file mode 100644
index 0000000000..7c3fbe43cd
--- /dev/null
+++ b/platform/darwin/src/MGLSignpost.m
@@ -0,0 +1,32 @@
+@import Foundation;
+#include "MGLSignpost.h"
+
+os_log_t MGLDefaultSignpostLog = NULL;
+os_signpost_id_t MGLDefaultSignpostId = OS_SIGNPOST_ID_INVALID;
+
+void createDefaultSignpost(void) __attribute__((constructor));
+void destroyDefaultSignpost(void) __attribute__((destructor));
+
+void destroyDefaultSignpost() {
+ MGLDefaultSignpostLog = NULL;
+ MGLDefaultSignpostId = OS_SIGNPOST_ID_INVALID;
+}
+
+void createDefaultSignpost() {
+ MGLDefaultSignpostLog = MGLSignpostLogCreate("MGLSignposts");
+
+ if (MGLDefaultSignpostLog) {
+ if (__builtin_available(iOS 12.0, macOS 10.14, *)) {
+ MGLDefaultSignpostId = os_signpost_id_generate(MGLDefaultSignpostLog);
+ }
+ }
+}
+
+os_log_t MGLSignpostLogCreate(const char* name) {
+ if (name && [NSUserDefaults.standardUserDefaults boolForKey:@"MGLSignpostsEnabled"]) {
+ return os_log_create("com.mapbox.mapbox", name);
+ }
+ else {
+ return OS_LOG_DISABLED;
+ }
+}
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index c68f9ceb68..2e04a4cb86 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -17,8 +17,8 @@
#import "../src/MGLMapView_Experimental.h"
#import <objc/runtime.h>
-#import <os/log.h>
-#import <os/signpost.h>
+
+#import "MGLSignpost.h"
static const CLLocationCoordinate2D WorldTourDestinations[] = {
{ .latitude = 38.8999418, .longitude = -77.033996 },
@@ -217,27 +217,10 @@ CLLocationCoordinate2D randomWorldCoordinate() {
@property (nonatomic) NSMutableArray<UIWindow *> *helperWindows;
@property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays;
-@property (nonatomic) os_log_t log;
-@property (nonatomic) os_signpost_id_t signpost;
@property (nonatomic) NSMutableArray<dispatch_block_t> *pendingIdleBlocks;
@end
-#define OS_SIGNPOST_BEGIN_WITH_SELF(self, name) \
- if (@available(iOS 12.0, *)) { os_signpost_interval_begin(self.log, self.signpost, name); }
-
-#define OS_SIGNPOST_END_WITH_SELF(self, name) \
- if (@available(iOS 12.0, *)) { os_signpost_interval_end(self.log, self.signpost, name); }
-
-#define OS_SIGNPOST_BEGIN(name) \
- OS_SIGNPOST_BEGIN_WITH_SELF(self, name)
-
-#define OS_SIGNPOST_END(name) \
- OS_SIGNPOST_END_WITH_SELF(self, name)
-
-#define OS_SIGNPOST_EVENT(name, ...) \
- if (@available(iOS 12.0, *)) { os_signpost_event_emit(self.log, self.signpost, name, ##__VA_ARGS__); }
-
// Expose properties for testing
@interface MGLMapView (MBXViewController)
@property (nonatomic) NSDictionary *annotationViewReuseQueueByIdentifier;
@@ -263,10 +246,6 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[super viewDidLoad];
self.pendingIdleBlocks = [NSMutableArray array];
- self.log = os_log_create("com.mapbox.iosapp", "MBXViewController");
- if (@available(iOS 12.0, *)) {
- self.signpost = os_signpost_id_generate(self.log);
- }
// Keep track of current map state and debug preferences,
// saving and restoring when the application's state changes.
@@ -584,11 +563,11 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[weakSelf.pendingIdleBlocks addObject:^{
__typeof__(self) strongSelf = weakSelf;
NSLog(@"BEGIN: query-roads-batch");
- OS_SIGNPOST_BEGIN_WITH_SELF(strongSelf, "query-roads-batch");
+ MGL_SIGNPOST_BEGIN("query-roads-batch");
for (int i = 0; i < 10; i++) {
[strongSelf queryRoads];
}
- OS_SIGNPOST_END_WITH_SELF(strongSelf, "query-roads-batch");
+ MGL_SIGNPOST_END("query-roads-batch");
NSLog(@"END: query-roads-batch");
}];
}];
@@ -1777,13 +1756,12 @@ CLLocationCoordinate2D randomWorldCoordinate() {
- (void)queryRoads
{
- OS_SIGNPOST_BEGIN("query-roads");
+ MGL_SIGNPOST_BEGIN("query-roads");
NSArray *roadStyleLayerIdentifiers = [self.mapView.style.roadStyleLayers valueForKey:@"identifier"];
NSArray *visibleRoadFeatures = [self.mapView visibleFeaturesInRect:self.mapView.bounds inStyleLayersWithIdentifiers:[NSSet setWithArray:roadStyleLayerIdentifiers]];
- OS_SIGNPOST_END("query-roads");
- OS_SIGNPOST_EVENT("query-roads-count", "%lu", (unsigned long)visibleRoadFeatures.count);
+ MGL_SIGNPOST_END("query-roads", "%lu", (unsigned long)visibleRoadFeatures.count);
NSLog(@"Roads & labels feature count: %lu", (unsigned long)visibleRoadFeatures.count);
}
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 5a5cb00b49..983f69b72a 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -521,6 +521,10 @@
CAA69DA4206DCD0E007279CD /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA4A26961CB6E795000B7809 /* Mapbox.framework */; };
CAA69DA5206DCD0E007279CD /* Mapbox.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DA4A26961CB6E795000B7809 /* Mapbox.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CABE5DAD2072FAB40003AF3C /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA8847D21CBAF91600AB86E3 /* Mapbox.framework */; };
+ CAC3A3E022E75AC200BC8DEF /* MGLSignpost.h in Headers */ = {isa = PBXBuildFile; fileRef = CAC3A3DE22E75AC100BC8DEF /* MGLSignpost.h */; };
+ CAC3A3E122E75AC200BC8DEF /* MGLSignpost.h in Headers */ = {isa = PBXBuildFile; fileRef = CAC3A3DE22E75AC100BC8DEF /* MGLSignpost.h */; };
+ CAC3A3E222E75AC200BC8DEF /* MGLSignpost.m in Sources */ = {isa = PBXBuildFile; fileRef = CAC3A3DF22E75AC200BC8DEF /* MGLSignpost.m */; };
+ CAC3A3E322E75AC200BC8DEF /* MGLSignpost.m in Sources */ = {isa = PBXBuildFile; fileRef = CAC3A3DF22E75AC200BC8DEF /* MGLSignpost.m */; };
CAD9D0AA22A86D6F001B25EE /* MGLResourceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CAD9D0A922A86D6F001B25EE /* MGLResourceTests.mm */; };
CAE7AD5520F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAE7AD5420F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift */; };
CF75A91522D85E860058A5C4 /* MGLLoggingConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */; };
@@ -1205,6 +1209,8 @@
CA6914B420E67F50002DB0EE /* MGLAnnotationViewIntegrationTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLAnnotationViewIntegrationTests.mm; path = "Annotation Tests/MGLAnnotationViewIntegrationTests.mm"; sourceTree = "<group>"; };
CA88DC2F21C85D900059ED5A /* MGLStyleURLIntegrationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLStyleURLIntegrationTest.m; sourceTree = "<group>"; };
CA8FBC0821A47BB100D1203C /* MGLRendererConfigurationTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLRendererConfigurationTests.mm; path = ../../darwin/test/MGLRendererConfigurationTests.mm; sourceTree = "<group>"; };
+ CAC3A3DE22E75AC100BC8DEF /* MGLSignpost.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MGLSignpost.h; sourceTree = "<group>"; };
+ CAC3A3DF22E75AC200BC8DEF /* MGLSignpost.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLSignpost.m; sourceTree = "<group>"; };
CAD9D0A922A86D6F001B25EE /* MGLResourceTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = MGLResourceTests.mm; path = ../../darwin/test/MGLResourceTests.mm; sourceTree = "<group>"; };
CAE7AD5320F46EF5003B6782 /* integration-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "integration-Bridging-Header.h"; sourceTree = "<group>"; };
CAE7AD5420F46EF5003B6782 /* MGLMapSnapshotterSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MGLMapSnapshotterSwiftTests.swift; sourceTree = "<group>"; };
@@ -2147,6 +2153,8 @@
1F6A82A021360F9C00BA5B41 /* MGLLoggingConfiguration.h */,
CF75A91422D85E860058A5C4 /* MGLLoggingConfiguration.mm */,
1F6A82A62138871900BA5B41 /* MGLLoggingConfiguration_Private.h */,
+ CAC3A3DE22E75AC100BC8DEF /* MGLSignpost.h */,
+ CAC3A3DF22E75AC200BC8DEF /* MGLSignpost.m */,
);
name = Foundation;
path = ../darwin/src;
@@ -2519,6 +2527,7 @@
9221BAAD2069843A0054BDF4 /* MGLTilePyramidOfflineRegion_Private.h in Headers */,
96F3F73C1F57124B003E2D2C /* MGLUserLocationHeadingIndicator.h in Headers */,
408AA8571DAEDA1700022900 /* NSDictionary+MGLAdditions.h in Headers */,
+ CAC3A3E022E75AC200BC8DEF /* MGLSignpost.h in Headers */,
9C6E281422A97FDC0056B7BE /* UIKit+MMEMobileEvents.h in Headers */,
DA88483F1CBAFB8500AB86E3 /* MGLUserLocation.h in Headers */,
558DE7A01E5615E400C7916D /* MGLFoundation_Private.h in Headers */,
@@ -2712,6 +2721,7 @@
96E516F32000597100A02306 /* NSDictionary+MGLAdditions.h in Headers */,
1FCAE2A920B88B3800C577DD /* MGLLocationManager_Private.h in Headers */,
9C6E283422A982670056B7BE /* MMECommonEventData.h in Headers */,
+ CAC3A3E122E75AC200BC8DEF /* MGLSignpost.h in Headers */,
9C6E281E22A980AC0056B7BE /* CLLocation+MMEMobileEvents.h in Headers */,
96E516F02000595800A02306 /* NSBundle+MGLAdditions.h in Headers */,
96E516F920005A3500A02306 /* MGLFaux3DUserLocationAnnotationView.h in Headers */,
@@ -3398,6 +3408,7 @@
DA88482B1CBAFA6200AB86E3 /* MGLTypes.m in Sources */,
FA68F14D1E9D656600F9F6C2 /* MGLFillExtrusionStyleLayer.mm in Sources */,
404C26E41D89B877000AA13D /* MGLTileSource.mm in Sources */,
+ CAC3A3E222E75AC200BC8DEF /* MGLSignpost.m in Sources */,
355AE0011E9281DA00F3939D /* MGLScaleBar.mm in Sources */,
DA88481D1CBAFA6200AB86E3 /* MGLMapCamera.mm in Sources */,
DACA86282019218600E9693A /* MGLRasterDEMSource.mm in Sources */,
@@ -3525,6 +3536,7 @@
404C26E51D89B877000AA13D /* MGLTileSource.mm in Sources */,
355AE0021E9281DA00F3939D /* MGLScaleBar.mm in Sources */,
4018B1C81CDC287F00F666AF /* MGLAnnotationView.mm in Sources */,
+ CAC3A3E322E75AC200BC8DEF /* MGLSignpost.m in Sources */,
07D8C6FB1F67560100381808 /* MGLComputedShapeSource.mm in Sources */,
DAA4E4341CBB730400178DFB /* MGLFaux3DUserLocationAnnotationView.m in Sources */,
DACA86292019218600E9693A /* MGLRasterDEMSource.mm in Sources */,
diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md
index cd80f0c1ea..8c83db5e2c 100644
--- a/platform/macos/CHANGELOG.md
+++ b/platform/macos/CHANGELOG.md
@@ -28,7 +28,7 @@
* `-[MGLMapView setVisibleCoordinateBounds:edgePadding:animated:completionHandler:]`
* `-[MGLMapView setContentInsets:animated:completionHandler:]`
* `-[MGLMapView showAnnotations:edgePadding:animated:completionHandler:]`
-* Improved feature querying performance (focussed on roads). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183))
+* Improved feature querying performance (primarily road features). ([#15183](https://github.com/mapbox/mapbox-gl-native/pull/15183))
## 0.14.0 - May 22, 2018