Created
February 4, 2021 17:14
-
-
Save chrisvasselli/d618c2ffbf748b0987166cad349f33c7 to your computer and use it in GitHub Desktop.
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
import os | |
class DisplayLink { | |
static let shared = DisplayLink() | |
var displayLink: CADisplayLink! | |
var lastTimestamp: CFTimeInterval? | |
private let pointsOfInterestLog = OSLog(subsystem: "displaylink", category: .pointsOfInterest) | |
init() { | |
self.displayLink = CADisplayLink(target: self, selector: #selector(update)) | |
self.displayLink.add(to: .main, forMode: .common) | |
} | |
@objc func update() { | |
let duration = displayLink.timestamp - (lastTimestamp ?? displayLink.timestamp) | |
lastTimestamp = displayLink.timestamp | |
if duration > 0.017 { | |
os_signpost(.event, log: self.pointsOfInterestLog, name: "Frame Drop", "%f", duration * 1000) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment