Skip to content

Commit

Permalink
perf: direct assign sensors to sensors model
Browse files Browse the repository at this point in the history
  • Loading branch information
orblazer committed May 1, 2023
1 parent 9d315c3 commit 495aab2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package/contents/ui/components/graph/CpuGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RMBaseGraph.SensorGraph {
property color temperatureColor: Plasmoid.configuration.customCpuTemperatureColor ? Plasmoid.configuration.cpuTemperatureColor : theme.textColor

// Graph options
// NOTE: "sensors" is set by "_updateSensors"
// NOTE: "sensorsModel.sensors" is set by "_updateSensors"
chartColor: Plasmoid.configuration.customCpuColor ? Plasmoid.configuration.cpuColor : theme.highlightColor

chart.yRange {
Expand All @@ -39,6 +39,6 @@ RMBaseGraph.SensorGraph {
}

function _updateSensors() {
sensors = ["cpu/all/" + Plasmoid.configuration.cpuUnit, "cpu/all/averageFrequency", "cpu/all/averageTemperature"];
sensorsModel.sensors = ["cpu/all/" + Plasmoid.configuration.cpuUnit, "cpu/all/averageFrequency", "cpu/all/averageTemperature"];
}
}
2 changes: 1 addition & 1 deletion package/contents/ui/components/graph/DisksGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RMBaseGraph.TwoSensorsGraph {
}

// Graph options
sensors: ["disk/all/read", "disk/all/write"]
sensorsModel.sensors: ["disk/all/read", "disk/all/write"]
colors: [(Plasmoid.configuration.customDiskReadColor ? Plasmoid.configuration.diskReadColor : theme.highlightColor), (Plasmoid.configuration.customDiskWriteColor ? Plasmoid.configuration.diskWriteColor : theme.positiveTextColor)]

function _updateUplimits() {
Expand Down
6 changes: 3 additions & 3 deletions package/contents/ui/components/graph/GpuGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ RMBaseGraph.TwoSensorsGraph {
}

// Graph options
// NOTE: "sensors" set from "maxQueryModel"
// NOTE: "sensorsModel.sensors" set from "maxQueryModel"
colors: [(Plasmoid.configuration.customGpuColor ? Plasmoid.configuration.gpuColor : theme.highlightColor), (Plasmoid.configuration.customGpuMemoryColor ? Plasmoid.configuration.gpuMemoryColor : theme.positiveTextColor)]

// Override methods, for handle memeory in percent
_update: () => {
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
let value = sensorsModel.getInfo(i);
if (i === 1 && Plasmoid.configuration.gpuMemoryInPercent) {
value = value / uplimits[1];
Expand Down Expand Up @@ -73,7 +73,7 @@ RMBaseGraph.TwoSensorsGraph {
if (maxMemory >= 0) {
enabled = false;
root.uplimits = [100, Plasmoid.configuration.gpuMemoryInPercent ? 100 : maxMemory];
root.sensors = ["gpu/gpu0/usage", "gpu/gpu0/usedVram", "gpu/gpu0/temperature"];
root.sensorsModel.sensors = ["gpu/gpu0/usage", "gpu/gpu0/usedVram", "gpu/gpu0/temperature"];
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions package/contents/ui/components/graph/MemoryGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ RMBaseGraph.TwoSensorsGraph {
}

// Graph options
// NOTE: "sensors" is set by "_updateSensors"
// NOTE: "sensorsModel.sensors" is set by "_updateSensors"
colors: [(Plasmoid.configuration.customRamColor ? Plasmoid.configuration.ramColor : theme.highlightColor), (Plasmoid.configuration.customSwapColor ? Plasmoid.configuration.swapColor : theme.negativeTextColor)]

// Initialize limits and threshold
Expand Down Expand Up @@ -92,9 +92,9 @@ RMBaseGraph.TwoSensorsGraph {
const suffix = info[1] === "percent" ? "Percent" : "";
const memSensor = "memory/physical/" + (info[0] === "physical" ? "used" : "application") + suffix;
if (Plasmoid.configuration.memorySwapGraph) {
sensors = [memSensor, "memory/swap/used" + suffix];
sensorsModel.sensors = [memSensor, "memory/swap/used" + suffix];
} else {
sensors = [memSensor];
sensorsModel.sensors = [memSensor];
}
}
}
8 changes: 4 additions & 4 deletions package/contents/ui/components/graph/NetworkGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RMBaseGraph.TwoSensorsGraph {
// Cummulate sensors by group
let data;
let downloadValue = 0, uploadValue = 0;
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
data = sensorsModel.getData(i);
if (data.sensorId.indexOf('/download') !== -1) {
downloadValue += data.value;
Expand Down Expand Up @@ -74,14 +74,14 @@ RMBaseGraph.TwoSensorsGraph {
if (!visible || typeof networkInterfaces.model.count === "undefined") {
return;
}
const _sensors = [];
const sensors = [];
for (let i = 0; i < networkInterfaces.model.count; i++) {
const name = networkInterfaces.model.get(i).name;
if (Plasmoid.configuration.ignoredNetworkInterfaces.indexOf(name) === -1) {
_sensors.push("network/" + name + "/download", "network/" + name + "/upload");
sensors.push("network/" + name + "/download", "network/" + name + "/upload");
}
}
sensors = _sensors;
sensorsModel.sensors = sensors;
_clear();
}

Expand Down
16 changes: 3 additions & 13 deletions package/contents/ui/components/graph/base/BaseSensorGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Item {
signal showValueInLabel
signal labelChanged(PlasmaComponents.Label label, var value)

property var sensors: []

// Aliases
readonly property alias textContainer: textContainer
readonly property alias sensorsModel: sensorsModel
Expand All @@ -31,7 +29,7 @@ Item {

onShowValueInLabel: {
// Update labels
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
_updateData(i);
}

Expand All @@ -45,7 +43,6 @@ Item {
id: sensorsModel
updateRateLimit: -1
enabled: root.visible
sensors: root.sensors

/**
* Get the data from sensor
Expand Down Expand Up @@ -79,22 +76,15 @@ Item {
}
}

Connections {
target: root
function onSensorsChanged() {
sensorsModel.sensors = sensors;
}
}

// Process functions
property var _insertChartData: (column, value) => {} // NOTE: this is implemented by children
property var _clear: () => {
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
_updateData(i);
}
}
property var _update: () => {
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
root._insertChartData(i, sensorsModel.getInfo(i));

// Update label
Expand Down
2 changes: 1 addition & 1 deletion package/contents/ui/components/graph/base/SensorGraph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RMBaseGraph.BaseSensorGraph {
property var _setMaximumHistory: (value) => chartData.maximumHistory = value
_clear: () => {
chartData.clear();
for (const i = 0; i < sensors.length; i++) {
for (const i = 0; i < sensorsModel.sensors.length; i++) {
_updateData(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RMBaseGraph.BaseSensorGraph {
_clear: () => {
firstChartData.clear()
secondChartData.clear()
for (let i = 0; i < sensors.length; i++) {
for (let i = 0; i < sensorsModel.sensors.length; i++) {
_updateData(i);
}
}
Expand Down

0 comments on commit 495aab2

Please sign in to comment.