diagnostic.dart
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'dart:math' as math;
import 'package:meta/meta.dart';
import '../format/stream.dart';
mixin PdfDiagnostic {
static const _maxSize = 300;
final _properties = <String>[];
int? _offset;
Stopwatch? _stopwatch;
int get elapsedStopwatch => _stopwatch?.elapsedMicroseconds ?? 0;
@protected
@mustCallSuper
void debugFill(String value) {
assert(() {
if (_properties.isEmpty) {
_properties.add('');
_properties.add('-' * 78);
_properties.add('$runtimeType');
}
_properties.add(value);
return true;
}());
}
void setInsertion(PdfStream os) {
assert(() {
_offset = os.offset;
os.putComment(' ' * _maxSize);
return true;
}());
}
void writeDebug(PdfStream os) {
assert(() {
if (_offset != null) {
final o = PdfStream();
_properties.forEach(o.putComment);
final b = o.output();
os.setBytes(
_offset!,
b.sublist(0, math.min(_maxSize + 2, b.lengthInBytes - 1)),
);
}
return true;
}());
}
void startStopwatch() {
_stopwatch ??= Stopwatch();
_stopwatch!.start();
}
void stopStopwatch() {
_stopwatch?.stop();
}
}