Commit 561d17a8 authored by Devon Carew's avatar Devon Carew Committed by GitHub

add a profile() method (#11443)

* add a profile() method

* add todos
parent 6655074b
......@@ -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';
// 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();
}
// 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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment