Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception capturing CPU profile ("type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast") #8567

Open
DanTup opened this issue Nov 27, 2024 · 11 comments
Assignees
Labels
blocked Issue or PR is blocked on another issue or PR. bug Something isn't working cpu profiler P1 high priority issues at the top of the work list, actively being worked on. regression

Comments

@DanTup
Copy link
Contributor

DanTup commented Nov 27, 2024

I hit this error while trying to do some CPU profiling of the analysis server. I don't know if I'll be able to repro, but I thought I should record it here before I lose it.

The steps I followed:

  • Open my flutter_counter test app in VS Code
  • Run the Preferences: Open Workspace Settings (JSON) command from the command palette
    Add "dart.analyzerVmServicePort": 8855 (port number is not important but you'll need it further down) and Save
    A toast notification should appear in the bottom right warning you that the analysis servers VM Service is enabled
  • Wait for all initial analysis to complete (No "Analyzing..." or spinners on status bar)
  • Open a file and find a location to type in
  • Run the Dart: Open DevTools in Browser command from the palette
  • In DevTools, enter http://localhost:8855/ (using the port number from above) and click Connect
  • Navigate to the CPU Profiler tab
  • Click "Enable Profiler"
  • Click "Start recording"
  • Switch back to VS Code and type in the editor to reproduce the poor performance
  • Click "Stop recording"
  • At this point, it just got stuck on "Fetching CPU samples" forever

Chrome dev tools console has this:

js_util_patch.dart:81 getDartDevelopmentServiceVersion: (-32601) Method not found
cAU @ js_util_patch.dart:81Understand this warningAI
:9100/api/serveAvailableExtensions?packageRootUri=org-dartlang-sdk%3A%2F%2F%2Fsdk%2Flib%2F_internal%2Fvm:1 
        
        
       Failed to load resource: the server responded with a status of 500 (Internal Server Error)Understand this errorAI
js_util_patch.dart:81 HttpRequest api/serveAvailableExtensions failed status = 500, responseText = {"error":"Invalid argument (must be a file:// URI String): \"org-dartlang-sdk:///sdk/lib/_internal/vm\"","logs":["ExtensionsManager.serveAvailableExtensions for rootPathFileUri: org-dartlang-sdk:///sdk/lib/_internal/vm","ExtensionsManager.serveAvailableExtensions adding extensions for app root."]}
cAU @ js_util_patch.dart:81Understand this warningAI
js_util_patch.dart:81 Could not time async operation "cpuProfileProcessingTime" because an exception was thrown:
TypeError: Instance of 'minified:yY': type 'minified:yY' is not a subtype of type 'minified:fC?'

    at Object.p (http://127.0.0.1:9100/main.dart.js:3623:19)
    at Object.c52 (http://127.0.0.1:9100/main.dart.js:4445:18)
    at p2.cvF [as a] (http://127.0.0.1:9100/main.dart.js:4444:3)
    at am5.cgh (http://127.0.0.1:9100/main.dart.js:47598:10)
    at Object.ah (http://127.0.0.1:9100/main.dart.js:47455:15)
    at aM8.$1 (http://127.0.0.1:9100/main.dart.js:91925:14)
    at F.d9 (http://127.0.0.1:9100/main.dart.js:59451:23)
    at aT.u (http://127.0.0.1:9100/main.dart.js:59431:16)
    at Object.c_M (http://127.0.0.1:9100/main.dart.js:6377:17)
    at Object.H (http://127.0.0.1:9100/main.dart.js:6370:15)
cAU @ js_util_patch.dart:81Understand this warningAI
core_patch.dart:279 Uncaught Error: TypeError: Instance of 'minified:yY': type 'minified:yY' is not a subtype of type 'minified:fC?'
    at Object.p (js_helper.dart:1209:19)
    at Object.c52 (rti.dart:1405:3)
    at p2.cvF [as a] (rti.dart:1395:3)
    at am5.cgh (vm_service.dart:3219:5)
    at Object.ah (vm_service.dart:69:14)
    at aM8.$1 (vm_service_private_extensions.dart:899:12)
    at F.d9 (iterable.dart:435:29)
    at aT.u (iterable.dart:364:5)
    at Object.c_M (core_patch.dart:367:5)
    at Object.H (core_patch.dart:348:39)Understand this errorAI
js_util_patch.dart:81 [zoneGuarded]: TypeError: Instance of 'minified:yY': type 'minified:yY' is not a subtype of type 'minified:fC?'
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/js_helper.dart 1209:19                  wrapException
org-dartlang-sdk:///dart-sdk/lib/_internal/js_shared/lib/rti.dart 1405:3                          _failedAsCheck
org-dartlang-sdk:///dart-sdk/lib/_internal/js_shared/lib/rti.dart 1395:3                          _generalNullableAsCheckImplementation
../../../../../../rc/tmp65uzhjoh/hosted/pub.dev/vm_service-14.3.0/lib/src/vm_service.dart 3219:5  CodeRef._fromJson
../../../../../../rc/tmp65uzhjoh/hosted/pub.dev/vm_service-14.3.0/lib/src/vm_service.dart 69:14   createServiceObject
../../../lib/src/screens/vm_developer/vm_service_private_extensions.dart 899:12                   ProfileCode._fromJson
org-dartlang-sdk:///dart-sdk/lib/internal/iterable.dart 435:29                                    MappedListIterable.elementAt
org-dartlang-sdk:///dart-sdk/lib/internal/iterable.dart 364:5                                     ListIterator.moveNext
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/core_patch.dart 367:5                   List._of
org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/core_patch.dart 348:39                  List.of

image

Flutter SDK: 3.27.0-0.1.pre
Dart version: 3.6.0-334.3.beta

@DanTup
Copy link
Contributor Author

DanTup commented Nov 27, 2024

I tried again and reproduced the same issue. Switching to Flutter stable the issue went away, so this could be a regression (FYI @kenzieschmoll).

@kenzieschmoll
Copy link
Member

Are you able to get a stack trace that is not minified? What version of DevTools is this using?

@DanTup
Copy link
Contributor Author

DanTup commented Nov 29, 2024

I should've probably done that first 🙃

Running from latest code (e1ead3d) I see the error below, which I presume is the same. The top of the stack is in vm_service so I don't know if this might actually be an issue there? (@bkonyi)

type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast
#0      new CodeRef._fromJson (package:vm_service/src/vm_service.dart:3224:66)
#1      CodeRef.parse (package:vm_service/src/vm_service.dart:3199:37)
#2      createServiceObject (package:vm_service/src/vm_service.dart:69:25)
#3      new ProfileCode._fromJson (package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart:867:12)
#4      ProfileCode.parse (package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart:871:41)
#5      CpuSamplesPrivateView.codes.<anonymous closure> (package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart:928:50)
#6      MappedListIterable.elementAt (dart:_internal/iterable.dart:442:31)
#7      ListIterator.moveNext (dart:_internal/iterable.dart:371:26)
#8      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:190:27)
#9      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#10     new List.of (dart:core-patch/array_patch.dart:40:18)
#11     ListIterable.toList (dart:_internal/iterable.dart:224:7)
#12     CpuSamplesPrivateView.codes (package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart:929:14)
#13     _CpuProfileTimelineTree._code (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1229:43)
#14     _CpuProfileTimelineTree.name (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1232:28)
#15     _extension#0.generateStackFramesJson.nameForStackFrame (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1326:19)
#16     _extension#0.generateStackFramesJson.processStackFrame (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1367:35)
#17     _extension#0.generateStackFramesJson.processStackFrame (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1375:9)
#18     _extension#0.generateStackFramesJson (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:1383:5)
#19     CpuProfileData.generateFromCpuSamples (package:devtools_app/src/screens/profiler/cpu_profile_model.dart:562:50)
#20     CpuProfilerExtension.getCpuProfile (package:devtools_app/src/screens/profiler/cpu_profile_service.dart:64:42)
<asynchronous suspension>
#21     CpuProfilerController.pullAndProcessProfile.pullAndProcessHelper (package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart:259:21)
<asynchronous suspension>
#22     timeAsync (package:devtools_app/src/shared/analytics/_analytics_stub.dart:64:3)
<asynchronous suspension>
#23     CpuProfilerController.pullAndProcessProfile (package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart:273:7)
<asynchronous suspension>
#24     ProfilerScreenController.stopRecording (package:devtools_app/src/screens/profiler/profiler_screen_controller.dart:144:5)
<asynchronous suspension>

flutter: [ERROR]: [zoneGuarded]: type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast
package:vm_service/src/vm_service.dart 3224:66                                           new CodeRef._fromJson
package:vm_service/src/vm_service.dart 3199:37                                           CodeRef.parse
package:vm_service/src/vm_service.dart 69:25                                             createServiceObject
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 867:12  new ProfileCode._fromJson
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 871:41  ProfileCode.parse
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 928:50  CpuSamplesPrivateView.codes.<fn>
dart:_internal                                                                           ListIterable.toList
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 929:14  CpuSamplesPrivateView.codes
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1229:43                 _CpuProfileTimelineTree._code
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1232:28                 _CpuProfileTimelineTree.name
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1326:19                 _extension#0.generateStackFramesJson.nameForStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1367:35                 _extension#0.generateStackFramesJson.processStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1375:9                  _extension#0.generateStackFramesJson.processStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1383:5                  _extension#0.generateStackFramesJson
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 562:50                  CpuProfileData.generateFromCpuSamples
package:devtools_app/src/screens/profiler/cpu_profile_service.dart 64:42                 CpuProfilerExtension.getCpuProfile
package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart 259:21            CpuProfilerController.pullAndProcessProfile.pullAndProcessHelper
package:devtools_app/src/shared/analytics/_analytics_stub.dart 64:3                      timeAsync
package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart 273:7             CpuProfilerController.pullAndProcessProfile
package:devtools_app/src/screens/profiler/profiler_screen_controller.dart 144:5          ProfilerScreenController.stopRecording

flutter: [ERROR]: [PlatformDispatcher]: type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast
package:vm_service/src/vm_service.dart 3224:66                                           new CodeRef._fromJson
package:vm_service/src/vm_service.dart 3199:37                                           CodeRef.parse
package:vm_service/src/vm_service.dart 69:25                                             createServiceObject
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 867:12  new ProfileCode._fromJson
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 871:41  ProfileCode.parse
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 928:50  CpuSamplesPrivateView.codes.<fn>
dart:_internal                                                                           ListIterable.toList
package:devtools_app/src/screens/vm_developer/vm_service_private_extensions.dart 929:14  CpuSamplesPrivateView.codes
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1229:43                 _CpuProfileTimelineTree._code
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1232:28                 _CpuProfileTimelineTree.name
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1326:19                 _extension#0.generateStackFramesJson.nameForStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1367:35                 _extension#0.generateStackFramesJson.processStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1375:9                  _extension#0.generateStackFramesJson.processStackFrame
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 1383:5                  _extension#0.generateStackFramesJson
package:devtools_app/src/screens/profiler/cpu_profile_model.dart 562:50                  CpuProfileData.generateFromCpuSamples
package:devtools_app/src/screens/profiler/cpu_profile_service.dart 64:42                 CpuProfilerExtension.getCpuProfile
package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart 259:21            CpuProfilerController.pullAndProcessProfile.pullAndProcessHelper
package:devtools_app/src/shared/analytics/_analytics_stub.dart 64:3                      timeAsync
package:devtools_app/src/screens/profiler/cpu_profiler_controller.dart 273:7             CpuProfilerController.pullAndProcessProfile
package:devtools_app/src/screens/profiler/profiler_screen_controller.dart 144:5          ProfilerScreenController.stopRecording

@DanTup DanTup changed the title Exception capturing CPU profile of Dart analysis server Exception capturing CPU profile ("type 'NativeFunction' is not a subtype of type 'FuncRef?' in type cast") Nov 29, 2024
@DanTup
Copy link
Contributor Author

DanTup commented Nov 29, 2024

May be been introduced by dart-lang/sdk@d60221e?

I think maybe this code assumes createServiceObject always returns FuncRef or null but doesn't consider native functions. The fix might be as simple as just checking it's a FuncRef before assigning? (but I'll defer to @bkonyi and/or @parlough because I don't know much about this).

@bkonyi
Copy link
Contributor

bkonyi commented Nov 29, 2024

Yeah, that change is the culprit.

The type of function in @Code should be (@Function|NativeFunction).

I think this should only be an issue when VM Developer Mode is enabled.

@bkonyi
Copy link
Contributor

bkonyi commented Nov 29, 2024

Fix up for review here. This is going to require a breaking change to package:vm_service which we'll have to shepard through to Flutter once it lands.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Nov 29, 2024
The function property of a Code object can contain either a Function or
a NativeFunction. This change updates the protocol specification to
properly document existing behavior and regenerates package:vm_service
to update `CodeRef.function` to have a `dynamic` type.

This is a breaking change to `package:vm_service`, so this will be
released as 15.0.0.

Related to flutter/devtools#8567

TEST=N/A

Change-Id: Ie89723cdba8176be0d84a57a878fbedbca57f9c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398260
Commit-Queue: Ben Konyi <[email protected]>
Reviewed-by: Derek Xu <[email protected]>
Auto-Submit: Ben Konyi <[email protected]>
@DanTup
Copy link
Contributor Author

DanTup commented Dec 2, 2024

I think this should only be an issue when VM Developer Mode is enabled.

Ah, this does seem to be the case. I don't know when/why I enabled it, but disabling it seems to prevent the issue.

@bkonyi
Copy link
Contributor

bkonyi commented Dec 2, 2024

I think this should only be an issue when VM Developer Mode is enabled.

Ah, this does seem to be the case. I don't know when/why I enabled it, but disabling it seems to prevent the issue.

This is because we don't typically request the Code objects from the VM for CPU profiles. We set a special parameter when VM developer mode is enabled that causes the VM to send back some more detailed information back for certain RPCs, including getCpuSamples.

@kenzieschmoll do we think we'll want to CP this? It might be a pain to CP package:vm_service 15.0.0 since it'll pull in changes to a bunch of intermediate changes to packages like package:test_core and package:coverage. Maybe we can disable this functionality in the profiler for now and CP that just so stable DevTools isn't broken?

bkonyi added a commit to bkonyi/devtools that referenced this issue Dec 2, 2024
…enabled

Works around flutter#8567 until
`package:vm_service` 15.0.0 is rolled through to Flutter.
@bkonyi
Copy link
Contributor

bkonyi commented Dec 2, 2024

Uploaded #8578 to disable this functionality for now while the package:vm_service release is rolled through.

@kenzieschmoll
Copy link
Member

If the breakage only occurs when VM developer mode is enabled, then I don't think we need to CP your workaround. Am I understanding this correctly that this only happens in VM developer mode?

@DanTup
Copy link
Contributor Author

DanTup commented Dec 2, 2024

Am I understanding this correctly that this only happens in VM developer mode?

This does seem to be the case in my testing (which also matches up with what Ben said above) - after disabling it, I was able to profile without errors.

bkonyi added a commit that referenced this issue Dec 2, 2024
…enabled (#8578)

Works around #8567 until
`package:vm_service` 15.0.0 is rolled through to Flutter.
@kenzieschmoll kenzieschmoll added P1 high priority issues at the top of the work list, actively being worked on. blocked Issue or PR is blocked on another issue or PR. labels Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Issue or PR is blocked on another issue or PR. bug Something isn't working cpu profiler P1 high priority issues at the top of the work list, actively being worked on. regression
Projects
None yet
Development

No branches or pull requests

3 participants