| Hit | Total | Coverage | |
|---|---|---|---|
| Lines | 34 | 34 | 100.0% | 
| Functions | 0 | 0 | - | 
| Branches | 0 | 0 | - | 
| Line | Branch | Hits | Source code | 
|---|---|---|---|
| 1 | part of 'worker.dart'; | 
                ||
| 2 |  | 
                ||
| 3 | class _Stats { | 
                ||
| 4 | 11 |   _Stats(Worker w) | 
                |
| 5 | 11 |       : _idle = microsecTimeStamp(), | 
                |
| 6 |         _worker = w; | 
                ||
| 7 |  | 
                ||
| 8 |   final Worker _worker; | 
                ||
| 9 |  | 
                ||
| 10 | 10 |   void start() { | 
                |
| 11 | 30 |     _idle = _started = microsecTimeStamp(); | 
                |
| 12 |   } | 
                ||
| 13 |  | 
                ||
| 14 | 11 |   void stop() { | 
                |
| 15 | 22 |     _stopped = microsecTimeStamp(); | 
                |
| 16 |   } | 
                ||
| 17 |  | 
                ||
| 18 | 10 |   void beginWork() { | 
                |
| 19 | 20 |     _workload++; | 
                |
| 20 | 30 |     if (_workload > _maxWorkload) { | 
                |
| 21 | 20 |       _maxWorkload = _workload; | 
                |
| 22 |     } | 
                ||
| 23 |   } | 
                ||
| 24 |  | 
                ||
| 25 | 10 |   void endWork([dynamic _]) { | 
                |
| 26 | 20 |     _workload--; | 
                |
| 27 | 20 |     _idle = microsecTimeStamp(); | 
                |
| 28 | 20 |     _totalWorkload++; | 
                |
| 29 |   } | 
                ||
| 30 |  | 
                ||
| 31 | 4 |   void failed() { | 
                |
| 32 | 8 |     _totalErrors++; | 
                |
| 33 |   } | 
                ||
| 34 |  | 
                ||
| 35 |   /// Start timestamp | 
                ||
| 36 |   int? _started; | 
                ||
| 37 |  | 
                ||
| 38 |   /// Stopped timestamp | 
                ||
| 39 |   int? _stopped; | 
                ||
| 40 |  | 
                ||
| 41 |   /// Idle timestamp. | 
                ||
| 42 |   int _idle; | 
                ||
| 43 |  | 
                ||
| 44 |   /// Current workload. | 
                ||
| 45 |   int _workload = 0; | 
                ||
| 46 |  | 
                ||
| 47 |   /// Maximum acceptable workload. | 
                ||
| 48 |   int _maxWorkload = 0; | 
                ||
| 49 |  | 
                ||
| 50 |   /// Total processed workload. | 
                ||
| 51 |   int _totalWorkload = 0; | 
                ||
| 52 |  | 
                ||
| 53 |   /// Total errors. | 
                ||
| 54 |   int _totalErrors = 0; | 
                ||
| 55 |  | 
                ||
| 56 | 12 |   Duration _getUpTime(int microsec) => (_started == null) | 
                |
| 57 |       ? Duration.zero | 
                ||
| 58 | 18 |       : Duration(microseconds: microsec - _started!); | 
                |
| 59 |  | 
                ||
| 60 | 18 |   Duration _getIdleTime(int microsec) => (_workload > 0) | 
                |
| 61 |       ? Duration.zero | 
                ||
| 62 | 18 |       : Duration(microseconds: microsec - _idle); | 
                |
| 63 |  | 
                ||
| 64 |   /// Indicates if the [Worker] has been stopped. | 
                ||
| 65 | 22 |   bool get isStopped => _stopped != null; | 
                |
| 66 |  | 
                ||
| 67 | 6 |   WorkerStat get snapshot { | 
                |
| 68 | 6 |     final ts = microsecTimeStamp(); | 
                |
| 69 | 6 |     return WorkerStatImpl.create( | 
                |
| 70 | 12 |       _worker.runtimeType, | 
                |
| 71 | 12 |       _worker.hashCode, | 
                |
| 72 | 6 |       isStopped, | 
                |
| 73 | 6 |       _workload, | 
                |
| 74 | 6 |       _maxWorkload, | 
                |
| 75 | 6 |       _totalWorkload, | 
                |
| 76 | 6 |       _totalErrors, | 
                |
| 77 | 12 |       _getUpTime(_stopped ?? ts), | 
                |
| 78 | 6 |       _getIdleTime(ts), | 
                |
| 79 | 18 |       _worker._channel?.activeConnections ?? 0, | 
                |
| 80 |     ); | 
                ||
| 81 |   } | 
                ||
| 82 | } |