diff --git a/packages/devtools_app/lib/src/screens/debugger/debugger_model.dart b/packages/devtools_app/lib/src/screens/debugger/debugger_model.dart index 2bac38fae18..c78a43076cf 100644 --- a/packages/devtools_app/lib/src/screens/debugger/debugger_model.dart +++ b/packages/devtools_app/lib/src/screens/debugger/debugger_model.dart @@ -5,6 +5,7 @@ import 'package:vm_service/vm_service.dart'; import '../../shared/diagnostics/primitives/source_location.dart'; +import '../../shared/primitives/simple_items.dart'; import '../../shared/primitives/trees.dart'; import '../../shared/ui/search.dart'; @@ -212,8 +213,6 @@ class StackFrameAndSourcePosition { String get description { const unoptimized = '[Unoptimized] '; const none = ''; - const anonymousClosure = ''; - const closure = ''; const asyncBreak = ''; if (frame.kind == FrameKind.kAsyncSuspensionMarker) { @@ -224,7 +223,7 @@ class StackFrameAndSourcePosition { if (name.startsWith(unoptimized)) { name = name.substring(unoptimized.length); } - name = name.replaceAll(anonymousClosure, closure); + name = name.replaceAll(anonymousClosureName, closureName); name = name == none ? name : '$name'; return name; } 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 1c595eade6c..3d65ffd1671 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 @@ -1335,6 +1335,32 @@ extension CpuSamplesExtension on vm_service.CpuSamples { if (className != null) { return '$className.${current.name}'; } + if (current.name == anonymousClosureName && + current._function is vm_service.FuncRef) { + final nameParts = [current.name]; + + final function = current._function as vm_service.FuncRef; + var owner = function.owner; + switch (owner.runtimeType) { + case vm_service.FuncRef: + owner = owner as vm_service.FuncRef; + final functionName = owner.name; + + String? className; + if (owner.owner is vm_service.ClassRef) { + className = (owner.owner as vm_service.ClassRef).name; + } + + nameParts.insertAll(0, [className, functionName]); + break; + case vm_service.ClassRef: + final className = (owner as vm_service.ClassRef).name; + nameParts.insert(0, className); + } + + nameParts.removeWhere((element) => element == null); + return nameParts.join('.'); + } return current.name; } diff --git a/packages/devtools_app/lib/src/shared/primitives/simple_items.dart b/packages/devtools_app/lib/src/shared/primitives/simple_items.dart index fb1406048ea..814ca75f8d4 100644 --- a/packages/devtools_app/lib/src/shared/primitives/simple_items.dart +++ b/packages/devtools_app/lib/src/shared/primitives/simple_items.dart @@ -46,3 +46,7 @@ enum ScreenMetaData { } const String traceEventsFieldName = 'traceEvents'; + +const closureName = ''; + +const anonymousClosureName = ''; diff --git a/packages/devtools_app/lib/src/shared/primitives/utils.dart b/packages/devtools_app/lib/src/shared/primitives/utils.dart index 45c51280c04..1a32cff250b 100644 --- a/packages/devtools_app/lib/src/shared/primitives/utils.dart +++ b/packages/devtools_app/lib/src/shared/primitives/utils.dart @@ -18,6 +18,8 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; +import 'simple_items.dart'; + bool isPrivate(String member) => member.startsWith('_'); /// Public properties first, then sort alphabetically @@ -292,7 +294,7 @@ String pluralize(String word, int count, {String? plural}) => /// See (https://github.com/dart-lang/sdk/issues/36999). String getSimpleStackFrameName(String? name) { name ??= ''; - final newName = name.replaceAll('', ''); + final newName = name.replaceAll(anonymousClosureName, closureName); // If the class name contains a space, then it is not a valid Dart name. We // throw out simplified names with spaces to prevent simplifying C++ class