Skip to content
haitaoyao edited this page Jun 19, 2011 · 13 revisions

Welcome to the perf-tools wiki!

What's this?

This is a simple tool to generate btrace script to profile all public method of a specific class . With btrace, we can profile a class method with the following code: ` @TLS private static long startTime;

    @OnMethod(clazz = "org.apache.hadoop.mapred.JobTracker", method = "getInfoPort")
    public static void onCall_getInfoPort() {
            startTime = timeMillis();
    }

    @OnMethod(clazz = "org.apache.hadoop.mapred.JobTracker", method = "getInfoPort", location = @Location(Kind.RETURN))
    public static void onReturn_getInfoPort() {
            print(strcat(str(timeMillis()),
                            " org.apache.hadoop.mapred.JobTracker#getInfoPort"));
            println(strcat(":(ms) ", str(timeMillis() - startTime)));
    }

`

What if there's dozens of methods of the class? Can this tiring job done by another tool? Yes, the perf-tool is what you'r looking for. With the full class name you want to profile and the jar file location or the class file location, the tool will generate the script for you .

How to use this?

1.installation

check out the source code and execute sh install_local.sh (make sure the maven is installed and the BTRACE_HOME is set.)

2.generate the perf script

execute sh $BTRACE_HOME/bin/generate_perf_script.sh to see the help information.

3.run the script with btrace

execute btrace $PID $your_generated_script_location to see the profiled result. #example Here's an example to profile the hadoop jobtracker using this tool.

Generate the script for the job tracker:

hadoop@arch-server:~$ generate_perf_script.sh org.apache.hadoop.mapred.JobTracker hadoop/hadoop-0.20.2-core.jar .

The script is generated as JobTracker_Script.java : hadoop@arch-server:~$ ls JobTracker_Script.java -la -rw-r--r-- 1 hadoop hadoop 34833 2011-06-19 16:53 JobTracker_Script.java

Get the jobtracker pid:

hadoop@arch-server:~$ jps|grep JobTracker 26545 JobTracker

Attach the jobtracker proess with btrace:

hadoop@arch-server:~$ btrace 26545 JobTracker_Script.java 
1308473766502 org.apache.hadoop.mapred.JobTracker#getTaskTracker:(ms) 1
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getNumberOfUniqueHosts:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getClusterStatus:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#getNextHeartbeatInterval:(ms) 0
1308473766503 org.apache.hadoop.mapred.JobTracker#heartbeat:(ms) 0

the output line : ' 1308473766502 org.apache.hadoop.mapred.JobTracker#getTaskTracker:(ms) 1 ' means : at 1308473766502, class: org.apache.hadoop.mapred.JobTracker, method: getTaskTracker is invoked, cost: 1 milisencond.