-
-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac94b33
commit 05de760
Showing
11 changed files
with
1,126 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'package:xml/xml.dart'; | ||
|
||
/// [ | ||
/// { | ||
/// "name": "GeForce RTX 3090", | ||
/// "temp": 40, | ||
/// "power": "30W / 350W", | ||
/// "memory": { | ||
/// "total": 24268, | ||
/// "used": 240, | ||
/// "unit": "MiB", | ||
/// "processes": [ | ||
/// { | ||
/// "pid": 1456, | ||
/// "name": "/usr/lib/xorg/Xorg", | ||
/// "memory": 40 | ||
/// }, | ||
/// ] | ||
/// }, | ||
/// } | ||
/// ] | ||
/// | ||
class NvdiaSmi { | ||
static List<NvdiaSmiItem> fromXml(String raw) { | ||
final xmlData = XmlDocument.parse(raw); | ||
final gpus = xmlData.findAllElements('gpu'); | ||
final result = List<NvdiaSmiItem?>.generate(gpus.length, (index) { | ||
final gpu = gpus.elementAt(index); | ||
final name = gpu.findElements('product_name').firstOrNull?.innerText; | ||
final temp = gpu | ||
.findElements('temperature') | ||
.firstOrNull | ||
?.findElements('gpu_temp') | ||
.firstOrNull | ||
?.innerText; | ||
final power = gpu.findElements('gpu_power_readings').firstOrNull; | ||
final powerDraw = | ||
power?.findElements('power_draw').firstOrNull?.innerText; | ||
final powerLimit = | ||
power?.findElements('current_power_limit').firstOrNull?.innerText; | ||
final memory = gpu.findElements('fb_memory_usage').firstOrNull; | ||
final memoryUsed = memory?.findElements('used').firstOrNull?.innerText; | ||
final memoryTotal = memory?.findElements('total').firstOrNull?.innerText; | ||
final processes = gpu | ||
.findElements('processes') | ||
.firstOrNull | ||
?.findElements('process_info'); | ||
final memoryProcesses = | ||
List<NvdiaSmiMemProcess?>.generate(processes?.length ?? 0, (index) { | ||
final process = processes?.elementAt(index); | ||
final pid = process?.findElements('pid').firstOrNull?.innerText; | ||
final name = | ||
process?.findElements('process_name').firstOrNull?.innerText; | ||
final memory = | ||
process?.findElements('used_memory').firstOrNull?.innerText; | ||
if (pid != null && name != null && memory != null) { | ||
return NvdiaSmiMemProcess( | ||
int.parse(pid), | ||
name, | ||
int.parse( | ||
memory.split(' ').firstOrNull ?? '0', | ||
), | ||
); | ||
} | ||
return null; | ||
}); | ||
memoryProcesses.removeWhere((element) => element == null); | ||
if (name != null && | ||
temp != null && | ||
powerDraw != null && | ||
powerLimit != null && | ||
memory != null) { | ||
return NvdiaSmiItem( | ||
name, | ||
int.parse(temp.split(' ').firstOrNull ?? '0'), | ||
'$powerDraw / $powerLimit', | ||
NvdiaSmiMem( | ||
int.parse(memoryTotal?.split(' ').firstOrNull ?? '0'), | ||
int.parse(memoryUsed?.split(' ').firstOrNull ?? '0'), | ||
'MiB', | ||
List.from(memoryProcesses), | ||
), | ||
); | ||
} | ||
return null; | ||
}); | ||
result.removeWhere((element) => element == null); | ||
return List.from(result); | ||
} | ||
} | ||
|
||
class NvdiaSmiItem { | ||
final String name; | ||
final int temp; | ||
final String power; | ||
final NvdiaSmiMem memory; | ||
|
||
const NvdiaSmiItem(this.name, this.temp, this.power, this.memory); | ||
|
||
@override | ||
String toString() { | ||
return 'NvdiaSmiItem{name: $name, temp: $temp, power: $power, memory: $memory}'; | ||
} | ||
} | ||
|
||
class NvdiaSmiMem { | ||
final int total; | ||
final int used; | ||
final String unit; | ||
final List<NvdiaSmiMemProcess> processes; | ||
|
||
const NvdiaSmiMem(this.total, this.used, this.unit, this.processes); | ||
|
||
@override | ||
String toString() { | ||
return 'NvdiaSmiMem{total: $total, used: $used, unit: $unit, processes: $processes}'; | ||
} | ||
} | ||
|
||
class NvdiaSmiMemProcess { | ||
final int pid; | ||
final String name; | ||
final int memory; | ||
|
||
const NvdiaSmiMemProcess(this.pid, this.name, this.memory); | ||
|
||
@override | ||
String toString() { | ||
return 'NvdiaSmiMemProcess{pid: $pid, name: $name, memory: $memory}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ class Defaults { | |
'cpu', | ||
'mem', | ||
'swap', | ||
'gpu', | ||
'disk', | ||
'net', | ||
'temp' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.