Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Memory Analyzer » Using MemoryAnalyzer api's in Java(Using MemoryAnalyzer api's in Java)
Using MemoryAnalyzer api's in Java [message #731221] Fri, 30 September 2011 06:11 Go to next message
pradeep  is currently offline pradeep
Messages: 5
Registered: September 2011
Junior Member

we wanted to use Memory Analyzer API's in our Java code (ie not writing extensions to MAT)...
Approach followed was to copy all jars(found in "plugin" folder of MemoryAnalyzer) to classpath of project .(in Jdeveloper)

and have sample progam to get "ISnapshot" of hprof file

Sample Program
=================
public static void main(String[] args) {


File hproffile=new File("scratch/ana1","jrockit_568.hprof");
ISnapshot iSnap=null;
VoidProgressListener progressListner=new VoidProgressListener();

try {
System.out.println("Opening .....");
iSnap= SnapshotFactory.openSnapshot(hproffile,progressListner);
System.out.println("done....");
} catch (SnapshotException e) {
e.printStackTrace();
}
finally{
System.out.println("Finally Block");
SnapshotFactory.dispose(iSnap);
}


}


Error while getting Platform's Extension registry
====================================================
was getting following runtime error
Caused by: java.lang.NullPointerException
at org.eclipse.mat.snapshot.SnapshotFactory.<clinit>(SnapshotFactory.java:82)


On checking "SnapshotFactory.java" ..found that it was failing while getting "extensionPoint"

IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(
MATPlugin.PLUGIN_ID + ".factory");




with this
1>whats the right approach to use api's of MAT (ie using SnapshotFactory,ISnapshot etc) in Java ..
2>is there any "extension" setup , to override above error message
2>any relevant documentation regarding this
Re: Using MemoryAnalyzer api's in Java [message #733189 is a reply to message #731221] Tue, 04 October 2011 11:29 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew Johnson
Messages: 112
Registered: July 2009
Senior Member
Eclipse and Memory Analyzer tool use an OSGi environment, so just using the jars on a class path won't work, as things like Eclipse extension point definitions won't be found.
Re: Using MemoryAnalyzer api's in Java [message #733596 is a reply to message #733189] Wed, 05 October 2011 03:52 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum Tsvetkov
Messages: 148
Registered: July 2009
Senior Member
As Andrew wrote it is not possible to just put the MAT jars on the classpath and use it within your tool. But you could have your own Eclipse plugins which use the API. And in case you don't need GUI, you can define your own org.eclipse.core.runtime.applications extension, have a class that implements IApplication and run it with some script.
MAT offers for example the possibility to parse a heap dump without running the GUI. Have a look at the ParseHeapDump script. The extension point is defined in the org.eclipse.mat.api plugin and implemented in the org.eclipse.mat.internal.apps.ParseSnapshotApp class.
I guess this could be a way for you to build some tools on top of MAT APIs.

What do you think?

Regards,
Krum
Re: Using MemoryAnalyzer api's in Java [message #734423 is a reply to message #733596] Fri, 07 October 2011 13:56 Go to previous messageGo to next message
pradeep  is currently offline pradeep
Messages: 5
Registered: September 2011
Junior Member
Andrew,Krum - Thanks for the Information provided .

As per the information provided created extension

1>using "org.eclipse.mat.api" plugin and a
2>Extension class to implement Interface "org.eclipse.equinox.app.IApplication"

( "extesnion" java file attached )

On Running the plugin
Run-->Run As--> Eclipse applciation

following errors are encountered..
1>org.eclipse.core.runtime.CoreException: Plug-in org.eclipse.mat.ui.rcp was unable to load class org.eclipse.mat.ui.rcp.Application.
2>org.osgi.framework.BundleException: The activator org.eclipse.mat.ui.rcp.RCPPlugin for bundle org.eclipse.mat.ui.rcp is invalid
3>org.osgi.framework.BundleException: The activator org.eclipse.ui.internal.WorkbenchPlugin for bundle org.eclipse.ui.workbench is invalid

Re: Using MemoryAnalyzer api's in Java [message #735159 is a reply to message #734423] Tue, 11 October 2011 02:36 Go to previous messageGo to next message
pradeep  is currently offline pradeep
Messages: 5
Registered: September 2011
Junior Member
How to run or debug the plugin (non GUI) using eclipse ide..
and
how to specify the parameters in ide during debug like
org.eclipse.mat.api:suspects
or
org.eclipse.mat.api:top_components

which we provide while running the applciation as script...
like ./MemoryAnalyzer -consolelog -application <<applciationName>> "$@"
Re: Using MemoryAnalyzer api's in Java [message #735538 is a reply to message #735159] Wed, 12 October 2011 02:46 Go to previous messageGo to next message
pradeep  is currently offline pradeep
Messages: 5
Registered: September 2011
Junior Member
Krum ,Andrew- Thanks for the advice, we are able to progess on that.

We were able to progress on getting java instance of
Collection of histogram records and
execute applciation relevant OQL queries .
--- to traverse the result and derive logic

with this i have couple of questions to progress further

1>what is the java api to get "leak suspect" information of a hprof
which object has leak suspect information?

2>Once we get OQL result in "IResultTable" object.
how to sort the resulttable on a specific column.

ie
IOQLQuery query1 = SnapshotFactory.createQuery(" SELECT m.@retainedHeapSize FROM java.lang.String m ");
IResultTable res =((IResultTable)query1.execute(snapshot, listener));

how to sort on DESC order of "m.@retainedHeapSize"



Re: Using MemoryAnalyzer api's in Java [message #740243 is a reply to message #735538] Tue, 18 October 2011 05:55 Go to previous messageGo to next message
venagara  is currently offline venagara
Messages: 6
Registered: August 2011
Junior Member
Andrew, Krum -

1) Can you point us to a Java API, which gives us handle to "Leak Suspect" results as java-object instances.

2) Is there any In-Built sorting mechanism provided to sort rows in "IResultTable" ?

Thanks
Vinod
Re: Using MemoryAnalyzer api's in Java [message #741156 is a reply to message #740243] Wed, 19 October 2011 04:31 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew Johnson
Messages: 112
Registered: July 2009
Senior Member
1. Try the find_leaks query, called using SnapshotQuery.lookup("find_leaks", snapshot)
2. Try RefinedResultBuilder
and setSortOrder()

Re: Using MemoryAnalyzer api's in Java [message #741641 is a reply to message #741156] Wed, 19 October 2011 14:51 Go to previous messageGo to next message
pradeep  is currently offline pradeep
Messages: 5
Registered: September 2011
Junior Member
Facing ClassCastException ,when casting OQLQuery result to "RefinedResultBuilder"

ie

IOQLQuery query1 =SnapshotFactory.createQuery("<<OQL Query>> ");
RefinedResultBuilder res =((RefinedResultBuilder)query1.execute(snapshot, listener));

is there any way to get OQLQuery Result in "RefinedResultBuilder" Object?


Re: Using MemoryAnalyzer api's in Java [message #742113 is a reply to message #741641] Thu, 20 October 2011 03:26 Go to previous message
Andrew Johnson is currently offline Andrew Johnson
Messages: 112
Registered: July 2009
Senior Member
Use the constructor for RefinedResultBuilder, set the sort order, then build the RefinedStructuredResult.
Previous Topic:SAXException when trying to run Leak Suspect report
Next Topic:Is direct children object/vvariable wrong in dominator tree?
Goto Forum:
  


Current Time: Sat Apr 19 13:22:59 EDT 2014

Powered by FUDForum. Page generated in 0.02490 seconds