Transpiled version (11078L) is out of date.
1 | asclass AbstractProfiler is AutoCloseable { |
2 | // config |
3 | settable int interval = 40; // 25 Hz |
4 | settable bool skipSleeping; |
5 | |
6 | // results |
7 | new MultiSet<S> stackTraceMultiSet; |
8 | gettable volatile int samples; |
9 | |
10 | // temporary |
11 | java.util.Timer timer; |
12 | Lock lock = lock(); |
13 | |
14 | void start { |
15 | lock lock; |
16 | assertCanStart(); |
17 | printWithMS("Starting " + this); |
18 | stop(); |
19 | clear(); |
20 | timer = doEvery_daemon("Profiler", interval, r stepImpl); |
21 | } |
22 | |
23 | void assertCanStart {} |
24 | abstract void stepImpl(); |
25 | |
26 | public void stop aka close() { |
27 | lock lock; |
28 | if (timer != null) { |
29 | stopTimer(timer); |
30 | timer = null; |
31 | printWithMS("Stopped " + this); |
32 | } |
33 | } |
34 | |
35 | void clear() { |
36 | lock lock; |
37 | stackTraceMultiSet.clear(); |
38 | samples = 0; |
39 | } |
40 | |
41 | MultiSet<S> results() { |
42 | lock lock; |
43 | ret cloneMultiSet(stackTraceMultiSet); |
44 | } |
45 | |
46 | MultiSet<S> stopAndGetResults() { |
47 | lock lock; |
48 | stop(); |
49 | ret results(); |
50 | } |
51 | |
52 | S renderFullResults(bool mostImportantLast) { |
53 | var traces = results(); |
54 | int n = traces.size(); |
55 | int percent = ratioToIntPercent(l(traces), samples); |
56 | ret (samples == 0 ? "Nothing sampled" |
57 | : percent + "% core activity [" + n2(samples, "sample") + " taken]") + "\n\n" |
58 | + joinMap(mostImportantLast ? traces.lowestFirst() : traces.highestFirst(), trace -> |
59 | traces.get(trace) + "/" + n + "\n" + trace + "\n\n" |
60 | ); |
61 | } |
62 | |
63 | // must be locked first |
64 | protected void addSample(StackTraceElement[] stackTrace) { |
65 | stackTraceMultiSet.add(stackTraceToString(stackTrace)); |
66 | } |
67 | } |
Began life as a copy of #1035050
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036378 |
Snippet name: | AbstractProfiler |
Eternal ID of this version: | #1036378/10 |
Text MD5: | 728419c663cf104ae35694525a04a315 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-30 11:59:30 |
Source code size: | 1612 bytes / 67 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 138 / 212 |
Version history: | 9 change(s) |
Referenced in: | [show references] |