@@ -42,6 +42,7 @@ export 'src/foundation/licenses.dart';
|
||||
export 'src/foundation/observer_list.dart';
|
||||
export 'src/foundation/platform.dart';
|
||||
export 'src/foundation/print.dart';
|
||||
export 'src/foundation/profile.dart';
|
||||
export 'src/foundation/serialization.dart';
|
||||
export 'src/foundation/synchronous_future.dart';
|
||||
export 'src/foundation/tree_diagnostics_mixin.dart';
|
||||
|
||||
18
packages/flutter/lib/src/foundation/profile.dart
Normal file
18
packages/flutter/lib/src/foundation/profile.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
/// Whether we've been built in release mode.
|
||||
const bool _kReleaseMode = const bool.fromEnvironment("dart.vm.product");
|
||||
|
||||
/// When running in profile mode (or debug mode), invoke the given function.
|
||||
///
|
||||
/// In release mode, the function is not invoked.
|
||||
// TODO(devoncarew): Going forward, we'll want the call to profile() to be tree-shaken out.
|
||||
void profile(VoidCallback function) {
|
||||
if (_kReleaseMode)
|
||||
return;
|
||||
function();
|
||||
}
|
||||
21
packages/flutter/test/foundation/profile_test.dart
Normal file
21
packages/flutter/test/foundation/profile_test.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// We run our tests in debug mode, to this will always evaluate to false...
|
||||
const bool isReleaseMode = const bool.fromEnvironment("dart.vm.product");
|
||||
|
||||
void main() {
|
||||
// TODO(devoncarew): This test - while very nice - isn't testing what we really want to know:
|
||||
// that the code in the `profile` closure is omitted in release mode.
|
||||
test("profile invokes its closure in debug or profile mode", () {
|
||||
int count = 0;
|
||||
profile(() {
|
||||
count++;
|
||||
});
|
||||
expect(count, isReleaseMode ? 0 : 1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user