diff --git a/projects/rocprofiler/bin/rpl_run.sh b/projects/rocprofiler/bin/rpl_run.sh index 3e4c72b216..211343d955 100755 --- a/projects/rocprofiler/bin/rpl_run.sh +++ b/projects/rocprofiler/bin/rpl_run.sh @@ -81,6 +81,7 @@ fatal() { echo "$0: Error: $1" echo "" usage + exit 1 } error() { @@ -409,11 +410,13 @@ if [ -n "$csv_output" ] ; then rm -f $csv_output fi +RET=0 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="" + RET=1 break fi done @@ -439,4 +442,4 @@ if [ "$DATA_PATH" = "$TMP_DIR" ] ; then fi fi -exit 0 +exit $RET diff --git a/projects/rocprofiler/src/core/metrics.h b/projects/rocprofiler/src/core/metrics.h index 5c9f358082..547156de4d 100644 --- a/projects/rocprofiler/src/core/metrics.h +++ b/projects/rocprofiler/src/core/metrics.h @@ -30,12 +30,14 @@ THE SOFTWARE. #include #include #include +#include #include #include #include "core/types.h" #include "util/exception.h" #include "util/hsa_rsrc_factory.h" +#include "util/logger.h" #include "xml/expr.h" #include "xml/xml.h" @@ -212,9 +214,16 @@ class MetricsDict { } void ImportMetrics(const util::AgentInfo* agent_info, const std::string& scope) { - auto metrics_list = xml_->GetNodes("top." + scope + ".metric"); + auto arr = xml_->GetNodes("top." + scope + ".metric"); + xml::Xml::node_list_t metrics_list(arr.begin(), arr.end()); + uint32_t metrics_number = metrics_list.size(); + bool do_lookup = true; if (!metrics_list.empty()) { - for (auto node : metrics_list) { + uint32_t it_number = metrics_number; + auto it = metrics_list.begin(); + auto end = metrics_list.end(); + while (it != end) { + auto node = *it; const std::string name = node->opts["name"]; const std::string expr_str = node->opts["expr"]; std::string descr = node->opts["descr"]; @@ -244,20 +253,41 @@ class MetricsDict { AddMetric(name, alias, counter); } } else { - xml::Expr* expr_obj = new xml::Expr(expr_str, new ExprCache(&cache_)); -#if 0 - std::cout << "# " << descr << std::endl; - std::cout << name << "=" << expr_obj->String() << "\n" << std::endl; -#endif - counters_vec_t counters_vec; - for (const std::string var : expr_obj->GetVars()) { - auto it = cache_.find(var); - if (it == cache_.end()) - EXC_RAISING(HSA_STATUS_ERROR, "Bad metric '" << name << "', var '" << var - << "' is not found"); - it->second->GetCounters(counters_vec); + xml::Expr* expr_obj = NULL; + try { + expr_obj = new xml::Expr(expr_str, new ExprCache(&cache_)); + } catch(const xml::exception_t& exc) { + if (do_lookup) metrics_list.push_back(node); + else throw(exc); + } + if (expr_obj) { +#if 0 + std::cout << "# " << descr << std::endl; + std::cout << name << "=" << expr_obj->String() << "\n" << std::endl; +#endif + counters_vec_t counters_vec; + for (const std::string var : expr_obj->GetVars()) { + auto it = cache_.find(var); + if (it == cache_.end()) { + EXC_RAISING(HSA_STATUS_ERROR, "Bad metric '" << name << "', var '" << var << "' is not found"); + } + it->second->GetCounters(counters_vec); + } + AddMetric(name, counters_vec, expr_obj); + } + } + + auto cur = it++; + metrics_list.erase(cur); + if (--it_number == 0) { + it_number = metrics_list.size(); + if (it_number < metrics_number) { + metrics_number = it_number; + } else if (it_number == metrics_number) { + do_lookup = false; + } else { + EXC_RAISING(HSA_STATUS_ERROR, "Internal error"); } - AddMetric(name, counters_vec, expr_obj); } } } diff --git a/projects/rocprofiler/src/xml/xml.h b/projects/rocprofiler/src/xml/xml.h index 5643c7ea32..608f3c548e 100644 --- a/projects/rocprofiler/src/xml/xml.h +++ b/projects/rocprofiler/src/xml/xml.h @@ -43,7 +43,10 @@ class Xml { typedef std::vector token_t; struct level_t; - typedef std::vector nodes_t; + typedef std::vector node_vect_t; + typedef std::list node_list_t; + + typedef node_vect_t nodes_t; typedef std::map opts_t; struct level_t { std::string tag; @@ -143,6 +146,7 @@ class Xml { struct print_func { bool fun(const std::string& global_tag, level_t* node) { + std::cout << global_tag << ":" << std::endl; for (auto& opt : node->opts) { std::cout << global_tag << "." << opt.first << " = " << opt.second << std::endl; } diff --git a/projects/rocprofiler/test/tool/gfx_metrics.xml b/projects/rocprofiler/test/tool/gfx_metrics.xml index 84abdc14e5..698826c689 100644 --- a/projects/rocprofiler/test/tool/gfx_metrics.xml +++ b/projects/rocprofiler/test/tool/gfx_metrics.xml @@ -77,7 +77,7 @@ - +