Skip to content

Instantly share code, notes, and snippets.

@winse
Last active November 24, 2023 03:28
Show Gist options
  • Save winse/65823ba134b9e524fcf06c149fd67aed to your computer and use it in GitHub Desktop.
Save winse/65823ba134b9e524fcf06c149fd67aed to your computer and use it in GitHub Desktop.
磁盘使用情况火焰图
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/perl -w
#
# example:
#
# $ path=.
# $ depth=3
#
# $ du $path --max-depth=$depth -b > out.du
# or use
# $ du $path -b > out.du
#
# $ ~/git/FlameGraph/stackcollapse-du.pl out.du > out.du-folded
# $ ~/git/FlameGraph/flamegraph.pl out.du-folded >du.svg
#
use strict;
my $numArgs = $#ARGV + 1;
if ($numArgs != 1)
{
print "$ARGV[0]\n";
print "Usage : stackcollapse-du.pl <out.du> > out.txt\n";
exit;
}
my $inputDUFile = $ARGV[0];
open(my $fh, '<', $inputDUFile) or die "Can't read file '$inputDUFile' [$!]\n";
while (my $currLine = <$fh>){
chomp $currLine;
$currLine =~ (/^\s*(\d+(?:\.\d*)?)\s+?(.*)$/) or die "Error in regular expression on the current line\n";
my $value = $1;
my $path = $2;
if ($path) {
my @stack = split(/\//, $path);
my @result = ();
my $tempString = '';
my $i;
for($i=0; $i!=@stack; ++$i) {
if(!($stack[$i] eq '')) {
$result[@result] = $stack[$i];
}
}
$tempString = join(";", @result)." $value\n";
if ($value != 0){
print "$tempString";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment