mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-16 23:04:22 +01:00
fix: gpu parse
This commit is contained in:
@@ -9,6 +9,14 @@
|
||||
# packages, and plugins designed to encourage good coding practices.
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- '**/*.g.dart'
|
||||
language:
|
||||
# strict-casts: true
|
||||
# strict-inference: true
|
||||
# strict-raw-types: true
|
||||
|
||||
linter:
|
||||
# The lint rules applied to this project can be customized in the
|
||||
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
|
||||
|
||||
@@ -2,10 +2,9 @@ import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
import 'package:toolbox/data/model/app/version_related.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
|
||||
enum ServerDetailCards implements VersionRelated {
|
||||
enum ServerDetailCards {
|
||||
about(Icons.info),
|
||||
cpu(Icons.memory),
|
||||
mem(Bootstrap.memory),
|
||||
@@ -20,7 +19,6 @@ enum ServerDetailCards implements VersionRelated {
|
||||
custom(Icons.code, sinceBuild: 825),
|
||||
;
|
||||
|
||||
@override
|
||||
final int? sinceBuild;
|
||||
|
||||
final IconData icon;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'package:toolbox/data/model/app/server_detail_card.dart';
|
||||
|
||||
abstract interface class VersionRelated {
|
||||
int? get sinceBuild;
|
||||
|
||||
static final funcs = <void Function(int cur)>[
|
||||
ServerDetailCards.autoAddNewCards,
|
||||
];
|
||||
}
|
||||
@@ -56,11 +56,9 @@ class NvidiaSmi {
|
||||
process?.findElements('used_memory').firstOrNull?.innerText;
|
||||
if (pid != null && name != null && memory != null) {
|
||||
return NvidiaSmiMemProcess(
|
||||
int.parse(pid),
|
||||
int.tryParse(pid) ?? 0,
|
||||
name,
|
||||
int.parse(
|
||||
memory.split(' ').firstOrNull ?? '0',
|
||||
),
|
||||
int.tryParse(memory.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
@@ -81,16 +79,16 @@ class NvidiaSmi {
|
||||
return NvidiaSmiItem(
|
||||
name: name,
|
||||
uuid: gpu.findElements('uuid').firstOrNull?.innerText ?? '',
|
||||
temp: int.parse(temp.split(' ').firstOrNull ?? '0'),
|
||||
percent: int.parse(percent?.split(' ').firstOrNull ?? '0'),
|
||||
temp: int.tryParse(temp.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
percent: int.tryParse(percent?.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
power: '$powerDraw / $powerLimit',
|
||||
memory: NvidiaSmiMem(
|
||||
int.parse(memoryTotal?.split(' ').firstOrNull ?? '0'),
|
||||
int.parse(memoryUsed?.split(' ').firstOrNull ?? '0'),
|
||||
int.tryParse(memoryTotal?.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
int.tryParse(memoryUsed?.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
'MiB',
|
||||
List.from(memoryProcesses),
|
||||
),
|
||||
fanSpeed: int.parse(fanSpeed?.split(' ').firstOrNull ?? '0'),
|
||||
fanSpeed: int.tryParse(fanSpeed?.split(' ').firstOrNull ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -15,7 +15,7 @@ import 'package:toolbox/core/utils/sync/icloud.dart';
|
||||
import 'package:toolbox/core/utils/sync/webdav.dart';
|
||||
import 'package:toolbox/data/model/app/menu/server_func.dart';
|
||||
import 'package:toolbox/data/model/app/net_view.dart';
|
||||
import 'package:toolbox/data/model/app/version_related.dart';
|
||||
import 'package:toolbox/data/model/app/server_detail_card.dart';
|
||||
import 'package:toolbox/data/model/server/custom.dart';
|
||||
import 'package:toolbox/data/model/server/private_key_info.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
@@ -131,12 +131,15 @@ void _setupDebug() {
|
||||
}
|
||||
}
|
||||
|
||||
// It may contains some async heavy funcs.
|
||||
Future<void> _doVersionRelated() async {
|
||||
final curVer = Stores.setting.lastVer.fetch();
|
||||
const newVer = BuildData.build;
|
||||
// It's only the version upgrade trigger logic.
|
||||
// How to upgrade the data is inside each own func.
|
||||
if (curVer < newVer) {
|
||||
/// Call [Iterable.toList] to consume the lazy iterable.
|
||||
VersionRelated.funcs.map((e) => e(newVer)).toList();
|
||||
// DO version check inside each func.
|
||||
ServerDetailCards.autoAddNewCards(newVer);
|
||||
Stores.setting.lastVer.put(newVer);
|
||||
}
|
||||
}
|
||||
|
||||
3276
test/nvidia.txt
Normal file
3276
test/nvidia.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:toolbox/data/model/server/nvdia.dart';
|
||||
|
||||
@@ -860,4 +862,10 @@ void main() {
|
||||
expect(processes[2].pid, 16484);
|
||||
expect(processes[2].memory, 76);
|
||||
});
|
||||
|
||||
test('nvidia-smi with N/A', () async {
|
||||
final raw = await File('test/nvidia.txt').readAsString();
|
||||
final items = NvidiaSmi.fromXml(raw);
|
||||
expect(items.length, 4);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user