diff --git a/projects/rocprofiler/bin/rpl_run.sh b/projects/rocprofiler/bin/rpl_run.sh index 134b9b2fc1..e1540333c8 100755 --- a/projects/rocprofiler/bin/rpl_run.sh +++ b/projects/rocprofiler/bin/rpl_run.sh @@ -44,6 +44,7 @@ export PATH=.:$PATH export HSA_TOOLS_REPORT_LOAD_FAILURE=1 export HSA_VEN_AMD_AQLPROFILE_LOG=1 export ROCPROFILER_LOG=1 +unset ROCPROFILER_SESS # ROC Profiler environment # Loading of ROC Profiler by HSA runtime @@ -317,12 +318,22 @@ elif [ "$input_type" = "txt" ] ; then echo "RPL: output dir '$RES_DIR'" $BIN_DIR/txt2xml.sh $INPUT_FILE $RES_DIR input_list=`/bin/ls $RES_DIR/input*.xml` + export ROCPROFILER_SESS=$RES_DIR else fatal "Bad input file type '$INPUT_FILE'" fi +if [ -n "$csv_output" ] ; then + rm -f $csv_output +fi + for name in $input_list; do run $name $OUTPUT_DIR $APP_CMD + if [ -n "$ROCPROFILER_SESS" -a -e "$ROCPROFILER_SESS/error" ] ; then + echo "Error found, profiling aborted." + csv_output="" + break + fi done if [ -n "$csv_output" ] ; then diff --git a/projects/rocprofiler/src/core/rocprofiler.cpp b/projects/rocprofiler/src/core/rocprofiler.cpp index 5c26d75063..183d4f3b2a 100644 --- a/projects/rocprofiler/src/core/rocprofiler.cpp +++ b/projects/rocprofiler/src/core/rocprofiler.cpp @@ -259,7 +259,8 @@ PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t fa } // Loading a tool lib and setting of intercept mode - intercept_mode = rocprofiler::LoadTool(); + const bool intercept_mode_on = rocprofiler::LoadTool(); + if (intercept_mode_on) intercept_mode = true; // HSA intercepting if (intercept_mode) { diff --git a/projects/rocprofiler/src/util/logger.h b/projects/rocprofiler/src/util/logger.h index d290aef737..dcfa80f6e3 100644 --- a/projects/rocprofiler/src/util/logger.h +++ b/projects/rocprofiler/src/util/logger.h @@ -68,6 +68,7 @@ class Logger { static void begm() { Instance().ResetStreaming(true); } static void endl() { Instance().ResetStreaming(false); } + static void errm() { Instance().SetError(); } static const std::string& LastMessage() { Logger& logger = Instance(); @@ -96,19 +97,27 @@ class Logger { static uint32_t GetPid() { return syscall(__NR_getpid); } static uint32_t GetTid() { return syscall(__NR_gettid); } - Logger() : file_(NULL), dirty_(false), streaming_(false), messaging_(false) { - const char* path = getenv("ROCPROFILER_LOG"); - if (path != NULL) { - file_ = fopen("/tmp/rocprofiler_log.txt", "a"); + Logger() : file_(NULL), session_file_(NULL), dirty_(false), streaming_(false), messaging_(false), error_(false) { + const char* var = getenv("ROCPROFILER_LOG"); + if (var != NULL) file_ = fopen("/tmp/rocprofiler_log.txt", "a"); + + var = getenv("ROCPROFILER_SESS"); + if (var != NULL) { + std::string dir = var; + if (dir.back() != '/') dir.push_back('/'); + std::string name = dir + "log.txt"; + session_file_ = fopen(name.c_str(), "a"); + if (session_file_ != NULL) session_dir_ = dir; + else std::cerr << "ROCProfiler: cannot create session log '" << name << "'" << std::endl << std::flush; } + ResetStreaming(false); } ~Logger() { - if (file_ != NULL) { - if (dirty_) Put("\n"); - fclose(file_); - } + if (dirty_) Put("\n"); + if (file_ != NULL) fclose(file_); + if (session_file_ != NULL) fclose(session_file_); } void ResetStreaming(const bool messaging) { @@ -131,8 +140,15 @@ class Logger { if (file_ != NULL) { dirty_ = true; flock(fileno(file_), LOCK_EX); + fprintf(file_, "%s", m.c_str()); fflush(file_); + + if (session_file_ != NULL) { + fprintf(session_file_, "%s", m.c_str()); + fflush(session_file_); + } + flock(fileno(file_), LOCK_UN); } } @@ -148,10 +164,21 @@ class Logger { Put(oss.str()); } + void SetError() { + std::lock_guard lck(mutex_); + if (error_ == false) { + error_ = true; + if (session_dir_.empty() == false) fopen(std::string(session_dir_ + "error").c_str(), "w"); + } + } + FILE* file_; + FILE* session_file_; bool dirty_; bool streaming_; bool messaging_; + bool error_; + std::string session_dir_; static mutex_t mutex_; static Logger* instance_; @@ -163,7 +190,8 @@ class Logger { #define ERR_LOGGING(stream) \ { \ - rocprofiler::util::Logger::Instance() << "error: " << rocprofiler::util::Logger::begm \ + rocprofiler::util::Logger::Instance() << rocprofiler::util::Logger::errm \ + << "error: " << rocprofiler::util::Logger::begm \ << stream << rocprofiler::util::Logger::endl; \ }