TF-495 Only apply benchmark and fps on debug or profile mode
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -1,28 +1,35 @@
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/core.dart';
|
||||
|
||||
class _Benchmark {
|
||||
final Map<String, int> _starts = <String, int>{};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user