1 | static long[] linux_cpuLoad_parse() { |
2 | S line = first(toLines(loadTextFile("/proc/stat"))); |
3 | S[] CPU = line.split("\\s+"); |
4 | long IDLE = parseLong(CPU[4]); //Get the idle CPU time. |
5 | long TOTAL = parseLong(CPU[1]) + parseLong(CPU[2]) + parseLong(CPU[3]) + parseLong(CPU[4]); |
6 | ret new long[] { IDLE, TOTAL }; |
7 | } |
8 | |
9 | static float linux_cpuLoad() { |
10 | long[] a = linux_cpuLoad_parse(); |
11 | sleepSeconds(1); |
12 | long[] b = linux_cpuLoad_parse(); |
13 | long DIFF_IDLE = b[0] - a[0]; |
14 | long DIFF_TOTAL = b[1] - a[1]; |
15 | float DIFF_USAGE = DIFF_TOTAL == 0 ? 0 : 100f * (DIFF_TOTAL - DIFF_IDLE) / DIFF_TOTAL; |
16 | ret DIFF_USAGE; |
17 | } |
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: | 504 / 491 |
Referenced in: | [show references] |