#!/bin/bash # # This is _example_ of how to do host and guest tracing. # # To use this script: # # 1. Edit the Host config and Guest config sections to match # you setup # # 2. Edit start_host_tracing() and guest_trace_run() to # add/remove tracepoints, function filters and etc # # 3. Then run with: # # # trace-host-and-guest < program > set -e # Host config host_addr= host_cpu_mask=0xFFFFFFFFFF host_trace_dir=/root/tracing host_trace_file=$host_trace_dir/host-trace.dat host_guest_trace_file=$host_trace_dir/guest-trace.dat host_trace=/usr/local/bin/trace-cmd host_cpu_buffer=2000000 # Guest config guest_cpu_mask=0xF guest_trace_file=/root/tracing/trace.dat guest_trace=/usr/local/bin/trace-cmd guest_cpu_buffer=2000000 plugin=function start_host_tracing() { echo "Starting host tracing..." ssh $host_addr $host_trace start \ -M $host_cpu_mask \ -p ${plugin} \ -b ${host_cpu_buffer} \ -C x86-tsc \ -e kvm \ -e sched_switch \ -e sched_wakeup echo "...finished" } start_guest_tracing() { echo "Starting guest tracing..." $guest_trace start \ -M $guest_cpu_mask \ -p ${plugin} \ -b ${guest_cpu_buffer} \ -C x86-tsc \ -e sched_switch \ -e sched_wakeup echo "...finished" } stop_guest_tracing() { echo "Stopping guest tracing..." $guest_trace stop echo "...finished" } stop_host_tracing() { echo "Stopping host tracing..." ssh $host_addr $host_trace stop echo "...finished" } record_host_trace() { local outf=$1 echo "Recording host trace..." ssh $host_addr $host_trace extract -o $outf echo "...finished" } record_guest_trace() { local outf=$1 echo "Recording guest trace..." $guest_trace extract -o $outf echo "...finished" } reset_host_tracing() { echo "Resetting host tracing..." ssh $host_addr $host_trace reset echo "...finished" } reset_guest_tracing() { echo "Resetting guest tracing..." $guest_trace reset echo "...finished" } copy_guest_trace() { echo "SCPing guest trace..." if scp $guest_trace_file $host_addr:$host_guest_trace_file; then rm -v $guest_trace_file echo "...finished" else echo "...ERROR: scp failed" fi } if [ "$(id -u)" -ne 0 ]; then echo "ERROR: must run as root" exit 1 fi start_host_tracing start_guest_tracing echo "Running \"$@\"..." $@ echo "...finished" stop_guest_tracing stop_host_tracing record_guest_trace $guest_trace_file record_host_trace $host_trace_file reset_host_tracing reset_guest_tracing copy_guest_trace