diff --git a/core/lib/core.dart b/core/lib/core.dart index 81e3558d7..4ebc370e7 100644 --- a/core/lib/core.dart +++ b/core/lib/core.dart @@ -28,6 +28,7 @@ export 'data/utils/device_manager.dart'; export 'utils/app_logger.dart'; export 'utils/benchmark.dart'; export 'utils/fps_manager.dart'; +export 'utils/build_utils.dart'; // Views export 'presentation/views/text/slogan_builder.dart'; diff --git a/core/lib/utils/benchmark.dart b/core/lib/utils/benchmark.dart index 4994ef674..4af69cbab 100644 --- a/core/lib/utils/benchmark.dart +++ b/core/lib/utils/benchmark.dart @@ -1,28 +1,35 @@ -import 'package:core/utils/app_logger.dart'; +import 'package:core/core.dart'; class _Benchmark { final Map _starts = {}; void start(dynamic id) { - final String benchId = id.toString(); - if (_starts.containsKey(benchId)) { - log('_Benchmark::start(): Benchmark already have comparing with id=$benchId in time'); - } else { - _starts[benchId] = DateTime.now().microsecondsSinceEpoch; + if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) { + final String benchId = id.toString(); + if (_starts.containsKey(benchId)) { + log('_Benchmark::start(): Benchmark already have comparing with id=$benchId in time'); + } else { + _starts[benchId] = DateTime.now().microsecondsSinceEpoch; + } } } double end(dynamic id) { - final String benchId = id.toString(); - if (!_starts.containsKey(benchId)) { - throw Exception('In Benchmark not placed comparing with id=$benchId'); + if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) { + final String benchId = id.toString(); + if (!_starts.containsKey(benchId)) { + throw Exception('In Benchmark not placed comparing with id=$benchId'); + } + final double diff = (DateTime + .now() + .microsecondsSinceEpoch - _starts[benchId]!) / 1000; + final String info = '$benchId need ${diff}ms'; + log('_Benchmark::end(): $info'); + _starts.remove(benchId); + return diff; } - final double diff = (DateTime.now().microsecondsSinceEpoch - _starts[benchId]!) / 1000; - final String info = '$benchId need ${diff}ms'; - log('_Benchmark::end(): $info'); - _starts.remove(benchId); - return diff; + return 0; } } diff --git a/core/lib/utils/build_utils.dart b/core/lib/utils/build_utils.dart new file mode 100644 index 000000000..be54cc5e4 --- /dev/null +++ b/core/lib/utils/build_utils.dart @@ -0,0 +1,11 @@ +import 'package:flutter/foundation.dart' as Foundation; + +abstract class BuildUtils { + static const bool isDebugMode = Foundation.kDebugMode; + + static const bool isReleaseMode = Foundation.kReleaseMode; + + static const bool isWeb = Foundation.kIsWeb; + + static const bool isProfileMode = Foundation.kProfileMode; +} \ No newline at end of file diff --git a/core/lib/utils/fps_manager.dart b/core/lib/utils/fps_manager.dart index 5c9a1da83..cf0378229 100644 --- a/core/lib/utils/fps_manager.dart +++ b/core/lib/utils/fps_manager.dart @@ -1,6 +1,7 @@ import 'dart:collection'; import 'dart:ui'; +import 'package:core/core.dart'; import 'package:flutter/scheduler.dart'; /// FpsManager callback. @@ -46,16 +47,20 @@ class FpsManager { } void start() async { - if (!_started) { - SchedulerBinding.instance?.addTimingsCallback(_onTimingsCallback); - _started = true; + if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) { + if (!_started) { + SchedulerBinding.instance?.addTimingsCallback(_onTimingsCallback); + _started = true; + } } } void stop() { - if (_started) { - SchedulerBinding.instance?.removeTimingsCallback(_onTimingsCallback); - _started = false; + if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) { + if (_started) { + SchedulerBinding.instance?.removeTimingsCallback(_onTimingsCallback); + _started = false; + } } }