From 519cbbaa9a4e766772015cfe309fd4c6e524d96f Mon Sep 17 00:00:00 2001 From: Vasily Leonenko Date: Fri, 30 Jul 2021 18:07:53 +0300 Subject: [PATCH] [PR] Instrumentation: Introduce instrumentation-binpath argument Summary: This commit introduces -instrumentation-binpath argument used to point instuqmented binary in runtime in case if /proc/self/map_files path is not accessible due to access restriction issues. Vasily Leonenko Advanced Software Technology Lab, Huawei (cherry picked from FBD30092681) --- bolt/runtime/instr.cpp | 5 +++++ bolt/src/Passes/Instrumentation.cpp | 6 ++++++ bolt/src/RuntimeLibs/InstrumentationRuntimeLibrary.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp index f4ac4a656cf6..446cd3562313 100644 --- a/bolt/runtime/instr.cpp +++ b/bolt/runtime/instr.cpp @@ -90,6 +90,8 @@ extern bool __bolt_instr_no_counters_clear; extern bool __bolt_instr_wait_forks; // Filename to dump data to extern char __bolt_instr_filename[]; +// Instumented binary file path +extern char __bolt_instr_binpath[]; // If true, append current PID to the fdata filename when creating it so // different invocations of the same program can be differentiated. extern bool __bolt_instr_use_pid; @@ -597,6 +599,9 @@ static char *getBinaryPath() { static char TargetPath[NameMax] = {}; char Buf[BufSize]; + if (__bolt_instr_binpath[0] != '\0') + return __bolt_instr_binpath; + if (TargetPath[0] != '\0') return TargetPath; diff --git a/bolt/src/Passes/Instrumentation.cpp b/bolt/src/Passes/Instrumentation.cpp index d03c4434e9d0..cc882f557daa 100644 --- a/bolt/src/Passes/Instrumentation.cpp +++ b/bolt/src/Passes/Instrumentation.cpp @@ -27,6 +27,12 @@ cl::opt InstrumentationFilename( "/tmp/prof.fdata)"), cl::init("/tmp/prof.fdata"), cl::Optional, cl::cat(BoltInstrCategory)); +cl::opt InstrumentationBinpath( + "instrumentation-binpath", + cl::desc("path to instumented binary in case if /proc/self/map_files " + "is not accessible due to access restriction issues"), + cl::Optional, cl::cat(BoltInstrCategory)); + cl::opt InstrumentationFileAppendPID( "instrumentation-file-append-pid", cl::desc("append PID to saved profile file name (default: false)"), diff --git a/bolt/src/RuntimeLibs/InstrumentationRuntimeLibrary.cpp b/bolt/src/RuntimeLibs/InstrumentationRuntimeLibrary.cpp index 11dfbf978841..4412628b4257 100644 --- a/bolt/src/RuntimeLibs/InstrumentationRuntimeLibrary.cpp +++ b/bolt/src/RuntimeLibs/InstrumentationRuntimeLibrary.cpp @@ -25,6 +25,7 @@ extern cl::OptionCategory BoltOptCategory; extern cl::opt InstrumentationFileAppendPID; extern cl::opt InstrumentationFilename; +extern cl::opt InstrumentationBinpath; extern cl::opt InstrumentationSleepTime; extern cl::opt InstrumentationNoCountersClear; extern cl::opt InstrumentationWaitForks; @@ -178,6 +179,7 @@ void InstrumentationRuntimeLibrary::emitBinary(BinaryContext &BC, Summary->IndCallTargetDescriptions.size()); emitIntValue("__bolt_instr_num_funcs", Summary->FunctionDescriptions.size()); emitString("__bolt_instr_filename", opts::InstrumentationFilename); + emitString("__bolt_instr_binpath", opts::InstrumentationBinpath); emitIntValue("__bolt_instr_use_pid", !!opts::InstrumentationFileAppendPID, 1); if (BC.isMachO()) {