Libraryless. Click here for Pure Java version (5178L/35K).
1 | !7 |
2 | |
3 | module SteadyBeat extends DynBigNumber { |
4 | S priority = 'max; |
5 | int interval = 50, showInterval = 1000; |
6 | int reportFrom = 75; // pause must be this long to be reported |
7 | Map<Long, Pause> reportedPauses = synchroMap(); |
8 | |
9 | sclass Pause { |
10 | long count, lastSeen; |
11 | } |
12 | |
13 | transient long lastTick; |
14 | transient long count, maxDelaySeen, averageSum; |
15 | transient long anomalies; |
16 | |
17 | start { |
18 | if (eq(priority, 'max)) |
19 | doEvery_maxPriority(interval, r tick); |
20 | else |
21 | doEvery(interval, r tick); |
22 | doEvery(showInterval, r show); |
23 | } |
24 | |
25 | void show enter { |
26 | //setDescription("MAX/AVG TICK DELAY (TARGET: " + interval + " MS)"); |
27 | //setValue(maxDelaySeen + "/" + average(); |
28 | setDescription("ANOMALIES/MAX TICK DELAY (TARGET: " + interval + " MS)"); |
29 | setValue(anomalies + "/" + maxDelaySeen + " ms"); |
30 | } |
31 | |
32 | void tick enter { |
33 | long now = sysNow(); |
34 | if (lastTick != 0) { |
35 | long delay = now-lastTick; |
36 | maxDelaySeen = max(maxDelaySeen, delay); |
37 | ++count; |
38 | averageSum += delay; |
39 | if (delay >= reportFrom) { |
40 | anomalies++; |
41 | long rounded = (delay+interval-1)/interval; // round up to next multiple of target interval (50, 100, 150, ...) |
42 | Pause p = reportedPauses.get(rounded); |
43 | if (p == null) reportedPauses.put(rounded, p = new Pause); |
44 | p.lastSeen = now; |
45 | p.count++; |
46 | } |
47 | } |
48 | lastTick = now; |
49 | } |
50 | |
51 | // API |
52 | |
53 | long average() { |
54 | ret (averageSum+count/2)/count; |
55 | } |
56 | } |
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1019937 |
Snippet name: | Steady Beat [dev.] |
Eternal ID of this version: | #1019937/11 |
Text MD5: | a2090a68ac3c8d83478bd6342e71462f |
Transpilation MD5: | fabbe5d9a4a9dd19da2f366792d6dbcb |
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-12-01 17:08:46 |
Source code size: | 1524 bytes / 56 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 356 / 3912 |
Version history: | 10 change(s) |
Referenced in: | [show references] |