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