-
Notifications
You must be signed in to change notification settings - Fork 344
Store an instance to console #5049
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
Changes from all commits
081f1c7
eea9357
92fdadc
99c9684
f3277b5
d393f73
7be627e
9623724
5f2b3e2
d3fd43f
e69ddcc
430ca28
0cbfc1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2023 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'package:vm_service/vm_service.dart'; | ||
|
||
import '../../../../../shared/globals.dart'; | ||
import '../../../shared/primitives/class_name.dart'; | ||
import '../../../shared/primitives/instance_set_view.dart'; | ||
|
||
class HeapClassSampler extends ClassSampler { | ||
HeapClassSampler(this.className); | ||
|
||
final HeapClassName className; | ||
|
||
@override | ||
Future<void> oneVariableToConsole() async { | ||
final isolateRef = serviceManager.isolateManager.mainIsolate.value!; | ||
final isolateId = isolateRef.id!; | ||
|
||
// It would be great to find out how to avoid full scan of classes. | ||
polina-c marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final theClass = (await serviceManager.service!.getClassList(isolateId)) | ||
.classes! | ||
.firstWhere((ref) => className.matches(ref)); | ||
|
||
final instances = await serviceManager.service!.getInstances( | ||
isolateId, | ||
theClass.id!, | ||
1, | ||
); | ||
|
||
final instance = instances.instances!.first as InstanceRef; | ||
|
||
// drop to console | ||
serviceManager.consoleService.appendInstanceRef( | ||
value: instance, | ||
diagnostic: null, | ||
isolateRef: isolateRef, | ||
forceScrollIntoView: true, | ||
); | ||
|
||
// TODO (polina-c): convert drafts below to separate commands | ||
// before opening the flag. | ||
|
||
// eval object | ||
final response1 = await serviceManager.service! | ||
.evaluate(isolateId, instance.id!, 'toString()'); | ||
print('!!!! eval without scope: ' + response1.json!['valueAsString']); | ||
|
||
// eval object | ||
final response2 = await serviceManager.service!.evaluate( | ||
isolateId, | ||
instance.id!, | ||
'identityHashCode(this)', | ||
scope: {'this': instance.id!}, | ||
); | ||
print('!!!! eval with scope: ' + response2.json!['valueAsString']); | ||
Comment on lines
+46
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are these supposed to still be there? both the responses and the prints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are under TODO to move them out |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,19 @@ | |
// found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:vm_service/vm_service.dart'; | ||
|
||
import '../../../../shared/analytics/constants.dart'; | ||
import '../../../../shared/common_widgets.dart'; | ||
import '../../../../shared/primitives/utils.dart'; | ||
|
||
typedef SampleObtainer = InstanceRef Function(); | ||
abstract class ClassSampler { | ||
Future<void> oneVariableToConsole(); | ||
} | ||
|
||
class InstanceSetView extends StatelessWidget { | ||
const InstanceSetView({ | ||
/// A button with label '...' to show near count of instances, | ||
/// with drop down menu to explore the instances. | ||
class InstanceSetButton extends StatelessWidget { | ||
const InstanceSetButton({ | ||
super.key, | ||
this.textStyle, | ||
required this.count, | ||
|
@@ -22,7 +25,7 @@ class InstanceSetView extends StatelessWidget { | |
}) : assert(showMenu == (sampleObtainer != null)); | ||
|
||
final int count; | ||
final SampleObtainer? sampleObtainer; | ||
final ClassSampler? sampleObtainer; | ||
final bool showMenu; | ||
final TextStyle? textStyle; | ||
final MemoryAreas gaContext; | ||
|
@@ -38,41 +41,46 @@ class InstanceSetView extends StatelessWidget { | |
if (showMenu) | ||
ContextMenuButton( | ||
style: textStyle, | ||
menu: _menu(), | ||
menu: _menu(sampleObtainer!), | ||
), | ||
if (!showMenu) const SizedBox(width: ContextMenuButton.width), | ||
], | ||
); | ||
} | ||
} | ||
|
||
class _MenuForSubset extends StatelessWidget { | ||
const _MenuForSubset(this.menuText); | ||
class _StoreAsVariableMenu extends StatelessWidget { | ||
const _StoreAsVariableMenu(this.menuText, this.sampleObtainer); | ||
|
||
final String menuText; | ||
final ClassSampler sampleObtainer; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SubmenuButton( | ||
menuChildren: <Widget>[ | ||
MenuItemButton( | ||
onPressed: () => {}, | ||
child: const Text('Fields'), | ||
onPressed: sampleObtainer.oneVariableToConsole, | ||
child: const Text('One instance'), | ||
), | ||
const MenuItemButton( | ||
child: Text('Outgoing references'), | ||
child: Text('First 20 instances'), | ||
), | ||
const MenuItemButton( | ||
child: Text('Incoming references'), | ||
child: Text('All instances'), | ||
), | ||
], | ||
child: Text(menuText), | ||
); | ||
} | ||
} | ||
|
||
List<Widget> _menu() => [ | ||
const _MenuForSubset('Store one instance as a console variable'), | ||
const _MenuForSubset('Store first 100 instances as a console variable'), | ||
const _MenuForSubset('Store all instances as a console variable'), | ||
List<Widget> _menu(ClassSampler sampleObtainer) => [ | ||
_StoreAsVariableMenu( | ||
'Store as a console variable', | ||
sampleObtainer, | ||
), | ||
const MenuItemButton( | ||
child: Text('Browse an instance in console'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should mention the work "references" to make it clear what you can browse |
||
), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these can both be super parameters in the constructor directly