Using Sun Studio Collector/Analyzer: 1. Overview

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

Using Sun Studio Collector/Analyzer

1. Overview We use Sun Studio Collector/Analzyer extensive for profiling Java programs. It is a samplingbased CPU profiler, which has much lower overhead compared with some other profilers. It also has a memory profiler that reports object allocation information for each method. This makes it a little easier to spot hot methods and is different from most other profilers that report allocation information for each class. There are two components: (i) Collector - Collector is used to collect the profiling data and write it to files (ii) Analyzer - Analyzer is used to display the data collected by Collector Collector/Analyzer is also used by other groups within Oracle to profile C/C++ programs. Our teams have only used it for profiling Java programs. 2. Installation Location For Solaris, Sun Studio Analyzer is already installed on ap626sun:/dx/studio9/SUNWspro Collector: /dx/studio9/SUNWspro/bin/collect Analyzer: /dx/studio9/SUNWspro/bin/analyzer For Linux: ap6001perf:/d1/studio10/sunstudio10u1 (You can rsync/tar up this directory and copy to your machine) 3. Using Collector To start iAS 1.0.2.2 with collector: 1. Change $IAS_HOME/Apache/Apache/bin/java.sh, comment out the original exec line and replace as shown (use the appropriate directory based on where you installed Sun Studio):
#Comment this out #exec $JSERVJAVA $JAVA_ADDITIONAL_ARGS $ARGV 1>> $STDOUTLOG 2>> $STDERRLOG # Collector cpu and sync waits for Java # With all sync wait exec /dx/studio9/SUNWspro/bin/collect -S off -F on -y 20 -l 30 -s 0 -p high -j on -d /tmp /usr/j2se/bin/java $JAVA_ADDITIONAL_ARGS $ARGV 1>> $STDOUTLOG 2>> $STDERRLOG #Collector Heap for Java #exec /dx/studio9/SUNWspro/bin/collect -H on -S off -F on -y 20 -l 30 -s off -p high -j on -d /tmp /usr/j2se/bin/java $JAVA_ADDITIONAL_ARGS $ARGV 1>> $STDOUTLOG 2>> $STDERRLOG

2. Start Apache and Jserv using $COMMON_TOP/admin/scripts/<node>/adapcctl.sh start 3. Do kill 20 <jvm process id> to enable data collection, kill 30 <oc4j process id> to take snapshots, kill 20 <jvm process id> again to disable collection To start OC4J with collector: 1. Login in to Enterprise Manager Application Server Control (assume you have a full iAS 10.1.2 install) 2. Click your OC4J instance 3. Click the Administration subtab

4. Click server properties 5. Enter <collector>/bin/collect in Java Executable field 6. Enter additional options in Java Options field For example, for CPU and sync wait profiling: -S off -F on -y 20 -l 30 -s 0 -p high -j on -d /tmp /usr/j2se/bin/java verbosegc for memory profiling: -H on -S off -F on -y 20 -l 30 -s off -p high -j on -d /tmp /usr/j2se/bin/java -verbosegc 7. If you do not want to use Application Server Control, you can edit $ORACLE_HOME/opmn/config/opmn.xml directly by adding the <data id=java-bin tag under <category id=start-parameters, and changing the java-options field to add the above options. For example:
<ias-component id="OC4J"> <process-type id="home" module-id="OC4J" status="enabled"> <module-data> <category id="start-parameters"> <data id="java-options" value="-S off -F on -y 20 -l 30 -s 0 -p high -j on -d /tmp /usr/j2se/bin/java -verbose:gc -Xmx512M -Xms512M -XX:MaxPermSize=128M -XX:+PrintGCTimeStamps -XX:+PrintClassHistogram -Djava.security.policy=$ORACLE_HOME/j2ee/oacore/config/java2.policy -Djava.awt.headless=true -Dhttp.webdir.enable=false"/> <data id="java-bin" value="/dx/studio9/SUNWspro/bin/collect"/> . . .

