From d2efc1f264791f1ac0f7a696ca2745f8033accd8 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Tue, 24 Aug 2021 21:38:14 +0200 Subject: [PATCH] feat: added CPU scheduler and speed limits to the popup (#540) --- Modules/CPU/main.swift | 13 ++++++++---- Modules/CPU/popup.swift | 46 ++++++++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Modules/CPU/main.swift b/Modules/CPU/main.swift index 129c828f..5a3eca1d 100644 --- a/Modules/CPU/main.swift +++ b/Modules/CPU/main.swift @@ -106,13 +106,18 @@ public class CPU: Module { } self.temperatureReader?.callbackHandler = { [unowned self] value in - if value != nil { - self.popupView.temperatureCallback(value!) + if let v = value { + self.popupView.temperatureCallback(v) } } self.frequencyReader?.callbackHandler = { [unowned self] value in - if value != nil { - self.popupView.frequencyCallback(value!) + if let v = value { + self.popupView.frequencyCallback(v) + } + } + self.limitReader?.callbackHandler = { [unowned self] value in + if let v = value { + self.popupView.limitCallback(v) } } diff --git a/Modules/CPU/popup.swift b/Modules/CPU/popup.swift index b7120132..6966678b 100644 --- a/Modules/CPU/popup.swift +++ b/Modules/CPU/popup.swift @@ -19,14 +19,14 @@ internal class Popup: NSView, Popup_p { private let dashboardHeight: CGFloat = 90 private let chartHeight: CGFloat = 90 + Constants.Popup.separatorHeight - private let detailsHeight: CGFloat = (22*3) + Constants.Popup.separatorHeight + private let detailsHeight: CGFloat = (22*5) + Constants.Popup.separatorHeight private let processHeight: CGFloat = 22 - private var loadField: NSTextField? = nil - private var systemField: NSTextField? = nil private var userField: NSTextField? = nil private var idleField: NSTextField? = nil + private var shedulerLimitField: NSTextField? = nil + private var speedLimitField: NSTextField? = nil private var chart: LineChartView? = nil private var circle: PieChartView? = nil @@ -36,6 +36,7 @@ internal class Popup: NSView, Popup_p { private var initializedTemperature: Bool = false private var initializedFrequency: Bool = false private var initializedProcesses: Bool = false + private var initializedLimits: Bool = false private var processes: [ProcessView] = [] private var maxFreq: Double = 0 @@ -164,9 +165,11 @@ internal class Popup: NSView, Popup_p { let separator = separatorView(localizedString("Details"), origin: NSPoint(x: 0, y: self.detailsHeight-Constants.Popup.separatorHeight), width: self.frame.width) let container: NSView = NSView(frame: NSRect(x: 0, y: 0, width: self.frame.width, height: separator.frame.origin.y)) - self.systemField = popupWithColorRow(container, color: NSColor.systemRed, n: 2, title: "\(localizedString("System")):", value: "") - self.userField = popupWithColorRow(container, color: NSColor.systemBlue, n: 1, title: "\(localizedString("User")):", value: "") - self.idleField = popupWithColorRow(container, color: NSColor.lightGray.withAlphaComponent(0.5), n: 0, title: "\(localizedString("Idle")):", value: "") + self.systemField = popupWithColorRow(container, color: NSColor.systemRed, n: 4, title: "\(localizedString("System")):", value: "") + self.userField = popupWithColorRow(container, color: NSColor.systemBlue, n: 3, title: "\(localizedString("User")):", value: "") + self.idleField = popupWithColorRow(container, color: NSColor.lightGray.withAlphaComponent(0.5), n: 2, title: "\(localizedString("Idle")):", value: "") + self.shedulerLimitField = popupRow(container, n: 1, title: "\(localizedString("Scheduler limit")):", value: "").1 + self.speedLimitField = popupRow(container, n: 0, title: "\(localizedString("Speed limit")):", value: "").1 view.addSubview(separator) view.addSubview(container) @@ -196,19 +199,17 @@ internal class Popup: NSView, Popup_p { public func loadCallback(_ value: CPU_Load) { DispatchQueue.main.async(execute: { if (self.window?.isVisible ?? false) || !self.initialized { - self.systemField?.stringValue = "\(Int(value.systemLoad.rounded(toPlaces: 2) * 100)) %" - self.userField?.stringValue = "\(Int(value.userLoad.rounded(toPlaces: 2) * 100)) %" - self.idleField?.stringValue = "\(Int(value.idleLoad.rounded(toPlaces: 2) * 100)) %" - - let v = Int(value.totalUsage.rounded(toPlaces: 2) * 100) - self.loadField?.stringValue = "\(v) %" - self.initialized = true + self.systemField?.stringValue = "\(Int(value.systemLoad.rounded(toPlaces: 2) * 100))%" + self.userField?.stringValue = "\(Int(value.userLoad.rounded(toPlaces: 2) * 100))%" + self.idleField?.stringValue = "\(Int(value.idleLoad.rounded(toPlaces: 2) * 100))%" self.circle?.setValue(value.totalUsage) self.circle?.setSegments([ circle_segment(value: value.systemLoad, color: NSColor.systemRed), circle_segment(value: value.userLoad, color: NSColor.systemBlue) ]) + + self.initialized = true } self.chart?.addValue(value.totalUsage) }) @@ -262,16 +263,27 @@ internal class Popup: NSView, Popup_p { } for i in 0..