public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: linux-kernel@vger.kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>, Gleb Natapov <gleb@redhat.com>,
	David Sharp <dhsharp@google.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>,
	Ingo Molnar <mingo@redhat.com>,
	yrl.pp-manager.tt@hitachi.com,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [EXAMPLE] tools: a tool for merging trace data of a guest and a host
Date: Tue, 04 Jun 2013 17:38:29 +0900	[thread overview]
Message-ID: <51ADA785.4000904@hitachi.com> (raw)
In-Reply-To: <20130604083616.22713.24922.stgit@yunodevel>

[-- Attachment #1: Type: text/plain, Size: 2564 bytes --]

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



[-- Attachment #2: trace-merge.pl --]
[-- Type: text/plain, Size: 2402 bytes --]

#!/usr/bin/perl
#
# Tool for merging and sorting trace data of a guest and host
#
# Created by Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
#
# - How to use
# ./trace-merge.pl <-h host_data -g guest_data -t tsc_offset_value>
#
use strict;
use bigint;
use warnings;
use Getopt::Long qw(:config posix_default no_ignore_case);

my @merged_data = ();
my @sorted_data = ();

my ($opt_host, $opt_guest, $opt_offset);
GetOptions(
	"host_data|h=s"	=> \$opt_host,
	"guest_data|g=s"=> \$opt_guest,
	"tsc_offset|t=i"=> \$opt_offset
);

my $tsc_offset = 0;
my $MASK64 = (1 << 64) - 1;

&get_tsc_offset();
&read_all_data();

sub read_all_data {
	my $h_tsc = 0;
	my $g_comm = "";
	my $g_tsc = 0;
	my $g_event = "";
	my $h_line = "";
	my $g_line = "";

	open HOST_DATA, "<", $opt_host or die "Cannot open host file: $!";
	open GUEST_DATA, "<", $opt_guest or die "Cannot open guest file: $!";

	# skip header information of trace files
	while (!$h_tsc) {
		$h_line = <HOST_DATA>;
		if ($h_line =~ /\[[0-9]+\]\s.{4}\s([0-9]+):/) {
			$h_tsc = $1;
		}
	}

	# skip header information of trace files
	while (!$g_tsc) {
		$g_line = <GUEST_DATA>;
		if ($g_line =~ /^(.+\[[0-9]+\]\s.{4}\s)([0-9]+)(:.+)/) {
			$g_comm = $1;
			$g_tsc = ($2 - $tsc_offset) & $MASK64;
			$g_event = $3;
		}
	}

	# sort trace data by tsc
	while ($h_line) {
		if ($h_tsc < $g_tsc) {
			print "h $h_line";
			$h_line = <HOST_DATA>;
			if (!$h_line) {
				last;
			}
			if ($h_line =~ /\[[0-9]+\]\s.{4}\s([0-9]+):/) {
				$h_tsc = $1;
			}
		} else {
			print "g $g_comm$g_tsc$g_event\n";
			$g_line = <GUEST_DATA>;
			if (!$g_line) {
				last;
			}
			if ($g_line =~ /^(.+\[[0-9]+\]\s.{4}\s)([0-9]+)(:.+)/) {
				$g_comm = $1;
				$g_tsc = ($2 - $tsc_offset) & $MASK64;
				$g_event = $3;
			}
		}
	}

	#flush host data
	while ($h_line) {
		print "h $h_line";
		$h_line = <HOST_DATA>;
		if (!$h_line) {
			last;
		}
	}

	#flush guest data
	while ($g_line) {
		print "g $g_comm$g_tsc$g_event\n";
		$g_line = <GUEST_DATA>;
		if (!$g_line) {
			last;
		}
		if ($g_line =~ /^(.+\[[0-9]+\]\s.{4}\s)([0-9]+)(:.+)/) {
			$g_comm = $1;
			$g_tsc = ($2 - $tsc_offset) & $MASK64;
			$g_event = $3;
		}
	}

	close HOST_DATA;
	close GUEST_DATA;
}

sub get_tsc_offset {
	if (!$opt_offset) {
		$tsc_offset = 0;
	} else {
		$tsc_offset = &convert_tscoffset($opt_offset);
	}
}

sub convert_tscoffset {
	my $offset = shift;

	return $offset - (1 << 64);
}

  parent reply	other threads:[~2013-06-04  8:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04  8:36 [PATCH V2 0/1] kvm/vmx: Output TSC offset Yoshihiro YUNOMAE
2013-06-04  8:36 ` [PATCH V2 1/1] kvm/vmx: Add a tracepoint write_tsc_offset Yoshihiro YUNOMAE
2013-06-06  0:23   ` Marcelo Tosatti
2013-06-06 11:33     ` Gleb Natapov
2013-06-06 21:43       ` Marcelo Tosatti
2013-06-07  5:22       ` Yoshihiro YUNOMAE
2013-06-07 21:55         ` Marcelo Tosatti
2013-06-09 11:14         ` Gleb Natapov
2013-06-10  9:30           ` Yoshihiro YUNOMAE
2013-06-10 10:05             ` Gleb Natapov
2013-06-10 11:37               ` Yoshihiro YUNOMAE
2013-06-10 14:04               ` Marcelo Tosatti
2013-06-10 16:38                 ` Gleb Natapov
2013-06-10 20:28                   ` Marcelo Tosatti
2013-06-11  6:50                     ` Gleb Natapov
2013-06-11  9:26                       ` Yoshihiro YUNOMAE
2013-06-04  8:38 ` Yoshihiro YUNOMAE [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-06-12  7:43 [PATCH V3 0/1] kvm: Output TSC offset Yoshihiro YUNOMAE
2013-06-12  7:46 ` [EXAMPLE] tools: a tool for merging trace data of a guest and a host Yoshihiro YUNOMAE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51ADA785.4000904@hitachi.com \
    --to=yoshihiro.yunomae.ez@hitachi.com \
    --cc=dhsharp@google.com \
    --cc=gleb@redhat.com \
    --cc=hidehiro.kawai.ez@hitachi.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=yrl.pp-manager.tt@hitachi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox