ente/mobile/lib/extensions/stop_watch.dart
2024-04-10 10:53:18 +05:30

32 lines
704 B
Dart

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