ente/mobile/lib/extensions/stop_watch.dart

32 lines
704 B
Dart
Raw Permalink Normal View History

2022-11-13 00:50:11 +00:00
import 'package:flutter/foundation.dart';
class EnteWatch extends Stopwatch {
final String context;
int previousElapsed = 0;
EnteWatch(this.context) : super();
2022-11-13 00:50:11 +00:00
void log(String msg) {
if (kDebugMode) {
debugPrint("[$context]: $msg took ${Duration(
microseconds: elapsedMicroseconds - previousElapsed,
).inMilliseconds} ms total: "
"${elapsed.inMilliseconds} ms");
}
previousElapsed = elapsedMicroseconds;
2022-11-13 00:50:11 +00:00
}
void logAndReset(String msg) {
if (kDebugMode) {
debugPrint("[$context]: $msg took ${elapsed.inMilliseconds} ms");
}
2022-11-13 00:50:11 +00:00
reset();
previousElapsed = 0;
2022-11-13 00:50:11 +00:00
}
2024-04-10 05:23:18 +00:00
void stopWithLog(String msg) {
log(msg);
stop();
}
2022-11-13 00:50:11 +00:00
}