static long[] linux_cpuLoad_parse() { S line = first(toLines(loadTextFile("/proc/stat"))); S[] CPU = line.split("\\s+"); long IDLE = parseLong(CPU[4]); //Get the idle CPU time. long TOTAL = parseLong(CPU[1]) + parseLong(CPU[2]) + parseLong(CPU[3]) + parseLong(CPU[4]); ret new long[] { IDLE, TOTAL }; } static float linux_cpuLoad() { long[] a = linux_cpuLoad_parse(); sleepSeconds(1); long[] b = linux_cpuLoad_parse(); long DIFF_IDLE = b[0] - a[0]; long DIFF_TOTAL = b[1] - a[1]; float DIFF_USAGE = DIFF_TOTAL == 0 ? 0 : 100f * (DIFF_TOTAL - DIFF_IDLE) / DIFF_TOTAL; ret DIFF_USAGE; }
Began life as a copy of #1006501
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006504 |
Snippet name: | linux_cpuLoad - takes 1 second to run |
Eternal ID of this version: | #1006504/1 |
Text MD5: | efddd67c3b55fbde73cb1d5a821cecfc |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-01-11 15:25:28 |
Source code size: | 625 bytes / 17 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 503 / 489 |
Referenced in: | [show references] |