Browse Source

Adding perf logging markers.

pull/92/head
Abhishek 6 years ago
parent
commit
051bbcc250
  1. 5
      Clocker/Clocker.xcodeproj/xcshareddata/xcschemes/Clocker.xcscheme
  2. 26
      Clocker/Overall App/Logger.swift
  3. 42
      Clocker/Panel/PanelController.swift
  4. 34
      Clocker/Panel/ParentPanelController.swift

5
Clocker/Clocker.xcodeproj/xcshareddata/xcschemes/Clocker.xcscheme

@ -90,6 +90,11 @@
value = "disable" value = "disable"
isEnabled = "NO"> isEnabled = "NO">
</EnvironmentVariable> </EnvironmentVariable>
<EnvironmentVariable
key = "ENABLE_PERF_LOGGING"
value = "NO"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables> </EnvironmentVariables>
<AdditionalOptions> <AdditionalOptions>
</AdditionalOptions> </AdditionalOptions>

26
Clocker/Overall App/Logger.swift

@ -14,14 +14,28 @@ class Logger: NSObject {
@available(OSX 10.14, *) @available(OSX 10.14, *)
class PerfLogger: NSObject { class PerfLogger: NSObject {
static let openPanelLog = OSLog(subsystem: "com.abhishek.Clocker", category: "Open Panel")
static let signpostID = OSSignpostID(log: openPanelLog)
@objc class func signpostBegin() { static var panelLog = OSLog(subsystem: "com.abhishek.Clocker",
os_signpost(.begin, log: openPanelLog, name: "Open Panel", signpostID: signpostID) category: "Open Panel")
static let signpostID = OSSignpostID(log: panelLog)
class func disable() {
panelLog = .disabled
}
class func startMarker(_ name: StaticString) {
os_signpost(.begin,
log: panelLog,
name: name,
signpostID: signpostID)
} }
@objc class func signpostEnd() { class func endMarker(_ name: StaticString) {
os_signpost(.end, log: openPanelLog, name: "Open Panel", signpostID: signpostID) os_signpost(.end,
log: panelLog,
name: name,
signpostID: signpostID)
} }
} }

42
Clocker/Panel/PanelController.swift

@ -20,6 +20,8 @@ class PanelController: ParentPanelController {
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
enablePerformanceLoggingIfNeccessary()
window?.title = "Clocker Panel" window?.title = "Clocker Panel"
window?.setAccessibilityIdentifier("Clocker Panel") window?.setAccessibilityIdentifier("Clocker Panel")
@ -39,6 +41,14 @@ class PanelController: ParentPanelController {
super.updateDefaultPreferences() super.updateDefaultPreferences()
} }
private func enablePerformanceLoggingIfNeccessary() {
if !ProcessInfo.processInfo.environment.keys.contains("ENABLE_PERF_LOGGING") {
if #available(OSX 10.14, *) {
PerfLogger.disable()
}
}
}
@objc override func updateDefaultPreferences() { @objc override func updateDefaultPreferences() {
super.updateDefaultPreferences() super.updateDefaultPreferences()
} }
@ -62,7 +72,7 @@ class PanelController: ParentPanelController {
func open() { func open() {
if #available(OSX 10.14, *) { if #available(OSX 10.14, *) {
PerfLogger.signpostBegin() PerfLogger.startMarker("Open")
} }
guard isWindowLoaded == true else { guard isWindowLoaded == true else {
@ -100,13 +110,17 @@ class PanelController: ParentPanelController {
log() log()
if #available(OSX 10.14, *) { if #available(OSX 10.14, *) {
PerfLogger.signpostEnd() PerfLogger.endMarker("Open")
} }
} }
// New way to set the panel's frame. // New way to set the panel's frame.
// This takes into account the screen's dimensions. // This takes into account the screen's dimensions.
private func setPanelFrame() { private func setPanelFrame() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Set Panel Frame")
}
guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else { guard let appDelegate = NSApplication.shared.delegate as? AppDelegate else {
return return
} }
@ -139,10 +153,17 @@ class PanelController: ParentPanelController {
statusItemFrame.origin.y = minY statusItemFrame.origin.y = minY
setFrameTheNewWay(statusItemFrame, screenMaxX) setFrameTheNewWay(statusItemFrame, screenMaxX)
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Set Panel Frame")
}
} }
} }
private func log() { private func log() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Logging")
}
let preferences = DataStore.shared().timezones() let preferences = DataStore.shared().timezones()
guard let theme = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber, guard let theme = DataStore.shared().retrieve(key: CLThemeKey) as? NSNumber,
@ -186,17 +207,34 @@ class PanelController: ParentPanelController {
] ]
Logger.log(object: panelEvent, for: "openedPanel") Logger.log(object: panelEvent, for: "openedPanel")
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Logging")
}
} }
private func startWindowTimer() { private func startWindowTimer() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Start Window Timer")
}
stopMenubarTimerIfNeccesary() stopMenubarTimerIfNeccesary()
if let timer = parentTimer, timer.state == .paused { if let timer = parentTimer, timer.state == .paused {
parentTimer?.start() parentTimer?.start()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Start Window Timer")
}
return return
} }
startTimer() startTimer()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Start Window Timer")
}
} }
private func startTimer() { private func startTimer() {

34
Clocker/Panel/ParentPanelController.swift

@ -408,6 +408,10 @@ class ParentPanelController: NSWindowController {
} }
@objc func updateDefaultPreferences() { @objc func updateDefaultPreferences() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Update Default Preferences")
}
updatePanelColor() updatePanelColor()
let defaults = DataStore.shared().timezones() let defaults = DataStore.shared().timezones()
@ -421,6 +425,10 @@ class ParentPanelController: NSWindowController {
mainTableView.panelDelegate = datasource mainTableView.panelDelegate = datasource
updateDatasource(with: convertedTimezones) updateDatasource(with: convertedTimezones)
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Update Default Preferences")
}
} }
func updateDatasource(with timezones: [TimezoneData]) { func updateDatasource(with timezones: [TimezoneData]) {
@ -646,16 +654,23 @@ class ParentPanelController: NSWindowController {
} }
func retrieveCalendarEvents() { func retrieveCalendarEvents() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Retrieve Calendar Events")
}
let eventCenter = EventCenter.sharedCenter() let eventCenter = EventCenter.sharedCenter()
if eventCenter.calendarAccessGranted() { if eventCenter.calendarAccessGranted() {
fetchCalendarEvents() fetchCalendarEvents()
} else if eventCenter.calendarAccessNotDetermined() { } else if eventCenter.calendarAccessNotDetermined() {
/* Wait till we get the thumbs up. */ /* Wait till we get the thumbs up. */
return
} else { } else {
removeUpcomingEventView() removeUpcomingEventView()
} }
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Retrieve Calendar Events")
}
} }
@IBAction func shareAction(_ sender: NSButton) { @IBAction func shareAction(_ sender: NSButton) {
@ -713,6 +728,10 @@ class ParentPanelController: NSWindowController {
} }
private func fetchCalendarEvents() { private func fetchCalendarEvents() {
if #available(OSX 10.14, *) {
PerfLogger.startMarker("Fetch Calendar Events")
}
let eventCenter = EventCenter.sharedCenter() let eventCenter = EventCenter.sharedCenter()
let now = Date() let now = Date()
@ -720,6 +739,9 @@ class ParentPanelController: NSWindowController {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
guard let upcomingEvent = eventCenter.nextOccuring(events) else { guard let upcomingEvent = eventCenter.nextOccuring(events) else {
self.setPlaceholdersForUpcomingCalendarView() self.setPlaceholdersForUpcomingCalendarView()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
return return
} }
@ -729,6 +751,9 @@ class ParentPanelController: NSWindowController {
if upcomingEvent.isAllDay == true { if upcomingEvent.isAllDay == true {
let title = events.count == 1 ? "All-Day" : "All Day - Total \(events.count) events today" let title = events.count == 1 ? "All-Day" : "All Day - Total \(events.count) events today"
self.setCalendarButtonTitle(buttonTitle: title) self.setCalendarButtonTitle(buttonTitle: title)
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
return return
} }
@ -737,9 +762,16 @@ class ParentPanelController: NSWindowController {
let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString) let withoutAgo = withoutAn.replacingOccurrences(of: "ago", with: CLEmptyString)
self.setCalendarButtonTitle(buttonTitle: "in \(withoutAgo.lowercased())") self.setCalendarButtonTitle(buttonTitle: "in \(withoutAgo.lowercased())")
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
} }
} else { } else {
setPlaceholdersForUpcomingCalendarView() setPlaceholdersForUpcomingCalendarView()
if #available(OSX 10.14, *) {
PerfLogger.endMarker("Fetch Calendar Events")
}
} }
} }

Loading…
Cancel
Save