From a76341e30c64a74d7cc020fcb16dc21c623fa52b Mon Sep 17 00:00:00 2001 From: Sriraksha Nagaraj Date: Mon, 2 Oct 2023 14:08:26 +0000 Subject: [PATCH] Enabling -m and --basenames option Change-Id: Ic19ac28ab6ec842daf2a93a311ed7690b61b1e2a --- bin/rocprofv2 | 15 ++++ src/core/counters/metrics/metrics.h | 1 + src/utils/helper.cpp | 76 ++++++++++--------- .../featuretests/profiler/profiler_gtest.cpp | 1 + .../unittests/profiler/profiler_gtest.cpp | 25 +++++- 5 files changed, 81 insertions(+), 37 deletions(-) diff --git a/bin/rocprofv2 b/bin/rocprofv2 index 4012f10c39..36c010abf9 100755 --- a/bin/rocprofv2 +++ b/bin/rocprofv2 @@ -31,6 +31,8 @@ usage() { echo -e "${GREEN}-t | --test ${RESET} For Running the tests" echo -e "${GREEN}-mt | --mem-test ${RESET} For Running the Memory Leak tests. This run requires building using -acb | --asan-clean-build option" fi + echo -e "${GREEN}-m ${RESET} For providing an absolute path of a custom metrics file" + echo -e "${GREEN}--basenames ${RESET} For Truncating the kernel names" echo -e "${GREEN}--hip-api ${RESET} For Collecting HIP API Traces" echo -e "${GREEN}--hip-activity | --hip-trace ${RESET} For Collecting HIP API Activities Traces" echo -e "${GREEN}--hsa-api ${RESET} For Collecting HSA API Traces" @@ -163,6 +165,19 @@ while [ 1 ]; do export ROCPROFILER_ENABLE_ROCSYS=$2 shift shift + elif [ "$1" = "-m" ]; then + if [ $2 ] && [ -n $2 ] && [ -r $2 ]; then + export ROCPROFILER_METRICS_PATH=$2 + else + echo -e "Error: \"$2\" path doesn't exist!" + usage + exit 1 + fi + shift + shift + elif [ "$1" = "--basenames" ]; then + export ROCPROFILER_TRUNCATE_KERNEL_PATH=1 + shift elif [ "$1" = "--plugin" ]; then if [ -n $2 ]; then PLUGIN=$2 diff --git a/src/core/counters/metrics/metrics.h b/src/core/counters/metrics/metrics.h index f51171454f..08c28ff5bf 100644 --- a/src/core/counters/metrics/metrics.h +++ b/src/core/counters/metrics/metrics.h @@ -199,6 +199,7 @@ class MetricsDict { MetricsDict(const rocprofiler::HSAAgentInfo* agent_info) : xml_(NULL), agent_info_(agent_info) { std::string xml_name = []() { + if (const char* path = getenv("ROCPROFILER_METRICS_PATH"); path != nullptr) return path; return ""; }(); diff --git a/src/utils/helper.cpp b/src/utils/helper.cpp index 366861d9ff..60e5fdaf96 100644 --- a/src/utils/helper.cpp +++ b/src/utils/helper.cpp @@ -154,43 +154,49 @@ input string. By using the iterators it finds the window in the string which contains only the kernel name. For example 'Foo::foo(a[], int (int))' -> 'foo'*/ std::string truncate_name(const std::string& name) { - auto rit = name.rbegin(); - auto rend = name.rend(); - uint32_t counter = 0; - char open_token = 0; - char close_token = 0; - while (rit != rend) { - if (counter == 0) { - switch (*rit) { - case ')': - counter = 1; - open_token = ')'; - close_token = '('; - break; - case '>': - counter = 1; - open_token = '>'; - close_token = '<'; - break; - case ']': - counter = 1; - open_token = ']'; - close_token = '['; - break; - case ' ': - ++rit; - continue; + + const char* path = getenv("ROCPROFILER_TRUNCATE_KERNEL_PATH"); + if(path != nullptr) { + auto rit = name.rbegin(); + auto rend = name.rend(); + uint32_t counter = 0; + char open_token = 0; + char close_token = 0; + while (rit != rend) { + if (counter == 0) { + switch (*rit) { + case ')': + counter = 1; + open_token = ')'; + close_token = '('; + break; + case '>': + counter = 1; + open_token = '>'; + close_token = '<'; + break; + case ']': + counter = 1; + open_token = ']'; + close_token = '['; + break; + case ' ': + ++rit; + continue; + } + if (counter == 0) break; + } else { + if (*rit == open_token) counter++; + if (*rit == close_token) counter--; + } + ++rit; } - if (counter == 0) break; - } else { - if (*rit == open_token) counter++; - if (*rit == close_token) counter--; - } - ++rit; + auto rbeg = rit; + while ((rit != rend) && (*rit != ' ') && (*rit != ':')) rit++; + return name.substr(rend - rit, rit - rbeg); } - auto rbeg = rit; - while ((rit != rend) && (*rit != ' ') && (*rit != ':')) rit++; - return name.substr(rend - rit, rit - rbeg); + else + return name; } // C++ symbol demangle diff --git a/tests-v2/featuretests/profiler/profiler_gtest.cpp b/tests-v2/featuretests/profiler/profiler_gtest.cpp index 4be8b9d677..082c1c1bca 100644 --- a/tests-v2/featuretests/profiler/profiler_gtest.cpp +++ b/tests-v2/featuretests/profiler/profiler_gtest.cpp @@ -73,6 +73,7 @@ void __attribute__((constructor)) globalsetting() { gfx_path << app_path << metrics_path; setenv("ROCPROFILER_METRICS_PATH", gfx_path.str().c_str(), true); setenv("ROCPROFILER_MAX_ATT_PROFILES", "2", 1); + setenv("ROCPROFILER_TRUNCATE_KERNEL_PATH", "1", true); } /** diff --git a/tests-v2/unittests/profiler/profiler_gtest.cpp b/tests-v2/unittests/profiler/profiler_gtest.cpp index 9827d560ef..7238da113a 100644 --- a/tests-v2/unittests/profiler/profiler_gtest.cpp +++ b/tests-v2/unittests/profiler/profiler_gtest.cpp @@ -310,7 +310,7 @@ TEST(WhenTrucatingLongKernelNames, KernelNameGetsTruncatedProperly) { "int, int, long long, long long, long long, long long, long long, long " "long, long long, long long, long long, float, float, float, float " "const*, float*, float const*, float*, float const*) [clone .kd]"; - + setenv("ROCPROFILER_TRUNCATE_KERNEL_PATH", "1", true); std::string trunkated_name = rocprofiler::truncate_name(long_kernel_name); EXPECT_EQ("kernel_7r_3d_pml", trunkated_name); @@ -332,7 +332,28 @@ TEST(WhenTrucatingKokkossKernelNames, KernelNameGetsTruncatedProperly) { "LAMMPS_NS::PairReaxFFKokkos::params_sing, false>, " "Kokkos::RangePolicy >, " "Kokkos::Experimental::HIP> const*)"; - + setenv("ROCPROFILER_TRUNCATE_KERNEL_PATH", "1", true); std::string trunkated_name = rocprofiler::truncate_name(long_kernel_name); EXPECT_EQ("hip_parallel_launch_local_memory", trunkated_name); } + +TEST(WhenTrucatingKokkossKernelNames, KernelNameDoesnotTruncated) { + std::string long_kernel_name = + "void " + "Kokkos::Experimental::Impl::hip_parallel_launch_local_memory, " + "LAMMPS_NS::PairReaxFFKokkos::params_sing, false>, " + "Kokkos::RangePolicy >, " + "Kokkos::Experimental::HIP>, 1024u, " + "1u>(Kokkos::Impl::ParallelFor, " + "LAMMPS_NS::PairReaxFFKokkos::params_sing, false>, " + "Kokkos::RangePolicy >, " + "Kokkos::Experimental::HIP> const*)"; + unsetenv("ROCPROFILER_TRUNCATE_KERNEL_PATH"); + std::string trunkated_name = rocprofiler::truncate_name(long_kernel_name); + EXPECT_EQ(long_kernel_name, trunkated_name); +}