Created
March 18, 2019 18:13
-
-
Save zmcartor/9aeb9f25eb1ce76b84bddd082b5bcbb7 to your computer and use it in GitHub Desktop.
OSLog extension for os_signpost usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usage | |
let log = OSLog(subsystem: "deep-secrets", category: "cookie-recipes") | |
let signpostID = log.beginSignpost(withName: "signpost name") | |
... Do work ... | |
log.endSignpost(withName: "signpost name" , signpostId: signpostId) | |
Signposts can also be started w objects instead of SignpostIDs when scope is an issue | |
OSLog(subsystem: "deep-secrets", category: "cookie-recipes").beginSignpost(withName: "some name", object: obj) | |
... Do Work... | |
... somewhere else where same obj is in scope ... | |
let log = OSLog(subsystem: "subby", category: "fruit") | |
log.endSignpost(withName: "some name", signpostID: log.signpostID(withObject: obj)) | |
*/ | |
extension OSLog { | |
@available(iOS 12.0, *) | |
func beginSignpost(withName name:StaticString) -> OSSignpostID { | |
let id = OSSignpostID(log: self) | |
os_signpost(.begin, log: self, name:name, signpostID: id) | |
return id | |
} | |
@available(iOS 12.0, *) | |
func endSignpost(withName name:StaticString, signpostID:OSSignpostID) { | |
os_signpost(.end, log: self, name: name, signpostID: signpostID) | |
} | |
@available(iOS 12.0, *) | |
func beginSignpost(withName name:StaticString, object:AnyObject) { | |
let id = OSSignpostID(log: self, object: object) | |
os_signpost(.begin, log: self, name:name, signpostID: id) | |
} | |
@available(iOS 12.0, *) | |
func signpostID() -> OSSignpostID { | |
return OSSignpostID(log: self) | |
} | |
@available(iOS 12.0, *) | |
func signpostID(withObject:AnyObject) -> OSSignpostID { | |
return OSSignpostID(log: self, object: withObject) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment