Skip to content

Commit

Permalink
fsperf: Workaround perf changing cwd via setns(2)
Browse files Browse the repository at this point in the history
"perf report" calls setns(2) to check process details, and it may change
CWD of this process. Probably, bug of perf.

To workaround this behavior, this makes sure cwd is changing back to
original by perf_fix_cwd().
  • Loading branch information
OGAWAHirofumi committed Mar 28, 2018
1 parent 38338e0 commit 2d5697b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fsperf/fsperf.pl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ (@)
warn "Warning: @_\n";
}
# "perf report" calls setns(2) to check process details, and it may
# change CWD of this process. Make sure, change back to original here.
sub perf_fix_cwd
{
if (not $ENV{FSPERF_CWD}) {
$ENV{FSPERF_CWD} = getcwd();
}
chdir($ENV{FSPERF_CWD});
}
sub safe_system_with_output
{
my $output = shift;
Expand Down Expand Up @@ -387,6 +397,8 @@ ($;$$)
my $curdir = shift;
my $path;
perf_fix_cwd();
if ($curdir) {
$path = $name;
} else {
Expand Down Expand Up @@ -447,6 +459,7 @@ ($)
my $re_addr16 = $re_addr . "{16}";
# No way to dump kallsyms by perf, so use "strings"
perf_fix_cwd();
open(my $fh, "-|", "strings $data") or die "Couldn't run `strings': $!";
my $last = -1;
Expand Down Expand Up @@ -4867,6 +4880,8 @@ sub trace_end
my $mode = $ENV{FSPERF_MODE};
my $func = $mode_table{$mode}->{func};
perf_fix_cwd();
# Call post process function
$func->();
Expand Down Expand Up @@ -5577,6 +5592,8 @@ sub cmd_debug_run
exit(0);
}
perf_fix_cwd();
my %cmd_func = (
"record" => \&cmd_record,
"report" => \&cmd_report,
Expand Down

0 comments on commit 2d5697b

Please sign in to comment.