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. 28
      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"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "ENABLE_PERF_LOGGING"
value = "NO"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>

28
Clocker/Overall App/Logger.swift

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

42
Clocker/Panel/PanelController.swift

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

34
Clocker/Panel/ParentPanelController.swift

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

Loading…
Cancel
Save