From 0d09bed6410b860bd42007c3b4bbc7d15c559a6d Mon Sep 17 00:00:00 2001 From: gobhardw Date: Tue, 20 Jun 2023 19:18:59 +0530 Subject: [PATCH] Handle user input if first PMC line is empty Change-Id: I456fd9360a4a8506fadcc975e71da112a26b07ae [ROCm/rocprofiler commit: c6729adaedb5f8dd8b07663a2f38ae1658cf7930] --- projects/rocprofiler/CHANGELOG.md | 1 + projects/rocprofiler/bin/rocprofv2 | 4 ++++ projects/rocprofiler/src/utils/exception.h | 10 ++++++---- projects/rocprofiler/src/utils/helper.cpp | 11 +++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/projects/rocprofiler/CHANGELOG.md b/projects/rocprofiler/CHANGELOG.md index 0f57a89455..d1be9b30e0 100644 --- a/projects/rocprofiler/CHANGELOG.md +++ b/projects/rocprofiler/CHANGELOG.md @@ -226,6 +226,7 @@ Rocprofiler for ROCm 5.7 added support for counter collection (PMC) and advanced - ATT analysis will not run by default. For ATT to have the same behaviour as 5.5, use --plugin att --mode network ### Optimized - ATT json filesizes +- Now profiler autocorrects user input errors for pmc and throws exception for wrong input with this message:"Bad input metric. usage --> pmc: [counter1] [counter2]" ### Added - Every API trace in V2 reported synchronously will have two records, one for Enter phase and for Exit phase - File Plugin now reports the HSA OPS operation kind as part of the output text diff --git a/projects/rocprofiler/bin/rocprofv2 b/projects/rocprofiler/bin/rocprofv2 index 4208e5b3ca..91c50a54b7 100755 --- a/projects/rocprofiler/bin/rocprofv2 +++ b/projects/rocprofiler/bin/rocprofv2 @@ -256,6 +256,10 @@ PMC_LINES=() if [ -n "$COUNTERS_PATH" ]; then input=$COUNTERS_PATH while IFS= read -r line || [[ -n "$line" ]]; do + #skip empty lines + if [[ -z "$line" ]]; then + continue + fi # if in att mode, only add the first line if [[ ! -n "$PMC_LINES" ]] || [[ ! -n "$ATT_ARGV" ]]; then PMC_LINES+=( "$line" ) diff --git a/projects/rocprofiler/src/utils/exception.h b/projects/rocprofiler/src/utils/exception.h index e327203185..bd078de842 100644 --- a/projects/rocprofiler/src/utils/exception.h +++ b/projects/rocprofiler/src/utils/exception.h @@ -36,14 +36,16 @@ class Exception : public std::runtime_error { Exception() = delete; explicit Exception(rocprofiler_status_t status, const char* what_arg = "") - : std::runtime_error(std::string(rocprofiler_error_str(status)) + " " + - what_arg), + : std::runtime_error(std::string(rocprofiler_error_str(status)) + " " + what_arg), status_(status) {} - rocprofiler_status_t status() const noexcept { return status_; } + explicit Exception(const std::string& message) : std::runtime_error(message) { message_ = message; } + const char* what() const noexcept override { return message_.c_str(); } + protected: - const rocprofiler_status_t status_; + rocprofiler_status_t status_; + std::string message_; }; }; // namespace rocprofiler diff --git a/projects/rocprofiler/src/utils/helper.cpp b/projects/rocprofiler/src/utils/helper.cpp index 3faa4175fd..b9f0f4e0ad 100644 --- a/projects/rocprofiler/src/utils/helper.cpp +++ b/projects/rocprofiler/src/utils/helper.cpp @@ -144,7 +144,6 @@ std::string string_printf(const char* format, ...) { #endif /* defined (ENABLE_BACKTRACE) */ std::string errmsg("ROCProfiler: fatal error: " + message); - fputs(errmsg.c_str(), stderr); std::cerr << errmsg << std::endl; abort(); @@ -251,7 +250,7 @@ void trim(std::string& str) { // replace unsuported specail chars with space static void handle_special_chars(std::string& str) { std::set specialChars = {'!', '@', '#', '$', '%', '&', '(', ')', ',', '*', '+', '-', '.', - '/', ';', '<', '=', '>', '?', '@', '{', '}', '^', '`', '~', '|'}; + '/', ';', '<', '=', '>', '?', '@', '{', '}', '^', '`', '~', '|', ':'}; // Iterate over the string and replace any special characters with a space. for (unsigned int i = 0; i < str.length(); i++) { @@ -277,6 +276,14 @@ void validate_counters_format(std::vector& counters, std::string li } } } + + // raise exception with correct usage if user still managed to corrupt input + for(const auto &itr: counters) + { + if(!has_counter_format(itr)){ + rocprofiler::fatal("Bad input metric. usage --> pmc: "); + } + } } } // namespace rocprofiler