feat: moved from JSON objects of metrics to simplified strings for the Stats Remote

This commit is contained in:
Serhiy Mytrovtsiy
2025-04-05 22:54:01 +02:00
parent d2688a35b2
commit f524f86429
8 changed files with 98 additions and 44 deletions

View File

@@ -52,9 +52,17 @@ public struct GPU_Info: Codable {
self.renderUtilization = render
self.tilerUtilization = tiler
}
public func remote() -> String {
var id = self.id
if self.id.isEmpty {
id = "0"
}
return "\(id),1,\(self.utilization ?? 0),\(self.renderUtilization ?? 0),\(self.tilerUtilization ?? 0),,"
}
}
public class GPUs: Codable {
public class GPUs: Codable, RemoteType {
private var queue: DispatchQueue = DispatchQueue(label: "eu.exelban.Stats.GPU.SynchronizedArray")
private var _list: [GPU_Info] = []
@@ -82,6 +90,18 @@ public class GPUs: Codable {
internal func active() -> [GPU_Info] {
return self.list.filter{ $0.state && $0.utilization != nil }.sorted{ $0.utilization ?? 0 > $1.utilization ?? 0 }
}
public func remote() -> Data? {
var string = "\(self.list.count),"
for (i, v) in self.list.enumerated() {
string += v.remote()
if i != self.list.count {
string += ","
}
}
string += "$"
return string.data(using: .utf8)
}
}
public class GPU: Module {