feat: added Apple Graphics to the GPU module (#260)

This commit is contained in:
Serhiy Mytrovtsiy
2020-12-31 11:57:25 +01:00
parent e33082f0ca
commit fb08e621ab
2 changed files with 22 additions and 19 deletions

View File

@@ -26,7 +26,7 @@ public struct GPU_Info {
public let model: String
public let IOClass: String
public let type: GPU_type
public var state: Bool = false
public var state: Bool = true
public var utilization: Double = 0
public var temperature: Int = 0

View File

@@ -81,15 +81,33 @@ internal class InfoReader: Reader<GPUs> {
var predictModel = ""
var type: GPU_types = .unknown
if ioClass == "nvAccelerator" || ioClass.contains("nvidia") {
let utilization = stats["Device Utilization %"] as? Int ?? stats["GPU Activity(%)"] as? Int ?? 0
var temperature = stats["Temperature(C)"] as? Int ?? 0
if ioClass == "nvAccelerator" || ioClass.contains("nvidia") { // nvidia
predictModel = "Nvidia Graphics"
type = .discrete
} else if ioClass.contains("amd") {
} else if ioClass.contains("amd") { // amd
predictModel = "AMD Graphics"
type = .discrete
} else if ioClass.contains("intel") {
if temperature == 0 {
if let tmp = self.smc?.pointee.getValue("TGDD") {
temperature = Int(tmp)
}
}
} else if ioClass.contains("intel") { // intel
predictModel = "Intel Graphics"
type = .integrated
if temperature == 0 {
if let tmp = self.smc?.pointee.getValue("TCGC") {
temperature = Int(tmp)
}
}
} else if ioClass.contains("AGX") { // apple
predictModel = stats["model"] as? String ?? "Apple Graphics"
type = .integrated
} else {
predictModel = "Unknown"
type = .unknown
@@ -106,21 +124,6 @@ internal class InfoReader: Reader<GPUs> {
return
}
let utilization = stats["Device Utilization %"] as? Int ?? stats["GPU Activity(%)"] as? Int ?? 0
var temperature = stats["Temperature(C)"] as? Int ?? 0
if temperature == 0 {
if IOClass == "IntelAccelerator" {
if let tmp = self.smc?.pointee.getValue("TCGC") {
temperature = Int(tmp)
}
} else if IOClass.starts(with: "AMDRadeon") {
if let tmp = self.smc?.pointee.getValue("TGDD") {
temperature = Int(tmp)
}
}
}
if let agcInfo = accelerator["AGCInfo"] as? [String:Int] {
self.gpus.list[idx].state = agcInfo["poweredOffByAGC"] == 0
}