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).

1  
static S renderUserThreadsWithStackTraces() {
2  
  ret renderUserThreadsWithStackTraces(mapWithout(Thread.getAllStackTraces(), currentThread()));
3  
}
4  
5  
static S renderUserThreadsWithStackTraces(Map<Thread, StackTraceElement[]> threadMap) {
6  
  ret renderUserThreadsWithStackTraces(threadMap, "thread");
7  
}
8  
9  
static S renderUserThreadsWithStackTraces(Map<Thread, StackTraceElement[]> threadMap, S threadDescription) {
10  
  new StringBuilder bufRunnable;
11  
  new StringBuilder bufWaiting;
12  
  
13  
  int nRunnable = 0, nWaiting = 0, nSystem = 0;
14  
  for (t, stackTrace : threadMap) {
15  
    bool runnable = isThreadRunnable_x(t, stackTrace);
16  
    var buf = runnable ? bufRunnable : bufWaiting;
17  
    
18  
    ThreadGroup g = t.getThreadGroup();
19  
    if (g != null && g.getName().equals("system"))
20  
      continue with ++nSystem;
21  
    if (runnable) ++nRunnable; else ++nWaiting;
22  
    printTo(buf, t);
23  
    for (StackTraceElement e : threadMap.get(t))
24  
      printTo(buf, "  " + e);
25  
    printTo(buf);
26  
  }
27  
  
28  
  ret asciiHeading2(n2(nRunnable, "runnable " + threadDescription))
29  
      + "\n" + bufRunnable
30  
    + asciiHeading2(n2(nWaiting, "sleeping " + threadDescription)
31  
      + " (+" + n2(nSystem, "system thread") + ")")
32  
      + "\n" + bufWaiting;
33  
}

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: 556 / 727
Version history: 13 change(s)
Referenced in: [show references]