8. Start Oracle HTTP Server and OC4J 9. Do kill 20 <oc4j process id> to enable data collection, kill 30 <oc4j process id> to take snapshots, kill 20 <oc4j process id> again to disable collection To start a Java program with collector: /dx/studio9/SUNWspro/bin/collect <collector options> /usr/j2se/bin/java <java options> YourClassName For example: CPU and sync wait profiling: /dx/studio9/SUNWspro/bin/collect -S off -F on -y 20 -l 30 -s 0 -p high -j on -d /tmp /usr/j2se/bin/java -verbosegc MyJavaServer Heap profiling: /dx/studio9/SUNWspro/bin/collect -H on -S off -F on -y 20 -l 30 -s off -p high -j on -d /tmp /usr/j2se/bin/java -verbosegc MyJavaServer Common Options: Option -S -F -y -l -s -p -j -d Description Whether automatic sampling is enabled, we usually turn it off Whether to trace child processes Signal to enable/disable collector. For profiling web applications, with this option set the collector will be started in disabled mode and will be enabled when you send the given signal. Sending the signal again will disable to collector Signal to take a snapshot Whether to capture sync wait information. We usually use "-s off" (no sync wait) or "-s 0" (all sync waits) Whether to collect clock-based sampling data. We usually "-p high" for highestresolution clock-based interval Whether to collect Java profiling data. We use "-j on" to collect Java information Directory where the captured data should be written to. Always use the temp

-H

directory or a subdirectory under it. For example, "/tmp". Whether to collect Java object allocation information

Collector will create a directory under the directory you specified with the -d parameter called test.<number>.er, where <number> is a unique number based on what already exist in that direcotry. Note: Memory profiling (-H) does not work with JDK 1.5 On Linux, -s and H do not work. For example, the following works but pretty much thats it: exec /d2/tools/sunstudio10u1/bin/collect -S off -y 20 -l 30 -p high -j on -d /tmp $JSERVJAVA $JAVA_ADDITIONAL_ARGS $ARGV 4. Using Analyzer To run Analyzer on the files generated by Collector, simply do: <Sun Studio Home>/bin/analyzer <full path to test.<number>.er> For example: /dx/studio9/SUNWspro/bin/analyzer /tmp/test.12.er On Linux, you most likely need to explicitly specify the location of the java executable since /usr/bin/java is not setup on most of our Linux boxes. You can either edit the analyzer script and set jdkhome variable to a valid Java installation (e.g. /local/java/jdk1.4.2) or specify the --jdkhome option (note there are two separate dashes) when running analyzer. For example: /d1/tools/SunStudio/bin/analyzer --jdkhome /local/java/jdk1.4.2 /tmp/test.1.er The Analyzer UI will come up. You can click Help for more information on what each tab means. Below is a screen shot of the UI when a CPU profile is opened:

The Functions tab summarizes CPU information for each method. Both inclusive (the second leftmost column) and exclusive (the leftmost column) timings are reported. You can sort on any column. To see extra columns, click View->Set Data Presentation and check/uncheck appropriate boxes. The Callers-Callees tab shows the callers and callees for a selected method. From the Functions tab, highlight the method you are interested in and click the Callers-Callees tab. You will see somethig similar to the following screen shot:

There are now additional columns showing the attributed times/counts (see Help for a detailed explanation of what it means). These values allow you to determine how much of the inclusive timings/counts for your methods is caused by calls from a particular caller or calls to a particular callee. The next screenshot shows a heap profile. By default, it displays Bytes Leaked and Leaks, we normally just go to View->Set Data Presentation and choose to display only Bytes Allocated and Allocations. The UI presents the data in a manner similar to how it presents the CPU profiling data.

You can use the Disassembly tab to map a method back to its bytecode, or the Source tab to map back to the source code (if you have the source available). We frequently use the Disassembly tab to see within a method where the object allocations are coming from. 5. Reference Information man pages are available at /dx/studio9/SUNWspro/man "man -M /dx/studio9/SUNWspro/man collect" gives you the man page for collector "man -M /dx/studio9/SUNWspro/man 3 collect" gives you information for the collector APIs that you can call to start/stop the collector. The Help in Analyzer also has plenty of useful information, much of which pertains to C/C++ profiling though.

You might also like