Fix bug with native frames in the CPU profiler (#5344)
diff --git a/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart b/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart index 1835515..1c595ea 100644 --- a/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart +++ b/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart
@@ -1232,14 +1232,13 @@ final bool isCodeTree; int frameId = kNoFrameId; - vm_service.FuncRef? get _function { + Object? get _function { if (isCodeTree) { return _code.function!; } final function = samples.functions![index].function; - if (function is vm_service.FuncRef) { - // TODO(jacobr): is this really anything else? The VMService API isn't - // clear. + if (function is vm_service.FuncRef || + function is vm_service.NativeFunction) { return function; } return null; @@ -1247,7 +1246,16 @@ vm_service.CodeRef get _code => samples.codes[index].code!; - String? get name => isCodeTree ? _code.name : _function?.name; + String? get name { + if (isCodeTree) return _code.name; + switch (_function.runtimeType) { + case vm_service.FuncRef: + return (_function as vm_service.FuncRef?)?.name; + case vm_service.NativeFunction: + return (_function as vm_service.NativeFunction?)?.name; + } + return null; + } String? get className { if (isCodeTree) return null; @@ -1261,22 +1269,23 @@ return null; } - String? get resolvedUrl => isCodeTree + String? get resolvedUrl => isCodeTree && _function is vm_service.FuncRef? ? // TODO(bkonyi): not sure if this is a resolved URL or not, but it's not // critical since this is only displayed when VM developer mode is // enabled. - _function?.location?.script!.uri + (_function as vm_service.FuncRef?)?.location?.script?.uri : samples.functions![index].resolvedUrl; int? get sourceLine { final function = _function; try { - return function?.location?.line; + if (function is vm_service.FuncRef?) { + return function?.location?.line; + } + return null; } catch (_) { - // Fail gracefully if `function` has no getter `location` (for example, if - // the function is an instance of [NativeFunction]) or generally if - // `function.location.line` throws an exception. + // Fail gracefully if `function.location.line` throws an exception. return null; } }
diff --git a/packages/devtools_app/lib/src/screens/profiler/panes/bottom_up.dart b/packages/devtools_app/lib/src/screens/profiler/panes/bottom_up.dart index 0c500e5..0ef4a63 100644 --- a/packages/devtools_app/lib/src/screens/profiler/panes/bottom_up.dart +++ b/packages/devtools_app/lib/src/screens/profiler/panes/bottom_up.dart
@@ -11,7 +11,7 @@ import '../cpu_profile_columns.dart'; import '../cpu_profile_model.dart'; -/// A table of the CPU's bottom-up call tree. +/// A table of the bottom up tree for a CPU profile. class CpuBottomUpTable extends StatelessWidget { factory CpuBottomUpTable( List<CpuStackFrame> bottomUpRoots, {
diff --git a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md index 826f37a..acfebb8 100644 --- a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md +++ b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
@@ -16,6 +16,7 @@ ## CPU profiler updates * Add ability to inspect statistics for a CPU profile - [#5340](https://github.com/flutter/devtools/pull/5340) +* Fix a bug where Native stack frames were missing their name - [#5344](https://github.com/flutter/devtools/pull/5344) ## Memory updates TODO: Remove this section if there are not any general updates.