Skip to content

Instantly share code, notes, and snippets.

@misha354
Created January 13, 2019 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misha354/15f74ad50c4fe67fe5ae2b9e046fe2f6 to your computer and use it in GitHub Desktop.
Save misha354/15f74ad50c4fe67fe5ae2b9e046fe2f6 to your computer and use it in GitHub Desktop.
vagrant@dns4-01-us1:~$ dpkg -l | grep image
ii linux-image-4.4.0-133-generic 4.4.0-133.159~14.04.1 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii linux-image-4.4.0-133-generic-dbgsym 4.4.0-133.159~14.04.1 amd64 Linux kernel debug image for version 4.4.0 on 64 bit x86 SMP
vagrant@dns4-01-us1:~$ cat flame-kernel.sh
#!/bin/bash
/home/vagrant/systemtapbin/bin/stap -s 32 --all-modules -v -D MAXBACKTRACE=100 -D MAXSTRINGLEN=4096 -D MAXMAPENTRIES=10240 -D DMAXACTION_INTERRUPTIBLE=500 -D MAXACTION=100000 -D STP_OVERLOAD_THRESHOLD=5000000000LL flame-kernel.stp > out.stap-stacks
vagrant@dns4-01-us1:~$
vagrant@dns4-01-us1:~$
vagrant@dns4-01-us1:~$ cat flame-kernel.stp
/*
Based on Brendan Gregg's work: http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
*/
global s%
# Two ways of getting the timer - either perf.hw.instructions
# (every 100m instructions), or timer.profile - every jiffie tick.
// probe perf.hw.instructions {
probe timer.profile {
s[backtrace()] <<< 1;
}
probe end {
foreach (i in s+) {
print_stack(i);
printf("\t%d\n", @count(s[i]));
}
}
%( $# > 1 %?
probe timer.sec($2) {
%:
probe timer.sec(30) {
%)
exit();
}
vagrant@dns4-01-us1:~$ sudo ./flame-kernel.sh
Pass 1: parsed user script and 476 library scripts using 113060virt/85524res/4696shr/81280data kb, in 340usr/40sys/373real ms.
Pass 2: analyzed script: 3 probes, 7 functions, 4 embeds, 1 global using 250408virt/224360res/6380shr/218628data kb, in 770usr/210sys/986real ms.
Pass 3: using cached /home/vagrant/.systemtap/cache/bc/stap_bce2f823b5dc20cf0d46bd31cf3cbeac_4369.c
Pass 4: using cached /home/vagrant/.systemtap/cache/bc/stap_bce2f823b5dc20cf0d46bd31cf3cbeac_4369.ko
Pass 5: starting run.
WARNING: Missing unwind data for a module, rerun with 'stap -d kernel'
WARNING: Missing unwind data for a module, rerun with 'stap -d (unknown; retry with -DDEBUG_UNWIND)'
WARNING: _stp_read_address failed to access memory location
Pass 5: run completed in 20usr/310sys/30662real ms.
vagrant@dns4-01-us1:~$ ./stackcollapse-stap.pl out.stap-stacks | ./flamegraph.pl > stap-kernel.svg
@fche
Copy link

fche commented Jan 29, 2019

By the way, if you wish to add userspace backtraces, also run ubacktrace() and/or print_ustack() -- but you can't defer the symbol resolution to a later timer probe (too late); you'd have to sprint_ubacktrace() inside the timer.profile probe. And you'll need to run stap with the proper variant of -d /lib/*/libc.so.* to unwind through at least glibc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment