Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1018523 // Process CPU % [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (3727L/19K).

!7

// uses advancedOSMXBean(), not OSHI

cmodule ProcessCPUPercentage > DynBigNumber {
  transient FixedRateTimer mainTimer;
  transient double loadRelativeToAllCores, recentLoad;
  transient RollingAverage avg = new(5); // =10 seconds
  
  start {
    setDescription("PROCESS CPU %");
    setToolTip("Percentage is per core (total: " + n2(numberOfCores(), "core") + ")");
    mainTimer = doEvery(2.0, r actualUpdate);
  }
  
  void actualUpdate {
    recentLoad = processCPULoad();
    avg.add(recentLoad);
    loadRelativeToAllCores = avg!;
    setValue(toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " %");
  }
}

Author comment

Began life as a copy of #1016652

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

No comments. add comment

Snippet ID: #1018523
Snippet name: Process CPU % [Dyn Module]
Eternal ID of this version: #1018523/12
Text MD5: 25d91206ada0df8a0a829ef0ea101818
Transpilation MD5: 752458b35e3387dc6785d380fd36fb73
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-18 11:33:40
Source code size: 650 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 425 / 262630
Version history: 11 change(s)
Referenced in: [show references]