Last active
November 24, 2023 03:28
-
-
Save winse/65823ba134b9e524fcf06c149fd67aed to your computer and use it in GitHub Desktop.
磁盘使用情况火焰图
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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