Files
harbour-server/qml/pages/CpuPage.qml
T

127 lines
4.2 KiB
QML

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")
}
}
}