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

56
LINES

< > BotCompany Repo | #1019937 // Steady Beat [dev.]

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

Libraryless. Click here for Pure Java version (5178L/35K).

!7

module SteadyBeat extends DynBigNumber {
  S priority = 'max;
  int interval = 50, showInterval = 1000;
  int reportFrom = 75; // pause must be this long to be reported
  Map<Long, Pause> reportedPauses = synchroMap();
  
  sclass Pause {
    long count, lastSeen;
  }
  
  transient long lastTick;
  transient long count, maxDelaySeen, averageSum;
  transient long anomalies;
  
  start {
    if (eq(priority, 'max))
      doEvery_maxPriority(interval, r tick);
    else
      doEvery(interval, r tick);
    doEvery(showInterval, r show);
  }
  
  void show enter {
    //setDescription("MAX/AVG TICK DELAY (TARGET: " + interval + " MS)");
    //setValue(maxDelaySeen + "/" + average();
    setDescription("ANOMALIES/MAX TICK DELAY (TARGET: " + interval + " MS)");
    setValue(anomalies + "/" + maxDelaySeen + " ms");
  }
  
  void tick enter {
    long now = sysNow();
    if (lastTick != 0) {
      long delay = now-lastTick;
      maxDelaySeen = max(maxDelaySeen, delay);
      ++count;
      averageSum += delay;
      if (delay >= reportFrom) {
        anomalies++;
        long rounded = (delay+interval-1)/interval; // round up to next multiple of target interval (50, 100, 150, ...)
        Pause p = reportedPauses.get(rounded);
        if (p == null) reportedPauses.put(rounded, p = new Pause);
        p.lastSeen = now;
        p.count++;
      }
    }
    lastTick = now;
  }
  
  // API
  
  long average() {
    ret (averageSum+count/2)/count;
  }
}

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: 354 / 3909
Version history: 10 change(s)
Referenced in: [show references]