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/app_logger.dart';
|
||||||
export 'utils/benchmark.dart';
|
export 'utils/benchmark.dart';
|
||||||
export 'utils/fps_manager.dart';
|
export 'utils/fps_manager.dart';
|
||||||
|
export 'utils/build_utils.dart';
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
export 'presentation/views/text/slogan_builder.dart';
|
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 {
|
class _Benchmark {
|
||||||
final Map<String, int> _starts = <String, int>{};
|
final Map<String, int> _starts = <String, int>{};
|
||||||
|
|
||||||
void start(dynamic id) {
|
void start(dynamic id) {
|
||||||
final String benchId = id.toString();
|
if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) {
|
||||||
if (_starts.containsKey(benchId)) {
|
final String benchId = id.toString();
|
||||||
log('_Benchmark::start(): Benchmark already have comparing with id=$benchId in time');
|
if (_starts.containsKey(benchId)) {
|
||||||
} else {
|
log('_Benchmark::start(): Benchmark already have comparing with id=$benchId in time');
|
||||||
_starts[benchId] = DateTime.now().microsecondsSinceEpoch;
|
} else {
|
||||||
|
_starts[benchId] = DateTime.now().microsecondsSinceEpoch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double end(dynamic id) {
|
double end(dynamic id) {
|
||||||
final String benchId = id.toString();
|
if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) {
|
||||||
if (!_starts.containsKey(benchId)) {
|
final String benchId = id.toString();
|
||||||
throw Exception('In Benchmark not placed comparing with id=$benchId');
|
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;
|
return 0;
|
||||||
final String info = '$benchId need ${diff}ms';
|
|
||||||
log('_Benchmark::end(): $info');
|
|
||||||
_starts.remove(benchId);
|
|
||||||
return diff;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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:collection';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:core/core.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
|
|
||||||
/// FpsManager callback.
|
/// FpsManager callback.
|
||||||
@@ -46,16 +47,20 @@ class FpsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void start() async {
|
void start() async {
|
||||||
if (!_started) {
|
if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) {
|
||||||
SchedulerBinding.instance?.addTimingsCallback(_onTimingsCallback);
|
if (!_started) {
|
||||||
_started = true;
|
SchedulerBinding.instance?.addTimingsCallback(_onTimingsCallback);
|
||||||
|
_started = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
if (_started) {
|
if (BuildUtils.isDebugMode || BuildUtils.isProfileMode) {
|
||||||
SchedulerBinding.instance?.removeTimingsCallback(_onTimingsCallback);
|
if (_started) {
|
||||||
_started = false;
|
SchedulerBinding.instance?.removeTimingsCallback(_onTimingsCallback);
|
||||||
|
_started = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user