Bug 305154 - Extend the programming model for MAT Queries - enable programming of queries doing comparison
Summary: Extend the programming model for MAT Queries - enable programming of queries ...
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.11.0   Edit
Assignee: Krum Tsvetkov CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 298078
  Show dependency tree
 
Reported: 2010-03-09 09:22 EST by Krum Tsvetkov CLA
Modified: 2020-10-13 10:59 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krum Tsvetkov CLA 2010-03-09 09:22:29 EST
It should be possible to program IQuery queries which perform comparison on several tables.

- It should be possible that the queries "receive" the tables as @Argument annotated fields
- The queries should be able to expose context menus, so that one can continue from the comparison result using context menus.

The ideas how to achieve this still need to be developed. Some comments already were pasted in the bug 298078.
Comment 1 Andrew Johnson CLA 2011-01-28 02:55:43 EST
My proposal is that:
table comparisons implement IQuery
@Argument is used to tag IResultTable arguments
For multisnapshot comparisons, a list or array of IQueryContext objects shows the corresponding contexts.
A single IQueryContext shows the context for the query itself - all object ids in the resulting IStructuredResult/TableComparisonResult are relative to this.

For SnapshotQuery.lookup to work then SnapshotQueryContext must say it accepts an IResultTable, or SnapshotQuery should also take a SnapshopQueryContext argument which could be a subclass providing IResultTables

The query argument wizard could have a combo-box for ITables. As it is hard to get the IQueryContexts to be set correspondingly then the combo-box should only include tables from the current snapshot. It also makes more sense to the user.

For the queries not to appear in an ordinary query menu, the query must be hidden, or filtered out by the policy. E.g. the policy could exclude multi IQueryContext queries. It might be possible to filter it out by having an argument of type SnapshotComparisonContext extending SnapshotQueryContext, but then we would have to expose that new type.

Ideally the compare basket would also have a query browser, with a policy only to find queries with multi IResultTables and multi IQueryContexts. The query argument wizard would not allow those  IResultTables and IQueryContexts to be changed.
Comment 2 Andrew Johnson CLA 2011-01-28 12:10:58 EST
I have added some code for this. It doesn't change the ordinary queries on a snapshot, but in the compare basket it adds a context menu bringing up a query browser for compare tables queries. This also has help for the compare tables query.

I've moved the compare tables query to the api bundle, so it can be used without the UI.

Next steps might be to make the compare queries direct context menu items, rather than via the query browser, possibly add intra-snapshot comparison queries to a snapshot context menu.
Comment 3 Andrew Johnson CLA 2011-01-30 16:38:34 EST
I've added table queries as context menu items.

I've done this by modifying QueryDropDownMenuAction (rather than QueryContextMenu), though the action to run the query is from QueryContextMenu.

It would be harder to also add the queries as drop down menu items as we need an editor to build the menu items (for the status display).

The status display doesn't work, but it doesn't for context menu in the inspector view either (the status finally appears on switching to the editor).
Comment 4 Andrew Johnson CLA 2011-04-12 09:02:38 EDT
CompareTablesQuery uses an array of IQueryContext to see whether the IResultTables are from the current dump. If the tables are from another dump then the object ids cannot be returned from the context menu and the set operations cannot be performed as the objects ids from two different dumps do not match.

This doesn't work so well for programmatic uses of the query as an IQueryContext is available to a query, but creating one from a snapshot e.g. SnapshotQueryContext is not an API.

Also, the argument set has problems with arrays/lists of a type which is satisfied by the context as it will find the argument from the context, but attempt to set it directly to the parameter as a list.

java.lang.ClassCastException: org.eclipse.mat.internal.snapshot.SnapshotQueryContext incompatible with java.util.List
	at org.eclipse.mat.query.registry.ArgumentSet.execute(ArgumentSet.java:87)
	at org.eclipse.mat.snapshot.query.SnapshotQuery.execute(SnapshotQuery.java:192)
	at org.eclipse.mat.tests.snapshot.QueryLookupTest.testFindCompareTables(QueryLookupTest.java:87)

1. Should CompareTablesQuery use a list/array of ISnapshot instead or as well as IQueryContext?
2. How should argument processing cope with lists/arrays of types satisfied from the context e.g. IQueryContext, ISnapshot, types from the parser?
Comment 5 Andrew Johnson CLA 2011-10-23 04:08:01 EDT
1.An multiple ISnapshot argument seems nearly as flexible as an IQueryContext and can easily be provided programmatically, so we should use this instead.
2.We can work out the argument processing later - at the moment it has to be provided as a List, not an array.
3.I can change CompareTablesQuery to use an array of ISnapshot.
4.A worthwhile enhancement would be to make a list/array of ISnapshot to be optional for a compare query. The query would then only be offered if the selection were of tables/trees from the current snapshot. I've some changes to CompareBasketView for this.
5.Should we remove IQueryContext lists/arrays as possible query arguments?
Comment 6 Andrew Johnson CLA 2020-10-13 04:06:31 EDT
See https://wiki.eclipse.org/MemoryAnalyzer/Extending_Memory_Analyzer#Comparison_Queries for some documentation. The use of RefinedStructuredResult can make queries more powerful as they operate on the filtered and sorted input tables and trees with
derived columns such as retained size.
Comment 7 Andrew Johnson CLA 2020-10-13 10:59:12 EDT
I'll mark this as fixed now that compare queries can be programmed and there is some documentation on the wiki.