On Thu, Jan 22, 2015 at 03:29:10PM +0200, Elazar Leibovich wrote: > When perf runs on a regular linux, it can collect the current > stacktraces (kernel or user) for each sample. This is a very important > feature, and is utilized by some visualization tools (see, e.g., > Brendan's post[0]). > > As far as I understand, it is not currently implemented in perf [1]. > > While providing a cross platform, safe solution that works every time > is a challenge, I think we can give a reasonable solution for Linux > guests only. > > I think we can, in a portable way, across multiple Linux versions, do > the following: > > 1) Find out at which stack the guest kernel is. > 2) Find out Kernel's text address. > 3) Scan the stack up to its maximal size. > 4) Record all addresses found in the kernel text segment. > > This is more or less what the kernel do when recording its own stack traces[2]. > > An alternative, more general design is, recording all integers that > looks like addresses in from the location of RIP to the start of the > physical page. This would give you a slightly trimmed stack trace, but > is pretty safe (you'll never get segfault, as RIP must be in a valid > page), and should work across many different guest OS. > > I have little experience in the internals of perf or KVM, and would be > happy to any feedback about implementing guest os callchain for KVM. > > [0] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html > [1] https://github.com/torvalds/linux/blob/master/arch/x86/kernel/cpu/perf_event.c#L1968 > /* TODO: We don't support guest os callchain now */ > [2] https://github.com/torvalds/linux/blob/master/arch/x86/kernel/dumpstack_64.c#L188 I'm not familiar with perf(1) internals but I guess a starting point is the perf-record(1) userspace call stack code, which collects call stacks for userspace processes. KVM guests are similar. i386 32-bit guest on x86_64 host is an interesting case. The host must be aware of the different calling conventions. CCing people who have been involved in perf-kvm(1). Stefan
Attachment:
pgpMeu3jnmOra.pgp
Description: PGP signature