Skip to main content


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 10:11 Go to next message
pradeep  is currently offline pradeep Friend
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 15:29 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew JohnsonFriend
Messages: 205
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 07:52 Go to previous messageGo to next message
Krum Tsvetkov is currently offline Krum TsvetkovFriend
Messages: 164
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 17:56 Go to previous messageGo to next message
pradeep  is currently offline pradeep Friend
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 06:36 Go to previous messageGo to next message
pradeep  is currently offline pradeep Friend
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 06:46 Go to previous messageGo to next message
pradeep  is currently offline pradeep Friend
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 09:55 Go to previous messageGo to next message
venagara  is currently offline venagara Friend
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 08:31 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew JohnsonFriend
Messages: 205
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 18:51 Go to previous messageGo to next message
pradeep  is currently offline pradeep Friend
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 07:26 Go to previous messageGo to next message
Andrew Johnson is currently offline Andrew JohnsonFriend
Messages: 205
Registered: July 2009
Senior Member
Use the constructor for RefinedResultBuilder, set the sort order, then build the RefinedStructuredResult.
Re: Using MemoryAnalyzer api's in Java [message #1385832 is a reply to message #733596] Wed, 11 June 2014 13:44 Go to previous message
Maria G is currently offline Maria GFriend
Messages: 1
Registered: June 2014
Junior Member
Hello,

I'm trying to use the Memory Analyzer API programmatically. I have followed the steps pointed in this post:

1. Create a new plug-in project
2. Add the required "org.eclipse.mat.api" plugin
3. Add a extension class implementing "org.eclipse.equinox.app.IApplication"

In the start method I tried to read a dump file and I get the following exception:

SEVERE: Error during creation of snapshot factory.
java.lang.NullPointerException at org.eclipse.mat.snapshot.SnapshotFactory.openSnapshot(SnapshotFactory.java:145)
...

Could you please help me? Should I add anything else for being able to use the MAT API?
Thanks!
Previous Topic:How to create heap dump for spring based web application running in weblogic
Next Topic:Memory Analyzer 1.4.0 is now released!
Goto Forum:
  


Current Time: Thu Mar 28 17:57:57 GMT 2024

Powered by FUDForum. Page generated in 0.05000 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top