summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-07-24 16:19:02 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-08-23 16:22:08 -0400
commit7949c5983c0937a06e37446781e1ad947e4b3308 (patch)
tree691c82767d3ca3eaf4ac0e9c3a3bb21b89cb1a35
parentbb2b962a1497635f33784aa257c97cc35b8d76eb (diff)
downloadqtlocation-mapboxgl-7949c5983c0937a06e37446781e1ad947e4b3308.tar.gz
Change macros to return signposts
-rw-r--r--platform/darwin/src/MGLSignpost.h38
-rw-r--r--platform/darwin/src/MGLSignpost.m15
-rw-r--r--platform/ios/app/MBXViewController.m8
3 files changed, 33 insertions, 28 deletions
diff --git a/platform/darwin/src/MGLSignpost.h b/platform/darwin/src/MGLSignpost.h
index 44f5b9ce6b..f9eed00c9f 100644
--- a/platform/darwin/src/MGLSignpost.h
+++ b/platform/darwin/src/MGLSignpost.h
@@ -4,10 +4,12 @@
#include <os/log.h>
#include <os/signpost.h>
+#define CONCAT2(x,y) x##y
+#define CONCAT(x,y) CONCAT2(x,y)
+#define SIGNPOST_NAME(x) CONCAT(signpost,x)
#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.
@@ -23,24 +25,30 @@ MGL_EXPORT extern os_signpost_id_t MGLDefaultSignpostId;
*/
MGL_EXPORT extern os_log_t MGLSignpostLogCreate(const char* name);
-#define MGL_NAMED_SIGNPOST_BEGIN(log, signpost, name) \
- __extension__({ \
+#define MGL_NAMED_SIGNPOST_BEGIN(log, name, ...) \
+ ({ \
+ os_signpost_id_t SIGNPOST_NAME(__LINE__) = OS_SIGNPOST_ID_INVALID; \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
- os_signpost_interval_begin(log, signpost, name); \
+ SIGNPOST_NAME(__LINE__) = os_signpost_id_generate(log); \
+ os_signpost_interval_begin(log, SIGNPOST_NAME(__LINE__), name, ##__VA_ARGS__); \
} \
+ SIGNPOST_NAME(__LINE__); \
})
#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__); \
+ if (signpost != OS_SIGNPOST_ID_INVALID) { \
+ 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, ...) \
+#define MGL_NAMED_SIGNPOST_EVENT(log, name, ...) \
__extension__({ \
if (__builtin_available(iOS 12.0, macOS 10.14, *)) { \
- os_signpost_event_emit(log, signpost, name, ##__VA_ARGS__); \
+ os_signpost_id_t SIGNPOST_NAME(__LINE__) = os_signpost_id_generate(log); \
+ os_signpost_event_emit(log, SIGNPOST_NAME(__LINE__), name, ##__VA_ARGS__); \
} \
})
@@ -50,14 +58,18 @@ MGL_EXPORT extern os_log_t MGLSignpostLogCreate(const char* name);
//
// For example:
//
-// MGL_SIGNPOST_BEGIN("example");
+// os_signpost_id_t signpost = MGL_SIGNPOST_BEGIN("example");
// [self performAComputationallyExpensiveOperation];
-// MGL_SIGNPOST_END("example", "%d", numberOfWidgets);
+// MGL_SIGNPOST_END(signpost, "example", "%d", numberOfWidgets);
//
// MGL_SIGNPOST_EVENT("error", "%d", errorCode);
-#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__)
+#define MGL_SIGNPOST_BEGIN(name, ...) MGL_NAMED_SIGNPOST_BEGIN(MGLDefaultSignpostLog, name, ##__VA_ARGS__)
+#define MGL_SIGNPOST_END(signpost, name, ...) MGL_NAMED_SIGNPOST_END(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
+#define MGL_SIGNPOST_EVENT(signpost, name, ...) MGL_NAMED_SIGNPOST_EVENT(MGLDefaultSignpostLog, signpost, name, ##__VA_ARGS__)
+
+#undef CONCAT
+#undef CONCAT2
+#undef SIGNPOST_NAME
#endif /* MGLSignpost_h */
diff --git a/platform/darwin/src/MGLSignpost.m b/platform/darwin/src/MGLSignpost.m
index 7c3fbe43cd..d421c155af 100644
--- a/platform/darwin/src/MGLSignpost.m
+++ b/platform/darwin/src/MGLSignpost.m
@@ -2,24 +2,16 @@
#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 createDefaultSignpostLog(void) __attribute__((constructor));
+void destroyDefaultSignpostLog(void) __attribute__((destructor));
-void destroyDefaultSignpost() {
+void destroyDefaultSignpostLog() {
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) {
@@ -30,3 +22,4 @@ os_log_t MGLSignpostLogCreate(const char* name) {
return OS_LOG_DISABLED;
}
}
+
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 2e04a4cb86..7f43f335b0 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -563,11 +563,11 @@ CLLocationCoordinate2D randomWorldCoordinate() {
[weakSelf.pendingIdleBlocks addObject:^{
__typeof__(self) strongSelf = weakSelf;
NSLog(@"BEGIN: query-roads-batch");
- MGL_SIGNPOST_BEGIN("query-roads-batch");
+ os_signpost_id_t signpost = MGL_SIGNPOST_BEGIN("query-roads-batch");
for (int i = 0; i < 10; i++) {
[strongSelf queryRoads];
}
- MGL_SIGNPOST_END("query-roads-batch");
+ MGL_SIGNPOST_END(signpost, "query-roads-batch");
NSLog(@"END: query-roads-batch");
}];
}];
@@ -1756,12 +1756,12 @@ CLLocationCoordinate2D randomWorldCoordinate() {
- (void)queryRoads
{
- MGL_SIGNPOST_BEGIN("query-roads");
+ os_signpost_id_t signpost = 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]];
- MGL_SIGNPOST_END("query-roads", "%lu", (unsigned long)visibleRoadFeatures.count);
+ MGL_SIGNPOST_END(signpost, "query-roads", "%lu", (unsigned long)visibleRoadFeatures.count);
NSLog(@"Roads & labels feature count: %lu", (unsigned long)visibleRoadFeatures.count);
}