LCOV - code coverage report

Current view
top level - src/stats - perf_counter.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines181994.7%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'package:meta/meta.dart';
2
3import 'perf_counter_snapshot.dart';
4
5/// Simple performance counter to consolidate statistics about woker tast execution: total number of calls, total
6/// number of errors, total elapsed time, and max elapsed time.
7class PerfCounter implements PerfCounterSnapshot {
8 /// Creates a performance counter.
92 PerfCounter(this.name)
10 : _maxTimeInMicroseconds = 0,
11 _totalTimeInMicroseconds = 0,
12 _totalCount = 0,
131 _totalErrors = 0;
14
15 /// The counter's name or label.
16 @override
17 final String name;
18
19 /// Maximum elapsed time for a single call, in microseconds.
201 @override
211 int get maxTimeInMicroseconds => _maxTimeInMicroseconds;
22 int _maxTimeInMicroseconds;
23
24 /// Total elapsed time, in microseconds.
251 @override
262 int get totalTimeInMicroseconds => _totalTimeInMicroseconds;
27 int _totalTimeInMicroseconds;
28
29 /// Total number of calls.
301 @override
312 int get totalCount => _totalCount;
32 int _totalCount;
33
34 /// Total number of errors.
351 @override
362 int get totalErrors => _totalErrors;
37 int _totalErrors;
38
39 /// Returns a snapshot of the [PerfCounter]'s values.
403 PerfCounterSnapshot get snapshot => PerfCounterSnapshot(this);
41}
42
43@internal
44extension PerfCounterExt on PerfCounter {
45 /// Updates counter value with the duration indicated by [timeInMicroseconds].
46 /// 1. update the maximum elapsed time if required.
47 /// 2. add specified time to the total elapsed time.
48 /// 3. depending on [success], increment the total number of calls or errors by 1.
492 void update(int timeInMicroseconds, bool success) {
503 if (timeInMicroseconds > _maxTimeInMicroseconds) {
512 _maxTimeInMicroseconds = timeInMicroseconds;
52 }
532 _totalTimeInMicroseconds += timeInMicroseconds;
541 if (success) {
552 _totalCount++;
56 } else {
570 _totalErrors++;
58 }
591 }
60}
Choose Features