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

25
LINES

< > BotCompany Repo | #1023851 // Save Stack Traces If Process CPU use > 50% of all cores for 10 seconds

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

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

!7

cmodule SaveStackTracesIfHighCPUUse > DynPrintLogAndEnabled {
  double period = 10.0;
  transient WaitForStableValue<Bool> high;
  
  start {
    high = WaitForStableValue(period);
    doEvery(2.0, r check);
  }
  
  void check enter {
    if (dm_osLoading()) ret;
    int load = iround(dm_processCPUPercentageRelativeToAllCores());
    high.set(load >= 50);
    if (isTrue(high!)) {
      time {
        S traces = renderAllThreadsWithStackTraces();
        logQuotedWithDate(javaxDataDir("high-cpu-stack-traces.txt"), traces);
      }
      done_always("CPU load: " + load + "%, saving stack trace");
      high.set(false); // wait another 10 seconds
    }
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1023851
Snippet name: Save Stack Traces If Process CPU use > 50% of all cores for 10 seconds
Eternal ID of this version: #1023851/11
Text MD5: c2cf319c083a1a05435a3bf6aa2375d5
Transpilation MD5: 1486bb812d336e66d3ac5bc438b036a4
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-24 13:37:49
Source code size: 692 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 30203
Version history: 10 change(s)
Referenced in: [show references]