Skip to content

Commit 7fa5ac4

Browse files
committed
Address PR comments. Minor Fixes
1 parent 54e5843 commit 7fa5ac4

File tree

10 files changed

+431
-329
lines changed

10 files changed

+431
-329
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
#pragma once
24+
25+
#include <cstdint>
26+
#include <string>
27+
#include <vector>
28+
29+
namespace rocprofsys
30+
{
31+
/**
32+
* @brief Structure for function/region argument information
33+
*
34+
* Represents metadata about function or region arguments including
35+
* their position, type, name, and value information.
36+
*/
37+
struct arg_info
38+
{
39+
uint32_t arg_number = 0; ///< Argument position/index
40+
std::string arg_type = {}; ///< Argument type (e.g., "int", "float*")
41+
std::string arg_name = {}; ///< Argument name
42+
std::string arg_value = {}; ///< Argument value as string
43+
};
44+
45+
using function_args_t = std::vector<arg_info>;
46+
47+
inline function_args_t
48+
process_arguments_string(const std::string& arg_str)
49+
{
50+
function_args_t args;
51+
const std::string delimiter = ";;";
52+
53+
auto split = [](const std::string& str, const std::string& _delimiter) {
54+
std::vector<std::string> tokens;
55+
size_t start = 0;
56+
size_t end = str.find(_delimiter);
57+
58+
while(end != std::string::npos)
59+
{
60+
tokens.push_back(str.substr(start, end - start));
61+
start = end + _delimiter.length();
62+
end = str.find(_delimiter, start);
63+
}
64+
65+
return tokens;
66+
};
67+
68+
auto tokens = split(arg_str, delimiter);
69+
70+
// Ensure the number of tokens is a multiple of 4
71+
if(tokens.size() % 4 != 0)
72+
{
73+
throw std::invalid_argument("Malformed argument string.");
74+
}
75+
76+
for(auto it = tokens.begin(); it != tokens.end(); it += 4)
77+
{
78+
arg_info arg = { static_cast<uint32_t>(std::stoi(*it)), *(it + 1), *(it + 2),
79+
*(it + 3) };
80+
args.push_back(arg);
81+
}
82+
83+
return args;
84+
}
85+
86+
} // namespace rocprofsys

projects/rocprofiler-systems/source/lib/core/trace_cache/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ set(trace_cache_headers
3838
${CMAKE_CURRENT_LIST_DIR}/rocpd_post_processing.hpp
3939
${CMAKE_CURRENT_LIST_DIR}/perfetto_post_processing.hpp
4040
${CMAKE_CURRENT_LIST_DIR}/sample_type.hpp
41+
${CMAKE_CURRENT_LIST_DIR}/common_types.hpp
4142
)
4243

4344
target_sources(

projects/rocprofiler-systems/source/lib/core/trace_cache/cache_manager.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,17 @@ cache_manager::post_process_bulk()
156156
shutdown();
157157
}
158158

159+
auto _cache_files = get_cache_files();
160+
159161
if(get_use_rocpd() || get_caching_perfetto())
160162
{
161163
ROCPROFSYS_PRINT(
162164
"Generating rocpd with collected data. This may take a while..\n");
163165

164-
auto _cache_files = get_cache_files();
165-
166-
std::vector<std::thread> rocpd_threads;
167-
ROCPROFSYS_SCOPED_SAMPLING_ON_CHILD_THREADS(false);
168-
169166
if(get_caching_perfetto())
170167
{
168+
perfetto_post_processing::initialize_perfetto();
169+
171170
for(const auto& [pid, files] : _cache_files)
172171
{
173172
if(!files.buff_storage.empty() && !files.metadata.empty())
@@ -203,12 +202,23 @@ cache_manager::post_process_bulk()
203202

204203
bool _perfetto_error = false;
205204
_perfetto_post_processing.post_process(_perfetto_error);
205+
206+
if(_perfetto_error)
207+
{
208+
ROCPROFSYS_WARNING(0,
209+
"Perfetto trace generation failed for "
210+
"process: %d\n",
211+
pid);
212+
}
206213
}
207214
}
208215
}
209216

210217
if(get_use_rocpd())
211218
{
219+
std::vector<std::thread> rocpd_threads;
220+
ROCPROFSYS_SCOPED_SAMPLING_ON_CHILD_THREADS(false);
221+
212222
rocpd_threads.emplace_back([this]() {
213223
auto pid = getpid();
214224
auto ppid = get_root_process_id();
@@ -251,19 +261,14 @@ cache_manager::post_process_bulk()
251261
_post_processing.register_parser_callback(_parser);
252262
_post_processing.post_process_metadata();
253263
_parser.consume_storage();
254-
std::remove(files.metadata.c_str()); // Remove metadata file
255264
});
256265
}
257266
}
258-
}
259267

260-
for(auto& thread : rocpd_threads)
261-
{
262-
thread.join();
263-
}
264-
if(get_caching_perfetto())
265-
{
266-
clear_cache_files();
268+
for(auto& thread : rocpd_threads)
269+
{
270+
thread.join();
271+
}
267272
}
268273
}
269274

0 commit comments

Comments
 (0)