Libraryless. Click here for Pure Java version (1123L/8K/26K).
!7 p-typewriter { long PREV_TOTAL = 0, PREV_IDLE = 0; repeat with sleep 1 { S line = first(toLines(loadTextFile("/proc/stat"))); print(line); S[] CPU = line.split("\\s+"); long IDLE = Long.parseLong(CPU[4]); //Get the idle CPU time. long TOTAL = Long.parseLong(CPU[1]) + Long.parseLong(CPU[2]) + Long.parseLong(CPU[3]) + Long.parseLong(CPU[4]); long DIFF_IDLE = IDLE - PREV_IDLE; long DIFF_TOTAL = TOTAL - PREV_TOTAL; long DIFF_USAGE = DIFF_TOTAL == 0 ? 0 : (1000 * (DIFF_TOTAL - DIFF_IDLE) / DIFF_TOTAL + 5) / 10; print("CPU: " + DIFF_USAGE + "%"); PREV_TOTAL = TOTAL; PREV_IDLE = IDLE; //return (float) DIFF_USAGE; } }
Thanks to http://stackoverflow.com/questions/28787946/get-cpu-load-per-core-using-java
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006501 |
Snippet name: | Linux: Try to get CPU info from /proc/stat [now moved to linux_cpuLoad] |
Eternal ID of this version: | #1006501/1 |
Text MD5: | da3d6e1d60ce5a5822c0450061f89343 |
Transpilation MD5: | 2746d0fa5888c1759bec326b7c9f7c9c |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-01-11 15:23:00 |
Source code size: | 709 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 545 / 604 |
Referenced in: | #1006504 - linux_cpuLoad - takes 1 second to run #1006505 - Show CPU load under Linux [WORKS] |