Uses 1113K of libraries. Click here for Pure Java version (13162L/63K).
1 | !7 |
2 | |
3 | cm > DynPrintLogAndEnabled { |
4 | switchable double interval = 1.0; // seconds |
5 | switchable int numberSize = 20; |
6 | S aCurrentStackTrace; |
7 | |
8 | sclass Entry { |
9 | long threadID; |
10 | S threadName; |
11 | WeakRef<Thread> thread; |
12 | StackTraceElement[] stackTrace; |
13 | bool runnable; |
14 | } |
15 | |
16 | transient L<Entry> entries; |
17 | transient volatile Map<Thread, StackTraceElement[]> stackTraces; // weakHashMap |
18 | transient volatile Map<Thread, StackTraceElement[]> runnableStackTraces; |
19 | |
20 | start { |
21 | dm_reloadOnFieldChange enabled(); |
22 | if (enabled) dm_doEvery(interval, r { |
23 | if (!enabled) ret; |
24 | |
25 | var raw = allThreadsWithStackTraces(); |
26 | raw = mapMinus(raw, currentThread()); |
27 | setField(entries := map(raw, (t, st) -> { |
28 | new Entry e; |
29 | e.threadID = threadID(t); |
30 | e.threadName = threadName(t); |
31 | e.thread = weakRef(t); |
32 | e.stackTrace = st; |
33 | e.runnable = isThreadRunnable_x(t, st); |
34 | ret e; |
35 | })); |
36 | |
37 | setField(stackTraces := toWeakHashMap(raw)); |
38 | setField(runnableStackTraces := mapToWeakHashMap(filter(entries, e -> e.runnable), e -> pair(e.thread!, e.stackTrace))); |
39 | setModuleName(n2(runnableStackTraces, "runnable thread") + " [Permanent Mini Profiler]"); |
40 | var rand = random(runnableStackTraces); |
41 | setField(aCurrentStackTrace := rand == null ?: |
42 | rand.a + "\n\n" + stackTraceToString(rand.b)); |
43 | |
44 | vmBus_send freshStackTraces(stackTraces, weakRef(me())); |
45 | }); |
46 | } |
47 | |
48 | S renderStats() { |
49 | ret stackTraces == null ? "" |
50 | : jlabel_centerHTML(joinWithBR( |
51 | hfontsize(numberSize, b(n2(runnableStackTraces))), |
52 | (l(runnableStackTraces) == 1 ? "thread" : "threads") + " running", |
53 | n2(l(stackTraces)-l(runnableStackTraces)) + " idle")); |
54 | } |
55 | |
56 | visual westAndCenterWithMargins( |
57 | dm_calculatedCenteredLabel renderStats(), |
58 | dm_uneditableTextArea aCurrentStackTrace()); |
59 | |
60 | // API |
61 | |
62 | Map<Thread, StackTraceElement[]> runnableStackTraces() { |
63 | ret runnableStackTraces; |
64 | } |
65 | } |
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031777 |
Snippet name: | Permanent Mini Profiler [get all stacktraces once a second] |
Eternal ID of this version: | #1031777/26 |
Text MD5: | e7fc194626e94daff58c189f75c6a259 |
Transpilation MD5: | ab0c69dadd5a6683c99b0db26f9a4f59 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-30 13:35:36 |
Source code size: | 2020 bytes / 65 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 237 / 15783 |
Version history: | 25 change(s) |
Referenced in: | [show references] |