summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPascal VITOUX <[email protected]>2017-02-23 13:11:30 +0000
committerDavid Edmundson <[email protected]>2017-02-23 13:11:43 +0000
commit9b2d766b2bb41a6725b585eaa8ca11fc9cf36b36 (patch)
treec9389a01538a2927ee09d5ec4f1be20c45034067
parent8a1d94b6d12560f91c3017ef2f5ec2bf5f0e2d46 (diff)
Add a cache monitor to the System Load Viewer applet
Add a cache monitor to the System Load Viewer applet using 'cache/dirty' and 'cache/writeback' infos from ksysguard 5.9.0 The monitor displays the dirty + writeback amount proportionaly scaled with the maximal amount reached, until the remaining dirty amount goes below a minimal threshold of 10MB. An interesting usecase is to show the real progress of a datas transfer to a slow storage device like a USB drive. REVIEW: 129917
-rw-r--r--applets/systemloadviewer/package/contents/config/main.xml9
-rw-r--r--applets/systemloadviewer/package/contents/ui/ColorSettings.qml26
-rw-r--r--applets/systemloadviewer/package/contents/ui/GeneralSettings.qml8
-rw-r--r--applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml83
4 files changed, 121 insertions, 5 deletions
diff --git a/applets/systemloadviewer/package/contents/config/main.xml b/applets/systemloadviewer/package/contents/config/main.xml
index 6bf16d5..a0f6d01 100644
--- a/applets/systemloadviewer/package/contents/config/main.xml
+++ b/applets/systemloadviewer/package/contents/config/main.xml
@@ -15,6 +15,12 @@
<entry name="memBuffersColor" type="Color">
<default>yellow</default>
</entry>
+ <entry name="cacheDirtyColor" type="Color">
+ <default>blue</default>
+ </entry>
+ <entry name="cacheWritebackColor" type="Color">
+ <default>yellow</default>
+ </entry>
<entry name="swapUsedColor" type="Color">
<default>turquoise</default>
</entry>
@@ -42,6 +48,9 @@
<entry name="swapActivated" type="Bool">
<default>true</default>
</entry>
+ <entry name="cacheActivated" type="Bool">
+ <default>false</default>
+ </entry>
<entry name="setColorsManually" type="Bool">
<default>false</default>
</entry>
diff --git a/applets/systemloadviewer/package/contents/ui/ColorSettings.qml b/applets/systemloadviewer/package/contents/ui/ColorSettings.qml
index b9247aa..ed87eaf 100644
--- a/applets/systemloadviewer/package/contents/ui/ColorSettings.qml
+++ b/applets/systemloadviewer/package/contents/ui/ColorSettings.qml
@@ -33,6 +33,8 @@ Item {
property alias cfg_cpuSysColor: cpuSysColorPicker.chosenColor
property alias cfg_cpuNiceColor: cpuNiceColorPicker.chosenColor
property alias cfg_swapUsedColor: swapUsedColorPicker.chosenColor
+ property alias cfg_cacheDirtyColor: cacheDirtyColorPicker.chosenColor
+ property alias cfg_cacheWritebackColor: cacheWritebackColorPicker.chosenColor
property alias cfg_setColorsManually: setColorsManuallyGroupBox.checked
GroupBox {
@@ -140,6 +142,30 @@ Item {
ColorPicker {
id: swapUsedColorPicker
}
+
+ Label {
+ text: i18n("Cache")
+ Layout.columnSpan: 2
+ font.bold: true
+ }
+
+ Label {
+ text: i18n("Dirty memory:")
+ Layout.alignment: Qt.AlignRight
+ }
+
+ ColorPicker {
+ id: cacheDirtyColorPicker
+ }
+
+ Label {
+ text: i18n("Writeback memory:")
+ Layout.alignment: Qt.AlignRight
+ }
+
+ ColorPicker {
+ id: cacheWritebackColorPicker
+ }
}
}
}
diff --git a/applets/systemloadviewer/package/contents/ui/GeneralSettings.qml b/applets/systemloadviewer/package/contents/ui/GeneralSettings.qml
index f1ab40a..05f275a 100644
--- a/applets/systemloadviewer/package/contents/ui/GeneralSettings.qml
+++ b/applets/systemloadviewer/package/contents/ui/GeneralSettings.qml
@@ -29,6 +29,7 @@ Item {
property alias cfg_cpuAllActivated: cpuAllActivatedCheckBox.checked
property alias cfg_memoryActivated: memoryActivatedCheckBox.checked
property alias cfg_swapActivated: swapActivatedCheckBox.checked
+ property alias cfg_cacheActivated: cacheActivatedCheckBox.checked
property alias cfg_updateInterval: updateIntervalSpinBox.value
property int cfg_monitorType: plasmoid.configuration.monitorType
@@ -55,7 +56,7 @@ Item {
Label {
text: i18n("Show:")
Layout.alignment: Qt.AlignRight
- Layout.rowSpan: 4
+ Layout.rowSpan: 5
anchors.verticalCenter: cpuActivatedCheckBox.verticalCenter
}
@@ -84,6 +85,11 @@ Item {
text: i18n("Swap monitor")
}
+ CheckBox {
+ id: cacheActivatedCheckBox
+ text: i18n("Cache monitor")
+ }
+
Label {
text: i18n("Monitor type:")
Layout.alignment: Qt.AlignRight
diff --git a/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml b/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml
index 5a0bc06..8e4d3a7 100644
--- a/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml
+++ b/applets/systemloadviewer/package/contents/ui/SystemLoadViewer.qml
@@ -57,6 +57,11 @@ Item {
property var swapColors: setColorsManually ? [plasmoid.configuration.swapUsedColor]
: [theme.hightlightColor]
+ property var cacheColors: setColorsManually ? [plasmoid.configuration.cacheDirtyColor,
+ plasmoid.configuration.cacheWritebackColor]
+ : [theme.buttonFocusColor,
+ theme.visitedLinkColor]
+
// Make labels visible first time so that the
// user knows which monitor is which.
implicitWidth: widestLabelWidth()*1.3 * columnCount()
@@ -89,6 +94,9 @@ Item {
if (plasmoid.configuration.memoryActivated) {
wantedWidth += swapColumn.minWidth
}
+ if (plasmoid.configuration.cacheActivated) {
+ wantedWidth += cacheColumn.minWidth
+ }
return wantedWidth
}
@@ -106,6 +114,9 @@ Item {
if (plasmoid.configuration.memoryActivated) {
wantedWidth += swapColumn.minWidth
}
+ if (plasmoid.configuration.cacheActivated) {
+ wantedWidth += cacheColumn.minWidth
+ }
return wantedWidth
}
@@ -140,16 +151,23 @@ Item {
property string swap: "mem/swap/"
property string swapUsed: swap + "used"
property string swapFree: swap + "free"
+ property string cache: "mem/cache/"
+ property string cacheDirty: cache + "dirty"
+ property string cacheWriteback: cache + "writeback"
property var totalCpuLoadProportions: [.0, .0, .0, .0]
property int maxCpuIndex: 0
property var memoryUsageProportions: [.0, .0, .0]
property double swapUsageProportion: .0
+ property var cacheUsageProportions: [.0, .0]
+
+ property double maxCache: 0.0
connectedSources: [niceLoad, userLoad, sysLoad,
ioWait, memFree, memApplication, memBuffers,
memCached, memUsed, swapUsed, swapFree,
- averageClock, totalLoad]
+ averageClock, totalLoad, cacheDirty,
+ cacheWriteback]
onSourceAdded: {
var match = source.match(/^cpu\/cpu(\w+)\//)
@@ -189,6 +207,10 @@ Item {
swapUsageProportion = fitSwapUsage(data.value)
swapUsageProportionChanged()
}
+ else if (sourceName == cacheWriteback) {
+ cacheUsageProportions = fitCacheUsage()
+ cacheUsageProportionsChanged()
+ }
}
interval: 1000 * plasmoid.configuration.updateInterval
}
@@ -230,11 +252,15 @@ Item {
var swapTotal = swapFree + swapUsed
var swapPart = i18n("Swap: %1/%2 MiB", Math.round(swapUsed), Math.round(swapTotal))
+ var cacheDirty = parseFloat(dataSource.data[dataSource.cacheDirty].value) / 1024
+ var cacheWriteback = parseFloat(dataSource.data[dataSource.cacheWriteback].value) / 1024
+ var cachePart = i18n("Cache Dirty, Writeback: %1 MiB, %2 MiB", Math.round(cacheDirty), Math.round(cacheWriteback))
+
if (cpuClockPart === "") {
- return [cpuLoadPart, memoryPart, swapPart].join("\n")
+ return [cpuLoadPart, memoryPart, swapPart, cachePart].join("\n")
}
- return [cpuLoadPart, cpuClockPart, memoryPart, swapPart].join("\n")
+ return [cpuLoadPart, cpuClockPart, memoryPart, swapPart, cachePart].join("\n")
}
function fitCpuLoad(load) {
@@ -257,11 +283,37 @@ Item {
return Math.min(x, 1);
}
+ function fitCacheUsage() {
+ var values = [ parseFloat(dataSource.data[dataSource.cacheDirty].value),
+ parseFloat(dataSource.data[dataSource.cacheWriteback].value) ];
+ var total = values[0] + values[1];
+ var props = [.0, .0];
+
+ // hide the persistent small amount of dirty cache (10M seems a good threshold)
+ if ( total < 10000 ) {
+ dataSource.maxCache = 0;
+ return props;
+ }
+
+ if (total > dataSource.maxCache) {
+ dataSource.maxCache = total;
+ }
+
+ for (var i = 0; i < values.length; i++) {
+ props[i] = values[i] / dataSource.maxCache;
+ if (isNaN(props[i])) { props[i] = 0; }
+ else { props[i] = Math.min(props[i], 0.99); }
+ }
+
+ return props;
+ }
+
function columnCount() {
var columns = 0;
var activeMonitors = [plasmoid.configuration.cpuActivated,
plasmoid.configuration.memoryActivated,
- plasmoid.configuration.swapActivated]
+ plasmoid.configuration.swapActivated,
+ plasmoid.configuration.cacheActivated]
for (var i = 0; i < activeMonitors.length; i++) {
if (activeMonitors[i]) {
@@ -291,6 +343,9 @@ Item {
if (plasmoid.configuration.swapActivated) {
widest = Math.max(widest, swapLabel.paintedWidth)
}
+ if (plasmoid.configuration.cacheActivated) {
+ widest = Math.max(widest, cacheLabel.paintedWidth)
+ }
return widest
}
@@ -465,5 +520,25 @@ Item {
proportions: [dataSource.swapUsageProportion]
}
}
+
+ ColumnLayout {
+ id: cacheColumn
+ property double minWidth: memColumn.minWidth
+ visible: plasmoid.configuration.cacheActivated
+ Layout.minimumWidth: minWidth
+ Layout.preferredWidth: height
+
+ PlasmaExtras.Heading {
+ id: cacheLabel
+ level: main.headingLevel
+ text: i18n("Cache")
+ visible: main.labelsVisible
+ }
+
+ ConditionallyLoadedMonitors {
+ colors: cacheColors
+ proportions: dataSource.cacheUsageProportions
+ }
+ }
} // rowLayout
} // main