Skip to content

Commit

Permalink
add -s for diffing profiles including hex numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
brendangregg committed Nov 4, 2014
1 parent fff2ad0 commit 7adc54e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions difffolded.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# difffolded.pl diff two folded stack files. Use this for generating
# flame graph differentials.
#
# USAGE: ./difffolded.pl folded1 folded2 | ./flamegraph.pl > diff2.svg
# USAGE: ./difffolded.pl [-hns] folded1 folded2 | ./flamegraph.pl > diff2.svg
#
# Options are described in the usage message (-h).
#
# The flamegraph will be colored based on higher samples (red) and smaller
# samples (blue). The frame widths will be based on the 2nd folded file.
Expand Down Expand Up @@ -51,26 +53,31 @@
# 28-Oct-2014 Brendan Gregg Created this.

use strict;
use Getopt::Long;
use Getopt::Std;

# defaults
my $normalize = 0; # make sample counts equal
my $striphex = 0; # strip hex numbers

sub usage {
print STDERR <<USAGE_END;
USAGE: $0 [-n] folded1 folded2 | flamegraph.pl > diff2.svg
USAGE: $0 [-hns] folded1 folded2 | flamegraph.pl > diff2.svg
-h # help message
-n # normalize sample counts
-s # strip hex numbers (addresses)
See stackcollapse scripts for generating folded files.
Also consider flipping the files and hues to highlight reduced paths:
$0 folded2 folded1 | ./flamegraph.pl --negate > diff1.svg
USAGE_END
exit 2;
}

usage if @ARGV < 2;
GetOptions(
'normalize|n' => \$normalize
) or usage();

usage() if @ARGV < 2;
our($opt_h, $opt_n, $opt_s);
getopts('ns') or usage();
usage() if $opt_h;
$normalize = 1 if defined $opt_n;
$striphex = 1 if defined $opt_s;

my ($total1, $total2) = (0, 0);
my %Folded;
Expand All @@ -82,6 +89,7 @@ sub usage {
while (<FILE>) {
chomp;
my ($stack, $count) = (/^(.*)\s+?(\d+(?:\.\d*)?)$/);
$stack =~ s/0x[0-9a-fA-F]+/0x.../g if $striphex;
$Folded{$stack}{1} += $count;
$total1 += $count;
}
Expand All @@ -91,6 +99,7 @@ sub usage {
while (<FILE>) {
chomp;
my ($stack, $count) = (/^(.*)\s+?(\d+(?:\.\d*)?)$/);
$stack =~ s/0x[0-9a-fA-F]+/0x.../g if $striphex;
$Folded{$stack}{2} += $count;
$total2 += $count;
}
Expand Down

0 comments on commit 7adc54e

Please sign in to comment.