feat: display cpu model (#477)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-07-23 12:03:10 +08:00
committed by GitHub
parent 41ec46f1d3
commit 87b3b76b0b
4 changed files with 58 additions and 17 deletions

View File

@@ -4,11 +4,14 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:server_box/data/model/server/time_seq.dart';
import 'package:server_box/data/res/status.dart';
/// Capacity of the FIFO queue
const _kCap = 30;
class Cpus extends TimeSeq<List<SingleCpuCore>> {
Cpus(super.init1, super.init2);
final Map<String, int> brand = {};
@override
void onUpdate() {
_coresCount = now.length;
@@ -175,6 +178,22 @@ class SingleCpuCore extends TimeSeqIface<SingleCpuCore> {
}
}
final class CpuBrand {
static Map<String, int> parse(String raw) {
final lines = raw.split('\n');
// {brand: count}
final brands = <String, int>{};
for (var line in lines) {
if (line.contains('model name')) {
final model = line.split(':').last.trim();
final count = brands[model] ?? 0;
brands[model] = count + 1;
}
}
return brands;
}
}
final _bsdCpuPercentReg = RegExp(r'(\d+\.\d+)%');
/// TODO: Change this implementation to parse cpu status on BSD system