flutter的stackframe

stackframe这个类是在stack_frame.dart这个文件里的,主要是解析报错信息的,就如下展示的报错信息:

#0      getSampleStack. (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:40:57)
#1      new Future.sync (dart:async/future.dart:224:31)
#2      getSampleStack (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:40:10)
#3      main (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:46:40)
#4      main (package:flutter_goldens/flutter_goldens.dart:43:17)

#5      main.. (file:///temp/path.whatever/listener.dart:47:18)
#6      _rootRun (dart:async/zone.dart:1126:13)
#7      _CustomZone.run (dart:async/zone.dart:1023:19)
#8      _runZoned (dart:async/zone.dart:1518:10)
#9      runZoned (dart:async/zone.dart:1465:12)
#10     Declarer.declare (package:test_api/src/backend/declarer.dart:130:22)
#11     RemoteListener.start... (package:test_api/src/remote_listener.dart:124:26)

#12     _rootRun (dart:async/zone.dart:1126:13)
#13     _CustomZone.run (dart:async/zone.dart:1023:19)
#14     _runZoned (dart:async/zone.dart:1518:10)
#15     runZoned (dart:async/zone.dart:1502:12)
#16     RemoteListener.start.. (package:test_api/src/remote_listener.dart:70:9)
#17     _rootRun (dart:async/zone.dart:1126:13)
#18     _CustomZone.run (dart:async/zone.dart:1023:19)
#19     _runZoned (dart:async/zone.dart:1518:10)
#20     runZoned (dart:async/zone.dart:1465:12)
#21     StackTraceFormatter.asCurrent (package:test_api/src/backend/stack_trace_formatter.dart:41:31)
#22     RemoteListener.start. (package:test_api/src/remote_listener.dart:69:29)
#23     _rootRun (dart:async/zone.dart:1126:13)
#24     _CustomZone.run (dart:async/zone.dart:1023:19)
#25     _runZoned (dart:async/zone.dart:1518:10)
#26     runZoned (dart:async/zone.dart:1465:12)
#27     SuiteChannelManager.asCurrent (package:test_api/src/suite_channel_manager.dart:34:31)
#28     RemoteListener.start (package:test_api/src/remote_listener.dart:68:27)
#29     serializeSuite (file:///temp/path.whatever/listener.dart:17:25)
#30     main (file:///temp/path.whatever/listener.dart:43:36)
#31     _runMainZoned.. (dart:ui/hooks.dart:239:25)
#32     _rootRun (dart:async/zone.dart:1126:13)
#33     _CustomZone.run (dart:async/zone.dart:1023:19)
#34     _runZoned (dart:async/zone.dart:1518:10)
#35     runZoned (dart:async/zone.dart:1502:12)
#36     _runMainZoned. (dart:ui/hooks.dart:231:5)
#37     _startIsolate. (dart:isolate-patch/isolate_patch.dart:307:19)
#38     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

