| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| |
| <!-- |
| Copyright (c) 2009, 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
| --> |
| |
| <html> |
| <head> |
| <title>Introduction to Profiling Java Applications in NetBeans IDE</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > |
| <meta name="description" content="An introduction to profiling an application using NetBeans IDE"> |
| <link rel="stylesheet" type="text/css" href="../../../netbeans.css"> |
| |
| </head> |
| |
| <body> |
| <a name="top"></a> |
| <h1>Introduction to Profiling Java Applications in NetBeans IDE</h1> |
| |
| <p>NetBeans IDE includes a powerful profiling tool that can provide important information about the runtime |
| behavior of your application. |
| The NetBeans profiling tool easily enables you to monitor thread states, CPU performance, and |
| memory usage of your application from within the IDE, and imposes relatively low overhead.</p> |
| |
| <p>This introductory document is an overview of the profiling tools included in the IDE and a guide to help you quickly start |
| profiling your NetBeans projects. |
| This document is intended to demonstrate the various profiling tasks available in the IDE and the profiling results you can obtain when |
| profiling a project. It does not cover all the profiling features included in the IDE, nor does it explore how to interpret profiling results to resolve specific performance issues |
| you may have in your application.</p> |
| <p>In this document you will use the profiling tool to obtain profiling data about the Anagram Game sample application, |
| a simple Java application that is included in the IDE. |
| Though the Anagram Game is a very simple Java application project, you would follow the same |
| steps to profile larger, more complex Java applications, as well as web and enterprise application projects.</p> |
| <p>This document shows how to use the IDE to profile the application and obtain the following profiling results:</p> |
| <ul> |
| <li>Runtime behavior of an application</li> |
| <li>CPU time used by an application's methods</li> |
| <li>Object creation</li> |
| </ul> |
| <p>Additionally, this document demonstrates how to take and compare snapshots of profiling results.</p> |
| |
| |
| <img src="../../../images_www/articles/73/netbeans-stamp-80-74-73.png" class="stamp" alt="Content on this page applies to NetBeans IDE 7.3, 7.4 and 8.0" title="Content on this page applies to the NetBeans IDE 7.3, 7.4 and 8.0" > |
| |
| <p><b>Contents</b></p> |
| |
| <ul class="toc"> |
| <li><a href="#firsttime">Profiling for the First Time</a> |
| <ul class="toc"> |
| <li><a href="#create">Creating the Sample Project</a></li> |
| <li><a href="#calibrate">Using the Profiler for the First Time</a></li> |
| </ul> |
| </li> |
| <li><a href="#select">Selecting a Profiling Task</a> |
| <ul class="toc"> |
| <li><a href="#monitor">Monitoring an Application</a></li> |
| <li><a href="#cpu">Analyzing Application Performance</a> |
| <li><a href="#memory">Analyzing Memory Usage</a></li> |
| </ul> |
| </li> |
| <li><a href="#snapshot">Taking Snapshots</a> |
| <ul class="toc"> |
| <li><a href="#takesnap">Taking and Comparing Memory Snapshots</a></li> |
| </ul> |
| </li> |
| </ul> |
| |
| <h2>Getting Started</h2> |
| <div class="indent"> |
| <h3>Prerequisites</h3> |
| <p>This document assumes you have some basic knowledge of, or programming experience with, the following technologies:</p> |
| <ul> |
| <li>Java Programming</li> |
| <li>NetBeans IDE</li> |
| </ul> |
| |
| <h3>Software Needed for the Tutorial</h3> |
| <p>For this tutorial you need to have the following software installed on your computer:</p> |
| <table> |
| <tbody> |
| <tr> |
| <th class="tblheader" scope="col">Software or Resource</th> |
| <th class="tblheader" scope="col">Version Required</th> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="https://netbeans.org/downloads/index.html">NetBeans IDE</a></td> |
| <td class="tbltd1">7.3, 7.4, 8.0</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java Development Kit (JDK)</a></td> |
| <td class="tbltd1">Version 7 or 8</td> |
| </tr> |
| |
| </tbody> |
| </table> |
| <p class="notes"><strong>Notes.</strong></p> |
| <ul> |
| <li>The profiling tool is bundled with NetBeans IDE, and no special setup is necessary in order to begin profiling an application.</li> |
| <li>If you are using NetBeans IDE 7.2 or earlier, see <a href="../../72/java/profiler-intro.html">Introduction to Profiling Java Applications in NetBeans IDE 7.2</a></li> |
| </ul> |
| </div> |
| |
| <a name="firsttime"></a> |
| <h2>Profiling for the First Time</h2> |
| <p>The first time that you use the profiling tool, the IDE needs to perform some initial operations to |
| ensure that accurate profile results are obtained and to integrate the tool with the project. |
| To demonstrate this, you will first create the AnagramGame project and then run the calibration. |
| The IDE will automatically perform the integration the first time you profile the AnagramGame project.</p> |
| |
| <div class="indent"> |
| <a name="create"></a> |
| <h3>Creating the Sample Project</h3> |
| <p>In this document you will profile the Anagram Game sample application. |
| To do this you will first use the New Project wizard to create the sample application |
| and set the project as the Main Project.</p> |
| <p>To create the Anagram Game application perform the following steps.</p> |
| <ol> |
| <li>Choose File > New Project (Ctrl-Shift-N; ⌘-Shift-N on Mac) from the main menu.</li> |
| <li>In the New Projects wizard, select the Samples > Java category.</li> |
| <li>Select the Anagram Game project. Click Next.</li> |
| <li>Specify a location for the project. Click Finish. |
| <p>When you click Finish, the IDE creates the Anagram Game sample project.</p> |
| </li> |
| <li>Choose Run > Set Main Project > AnagramGame from the main menu.</li> |
| </ol> |
| <p>After you set the project as the main project you can see that the name of the Anagram Game project is in bold in the Projects window. |
| By default, when using the IDE to profile a project, the IDE will profile the main project. |
| If no project is set as the main project the IDE will profile the project that is selected |
| in the Projects window.</p> |
| |
| <a name="calibrate"></a> |
| <h3>Using the Profiler for the First Time</h3> |
| <p>To achieve accurate profiling results, you must have calibration data for each Java platform that will be used for profiling. |
| If you are running the profiling tool for the first time, or if valid calibration data is unavailable for the Java platform, |
| the IDE will prompt you to run the calibration process for your platform.</p> |
| <p>The calibration only needs to be performed once. |
| However, if you make any substantial changes to the configuration of the machine that could affect machine performance, |
| you should run the calibration again. You can run the calibration at any time by performing the following steps.</p> |
| |
| <ol> |
| <li>Choose <strong>Advanced Commands</strong> > <strong>Manage Calibration Data</strong> from the Profile menu.</li> |
| <li>Select the Java Platform. Click Calibrate.</li> |
| </ol> |
| |
| <img src="../../../images_www/articles/80/java/profile-intro/calibrate-select-platform.png" class="margin-around box" alt="Select Java Platform dialog box" title="Dialog box to select the Java Platform when calibrating." /> |
| |
| <p>A dialog box appears when the calibration operation is complete. |
| You can click Show Details to view a dialog box with information about the calibration results. |
| The calibration data for each Java platform is saved in the <tt>.nbprofile</tt> directory in your home directory.</p> |
| <img src="../../../images_www/articles/72/java/profile-intro/calibrate-information.png" class="margin-around box" alt="screenshot of Calibration Information dialog" title="Calibration Information dialog" /> |
| |
| <p class="notes"><strong>Note.</strong> If you are using NetBeans IDE 7.4 or earlier, |
| |
| choose <strong>Advanced Commands</strong> > <strong>Run Profiler Calibration</strong> from the Profile menu |
| and select the Java platform in the Select Java Platform to Calibrate dialog box. |
| </p> |
| <div class="indent"> |
| <img src="../../../images_www/articles/72/java/profile-intro/calibrate-select-platform.png" class="margin-around box" alt="Select Java Platform dialog box" title="Dialog box to select the Java Platform when calibrating." /> |
| </div> |
| </div> |
| |
| <a name="select"></a> |
| <h2>Selecting a Profiling Task</h2> |
| |
| <p>The IDE provides a number of internal settings that let you tune profiling to your needs. |
| For example, you may decrease the profiling overhead at the cost |
| of some reduction in the amount of generated information. However, it may take |
| some time to understand the meaning and use of the numerous settings available. |
| For many applications, the default settings specified for the profiling tasks are sufficient in most situations.</p> |
| |
| <p>When profiling a project, you use the Select Profiling Task dialog box to choose a task according to the type of |
| profiling information you want to obtain. |
| The following table describes the profiling tasks and the profiling results obtained from running the task.</p> |
| <table> |
| <tbody> |
| <tr> |
| <th class="tblheader" scope="col">Profiling Task</th> |
| <th class="tblheader" scope="col">Results</th> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="#monitor">Monitor Application</a></td> |
| <td class="tbltd1">Choose this to obtain high-level information about properties of the target JVM, including thread activity and memory allocations.</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="#cpu">Analyze CPU Performance</a></td> |
| <td class="tbltd1">Choose this to obtain detailed data on application performance, including the time to execute methods and the number of times the method is invoked.</td> |
| </tr> |
| <tr> |
| <td class="tbltd1"><a href="#memory">Analyze Memory Usage</a></td> |
| <td class="tbltd1">Choose this to obtain detailed data on object allocation and garbage collection.</td> |
| </tr> |
| </table> |
| |
| <p>The Select Profiling Task dialog box is the main interface for running a profiling task. |
| After you select a task, you can modify the task settings to fine tune the results you will obtain. |
| For each of the profiling tasks, you can also create and save custom profiling tasks based on the task. |
| When you create a custom profiling task, the custom task is listed in the Select Profiling Task dialog box |
| so that you can easily find and run your custom settings later. |
| When you create a custom profiling task, you can modify more advanced profiling settings |
| by clicking <b>Advanced settings</b> in the Select Profiling Task dialog box.</p> |
| |
| <div class="indent"> |
| <a name="monitor"></a> |
| <h3>Monitoring an Application</h3> |
| <p>When you choose the Monitor task, the target application is started without any instrumentation. |
| When monitoring an application, you obtain high-level information about several important properties of the target JVM. |
| Because monitoring an application imposes very low overhead, you can run the application in this mode for extended periods of time.</p> |
| |
| <p>To monitor the Anagram Game application, perform the following steps.</p> |
| <ol> |
| <li>Confirm that the AnagramGame project is set as the main project.</li> |
| <li>Choose Profile > Profile Main Project from the main menu. |
| <p>Alternatively, right-click the project node in the Projects window and choose Profile.</p></li> |
| <li>Select Monitor in the Select Profiling Task dialog box.</li> |
| <li>Select additional monitor options, if desired. Click Run.<br> |
| <img src="../../../images_www/articles/72/java/profile-intro/monitor-task.png" class="margin-around box" alt="Select Profiling Task Dialog - Monitor Application" title="Selecting the Monitor Application profiling task"> |
| <p class="tips">You can hover the cursor over an option to |
| view a tooltip with details about the option.</p> |
| </li> |
| </ol> |
| |
| <p>When you click Run, the IDE launches the application and the Profiler window opens in the left pane of the IDE. |
| The Profiler window contains the controls that enable you to do the following:</p> |
| <ul> |
| <li>Control the profiling task</li> |
| <li>See the status of the current profiling task</li> |
| <li>Display profiling results</li> |
| <li>Manage profiling results snapshots</li> |
| <li>See basic telemetry statistics</li> |
| </ul> |
| |
| <p>You can use the controls in the Profiler window or the main menu to open the windows where you can view the monitoring data. |
| You can use the Telemetry Overview window to quickly get an overview of the monitoring data in real time. |
| If you place the cursor over a graph, you can see more detailed statistics about the data displayed in the graph. |
| You can double-click on any of the graphs in the Telemetry Overview window to open a larger and more detailed |
| version of the graph.</p> |
| |
| <img src="../../../images_www/articles/72/java/profile-intro/profile-intro-telemoverview.png" class="margin-around box" alt="screenshot of Telemetry Overview window" title="Telemetry Overview window"> |
| |
| <p class="tips">If the overview does not open automatically you can choose Window > Profiling > VM Telemetry Overview to |
| open the overview in the Output window. |
| You can open the VM Telemetry Overview window and see monitoring data at any time during any profiling session.<p> |
| |
| |
| |
| |
| <a name="cpu"></a> |
| <h3>Analyzing CPU Performance</h3> |
| <p>When you choose the CPU task, the IDE profiles the method-level CPU performance (execution time) of your application |
| and processes the results in real-time. |
| You can choose to analyze the performance by periodically taking a stack trace |
| or by instrumenting the methods in the application. |
| You can choose to instrument all the methods or limit the instrumentation to a |
| part of the application code, even down to a specific code fragment.</p> |
| |
| <p>To analyze CPU performance, you choose how the application is profiled by |
| selecting one of the following options.</p> |
| <ul> |
| <li><b>Quick (Sampled).</b> |
| In this mode, the IDE samples the application and takes a stack trace periodically. |
| This option is less precise than instrumenting methods, but the overhead is lower. |
| This option can help you locate methods that you might want to instrument.</li> |
| |
| <li><b>Advanced (Instrumented).</b> |
| In this mode, the methods of the profiled application are instrumented. |
| The IDE records when threads enter and exit project methods enabling you to see how much time is spent in each method. |
| When entering a method, threads generate a "method entry" event. |
| Threads generate a corresponding "method exit" event when exiting the method. |
| The timestamps for both of these events are recorded. This data is processed in real time. |
| |
| <p>You can choose to instrument all the methods in the application or limit the instrumentation to a subset of the application's code |
| by specifying one or more <b>root methods</b>. |
| You can specify a root method using the popup menu in the source code or by |
| clicking <b>customize</b> to open the Edit Profiling Roots dialog box.</p> |
| |
| <p>A root method is the method, class or package in your source code that you specify as an instrumentation root. |
| Profiling data is collected when one of the application's threads enters and leaves the instrumentation root. |
| No profiling data is collected until one of the application's threads enters the root method. |
| |
| Specifying a root method can significantly reduce the profiling overhead. |
| For some applications, specifying a root method may be the only way to obtain any detailed and/or realistic performance data |
| because profiling the entire application may generate so much profiling data |
| that the application becomes unusable or may even cause the application to crash.</p> |
| </li> |
| </ul> |
| |
| <p class="notes"><b>Note:</b> |
| The Quick profile mode is not available in NetBeans IDE 7.0 and earlier. |
| You can only use instrumentation to obtain profiling results, but you can choose to instrument the entire |
| application or limit instrumentation to part of the application by specifying one or more root methods. |
| </p> |
| |
| <p class="tips">You can further fine tune how much code is profiled by using a filter to limit |
| the sources that are instrumented.</p> |
| |
| <p>You will now use the IDE to analyze the CPU performance of the Anagram Game application. |
| You will choose the Part of Application option and then select <tt>WordLibrary.java</tt> as the profiling root. |
| By selecting this class as the profiling root, you limit the profiling to the methods in this class.</p> |
| |
| <ol> |
| <li>Click the Stop button in the Profiler window to stop the previous profiling session (if still running).</li> |
| <li>Choose Profile > Profile Main Project from the main menu.</li> |
| <li>Select CPU in the Select Profiling Task dialog box.</li> |
| <li>Select <strong>Advanced (Instrumented)</strong>. |
| <p>To use this option you also need to specify a profiling root method.</p></li> |
| <li>Click <b>customize</b> to open the Edit Profiling Roots dialog box.<br/> |
| <img src="../../../images_www/articles/72/java/profile-intro/select-cpu-task.png" class="margin-around box" alt="Select Profiling Task dialog box - CPU" title="Select CPU Profiling Task" /></li> |
| <li>In the Edit Profiling Roots dialog box, expand the AnagramGame node and select |
| <tt>Sources/com.toy.anagrams.lib/WordLibrary</tt>. |
| When profiling a project you can specify multiple root methods.<br /> |
| <img src="../../../images_www/articles/72/java/profile-intro/edit-profiling-roots.png" class="margin-around box" alt="dialog box for selecting the root methods" title="Dialog box for selecting the root methods" /></li> |
| <li>Click the Advanced button to open the Edit Profiling Roots (Advanced) dialog box which provides more advanced options |
| for adding, editing and removing root methods.<br/> |
| <img src="../../../images_www/articles/72/java/profile-intro/edit-profiling-roots-adv.png" class="margin-around box" alt="Dialog box for specifying the root methods" title="Dialog box for specifying the root methods" /> |
| <p>You can see that <tt>WordLibrary</tt> is listed as the root method. Click OK to close the Edit Profiling Roots (Advanced) dialog box.</p> |
| </li> |
| <li>Click OK to close the Edit Profiling Roots dialog box. |
| <p>After you select the profiling root you can click <b>edit</b> |
| in the Select Profiling Task dialog to modify the selected root method.</p></li> |
| <li>Select <b>Profile only project classes</b> for the Filter value. |
| <p> |
| The filter enables you to limit the classes that are instrumented. |
| You can choose from the IDE's predefined profiling filters or create your own custom filters. |
| You can click <b>Show filter value</b> to see a list of the classes that will be profiled when the selected filter is applied. |
| </p> |
| <img src="../../../images_www/articles/72/java/profile-intro/show-filter-value.png" class="margin-around box" alt="Show Filter Value Dialog box" title="Show Filter Value Dialog box" /> |
| </li> |
| <li>Click Run in the Select Profiling Task dialog box to start the profiling session.</li> |
| </ol> |
| <p>When you click Run, the IDE launches the application and starts the profiling session. |
| To view the profiling results, click Live Results in the Profiler window to open the Live Results window. |
| The Live Results window displays the profiling data collected thus far. |
| The data displayed is refreshed every few seconds by default. |
| When analyzing CPU performance, the Live Results window displays information on the time |
| spent in each method and the number of invocations of each method. |
| You can see that in the Anagram Game application only the selected root methods are invoked initially.</p> |
| <img src="../../../images_www/articles/72/java/profile-intro/cpu-liveresults1.png" class="margin-around box" alt="screenshot of CPU Live Results" title="CPU Live Results" /> |
| <p>You can quickly navigate to the source code containing any of the listed methods by right-clicking |
| the name of the method and choosing Go To Source. When you click Go To Source the class opens in the Source editor.</p> |
| |
| <a name="memory"></a> |
| <h3>Analyzing Memory Usage</h3> |
| <p>The Analyze Memory Usage task gives you data on objects that have been allocated in the target application such as the number, |
| type and location of the allocated objects. </p> |
| |
| <p>To analyze memory performance, you choose how much data you want to obtain by selecting one of the following options.</p> |
| |
| <ul> |
| <li><b>Quick.</b> |
| When this option is selected, the profiler samples the application to |
| provide data that is limited to the live objects. |
| This option only tracks live objects and does not track allocations when instrumenting. |
| It is not possible to record stack traces or to use profiling points if you select this option. |
| This option incurs a significantly lower overhead than the Advanced option. |
| </li> |
| <li><b>Advanced.</b> |
| When this option is selected application you can obtain information about the number, |
| type, and location of allocated objects. |
| All classes that are currently loaded by the target JVM (and each new class as it is loaded) |
| are instrumented to produce information about object allocations. |
| You need to select this option if you want to use profiling points when |
| analyzing memory usage or if you want to record the call stack. |
| This options incurs a greater profiling overhead than the Quick option. |
| </li> |
| </ul> |
| |
| <p>If you select the Advanced option you can also set the following options.</p> |
| <ul> |
| <li><strong>Record Full Object Lifestyle.</strong> Select this option to record all information for each object, including the number of generations survived.</li> |
| <li><strong>Record Stack Trace for Allocations.</strong> Select this option to record the full call stack. |
| This option enables you to view the reverse call tree for method calls when viewing a memory snapshot.</li> |
| <li><strong>Use defined Profiling Points.</strong> Select this option to enable profiling points. |
| Disabled profiling points are ignored. When deselected, all profiling points in the project are ignored.</li> |
| </ul> |
| |
| <p>The Overhead meter in the Select Profiling Tasks window gives a rough approximation of the increase or decrease |
| in the profiling overhead according to the profiling options that you select.</p> |
| |
| <p>In this exercise you will use the IDE to analyze the memory performance of the Anagram Game application. |
| You will choose the <b>Advanced</b> option and |
| select the <strong>Record Stack Trace for Allocations</strong> so that the IDE records the full call stack. |
| By selecting this option, when you take the memory snapshot you will be able to view a reverse call tree.</p> |
| |
| <ol> |
| <li>Click the Stop button in the Profiler window to stop the previous profiling session (if still running) |
| and stop the Anagram Game application.</li> |
| <li>Choose Profile > Profile Main Project from the main menu.</li> |
| <li>Select Memory in the Select Profiling Task dialog box.</li> |
| <li>Select <strong>Advanced</strong>.</li> |
| <li>Select <strong>Record Stack Trace for Allocations</strong>. Click Run to start the profiling session. |
| <p>Notice that when you selected this option the Overhead meter increased substantially, |
| but the application is small enough that the performance hit should be manageable.</p> |
| <img src="../../../images_www/articles/73/java/profile-intro/profile-java-memory.png" class="margin-around box" alt="Select Profiling Task dialog box - Memory" title="Select Memory Profiling Task" /></li> |
| </ol> |
| |
| <p>When you click Run, the IDE launches the application and starts the profiling session. |
| To view the profiling results, click Live Results in the Profiler window to open the Live Results window. |
| The Live Results window displays information on the size and number of objects that are allocated in our project. </p> |
| <p>By default the results are sorted and displayed by the number of Live Bytes, but you can click a column header to change how |
| the results are displayed. You can also filter the results by typing a class name in the filter box below the list.</p> |
| <img src="../../../images_www/articles/73/java/profile-intro/profile-java-memresults1.png" class="margin-around box" alt="Memory Profiling Results" title="Memory Profiling Results" /> |
| </div> |
| |
| <a name="snapshot"></a> |
| <h2>Taking Snapshots</h2> |
| <p>When a profiling session is in progress, you can capture profiling results by taking a snapshot. |
| A snapshot captures the profiling data at the moment you take the snapshot. |
| However, snapshots differ from live profiling results in the following ways:</p> |
| <ul> |
| <li>Snapshots can be examined when no profiling session is running.</li> |
| <li>Snapshots contain a more detailed record of profiling data than live results.</li> |
| <li>Snapshots can be easily compared (memory snapshots).</li> |
| </ul> |
| <p>Because a profiling session does not have to be in progress to open a project's snapshots, you can open a project's snapshot at any time |
| by selecting the snapshot in the list of saved snapshots in the Profiler window and clicking Open.</p> |
| |
| <div class="indent"> |
| <a name="takesnap"></a> |
| <h3>Taking and Comparing Memory Snapshots</h3> |
| <p>For the Anagram Game application, you can take a snapshot of the results to see the allocation stack trace for |
| the objects of type <tt>String</tt>. You can then take another snapshot and compare the two. |
| By comparing memory snapshots you can see what objects have been created or released from the heap in the interval |
| between when you took the two snapshots. |
| The snapshots must be comparable, which means that the profiling type (e.g., Allocations vs. Liveness) |
| and the number of tracked objects must match.</p> |
| <p>In this exercise you will take and save a snapshot to your project. |
| You will then take a second snapshot and compare the second snapshot to the saved snapshot. |
| </p> |
| |
| <ol> |
| <li>Make sure the profiling session is still running.<br /> |
| (If you stopped the profiling session, repeat the steps to analyze memory performance and open the |
| Live Results window.)</li> |
| <li>Right-click the line containing <tt>java.lang.String</tt> in the |
| Live Results window and choose Take Snapshot and Show Allocation Stack Traces. |
| <p class="tips">You can use the filter in the Live Results window to help you find the line.</p> |
| <img src="../../../images_www/articles/73/java/profile-intro/profile-java-memstack1.png" class="margin-around box" alt="Snapshot of Memory Profiling Results" title="Snapshot of Memory Profiling Results" /> |
| <p>The IDE takes a memory snapshot and opens the snapshot in the Allocation Stack Traces tab. |
| In the Allocation Stack Traces tab you can explore the reverse call tree for the methods that instantiated the selected object.</p> |
| |
| </li> |
| <li>Click the Save Snapshot to Project button in the snapshot toolbar (Ctrl-S; ⌘-S on Mac) to save the memory snapshot to your project. |
| When you save the snapshot to your project, the snapshot is added to the list of Anagram Game's saved snapshots in the Profiler window. |
| By default, snapshots are physically saved in the <tt>nbproject/private/profiler</tt> directory of your project. |
| Saved snapshots are appended with the <tt>.nps</tt> suffix. |
| |
| <p class="notes"><b>Note.</b> You can save snapshots anywhere on your filesystem, however only snapshots saved in the default location in your |
| project will be listed in the Profiler window. |
| You can also click the "Save current view to image" button in the snapshot's toolbar to save the snapshot |
| as an image files (<tt>.png</tt>) that can be viewed outside of the IDE.</p> |
| </li> |
| <li>Take another snapshot by clicking the Take Snapshot of Collected Results button in the Live Results toolbar (or |
| alternatively, click the Take Snapshot button in the Profiler window). Save the snapshot.</li> |
| <li>In the window of one of the memory snapshots, click the Compute Difference button |
| ( <img src="../../../images_www/articles/72/java/profile-intro/comparesnapshots.png" style="vertical-align:bottom;margin-top:2px;" alt="Compare Snapshot button" title="Compare Snapshot button" /> ) |
| in the snapshot toolbar. |
| Alternatively, choose Profile > Compare Memory Snapshots from the main menu.</li> |
| <li>In the Select Snapshot to Compare, select one of the open snapshots from the list. Click OK.<br> |
| <img src="../../../images_www/articles/73/java/profile-intro/profile-java-selectsnap.png" class="margin-around box" alt="screenshot of dialog for selecting the snapshots to compare" title="Select Snapshots to Compare dialog box" /> |
| <p>When a memory snapshot is open, you can compare it to other comparable memory snapshots. |
| You can compare the snapshot to unsaved snapshots that are currently open or to snapshots that are saved |
| to the project or elsewhere on your system.</p> |
| |
| <p>When you click OK, the Liveness Comparison window opens displaying the differences between the two memory snapshots.</p> |
| <img src="../../../images_www/articles/73/java/profile-intro/profile-java-compare.png" class="margin-around box" alt="screenshot of Liveness Comparison results" title="tab showing results of Liveness Comparison of two memory snapshots" /></li> |
| </ol> |
| |
| <p>The snapshot comparison looks similar to a memory snapshot but only displays the differences between the two compared snapshots. |
| When you look at the numbers in the columns you can see that a plus sign ( + ) indicates that the value increased |
| and a minus sign ( - ) indicates that the value decreased. |
| In the Live Bytes column a graphical bar enables you to easily see the difference in the bytes allocated. |
| If the left half of the cell in that column is green it means that the number of allocated bytes for that object is lower when the second snapshot was taken |
| than it was when the first was taken. |
| If the right half of the cell is red it means that the number of allocated bytes is higher in the second snapshot than in the first. |
| </p> |
| <p class="notes"><strong>Note.</strong> You can also set Take Snapshot profiling points for more |
| precise control over when snapshots are taken. For more on how to take snapshots using profiling points, see |
| <a href="../../docs/java/profiler-profilingpoints.html">Using Profiling Points in NetBeans IDE</a>.</p> |
| </div> |
| |
| |
| |
| |
| <div class="feedback-box"> |
| <a href="/about/contact_form.html?to=3&subject=Feedback:%20Introduction%20to%20Profiling">Send Feedback on This Tutorial</a></div> |
| |
| <br style="clear:both;"> |
| |
| <a name="seeAlso"></a> |
| <h2>See Also</h2> |
| |
| <p>This concludes the introduction to profiling an application using NetBeans IDE. |
| This document demonstrated the basics of how to use the IDE to profile a simple |
| NetBeans project and view the profiling results. The steps outlined above can be applied |
| when profiling most projects. Profiling more complex projects such as enterprise applications |
| and free-form projects may require additional configuration steps.</p> |
| <p>For more detailed information about profiling settings and features not covered in this document, |
| please consult the documentation included in the product and available from the Help menu item.<p> |
| <p>For related documentation, see the following resources:</p> |
| |
| <ul> |
| <li><a href="http://wiki.netbeans.org/wiki/view/NetBeansUserFAQ#section-NetBeansUserFAQ-Profiler">NetBeans Profiler FAQs</a><br /> |
| A document containing frequently asked questions regarding profiling applications in NetBeans IDE</li> |
| <li><a href="http://wiki.netbeans.org/wiki/view/FaqProfilerProfileFreeForm">FAQ: Profiling a Free-form project</a></li> |
| <li><a href="profiler-screencast.html">Screencast: Profiling Points, Drill Down Graph, Heap Walker</a><br /> |
| Demo showing some of the profiling features in NetBeans IDE.</li> |
| <li><a href="../../../community/magazine/html/04/profiler.html">Advanced Profiling: Theory in Practice</a></li> |
| <li><a href="http://www.javapassion.com/handsonlabs/nbprofilermemory/">Finding Memory Leaks Using the NetBeans Profiler</a><br /> |
| Hands-on lab at the <a href="http://www.javapassion.com/">JavaPassion site</a></li> |
| <li><a href="http://profiler.netbeans.org/index.html">profiler.netbeans.org</a><br /> |
| The NetBeans profiler project site</li> |
| <li><a href="http://blogs.oracle.com/nbprofiler">NetBeans Profiler blog</a></li> |
| <li><a href="http://profiler.netbeans.org/mailinglists.html">NetBeans Profiler Mailing Lists</a></li> |
| </ul> |
| |
| <p class="align-center"><a href="#top">top</a></p> |
| </body> |
| </html> |