Query Report

Run a single query to produce a report in batch mode.

Motivation

Sometime it is useful to run a single query on a heap dump when in batch mode. This could be because it is known in advance what needs to be run, or the heap dump needs to remain on a big machine with no easily available graphical user interface.

Arguments

Argument Description
-command The command line version of the query to be run. This is like the text typed into the 'Search Queries' query browser command line.
other report options See batch mode control of report options

Result

A report holding the result of the query (by default, in HTML).

Simple example of a histogram for Windows

.\mat\ParseHeapDump.bat myheapdump.hprof -command=histogram org.eclipse.mat.api:query

Simple example of a histogram for Linux or macOS

./mat/ParseHeapDump.sh myheapdump.hprof -command=histogram org.eclipse.mat.api:query

Simple example of a histogram in text format and unzipped (*_Query\pages\Query_Command2.txt) for Windows

.\mat\ParseHeapDump.bat myheapdump.hprof -command=histogram -format=txt -unzip org.eclipse.mat.api:query

Simple example of a histogram in text format and unzipped (*_Query/pages/Query_Command2.txt) for Linux or macOS

./mat/ParseHeapDump.sh myheapdump.hprof -command=histogram -format=txt -unzip org.eclipse.mat.api:query

Simple OQL example for Windows

.\mat\ParseHeapDump.bat myheapdump.hprof "-command=oql \\\"SELECT * FROM java.lang.String s\\\"" org.eclipse.mat.api:query
Note: The OQL query oql has the actual OQL statement surrounded by double quotes. These need to be escaped here as shown. The whole of the command option must be passed to Eclipse Memory Analyzer as a single argument starting with -command. As the query command has spaces the whole argument is surrounded by double quotes so the operating system treats it as a single item.

Simple OQL example for Linux or macOS

./mat/ParseHeapDump.sh myheapdump.hprof "-command=oql \"SELECT * FROM java.lang.String s\"" org.eclipse.mat.api:query
Note: The OQL query oql has the actual OQL statement surrounded by double quotes. These need to be escaped here as shown. The whole of the command option must be passed to Eclipse Memory Analyzer as a single argument starting with -command. As the query command has spaces the whole argument is surrounded by double quotes so the operating system treats it as a single item.

Another OQL example for Windows

.\mat\ParseHeapDump.bat myheapdump.hprof "-command=oql \\\"SELECT s AS Object, toString(s) AS \\\\\\\"String value\\\\\\\" FROM \\\\\\\"java.lang.String.*\\\\\\\" s WHERE toString(s) LIKE \\\\\\\".*\\..*\\\\\\\" AND s.hash ^^^> 0\\\"" org.eclipse.mat.api:query
Task: Reopening parsed heap dump file
[.........]

Subtask: Query
[
Subtask: Test 'Query command' of section 'Query'
[
Subtask: SELECT s AS Object, toString(s) AS "String value" FROM "java.lang.String.*" s WHERE ((toString(s) LIKE ".*\..*") and (s.hash > 0))
[
Subtask: Collecting objects of classes
[
Subtask: Checking class java.lang.StringConcatHelper
[
Subtask: Checking class java.lang.String[][]
[
Subtask: Checking class java.lang.StringLatin1
[
Subtask: Checking class java.lang.StringCoding$Result
[
Subtask: Checking class java.lang.StringBuilder
[
Subtask: Checking class java.lang.String$CaseInsensitiveComparator
[
Subtask: Checking class java.lang.StringCoding$1
[
Subtask: Checking class java.lang.String[]
[
Subtask: Checking class java.lang.StringCoding
[
Subtask: Checking class java.lang.String
[
				
Note: The OQL query oql has the actual OQL statement surrounded by double quotes. These need to be escaped here as shown. The whole of the command option must be passed to Eclipse Memory Analyzer as a single argument starting with -command. As the query command has spaces the whole argument is surrounded by double quotes so the operating system treats it as a single item. Any double quotes in the OQL statement need 7 backslashes before. The greater-than sign > needs to be escaped with 3 carets ^^^ as it appears to be outside of double-quotes to the Windows command line interpreter and so would be misinterpreted as a redirect. A backslash in the OQL statement needs to be doubled. There are no character escapes in OQL string literals. It is not therefore possible to add a double quote to a SELECT AS column name. It makes no sense to add it to a class pattern for a FROM item. It is not possible to add a double quote to a LIKE regular expression string literal. It would be possible to use the matches() method and build the pattern using a string concatenation using character quote holding a double quote.

Another OQL example for Linux or macOS

./mat/ParseHeapDump.sh myheapdump.hprof "-command=oql \"select s as \\\"a b\\\" from \\\"java.lang.String.*\\\" WHERE toString(s) LIKE \\\".*\\\..*\\\" AND s.hash > 0\"" org.eclipse.mat.api:query
Task: Reopening parsed heap dump file
[.........]

Subtask: Single Query
[
Subtask: Test 'Query Command' of section 'Single Query'
[
Subtask: SELECT s AS Object, toString(s) AS "String value" FROM "java.lang.String.*" s WHERE ((toString(s) LIKE ".*\..*") and (s.hash > 0))
[
Subtask: Collecting objects of classes
[
Subtask: Checking class java.lang.String[]
[
Subtask: Checking class java.lang.String[][]
[
Subtask: Checking class java.lang.String$CaseInsensitiveComparator
[
Subtask: Checking class java.lang.StringCoding$StringEncoder
[
Subtask: Checking class java.lang.StringCoding
[
Subtask: Checking class java.lang.StringBuffer
[
Subtask: Checking class java.lang.StringBuilder
[
Subtask: Checking class java.lang.String
[
Subtask: Checking class java.lang.StringCoding$StringDecoder
				
Note: The OQL query oql has the actual OQL statement surrounded by double quotes. These need to be escaped here as shown. The whole of the command option must be passed to Eclipse Memory Analyzer as a single argument starting with -command. As the query command has spaces the whole argument is surrounded by double quotes so the operating system treats it as a single item. Any double quotes in the OQL statement need 3 backslashes before. A backslash in the OQL statement needs to be doubled. There are no character escapes in OQL string literals. It is not therefore possible to add a double quote to a SELECT AS column name. It makes no sense to add it to a class pattern for a FROM item. It is not possible to add a double quote to a LIKE regular expression string literal. It would be possible to use the matches() method and build the pattern using a string concatenation using character quote holding a double quote.