| 1 | --- |
| 2 | id: channel-switch-timer |
| 3 | --- |
| 4 | |
| 5 | The _switch timer_ period is another important configurable feature of |
| 6 | channels to ensure periodic sub-buffer flushing. |
| 7 | |
| 8 | When the _switch timer_ fires, a sub-buffer switch happens. This timer |
| 9 | may be used to ensure that event data is consumed and committed to |
| 10 | trace files periodically in case of a low event throughput: |
| 11 | |
| 12 | <script type="text/javascript"> |
| 13 | document.write('<div class="img img-50" id="docsvg-channel-switch-timer"></div>'); |
| 14 | |
| 15 | $(document).ready(function() { |
| 16 | var doc = SVG('docsvg-channel-switch-timer'); |
| 17 | |
| 18 | doc.viewbox(0, 0, 2, 2); |
| 19 | |
| 20 | var div = 4; |
| 21 | var evDur = 1000; |
| 22 | var rb = rbBuildStd(doc, div, 0.97); |
| 23 | var switchText = doc.text('Switch!'); |
| 24 | |
| 25 | switchText.font({ |
| 26 | 'size': 0.1, |
| 27 | 'weight': 'bold' |
| 28 | }); |
| 29 | switchText.center(1, 1); |
| 30 | switchText.attr({ |
| 31 | 'opacity': 0, |
| 32 | 'fill': '#b02b2c' |
| 33 | }); |
| 34 | |
| 35 | var curSubBuf = 0; |
| 36 | var totalEvents = 0; |
| 37 | var onEventAdded = function() { |
| 38 | totalEvents++; |
| 39 | |
| 40 | var curSubBufEvCount = rb.getSubBufEvCount(curSubBuf % div); |
| 41 | |
| 42 | if (totalEvents >= 4) { |
| 43 | // switch timer fires |
| 44 | switchText.attr({ |
| 45 | 'opacity': 1 |
| 46 | }); |
| 47 | switchText.animate(500, '<>', 1000).attr({ |
| 48 | 'opacity': 0 |
| 49 | }); |
| 50 | rb.markSubBuf(curSubBuf % div, 'full'); |
| 51 | |
| 52 | var lastFullSubBuf = curSubBuf; |
| 53 | |
| 54 | setTimeout(function() { |
| 55 | rb.consumeSubBuf(lastFullSubBuf % div); |
| 56 | }, 3000); |
| 57 | totalEvents = 0; |
| 58 | curSubBuf++; |
| 59 | rb.markSubBuf(curSubBuf % div, 'cur'); |
| 60 | } |
| 61 | |
| 62 | rb.addEvent(curSubBuf % div, evDur, onEventAdded); |
| 63 | }; |
| 64 | |
| 65 | rb.addEvent(0, evDur, onEventAdded); |
| 66 | rb.markSubBuf(0, 'cur'); |
| 67 | |
| 68 | rb.getGroup().move(1, 1); |
| 69 | }); |
| 70 | </script> |
| 71 | |
| 72 | <noscript> |
| 73 | <div class="err"> |
| 74 | <p> |
| 75 | <span class="t">Oops!</span>JavaScript must be enabled in |
| 76 | order to view animations. |
| 77 | </p> |
| 78 | </div> |
| 79 | </noscript> |
| 80 | |
| 81 | It's also convenient when big sub-buffers are used to cope with |
| 82 | sporadic high event throughput, even if the throughput is normally |
| 83 | lower. |