是不是觉得很在console里常常看到这个?这个类就是解析这一部分信息的, 输出的结果就是如下图所示:

  StackFrame(number: 0,  className: '',                    method: 'getSampleStack', packageScheme: 'file',    package: '',       packagePath: '/path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart', line: 40,   column: 57, source: '#0      getSampleStack. (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:40:57)'),
  StackFrame(number: 1,  className: 'Future',              method: 'sync',           packageScheme: 'dart',    package: 'async',           packagePath: 'future.dart',                                                                 line: 224,  column: 31, isConstructor: true, source: '#1      new Future.sync (dart:async/future.dart:224:31)'),
  StackFrame(number: 2,  className: '',                    method: 'getSampleStack', packageScheme: 'file',    package: '',       packagePath: '/path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart', line: 40,   column: 10, source: '#2      getSampleStack (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:40:10)'),
  StackFrame(number: 3,  className: '',                    method: 'main',           packageScheme: 'file',    package: '',       packagePath: '/path/to/flutter/packages/flutter/foundation/error_reporting_test.dart',      line: 46,   column: 40, source: '#3      main (file:///path/to/flutter/packages/flutter/test/foundation/error_reporting_test.dart:46:40)'),
  StackFrame(number: 4,  className: '',                    method: 'main',           packageScheme: 'package', package: 'flutter_goldens', packagePath: 'flutter_goldens.dart',                                                        line: 43,   column: 17, source: '#4      main (package:flutter_goldens/flutter_goldens.dart:43:17)'),
  StackFrame.asynchronousSuspension,
  StackFrame(number: 5,  className: '',                    method: 'main',           packageScheme: 'file',    package: '',      packagePath: '/temp/path.whatever/listener.dart',                                           line: 47,   column: 18, source: '#5      main.. (file:///temp/path.whatever/listener.dart:47:18)'),
  StackFrame(number: 6,  className: '',                    method: '_rootRun',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1126, column: 13, source: '#6      _rootRun (dart:async/zone.dart:1126:13)'),
  StackFrame(number: 7,  className: '_CustomZone',         method: 'run',            packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1023, column: 19, source: '#7      _CustomZone.run (dart:async/zone.dart:1023:19)'),
  StackFrame(number: 8,  className: '',                    method: '_runZoned',      packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1518, column: 10, source: '#8      _runZoned (dart:async/zone.dart:1518:10)'),
  StackFrame(number: 9,  className: '',                    method: 'runZoned',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1465, column: 12, source: '#9      runZoned (dart:async/zone.dart:1465:12)'),
  StackFrame(number: 10, className: 'Declarer',            method: 'declare',        packageScheme: 'package', package: 'test_api',       packagePath: 'src/backend/declarer.dart',                                                   line: 130,  column: 22, source: '#10     Declarer.declare (package:test_api/src/backend/declarer.dart:130:22)'),
  StackFrame(number: 11, className: 'RemoteListener',      method: 'start',          packageScheme: 'package', package: 'test_api',       packagePath: 'src/remote_listener.dart',                                                    line: 124,  column: 26, source: '#11     RemoteListener.start... (package:test_api/src/remote_listener.dart:124:26)'),
  StackFrame.asynchronousSuspension,
  StackFrame(number: 12, className: '',                    method: '_rootRun',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1126, column: 13, source: '#12     _rootRun (dart:async/zone.dart:1126:13)'),
  StackFrame(number: 13, className: '_CustomZone',         method: 'run' ,           packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1023, column: 19, source: '#13     _CustomZone.run (dart:async/zone.dart:1023:19)'),
  StackFrame(number: 14, className: '',                    method: '_runZoned',      packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1518, column: 10, source: '#14     _runZoned (dart:async/zone.dart:1518:10)'),
  StackFrame(number: 15, className: '',                    method: 'runZoned',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1502, column: 12, source: '#15     runZoned (dart:async/zone.dart:1502:12)'),
  StackFrame(number: 16, className: 'RemoteListener',      method: 'start',          packageScheme: 'package', package: 'test_api',       packagePath: 'src/remote_listener.dart',                                                    line: 70,   column: 9, source: '#16     RemoteListener.start.. (package:test_api/src/remote_listener.dart:70:9)'),
  StackFrame(number: 17, className: '',                    method: '_rootRun',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1126, column: 13, source: '#17     _rootRun (dart:async/zone.dart:1126:13)'),
  StackFrame(number: 18, className: '_CustomZone',         method: 'run',            packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1023, column: 19, source: '#18     _CustomZone.run (dart:async/zone.dart:1023:19)'),
  StackFrame(number: 19, className: '',                    method: '_runZoned',      packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1518, column: 10, source: '#19     _runZoned (dart:async/zone.dart:1518:10)'),
  StackFrame(number: 20, className: '',                    method: 'runZoned',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1465, column: 12, source: '#20     runZoned (dart:async/zone.dart:1465:12)'),
  StackFrame(number: 21, className: 'StackTraceFormatter', method: 'asCurrent',      packageScheme: 'package', package: 'test_api',       packagePath: 'src/backend/stack_trace_formatter.dart',                                      line: 41,   column: 31, source: '#21     StackTraceFormatter.asCurrent (package:test_api/src/backend/stack_trace_formatter.dart:41:31)'),
  StackFrame(number: 22, className: 'RemoteListener',      method: 'start',          packageScheme: 'package', package: 'test_api',       packagePath: 'src/remote_listener.dart',                                                    line: 69,   column: 29, source: '#22     RemoteListener.start. (package:test_api/src/remote_listener.dart:69:29)'),
  StackFrame(number: 23, className: '',                    method: '_rootRun',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1126, column: 13, source: '#23     _rootRun (dart:async/zone.dart:1126:13)'),
  StackFrame(number: 24, className: '_CustomZone',         method: 'run',            packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1023, column: 19, source: '#24     _CustomZone.run (dart:async/zone.dart:1023:19)'),
  StackFrame(number: 25, className: '',                    method: '_runZoned',      packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1518, column: 10, source: '#25     _runZoned (dart:async/zone.dart:1518:10)'),
  StackFrame(number: 26, className: '',                    method: 'runZoned',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1465, column: 12, source: '#26     runZoned (dart:async/zone.dart:1465:12)'),
  StackFrame(number: 27, className: 'SuiteChannelManager', method: 'asCurrent',      packageScheme: 'package', package: 'test_api',       packagePath: 'src/suite_channel_manager.dart',                                              line: 34,   column: 31, source: '#27     SuiteChannelManager.asCurrent (package:test_api/src/suite_channel_manager.dart:34:31)'),
  StackFrame(number: 28, className: 'RemoteListener',      method: 'start',          packageScheme: 'package', package: 'test_api',       packagePath: 'src/remote_listener.dart',                                                    line: 68,   column: 27, source: '#28     RemoteListener.start (package:test_api/src/remote_listener.dart:68:27)'),
  StackFrame(number: 29, className: '',                    method: 'serializeSuite', packageScheme: 'file',    package: '',      packagePath: '/temp/path.whatever/listener.dart',                                           line: 17,   column: 25, source: '#29     serializeSuite (file:///temp/path.whatever/listener.dart:17:25)'),
  StackFrame(number: 30, className: '',                    method: 'main',           packageScheme: 'file',    package: '',      packagePath: '/temp/path.whatever/listener.dart',                                           line: 43,   column: 36, source: '#30     main (file:///temp/path.whatever/listener.dart:43:36)'),
  StackFrame(number: 31, className: '',                    method: '_runMainZoned',  packageScheme: 'dart',    package: 'ui',             packagePath: 'hooks.dart',                                                                  line:239,   column: 25, source: '#31     _runMainZoned.. (dart:ui/hooks.dart:239:25)'),
  StackFrame(number: 32, className: '',                    method: '_rootRun',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1126, column: 13, source: '#32     _rootRun (dart:async/zone.dart:1126:13)'),
  StackFrame(number: 33, className: '_CustomZone',         method: 'run' ,           packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1023, column: 19, source: '#33     _CustomZone.run (dart:async/zone.dart:1023:19)'),
  StackFrame(number: 34, className: '',                    method: '_runZoned',      packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1518, column: 10, source: '#34     _runZoned (dart:async/zone.dart:1518:10)'),
  StackFrame(number: 35, className: '',                    method: 'runZoned',       packageScheme: 'dart',    package: 'async',          packagePath: 'zone.dart',                                                                   line: 1502, column: 12, source: '#35     runZoned (dart:async/zone.dart:1502:12)'),
  StackFrame(number: 36, className: '',                    method: '_runMainZoned',  packageScheme: 'dart',    package: 'ui',             packagePath: 'hooks.dart',                                                                  line: 231,  column: 5, source: '#36     _runMainZoned. (dart:ui/hooks.dart:231:5)'),
  StackFrame(number: 37, className: '',                    method: '_startIsolate',  packageScheme: 'dart',    package: 'isolate-patch',  packagePath: 'isolate_patch.dart',                                                          line: 307,  column: 19, source: '#37     _startIsolate. (dart:isolate-patch/isolate_patch.dart:307:19)'),
  StackFrame(number: 38, className: '_RawReceivePortImpl', method: '_handleMessage', packageScheme: 'dart',    package: 'isolate-patch',  packagePath: 'isolate_patch.dart',                   

这个类内部逻辑很简单,就不做详细分析,而且对于我们实际开发的意义有限,做统计比较合适。

这是flutter框架源码分析的其中一篇,因能力有限,有诸多不足之处,还请斧正。

你可能感兴趣的:(flutter的stackframe)