Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751488Ab3FDIjG (ORCPT ); Tue, 4 Jun 2013 04:39:06 -0400 Received: from mail4.hitachi.co.jp ([133.145.228.5]:33242 "EHLO mail4.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011Ab3FDIjB (ORCPT ); Tue, 4 Jun 2013 04:39:01 -0400 X-AuditID: 85900ec0-d42c9b900000151e-35-51ada79e8bf1 Message-ID: <51ADA785.4000904@hitachi.com> Date: Tue, 04 Jun 2013 17:38:29 +0900 From: Yoshihiro YUNOMAE User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:13.0) Gecko/20120604 Thunderbird/13.0 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Gleb Natapov , David Sharp , Marcelo Tosatti , Steven Rostedt , Hidehiro Kawai , Ingo Molnar , yrl.pp-manager.tt@hitachi.com, Masami Hiramatsu , Thomas Gleixner Subject: [EXAMPLE] tools: a tool for merging trace data of a guest and a host References: <20130604083616.22713.24922.stgit@yunodevel> In-Reply-To: <20130604083616.22713.24922.stgit@yunodevel> Content-Type: multipart/mixed; boundary="------------020608000205000004030504" X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6474 Lines: 135 This is a multi-part message in MIME format. --------------020608000205000004030504 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit This tool merges trace data of a guest and a host in chronological order. Restrictions of this tool is as follows: - one guest (not for multiple guests) - stable TSC (not backward TSC) - synchronized TSC - unchanged TSC offset (the guest does not execute write_TSC) - How to use 1. [host] Enable kvm_write_tsc_offset before booting a guest # cd /sys/kernel/debug/tracing/instances # mkdir tsc_offset # cd tsc_offset # echo x86-tsc > trace_clock # echo 1 > events/kvm/kvm_write_tsc_offset/enable 2. [host] Enable events you want Note: I recommend to enable kvm_exit/entry events. # cd /sys/kernel/debug/tracing # echo kvm_entry >> set_event # echo kvm_exit >> set_event # [snip] # echo x86-tsc > trace_clock 3. [host] Boot the guest 4. [guest] Enable events you want # cd /sys/kernel/debug/tracing # echo sched_wakeup >> set_event # echo sched_switch >> set_event # [snip] # echo x86-tsc > trace_clock 5. [guest] Run programs 6. [guest/host] Get trace data # echo 0 > tracing_on # cat trace > /home/yourdir/log/guest_trace.txt (for the guest) (cat trace > /home/yourdir/log/host_trace.txt (for the host)) # scp [host_IP]:/home/yourdir/log/guest_trace.txt (only for the guest) 7. [host] Get next TSC offset # cat /sys/kernel/debug/tracing/instances/tsc_offset/trace qemu-kvm-22089 [000] d...4300151845072: kvm_write_tsc_offset: previous 0 next 18446739773557710924 8. [host] Run this tool with the next TSC offset for -t option. $ ./trace-merge.pl -g ~/log/guest_trace.txt -h ~/log/host_trace.txt \ -t 18446739773557710924 h qemu-kvm-2687 [003] d...50550079203669: kvm_exit: [detail] h qemu-kvm-2687 [003] d...50550079206816: kvm_entry: [detail] g comm-3826 [000] d.h.50550079226331: sched_wakeup: [detail] h qemu-kvm-2687 [003] d...50550079240656: kvm_exit: [detail] h qemu-kvm-2687 [003] d...50550079243467: kvm_entry: [detail] h qemu-kvm-2687 [003] d...50550079256103: kvm_exit: [detail] h qemu-kvm-2687 [003] d...50550079268391: kvm_entry: [detail] g comm-3826 [000] d...50550079279266: sched_switch: [detail] h qemu-kvm-2687 [003] d...50550079280829: kvm_exit: [detail] h qemu-kvm-2687 [003] d...50550079286028: kvm_entry: [detail] | \----guest/host Thanks, -- Yoshihiro YUNOMAE Software Platform Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: yoshihiro.yunomae.ez@hitachi.com --------------020608000205000004030504 Content-Type: text/plain; charset=Shift_JIS; name="trace-merge.pl" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="trace-merge.pl" IyEvdXNyL2Jpbi9wZXJsCiMKIyBUb29sIGZvciBtZXJnaW5nIGFuZC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from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/