0.2.0: card Memoria toccabile con dettaglio RAM per servizio/container
This commit is contained in:
1 parent
99aba8fa03
commit
714c4d5189
8 files changed
+237
-10
No files matched your search
@@ -0,0 +1,120 @@
|
||||
import QtQuick 2.0
|
||||
import Sailfish.Silica 1.0
|
||||
|
||||
// Dettaglio della card Memoria: chi occupa la RAM, dal più grande.
|
||||
// La fonte è la memoria ANONIMA dei cgroup: con hidepid=invisible i processi
|
||||
// degli altri utenti non sono leggibili da /proc, quindi l'unità di misura è
|
||||
// il servizio o il contenitore, non il singolo PID.
|
||||
Page {
|
||||
id: page
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
function list() {
|
||||
var d = statusClient.data
|
||||
if (!d || !d.memory || !d.memory.consumers) return []
|
||||
return d.memory.consumers
|
||||
}
|
||||
function totalBytes() {
|
||||
var d = statusClient.data
|
||||
return (d && d.memory && d.memory.total_bytes) ? d.memory.total_bytes : 0
|
||||
}
|
||||
function maxBytes() {
|
||||
var l = list()
|
||||
return (l.length > 0 && l[0].bytes > 0) ? l[0].bytes : 1
|
||||
}
|
||||
function sharePct(bytes) {
|
||||
var t = totalBytes()
|
||||
return t > 0 ? bytes / t * 100 : 0
|
||||
}
|
||||
function usedText() {
|
||||
var d = statusClient.data
|
||||
if (!d || !d.memory) return ""
|
||||
return qsTr("usata ") + statusClient.fmtNum(d.memory.percent, 0) + "% · "
|
||||
+ qsTr("su ") + statusClient.fmtBytes(d.memory.total_bytes)
|
||||
}
|
||||
|
||||
SilicaListView {
|
||||
id: view
|
||||
anchors.fill: parent
|
||||
model: page.list()
|
||||
|
||||
header: Column {
|
||||
width: view.width
|
||||
spacing: Theme.paddingSmall
|
||||
|
||||
PageHeader { title: qsTr("Memoria") }
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
text: page.usedText()
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
width: parent.width - 2 * Theme.paddingLarge
|
||||
text: qsTr("Memoria anonima per servizio e contenitore, ordinata dal più grande.")
|
||||
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.50
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
truncationMode: TruncationMode.Fade
|
||||
}
|
||||
|
||||
Label {
|
||||
text: statusClient.fmtBytes(modelData.bytes)
|
||||
width: parent.width * 0.32
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
|
||||
Label {
|
||||
text: statusClient.fmtNum(page.sharePct(modelData.bytes), 1) + "%"
|
||||
width: parent.width * 0.18
|
||||
horizontalAlignment: Text.AlignRight
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
color: Theme.secondaryColor
|
||||
}
|
||||
}
|
||||
|
||||
// Barra relativa al primo della lista: serve a confrontare le
|
||||
// grandezze fra loro, mentre la percentuale è sul totale della RAM.
|
||||
Rectangle {
|
||||
width: parent.width * Math.max(2, Math.min(100, modelData.bytes / page.maxBytes() * 100)) / 100
|
||||
height: 3
|
||||
radius: 1.5
|
||||
color: Theme.rgba(Theme.highlightColor, 0.5)
|
||||
}
|
||||
}
|
||||
|
||||
footer: Item {
|
||||
width: view.width
|
||||
height: Theme.paddingLarge * 2
|
||||
}
|
||||
|
||||
ViewPlaceholder {
|
||||
enabled: page.list().length === 0
|
||||
text: qsTr("Nessun dato")
|
||||
hintText: qsTr("Lo snapshot del server non è ancora arrivato")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,6 +225,8 @@ Page {
|
||||
detail: memText() + " · swap " + statusClient.fmtNum(swapPercent(), 0) + " %"
|
||||
progress: memPercent()
|
||||
level: Math.max(levelFor(memPercent(), 85, 95), levelFor(swapPercent(), 80, 95))
|
||||
interactive: true
|
||||
onClicked: pageStack.push(Qt.resolvedUrl("ProcessPage.qml"))
|
||||
}
|
||||
|
||||
MetricCard {
|
||||
|
||||
Reference in new issue
Block a user