File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 11
2+ import 'package:flutter/foundation.dart' ;
3+
24/// Whether [debugLog] should do anything.
35///
46/// This has an effect only in a debug build.
@@ -31,6 +33,30 @@ bool debugLog(String message) {
3133 return true ;
3234}
3335
36+ /// Print a piece of profiling data.
37+ ///
38+ /// This should be called only in profile mode:
39+ /// * In debug mode, any profiling results will be misleading.
40+ /// * In release mode, we should avoid doing the computation to even produce
41+ /// the [message] argument.
42+ ///
43+ /// As a reminder of that, this function will throw in debug mode.
44+ ///
45+ /// Example usage:
46+ /// ```dart
47+ /// final stopwatch = Stopwatch()..start();
48+ /// final data = await someSlowOperation();
49+ /// if (kProfileMode) {
50+ /// final t = stopwatch.elapsed;
51+ /// profilePrint("some-operation time: ${t.inMilliseconds}ms");
52+ /// }
53+ /// ```
54+ void profilePrint (String message) {
55+ assert (kProfileMode, 'Use profilePrint only within `if (kProfileMode)`.' );
56+ if (kReleaseMode) return ;
57+ print (message); // ignore: avoid_print
58+ }
59+
3460// This should only be used for error reporting functions that allow the error
3561// to be cancelled programmatically. The implementation is expected to handle
3662// `null` for the `message` parameter and promptly dismiss the reported errors.
Original file line number Diff line number Diff line change @@ -996,8 +996,9 @@ class UpdateMachine {
996996 final stopwatch = Stopwatch ()..start ();
997997 final initialSnapshot = await _registerQueueWithRetry (connection,
998998 stopAndThrowIfNoAccount: stopAndThrowIfNoAccount);
999- final t = (stopwatch..stop ()).elapsed;
1000- assert (debugLog ("initial fetch time: ${t .inMilliseconds }ms" ));
999+ if (kProfileMode) {
1000+ profilePrint ("initial fetch time: ${stopwatch .elapsed .inMilliseconds }ms" );
1001+ }
10011002
10021003 if (initialSnapshot.zulipVersion != account.zulipVersion
10031004 || initialSnapshot.zulipMergeBase != account.zulipMergeBase
You can’t perform that action at this time.
0 commit comments