Use wait_async for get_cpu_use
This commit is contained in:
parent
d65250d7e6
commit
e4e7eb9c81
@ -99,6 +99,7 @@ SystemMonitorGraph.prototype = {
|
|||||||
this.hdd_cpu_tot = 0;
|
this.hdd_cpu_tot = 0;
|
||||||
this.hdd_hdd_tot = 0;
|
this.hdd_hdd_tot = 0;
|
||||||
// values to graph
|
// values to graph
|
||||||
|
this.cpu_use = 0;
|
||||||
this.gpu_use = 0;
|
this.gpu_use = 0;
|
||||||
this.gpu_mem = new Array(2).fill(0.0);
|
this.gpu_mem = new Array(2).fill(0.0);
|
||||||
// set colors
|
// set colors
|
||||||
@ -151,10 +152,10 @@ SystemMonitorGraph.prototype = {
|
|||||||
// current values
|
// current values
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case "cpu":
|
case "cpu":
|
||||||
let cpu_use = this.get_cpu_use();
|
this.get_cpu_use();
|
||||||
value = cpu_use / 100;
|
value = this.cpu_use / 100;
|
||||||
text1 = _("CPU");
|
text1 = _("CPU");
|
||||||
text2 = Math.round(cpu_use).toString() + "%";
|
text2 = Math.round(this.cpu_use).toString() + "%";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ram":
|
case "ram":
|
||||||
@ -328,17 +329,23 @@ SystemMonitorGraph.prototype = {
|
|||||||
|
|
||||||
get_cpu_use: function() {
|
get_cpu_use: function() {
|
||||||
// https://rosettacode.org/wiki/Linux_CPU_utilization
|
// https://rosettacode.org/wiki/Linux_CPU_utilization
|
||||||
let cpu_line = Cinnamon.get_file_contents_utf8_sync("/proc/stat").match(/cpu\s.+/)[0];
|
let subprocess = new Gio.Subprocess({
|
||||||
let cpu_values = cpu_line.split(/\s+/);
|
argv: ['head', '-n', '1', '/proc/stat'],
|
||||||
|
flags: Gio.SubprocessFlags.STDOUT_PIPE|Gio.SubprocessFlags.STDERR_PIPE,
|
||||||
|
});
|
||||||
|
subprocess.init(null);
|
||||||
|
subprocess.wait_async(null, (sourceObject, res) => {
|
||||||
|
let [, stdout, stderr] = sourceObject.communicate_utf8(null, null);
|
||||||
|
let cpu_values = stdout.split(/\s+/);
|
||||||
let cpu_idl = parseFloat(cpu_values[4]);
|
let cpu_idl = parseFloat(cpu_values[4]);
|
||||||
let cpu_tot = 0;
|
let cpu_tot = 0;
|
||||||
for (let i = 1; i<10; i++){
|
for (let i = 1; i<10; i++){
|
||||||
cpu_tot += parseFloat(cpu_values[i])
|
cpu_tot += parseFloat(cpu_values[i])
|
||||||
}
|
}
|
||||||
let cpu_use = 100 * (1 - (cpu_idl - this.cpu_cpu_idl) / (cpu_tot - this.cpu_cpu_tot));
|
this.cpu_use = 100 * (1 - (cpu_idl - this.cpu_cpu_idl) / (cpu_tot - this.cpu_cpu_tot));
|
||||||
this.cpu_cpu_tot = cpu_tot;
|
this.cpu_cpu_tot = cpu_tot;
|
||||||
this.cpu_cpu_idl = cpu_idl;
|
this.cpu_cpu_idl = cpu_idl;
|
||||||
return cpu_use;
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
get_ram_values: function() {
|
get_ram_values: function() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user