ProfilingPointsDemo

Profiling Points Demo

This demo script is part of the NetBeans World Tour 2008 session #8, Integrated Profiling Tools. Refer to the top-level demo scripts page for additional information.

Main Points to Hit

  • Profiling points provide a source-line level of control over the data collected by the profiler. They are similar to debugger breakpoints (debugger watch-points are also a good analogy).
  • There are a variety of different types of profiling points. Some are triggered by conditions (time elapsed, memory used, etc.) instead of by the execution of a line of source code.

Prerequisities

  • JDK5 or JDK6
  • NetBeans 6.0 M10 (or higher)

Setup

  1. Create the AnagramGame sample project
  2. Open the AnagramGame project

Gotchas

  1. Sometimes clicking the open snapshot link in a profiling point's report window results in a dialog that says "Saved snapshot is no longer available." If that happens, just use the Saved Snapshots list in the Profile window and open the snapshot from there. An IZ has been filed.
  2. If using JDK 6 on Mac OS X, the profiler will throw a java.lang.NoSuchMethodException: sun.management.HotSpotDiagnostic.dumpHeap(java.lang.String, boolean). To get past this problem, run the project using JDK 5.

Demo Steps

CPU Profiling

  1. Run the AnagramGame project (no profiling). Suggested Comment (SC): "This program is a simple Swing application that displays the letters of a word scrambled. To play the game you guess the word."
  2. Type in the correct answer to the first word: abstraction and click Guess
  3. Click New Word. SC: "And then I can request another word to unscramble."
  4. Exit the AnagramGame. SC: "I'd like to do some specific profiling of this application - I want to know the breakdown of CPU time during the running of the constructor for the main class."
  5. Edit the com.toy.anagrams.ui.Anagrams.java file.
  6. If the file opens up in Design mode, click the Source button
  7. Right-click line 55, which is the first line of the constructor.
  8. Select Profiling > Insert Profiling Point
  9. Select Reset Results for the Profiling point type and click Next
  10. Click Finish. SC: "I've told the profiler to reset its buffer of collected results when it gets to the beginning of the first line of this method, which is the constructor for this class."
  11. Right-click line 64, which is the last line of the constructor.
  12. Select Profiling > Insert Profiling Point
  13. Select Take Snapshot for the Profiling point type and click Next. SC: "This second profiling point specifies that the profiler should take a snapshot at the end of this last line in the constructor."
  14. Click Finish
  15. Right-click AnagramGame and choose Profile Project.
  16. Click the CPU option on the left-side of the dialog
  17. Select Entire Application and set the filter to Profile Only Project Classes
  18. Important: Be sure the Use Defined Profiling Points option is selected
  19. Click Run
  20. When the AnagramGame displays, switch back to the IDE
  21. Select Window > Profiling > Profiling Points. The Profiling Points window will open in the Output area. SC: "We can see the profiling points listed here and counter values that show that each of them was hit one time."
    Image:pp_ProfilingPointsDemo.png
  22. Click the report link next to the second profiling point. SC: "We can find out more about what happened by looking at the report."
  23. In the report window, click the open snapshot link. SC: "Since this profiling point has a snapshot of results available, we can go directly to those results."
  24. The Results window opens. SC: "Looks like most of the time is being spent in the init() method...."
  25. Close the Results window. SC: "That's just one example. Profiling points can also be used to watch memory allocations."

Memory Profiling

  1. Select Profile > Stop Profiling Session
  2. Right-click the first profiling point in the Profiling Points window and select Remove.
  3. Repeat the previous step and remove the second profiling point.
  4. Insert a Reset Results profiling point on line 221 (the first line of the method nextTrialActionPerformed() and a Take Snapshot profiling point on line 226 (the final line of the method). SC: "What if I want to know the number and size of the objects that get allocated each time the application displays a new word to the user? This is similar to the previous demo in that I need to have the profiler do things during the running of just a certain portion of the application. The profiler's UI has buttons for doing these things, but my mouse is not fast enough to click those buttons at just the right moment.  :-) So I use profiling points with the profiler's memory profiling feature."
  5. Right-click AnagramGame and choose Profile Project.
  6. Click the Memory option on the left
  7. Select the Record object creation only option
  8. Set "track every" to 1
  9. Make sure that Record stack trace for allocations is not set.
  10. Important: Be sure the Use Defined Profiling Points option is selected
  11. Click Run
  12. When the AnagramGame displays, position it so that the IDE's Profiling Points window is also visible
  13. Click the AnagramGame's New Word button. Then click the New Word button a second time. SC: "Notice that each profiling point did get hit twice."
  14. Switch back over to the IDE. Click the report link next to the second profiling point to open the data window for it:
    Image:data_ProfilingPointsDemo.png
  15. Click the open snapshot link for the first hit. SC: "We can easily see the results for the first time the data were collected."
  16. Click the open snapshot link for the second hit. SC: "And for the second."
  17. Click back and forth a few times between the two snapshots. SC: "Hmm... it would be nice to have a delta report. And in 6.0 we have one!"  :-)
  18. On either of the snapshot windows, click the compare icon (it is the last one at the top of the snapshot window)
  19. Select the other snapshot from the dialog and then click OK.
    Image:compare_ProfilingPointsDemo.png
  20. Select Profile > Stop Profiling Session
  21. In the Profiling Points window, click the Add Profiling Point icon (it has a plus sign).
    Image:types_ProfilingPointsDemo.png
  22. SC: "One last thing to mention - there are other types of profiling points. You can insert stopwatch points, which are essentially the same as using System.currentTimeMillis(). There is a profiling point that will start a JMeter script for you. You can setup a profiling point that fires based on elapsed time, and finally you can create a profiling point that takes a snapshot based on a certain memory threshold being met."

Cleanup

  • Remove the profiling points
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo