Files
Edward Thomson dfbdaa28a5 benchmark: introduce profiling support
Introduce `--profile` support to the benchmark helper script, which will
invoke `perf` on Linux. Additionally, add a `--flamegraph` output
option based on that.
2025-01-13 21:21:17 +00:00

32 lines
638 B
Perl
Executable File

#!/usr/bin/perl
use Getopt::Std;
getopt('urt');
unless ($opt_r && $opt_t){
print "Usage: $0 [ -u user] -r sample_count -t sleep_time\n";
exit(0);
}
my $i;
my @proc = "";
for ($i = 0; $i < $opt_r ; $i++){
if ($opt_u){
$proc = `/usr/sysv/bin/ps -u $opt_u `;
$proc =~ s/^.*\n//;
$proc =~ s/\s*(\d+).*\n/\1 /g;
@proc = split(/\s+/,$proc);
} else {
opendir(my $dh, '/proc') || die "Cant't open /proc: $!";
@proc = grep { /^[\d]+$/ } readdir($dh);
closedir ($dh);
}
foreach my $pid (@proc){
my $command = "/usr/bin/procstack $pid";
print `$command 2>/dev/null`;
}
select(undef, undef, undef, $opt_t);
}