File tree 2 files changed +29
-2
lines changed 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 1
1
2
+ import 'package:flutter/foundation.dart' ;
3
+
2
4
/// Whether [debugLog] should do anything.
3
5
///
4
6
/// This has an effect only in a debug build.
@@ -31,6 +33,30 @@ bool debugLog(String message) {
31
33
return true ;
32
34
}
33
35
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
+
34
60
// This should only be used for error reporting functions that allow the error
35
61
// to be cancelled programmatically. The implementation is expected to handle
36
62
// `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 {
996
996
final stopwatch = Stopwatch ()..start ();
997
997
final initialSnapshot = await _registerQueueWithRetry (connection,
998
998
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
+ }
1001
1002
1002
1003
if (initialSnapshot.zulipVersion != account.zulipVersion
1003
1004
|| initialSnapshot.zulipMergeBase != account.zulipMergeBase
You can’t perform that action at this time.
0 commit comments