Libraryless. Click here for Pure Java version (4816L/26K).
1 | static new MultiSet<S> poorMansProfiling_results; |
2 | static int poorMansProfiling_samples; |
3 | static java.util.Timer poorMansProfiling_timer; |
4 | static Lock poorMansProfiling_lock = lock(); |
5 | static Thread poorMansProfiling_threadToSample; // otherwise sample all threads |
6 | |
7 | static void poorMansProfiling() { |
8 | poorMansProfiling(poorMansProfiling_defaultInterval()); |
9 | } |
10 | |
11 | static void poorMansProfiling(Thread thread) { |
12 | poorMansProfiling(poorMansProfiling_defaultInterval(), thread); |
13 | } |
14 | |
15 | static void poorMansProfiling(int interval) { |
16 | poorMansProfiling(interval, null); |
17 | } |
18 | |
19 | static void poorMansProfiling(int interval, Thread thread) { |
20 | lock poorMansProfiling_lock; |
21 | poorMansProfiling_threadToSample = thread; |
22 | poorMansProfiling_stop(); |
23 | poorMansProfiling_clear(); |
24 | poorMansProfiling_timer = doEvery_daemon(interval, r { |
25 | Map<Thread, StackTraceElement[]> map = |
26 | poorMansProfiling_threadToSample != null |
27 | ? litmap(poorMansProfiling_threadToSample, poorMansProfiling_threadToSample.getStackTrace()) |
28 | : runnableThreadsWithStackTraces(); |
29 | lock poorMansProfiling_lock; |
30 | poorMansProfiling_samples++; |
31 | for (Thread t : keys(map)) { |
32 | continue if isSystemThread(t); |
33 | new StringBuilder buf; |
34 | for (StackTraceElement e : map.get(t)) |
35 | buf.append(e).append("\n"); |
36 | poorMansProfiling_results.add(str(buf)); |
37 | } |
38 | }); |
39 | } |
40 | |
41 | static void poorMansProfiling_stop() { |
42 | lock poorMansProfiling_lock; |
43 | if (poorMansProfiling_timer != null) { |
44 | stopTimer(poorMansProfiling_timer); |
45 | poorMansProfiling_timer = null; |
46 | } |
47 | } |
48 | |
49 | static void poorMansProfiling_clear() { |
50 | lock poorMansProfiling_lock; |
51 | poorMansProfiling_results.clear(); |
52 | poorMansProfiling_samples = 0; |
53 | } |
54 | |
55 | static MultiSet<S> poorMansProfiling_results() { |
56 | ret new MultiSet(poorMansProfiling_results); |
57 | } |
58 | |
59 | static MultiSet<S> poorMansProfiling_stopAndGetResults() { |
60 | lock poorMansProfiling_lock; |
61 | poorMansProfiling_stop(); |
62 | ret poorMansProfiling_results(); |
63 | } |
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: | #1011686 |
Snippet name: | poorMansProfiling |
Eternal ID of this version: | #1011686/20 |
Text MD5: | f429a0a12a23fd4cd97b01acec96458a |
Transpilation MD5: | c7bc6733fd6f526cf4e8c751d19f3b3e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-20 12:21:11 |
Source code size: | 2006 bytes / 63 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 586 / 662 |
Version history: | 19 change(s) |
Referenced in: | [show references] |