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

47
LINES

< > BotCompany Repo | #1017372 // Thread Memory Allocation Rates [Dyn Module]

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

Libraryless. Click here for Pure Java version (14464L/100K).

1  
!7
2  
3  
sclass ThreadMemoryAllocationRates extends DynModule {
4  
  transient SimpleLiveValue<S> lv = stringLiveValue();
5  
  transient Map<Long> lastValues;
6  
  transient long lastTime;
7  
  
8  
  JComponent visualize() {
9  
    ret jLiveValueTypeWriterTextArea(lv);
10  
  }
11  
  
12  
  start {
13  
    doEveryAndNow(5.0, r doIt);
14  
  }
15  
  
16  
  void doIt {
17  
    temp enter();
18  
    if (!threadAllocatedMemoryEnabled())
19  
      ret with lv.set("Thread memory allocation not monitored");
20  
      
21  
    com.sun.management.ThreadMXBean bean = advancedThreadMXBean();
22  
    L<Thread> threads = allThreads_fast();
23  
    long[] values = bean.getThreadAllocatedBytes(threadIDs_array(threads));
24  
    new Map<Long> map;
25  
    new Map<Long, S> names;
26  
    for i over values: {
27  
      Thread t = threads.get(i);
28  
      long id = t.getId();
29  
      map.put(id, values[i]);
30  
      names.put(id, t.getName());
31  
    }
32  
    
33  
    long diffTime = sysNow()-lastTime;
34  
    lastTime = sysNow();
35  
    if (lastValues != null) {
36  
      new L<S> lines;
37  
      for (Long id, value : map) {
38  
        long diff = value - or(lastValues.get(id), 0L);
39  
        diff = diff*1000/diffTime;
40  
        if (diff != 0)
41  
          lines.add(padLeft(str(toK(diff)), 9) + " K/s: " + names.get(id));
42  
      }
43  
      lv.set(lines(reverseSorted(lines)));
44  
    }
45  
    lastValues = map;
46  
  }
47  
}

Author comment

Began life as a copy of #1016748

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017372
Snippet name: Thread Memory Allocation Rates [Dyn Module]
Eternal ID of this version: #1017372/7
Text MD5: ce5bcbda5c84e0786588cc08c33e2cb6
Transpilation MD5: 53d3055170cb76fc8984d7d3bd23e1ff
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: 2018-11-13 05:39:34
Source code size: 1316 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 375 / 514
Version history: 6 change(s)
Referenced in: [show references]