mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
fn.dart shouldn't spam the log
This CL introduces a flag to control whether fn.dart prints the render duration to the console. By default, the flag is off to avoid log spam. Also, improve the way we intialize _isInCheckedMode to make use of the fact that Dart intializes final fields lazily. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/982073002
This commit is contained in:
parent
e7335d39f4
commit
1f77a79a2c
@ -9,23 +9,19 @@ import 'dart:collection';
|
||||
import 'dart:sky' as sky;
|
||||
import 'reflect.dart' as reflect;
|
||||
|
||||
bool _checkedMode;
|
||||
|
||||
bool _debugWarnings() {
|
||||
bool _initIsInCheckedMode() {
|
||||
void testFn(double i) {}
|
||||
|
||||
if (_checkedMode == null) {
|
||||
_checkedMode = false;
|
||||
try {
|
||||
testFn('not a double');
|
||||
} catch (ex) {
|
||||
_checkedMode = true;
|
||||
}
|
||||
try {
|
||||
testFn('not a double');
|
||||
} catch (ex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return _checkedMode;
|
||||
return false;
|
||||
}
|
||||
|
||||
final bool _isInCheckedMode = _initIsInCheckedMode();
|
||||
final bool _shouldLogRenderDuration = false;
|
||||
|
||||
class EventHandler {
|
||||
final String type;
|
||||
final sky.EventListener listener;
|
||||
@ -152,7 +148,7 @@ abstract class Element extends Node {
|
||||
_className = style == null ? '': style._className;
|
||||
_children = children == null ? _emptyList : children;
|
||||
|
||||
if (_debugWarnings()) {
|
||||
if (_isInCheckedMode) {
|
||||
_debugReportDuplicateIds();
|
||||
}
|
||||
}
|
||||
@ -516,8 +512,10 @@ void _renderDirtyComponents() {
|
||||
|
||||
_dirtyComponents.clear();
|
||||
_renderScheduled = false;
|
||||
|
||||
sw.stop();
|
||||
print("Render took ${sw.elapsedMicroseconds} microseconds");
|
||||
if (_shouldLogRenderDuration)
|
||||
print("Render took ${sw.elapsedMicroseconds} microseconds");
|
||||
}
|
||||
|
||||
void _scheduleComponentForRender(Component c) {
|
||||
@ -646,18 +644,19 @@ abstract class Component extends Node {
|
||||
|
||||
abstract class App extends Component {
|
||||
sky.Node _host = null;
|
||||
App()
|
||||
: super(stateful: true) {
|
||||
|
||||
App() : super(stateful: true) {
|
||||
_host = sky.document.createElement('div');
|
||||
sky.document.appendChild(_host);
|
||||
|
||||
new Future.microtask(() {
|
||||
Stopwatch sw = new Stopwatch()..start();
|
||||
|
||||
_sync(null, _host, null);
|
||||
assert(_root is sky.Node);
|
||||
|
||||
sw.stop();
|
||||
print("Initial render: ${sw.elapsedMicroseconds} microseconds");
|
||||
if (_shouldLogRenderDuration)
|
||||
print("Initial render: ${sw.elapsedMicroseconds} microseconds");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user