#43 new: bsd base support

This commit is contained in:
lollipopkit
2023-08-22 21:07:17 +08:00
parent e3f2b211a9
commit 417cb4c89d
23 changed files with 499 additions and 234 deletions

View File

@@ -1,3 +1,5 @@
import 'package:toolbox/data/res/status.dart';
import 'time_seq.dart';
class Cpus extends TimeSeq<OneTimeCpuStatus> {
@@ -95,3 +97,22 @@ List<OneTimeCpuStatus> parseCPU(String raw) {
}
return cpus;
}
final _bsdCpuPercentReg = RegExp(r'(\d+\.\d+)%');
/// TODO: Change this implementation to parse cpu status on BSD system
///
/// [raw]:
/// CPU usage: 14.70% user, 12.76% sys, 72.52% idle
Cpus parseBsdCpu(String raw) {
final percents = _bsdCpuPercentReg
.allMatches(raw)
.map((e) => double.parse(e.group(1) ?? '0') * 100)
.toList();
if (percents.length != 3) return initCpuStatus;
return initCpuStatus
..now = [
OneTimeCpuStatus('cpu', percents[0].toInt(), percents[1].toInt(), 0,
percents[2].toInt(), 0, 0, 0)
];
}