0.3.0: card CPU toccabile con dettaglio per servizio/container
This commit is contained in:
1 parent
227c423d73
commit
70f7ac4bd2
7 files changed
+313
-46
No files matched your search
@@ -0,0 +1,126 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
// Dettaglio della card CPU: chi consuma processore, dal più affamato.
|
||||
// Come per la memoria, con hidepid=invisible il singolo PID degli altri utenti
|
||||
// non è leggibile da /proc: l'unità è il servizio o il contenitore, misurata
|
||||
// sul tempo di CPU dei cgroup v2.
|
||||
Page {
|
||||
id: page
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
function list() {
|
||||
var d = statusClient.data
|
||||
if (!d || !d.cpu || !d.cpu.consumers) return []
|
||||
return d.cpu.consumers
|
||||
}
|
||||
function maxPercent() {
|
||||
var l = list()
|
||||
return (l.length > 0 && l[0].percent > 0) ? l[0].percent : 1
|
||||
}
|
||||
function cores() {
|
||||
var d = statusClient.data
|
||||
return (d && d.cpu && d.cpu.cores) ? d.cpu.cores : 0
|
||||
}
|
||||
function headText() {
|
||||
var d = statusClient.data
|
||||
if (!d || !d.cpu) return ""
|
||||
var text = qsTr("adesso ") + statusClient.fmtNum(d.cpu.percent, 0) + "%"
|
||||
if (d.cpu.temp_c !== null && d.cpu.temp_c !== undefined)
|
||||
text += " · " + statusClient.fmtNum(d.cpu.temp_c, 0) + " °C"
|
||||
return text
|
||||
}
|
||||
function noteText() {
|
||||
var n = cores()
|
||||
if (n < 1) return qsTr("Percentuale sulla capacità totale del sistema, non sul singolo core.")
|
||||
return qsTr("Percentuale sulla capacità totale (") + n
|
||||
+ (n === 1 ? qsTr(" core), non sul singolo core.")
|
||||
: qsTr(" core), non sul singolo core."))
|
||||
}
|
||||
|
||||
SilicaListView {
|
||||
id: view
|
||||
anchors.fill: parent
|
||||
model: page.list()
|
||||
|
||||
header: Column {
|
||||
width: view.width
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
PageHeader { title: qsTr("CPU") }
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
text: page.headText()
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
text: page.noteText()
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
Item { width: 1; height: Theme.paddingSmall }
|
||||
}
|
||||
|
||||
delegate: Column {
|
||||
x: Theme.paddingLarge
|
||||
width: view.width - 2 * Theme.paddingLarge
|
||||
spacing: Theme.paddingSmall / 2
|
||||
|
||||
Row {
|
||||
width: parent.width
|
||||
|
||||
Label {
|
||||
text: modelData.name + (modelData.kind === "container" ? qsTr(" · contenitore") : "")
|
||||
width: parent.width * 0.68
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
text: statusClient.fmtNum(modelData.percent, 1) + "%"
|
||||
width: parent.width * 0.32
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: parent.width * Math.max(2, Math.min(100, modelData.percent / page.maxPercent() * 100)) / 100
|
||||
height: 3
|
||||
radius: 1.5
|
||||
color: Theme.rgba(Theme.highlightColor, 0.5)
|
||||
}
|
||||
}
|
||||
|
||||
footer: Column {
|
||||
width: view.width
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
text: qsTr("Media della finestra di campionamento (circa un minuto). Le voci sotto lo 0,5% non sono elencate.")
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
Item { width: 1; height: Theme.paddingLarge }
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: page.list().length === 0
|
||||
text: qsTr("Nessun dato")
|
||||
hintText: qsTr("Serve una seconda lettura del server per calcolare la percentuale")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,12 @@ Page {
|
||||
function cpuPct() { var d = statusClient.data; return (d && d.cpu && d.cpu.percent !== undefined) ? d.cpu.percent : -1 }
|
||||
function cpuTemp() { var d = statusClient.data; return (d && d.cpu && d.cpu.temp_c !== undefined) ? d.cpu.temp_c : -1 }
|
||||
function cpuCores() { var d = statusClient.data; return (d && d.cpu && d.cpu.cores !== undefined) ? d.cpu.cores : 0 }
|
||||
function cpuDetail() {
|
||||
var parts = []
|
||||
if (cpuTemp() >= 0) parts.push(statusClient.fmtNum(cpuTemp(), 0) + " °C")
|
||||
if (cpuCores() > 0) parts.push(cpuCores() + qsTr(" core"))
|
||||
return parts.join(" · ")
|
||||
}
|
||||
function memPercent() { var d = statusClient.data; return (d && d.memory && d.memory.percent !== undefined) ? d.memory.percent : -1 }
|
||||
function memText() {
|
||||
var d = statusClient.data
|
||||
@@ -212,9 +218,11 @@ Page {
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
title: qsTr("CPU")
|
||||
value: cpuPct() < 0 ? "—" : statusClient.fmtNum(cpuPct(), 0) + " %"
|
||||
detail: (cpuTemp() >= 0 ? statusClient.fmtNum(cpuTemp(), 0) + " °C · " : "") + cpuCores() + " core"
|
||||
detail: cpuDetail()
|
||||
progress: cpuPct()
|
||||
level: levelFor(cpuPct(), 85, 95)
|
||||
interactive: true
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("CpuPage.qml"))
|
||||
}
|
||||
|
||||
MetricCard {
|
||||
|
||||
Reference in new issue
Block a user