#!/bin/bash # # This is example of how to do host and guest tracing. This script # runs in the guest. # # To use this script: # # 1. Make sure the guest can access the host via ssh without a # password # # 2. Edit the Host config and Guest config sections to match # you setup # # 3. Edit start_host_tracing() and guest_trace_run() to # add/remove tracepoints, function filters and etc # # 4. Run the trace: # # # trace-host-and-guest < program > # # 5. Once the trace is finished, run the following command in # the host to merge the traces: # # $ trace-cmd report --ts-diff --ts2secs $HOST_FREQUENCY -t \ # -i host-trace.dat --ts-offset $(($GUEST_TSC_OFFSET)) \ # -i guest-trace.dat # # Where $GUEST_TSC_OFFSET is the vCPU TSC offset from # /sys/kernel/debug/kvm, and $HOST_FREQUENCY. Here's an example: # # $ trace-cmd report --ts-diff --ts2secs 26000000000 -t \ # -i host-trace.dat --ts-offset $(($GUEST_TSC_OFFSET)) \ # -i guest-trace.dat # # Luiz Capitulino set -e # Host config host_addr= host_cpu_mask= 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=trace-cmd # Guest config guest_cpu_mask= guest_trace_file=./trace.dat guest_trace=trace-cmd start_host_tracing() { ssh $host_addr $host_trace start \ -M $host_cpu_mask \ -p function \ -C x86-tsc \ -e kvm_entry \ -e kvm_exit \ -e sched_switch \ -l apic_timer_fn \ -l kvm_inject_pending_timer_irqs \ -l kvm_set_lapic_tscdeadline_msr } stop_host_tracing() { local outf=$1 ssh $host_addr $host_trace stop ssh $host_addr $host_trace extract -o $outf } guest_trace_run() { echo running $* $guest_trace record \ -M $guest_cpu_mask \ -p function \ -C x86-tsc \ -e sys_enter_clock_nanosleep \ -e sys_exit_clock_nanosleep \ -l smp_apic_timer_interrupt \ $* } copy_guest_trace() { scp $guest_trace_file $host_addr:$host_guest_trace_file } if [ "$(id -u)" -ne 0 ]; then echo "ERROR: must run as root" exit 1 fi start_host_tracing guest_trace_run $* stop_host_tracing $host_trace_file copy_guest_trace