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

33
LINES

< > BotCompany Repo | #1010502 // renderUserThreadsWithStackTraces

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9325L/52K).

static S renderUserThreadsWithStackTraces() {
  ret renderUserThreadsWithStackTraces(mapWithout(Thread.getAllStackTraces(), currentThread()));
}

static S renderUserThreadsWithStackTraces(Map<Thread, StackTraceElement[]> threadMap) {
  ret renderUserThreadsWithStackTraces(threadMap, "thread");
}

static S renderUserThreadsWithStackTraces(Map<Thread, StackTraceElement[]> threadMap, S threadDescription) {
  new StringBuilder bufRunnable;
  new StringBuilder bufWaiting;
  
  int nRunnable = 0, nWaiting = 0, nSystem = 0;
  for (t, stackTrace : threadMap) {
    bool runnable = isThreadRunnable_x(t, stackTrace);
    var buf = runnable ? bufRunnable : bufWaiting;
    
    ThreadGroup g = t.getThreadGroup();
    if (g != null && g.getName().equals("system"))
      continue with ++nSystem;
    if (runnable) ++nRunnable; else ++nWaiting;
    printTo(buf, t);
    for (StackTraceElement e : threadMap.get(t))
      printTo(buf, "  " + e);
    printTo(buf);
  }
  
  ret asciiHeading2(n2(nRunnable, "runnable " + threadDescription))
      + "\n" + bufRunnable
    + asciiHeading2(n2(nWaiting, "sleeping " + threadDescription)
      + " (+" + n2(nSystem, "system thread") + ")")
      + "\n" + bufWaiting;
}

Author comment

Began life as a copy of #1000960

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: #1010502
Snippet name: renderUserThreadsWithStackTraces
Eternal ID of this version: #1010502/14
Text MD5: 514919772fcc7bc58703454f85c0779f
Transpilation MD5: d64290844b9b4d9b8752e0ab51e13f6a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-21 17:16:43
Source code size: 1238 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 383 / 492
Version history: 13 change(s)
Referenced in: [show references]