<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java. Internet. Algorithms. Ideas. &#187; profiling</title>
	<atom:link href="http://philippeadjiman.com/blog/tag/profiling/feed/" rel="self" type="application/rss+xml" />
	<link>http://philippeadjiman.com/blog</link>
	<description>Just Another Blog About Geek Stuff, by Philippe Adjiman</description>
	<lastBuildDate>Tue, 25 May 2010 06:58:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flexible Java Profiling And Monitoring Using The Netbeans Profiler</title>
		<link>http://philippeadjiman.com/blog/2009/10/20/flexible-java-profiling-using-the-netbeans-profiler/</link>
		<comments>http://philippeadjiman.com/blog/2009/10/20/flexible-java-profiling-using-the-netbeans-profiler/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 13:52:43 +0000</pubDate>
		<dc:creator>padjiman</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://philippeadjiman.com/blog/?p=433</guid>
		<description><![CDATA[ I have tested a lot of those open source profiler.  My preference goes definitely to the integrated Netbeans profiler. It was simply the easiest and unified solution adapted to all the different settings I ever met, including profiling java applications that (i) were not developed under netbeans (ii) were only in the form [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot085.jpg" target="_blank"><img class="alignleft size-medium wp-image-434" title="cpuProfile" src="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot085-300x196.jpg" alt="cpuProfile" hspace="15" width="300" height="196" align="left" /></a> I have tested a lot of those <a href="http://java-source.net/open-source/profilers" target="_blank">open source profiler</a>.  My preference goes definitely to the integrated Netbeans profiler. It was simply the easiest and unified solution adapted to all the different settings I ever met, including profiling java applications that <strong><em>(i)</em></strong> were not developed under netbeans <strong><em>(ii)</em></strong> were only in the form of standalone jar <em><strong>(iii)</strong></em> were running on a remote Linux machine for which no X server were running (i.e. no UI), and other cases.</p>
<p>Here I describe how in 3 simple steps you can profile any java application using the wonderful Netbeans profiler.</p>
<p><strong>Step 1: Download and install the latest Netbeans version on your machine(s)</strong></p>
<p>On the <a href="http://www.netbeans.org/downloads/index.html" target="_blank">netbeans download page</a> choose the version adapted for your environment (Windows,Linux,Solaris,Mac&#8230;) and download/install it. All the bundles contain the profiler so I choose the lightest one: the JavaSE. If you want to profile a program running on a remote machine(s), you&#8217;ll have to download/install it on each machine.</p>
<p><strong>Step 2: Modify the command line that runs the java application that you want to profile/monitor</strong></p>
<p>You just have to add an argument to the Java VM.<br />
On windows, the argument to add is of the form:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;"> -agentpath:&quot;C:\Program Files\NetBeans 6.7.1\profiler3\lib\deployed\jdk16\windows\profilerinterface.dll&quot;=&quot;C:\Program Files\NetBeans 6.7.1\profiler3\lib,5140&quot;</pre></div></div>

<p>Replace the portion &#8220;C:\Program Files\NetBeans 6.7.1\profiler3&#8243; by the correct path (located where you installed Netbeans). Keep 5140, it is the port on which the application will listen for a remote profiler session (that you can also perform locally, as in this tutorial).<br />
On Linux, it is exactly the same, just look for the right path containing the profiler3 folder.<br />
So the java command line of the application to profile should look something like:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">java -agentpath:&quot;C:\Program Files\NetBeans 6.7.1\profiler3\lib\deployed\jdk16\windows\profilerinterface.dll&quot;=&quot;C:\Program Files\NetBeans 6.7.1\profiler3\lib,5140&quot; MyApp param1 param2</pre></div></div>

<p>When launching this command, you should see on your console a message saying:<br />
<em>Profiler Agent: Waiting for connection on port 5140 (Protocol version: 9)</em><br />
meaning that the application is listening and waiting for a profiler session on port 5140.</p>
<p><strong><span style="color: red;">Note the flexibility behind this approach</span></strong>: it allows you to add this simple argument to the exsiting command of <em><strong>(i)</strong></em> any java applications running inside eclipse (in that case just open the &#8220;Run configuration&#8221; windows, in the &#8220;Arguments&#8221; tab just add the -agentpath option in the &#8220;VM arguments&#8221; section) or other IDE than Netbeans, <em><strong>(ii)</strong></em> any remote java applications <em><strong>(iii)</strong></em> any standalone jar file, or whatever existing java command that runs any kind of java application you can imagine&#8230;</p>
<p><strong>Step 3: Run the Netbeans profiler GUI</strong></p>
<p>Just open Netbeans, profile -&gt; attach profiler. Choose which kind of profiling/monitoring you need, you can also configure it.</p>
<p><a href="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot086.jpg"><img class="aligncenter size-medium wp-image-452" title="attachProfiler" src="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot086-300x215.jpg" alt="attachProfiler" width="300" height="215" /></a></p>
<p>Press Attach. Note that the first time you attach a profiler it may fail since you have to calibrate the profiler (in that case, a simple textbox will tell you how, it takes seconds).</p>
<p>That&#8217;s it!! You can now see in real time which part of your application is the heaviest, estimate what its memory footprint, analyze the threads and much more.</p>
<p><a href="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot087.jpg"><img class="aligncenter size-medium wp-image-474" title="memory" src="http://philippeadjiman.com/blog/wp-content/uploads/2009/10/ScreenShot087-300x194.jpg" alt="memory" width="300" height="194" /></a></p>
<p>If you want even more, note that it also exists specific profilers for collections (HashMap, HashSet, ArrayList, &#8230;) like <a href="http://www.collectionspy.com/" target="_blank">collection spy</a> (not free).</p>
]]></content:encoded>
			<wfw:commentRss>http://philippeadjiman.com/blog/2009/10/20/flexible-java-profiling-using-the-netbeans-profiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
