opt.: only calc cpu0

This commit is contained in:
lollipopkit
2024-04-09 16:51:00 +08:00
parent 5f701980a4
commit 991d91b636
6 changed files with 68 additions and 71 deletions

View File

@@ -1,7 +1,6 @@
import 'dart:collection';
import 'package:fl_chart/fl_chart.dart';
import 'package:toolbox/data/model/app/range.dart';
import 'package:toolbox/data/model/server/time_seq.dart';
import 'package:toolbox/data/res/status.dart';
@@ -19,7 +18,7 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
_iowait = _getIowait();
_idle = _getIdle();
_updateSpots();
_updateRange();
//_updateRange();
}
double usedPercent({int coreIdx = 0}) {
@@ -68,12 +67,15 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
double _getIdle() => 100 - usedPercent();
void _coresLoop(void Function(int i) callback) {
/// Only update the entire core when [coresCount] > 4, or the chart will be too crowded
final onlyCalcSingle = coresCount > 4;
final maxIdx = onlyCalcSingle ? 1 : coresCount;
for (var i = onlyCalcSingle ? 0 : 1; i < maxIdx; i++) {
callback(i);
}
/// Only update the entire cpu when [coresCount] > 4, or the chart will be too crowded
// final onlyCalcSingle = coresCount > 4;
// final maxIdx = onlyCalcSingle ? 1 : coresCount;
// for (var i = onlyCalcSingle ? 0 : 1; i < maxIdx; i++) {
// callback(i);
// }
/// Only use cpu0
callback(0);
}
/// [core1, core2]
@@ -92,34 +94,34 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
});
}
var _rangeX = Range<double>(0.0, _kCap.toDouble());
Range<double> get rangeX => _rangeX;
// var _rangeY = Range<double>(0.0, 100.0);
// Range<double> get rangeY => _rangeY;
void _updateRange() {
double minX = 0;
double maxX = 0;
_coresLoop((i) {
final fifo = _spots[i];
if (fifo.isEmpty) return;
final first = fifo.first.x;
final last = fifo.last.x;
if (first > minX) minX = first;
if (last > maxX) maxX = last;
});
_rangeX = Range(minX, maxX);
// var _rangeX = Range<double>(0.0, _kCap.toDouble());
// Range<double> get rangeX => _rangeX;
// // var _rangeY = Range<double>(0.0, 100.0);
// // Range<double> get rangeY => _rangeY;
// void _updateRange() {
// double minX = 0;
// double maxX = 0;
// _coresLoop((i) {
// final fifo = _spots[i];
// if (fifo.isEmpty) return;
// final first = fifo.first.x;
// final last = fifo.last.x;
// if (first > minX) minX = first;
// if (last > maxX) maxX = last;
// });
// _rangeX = Range(minX, maxX);
// double? minY, maxY;
// for (var i = 1; i < now.length; i++) {
// final item = _spots[i];
// if (item.isEmpty) continue;
// final first = item.first.y;
// final last = item.last.y;
// if (minY == null || first < minY) minY = first;
// if (maxY == null || last > maxY) maxY = last;
// }
// if (minY != null && maxY != null) _rangeY = Range(minY, maxY);
}
// // double? minY, maxY;
// // for (var i = 1; i < now.length; i++) {
// // final item = _spots[i];
// // if (item.isEmpty) continue;
// // final first = item.first.y;
// // final last = item.last.y;
// // if (minY == null || first < minY) minY = first;
// // if (maxY == null || last > maxY) maxY = last;
// // }
// // if (minY != null && maxY != null) _rangeY = Range(minY, maxY);
// }
}
class SingleCpuCore extends TimeSeqIface<SingleCpuCore> {

View File

@@ -2,9 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 843;
static const int build = 844;
static const String engine = "3.19.5";
static const String buildAt = "2024-04-08 23:44:39";
static const int modifications = 4;
static const String buildAt = "2024-04-09 11:19:03";
static const int modifications = 2;
static const int script = 44;
}

View File

@@ -38,8 +38,7 @@ enum _NetSortType {
}
Widget _buildLineChart(
List<List<FlSpot>> spots,
Range<double> x, {
List<List<FlSpot>> spots, {
String? tooltipPrefix,
bool curve = false,
int verticalInterval = 20,
@@ -69,9 +68,8 @@ Widget _buildLineChart(
horizontalInterval: verticalInterval.toDouble(),
getDrawingHorizontalLine: (value) {
return const FlLine(
color: Color(0xff37434d),
color: Color.fromARGB(43, 88, 91, 94),
strokeWidth: 1,
dashArray: [5, 17],
);
},
),
@@ -89,7 +87,7 @@ Widget _buildLineChart(
leftTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
interval: 1,
interval: 20,
getTitlesWidget: (val, meta) {
if (val % verticalInterval != 0) return UIs.placeholder;
if (val == 0) return const Text('0 %', style: UIs.text12Grey);
@@ -103,8 +101,6 @@ Widget _buildLineChart(
),
),
borderData: FlBorderData(show: false),
minX: x.start,
maxX: x.end,
minY: -1,
maxY: 101,
lineBarsData: spots

View File

@@ -5,7 +5,6 @@ import 'package:provider/provider.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/dialog.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/data/model/app/range.dart';
import 'package:toolbox/data/model/app/server_detail_card.dart';
import 'package:toolbox/data/model/app/shell_func.dart';
import 'package:toolbox/data/model/server/battery.dart';
@@ -199,7 +198,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
width: _media.size.width - 26 - 34,
child: _buildLineChart(
ss.cpu.spots,
ss.cpu.rangeX,
//ss.cpu.rangeX,
tooltipPrefix: 'CPU',
),
),