in my project I wrote a java-agent library, which i want to profile. This question was already asked in 2013 here. So, I tried following the suggestion, using sprof, which failed due to this problem. I have also tried oprofile, however I am still not able to identify the bottlenecks of my application from its output.
So, my question is, what are the other suitable profilers for java native libraries? Does anyone have expirience in this kind of task?
You may find useful VTune Amplifier which is a profiler supporting Java code analysis. You will be able to see the hotspots in your Java code and the performance metrics distributed through your java source file. What's really valuable is that VTune Amplifier shows the accurate stacks for pure Java code and Java/C++ mixed mode code. Please ask if you have questions.
First of all you should choose "Hotspots and stacks" while you're configuring analysis. See screenshot below. When collection is done that you should switch to the "Top-down Tree" tab in VTune UI. More info about the "Top-down Tree" tab is here.
Try to use "Hotspots, call count and stacks" to get call counts.
Related
I'm developing a wrapper for a C/C++ library in Java, and it's gotten to the point where it is mostly working, but there are occasional segfaults and other errors popping up. I'm using Eclipse for development, and it looks like they are working towards mixed debugging, but it is not finished yet.
Can anyone suggest good techniques, best practises for this kind of debugging, beyond debugging the C++ and Java separately or adding lots of print statements?
EDIT just in case it is relevant - I'm not developing for Android, so any Android specific tools will not help
I've not found anything but using print statements for the Java
side, but it's quite possible to attach gdb to the Java process,
or start the JVM under gdb, and set break points, examine
variables, etc. with it.
A java app I have been writing for the last few years has now become quite bloated and I am conscious of including unused code etc…
I know for css and javascript you perform code cleanups and compact the code etc.. does anything like this exist for java?
For some reason developers always dismiss the importance of the java garbage collector.
This should help: http://www.devdaily.com/java/edu/pj/pj010008
Linda
The fact that you are quoting css as an example for an language that enables code cleanup, tells me that you are probably new to java.
Java has one of the Richest set of tools for performing code cleanup (or general re-factoring). There are two ways to perform code cleanups. One is to use Static code analyzer and other way is to have an instrumentation support to monitor your running programs.
There are many static code analyzer in the market and the some of the best ones are open source. If you are a serious Java developer then you cannot get a better IDE than Intellij ( no, I do not get paid by them..). They have one of the best code analyzer tools integrated with an IDE. This link should help you.
You do not have to use Intellij to get the same kind of code Analysis. You can use PMD and FindBugs plugins for any leading IDE. Among all the code analyzers, I believe these two are the best to dig out deep problems in the code and not just superficial mistakes. ( like formatting Issue).
These tools will help you clean up dead codes, find probably bugs and unclosed objects. You should also customize the tools based on your requirements, but that comes later.
Once you have identified and fixed all the problems identified by your static analyzer, then you need to monitor your program for potential problems like Memory Leak. Some problems are only found during runtime.Java had an inbuild instrumentation mechanism called JMX and almost all major Server Vendors have exposed it. You could also use Jconsole, that could act as an abstraction layer over JMX.
Have you considered using any code coverage tools to determine exactly what portions of your code are getting executed? Take a look at EMMA:
http://emma.sourceforge.net/
Optimizing and cleaning up are two separate issues. You can start on both using Eclipse.
Take a look at these sections of your Eclipse configuration:
Window > Preferences > Java > Code Style > Clean up / Code Templates / Formatter
And:
Window > preferences > Java > Compiler > Errors/Warnings
You'll find a lot of handy features for flagging and even automatically fixing things that are commonly considered to be bad code.
For performance optimization, you might try the Eclipse Test & Performance Tools Platform Project.
I need to profile several functions in my java code for Android.
I do know about traceview. And I actually found which functions to investigate using this tool. But it gives no information that can help in investigations inside specific functions.
So, is there any way I can get per-instruction profiling information for Java code on Android?
I would suggest you can try 'hprof' within your Java code to dump the profiled data to a file and you can analyse that file for more details.
API to use:
dumpHprofData(String fileName)
If you are interested in more granular level profiling then you can try 'readprofile' which works at Kernel level. You would need 'busybox' to use it though. However, I guess you need to map the instructions with your Java statements.
I'm looking for a tool that can graph method calls over time for a java app. Perhaps a profiler or other log parsing tool?
I know I can write something in python and I'll work towards doing this. I was just hoping not to reinvent the wheel.
edit:
What I ended up doing was writing some python to parse my logs and take snapshots at 5 second intervals. Then I used google docs and a spreadsheet to visualize my data with a chart that had 2 columns of data: time and frequency. Google docs was super useful. Use the "move chart to own sheet" for a nice fullsize view. I'll post my python when I clean it up a bit.
here is the output graph from the method I specify in my comment
Check out JProfiler. I wouldn't suggesting writing your own tool, this is a space with lots of players already....unless you're really looking for something to do. :-)
you can also check the NetBeans profiler, that's quite straight forward if you application a standard Java code (I mean, it's a bit more complicated with projects deployed in Glassfish for instance)
(from Google Image from Dr. Dobbs)
EDIT: sorry, after another look at your question, it's not exactly what you were looking for, but it might be interesting anyway
YourKit Java Profiler is probably the most powerful Java profiler out there. It is not free but not unreasonably expensive either. If it doesn't have the feature you are looking for, I kinda doubt any application would.
VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform.
Do you have any tips for effective profiling using Netbeans?
The profiler is quite nice and powerful. I've used it to find problems in some of my Eclipse RCP client applications. However, I get the feeling that I could get some more value out of it.
Normally I set it to profile either all my classes (starting with xxx.mydomain) using an inclusive filter, or I use an exclude filter to remove all org.eclipse classes. This helps keep the overhead down. After running the section of code I am interested, I take a snapshot. I analyze for hotspots and then change the code, repeat the profiling, take another snapshot and compare again.
Any other suggestions or tips on how to get the most out of the profiler with client applications?
The JavaOne lab exercises are available online for free, you should be able to get some good tips there.
http://developers.sun.com/learning/javaoneonline/j1labs2008.jsp?track=1&yr=2008
Specifically this link is interesting from the Java One Lab
http://developers.sun.com/learning/javaoneonline/j1lab.jsp?lab=LAB-8430&yr=2008&track=1