feat: adds gpu usages stat in the toolbar (#36)

* feat: adds gpu usages stat in the toolbar
This commit is contained in:
Ashraful Islam
2024-03-25 23:29:54 +06:00
committed by GitHub
parent 452b49aef0
commit c37018d7d2
4 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
import Foundation
import LLM
import MLX
@Observable
class DeviceStat {
var gpuUsage = GPU.snapshot()
private var initialGPUSnapshot = GPU.snapshot()
private var timer: Timer?
init() {
startTimer()
}
deinit {
stopTimer()
}
private func startTimer() {
timer?.invalidate()
timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { [weak self] _ in
self?.updateStats()
}
}
private func stopTimer() {
timer?.invalidate()
timer = nil
}
private func updateStats() {
updateGPUUsages()
}
private func updateGPUUsages() {
let gpuSnapshotDelta = initialGPUSnapshot.delta(GPU.snapshot())
DispatchQueue.main.async { [weak self] in
self?.gpuUsage = gpuSnapshotDelta
}
}
}