如何在Flutter中跟踪功能?

时间:2019-04-08 06:23:15

标签: timer dart flutter

我有一个习惯来跟踪功能运行了多长时间,在react native中,我可以将console.timereact-native-console-time-polyfill一起使用

myFunction(){
  console.time("Func Foo")
  //any logic here
  console.timeEnd("Func Foo")
}

如何使用Flutter做到这一点?

3 个答案:

答案 0 :(得分:0)

检查此URL。

您可以在flutter中获取所有调试信息

https://flutter.dev/docs/testing/debugging

它将为您提供帮助。

答案 1 :(得分:0)

也许您可以尝试一下。

void main() async {
  var dateTimeNow = DateTime.now();

  await someExecution(); // call your function here.

  var dateTimeAfterExecution = DateTime.now();

  var difference = dateTimeAfterExecution.difference(dateTimeNow);
  print(difference.inMilliseconds);
}

答案 2 :(得分:0)

尝试一下

myFunction(){
  var oldTime = DateTime.now().millisecondsSinceEpoch;
  //any logic here

  // total time taken to run the logic would be
  print("time = ${DateTime.now().millisecondsSinceEpoch - oldTime} ms");
}