ROCpd support [Part 2] (#109)
* Rocpd part 2, caching * Fix shadowed variables * backward compatibility * Fixed designated initializers * Fix timemory include * Remove benchmark & Fix build issues for rhel * Add missing bracket * Fix shadowing and pedantic * Fix pedantic pt2 * Fix duplicated SDK calls * Add decay in get_size_impl * Rename sample cache to trace cache * Add cache storage supported types * Resolving track naming in sampling module * fix sampling of flushing thread * fix sampling of flushing thread 2 * throw exception upon store while buffer storage is not running * Prevent fork crashing * Fix rebase issue * Applied suggestions from code review * Change flushing thread to use PTL * Fix agent creation order * Fix stream id ci throw * Remove force setup of rocprofiler-sdk * Code cleanup * Change initialization for agent * Add missing namespace * Fix the mismatch within the tool_agent->device_id * Switch from using handle to use agent type index * Fix pmc info comparator in metadata registry --------- Co-authored-by: Aleksandar <aleksandar.djordjevic@amd.com> Co-authored-by: Milan Radosavljevic <milan.radosavljevic@amd.com> Co-authored-by: Marjan Antic <marantic@amd.com>
Esse commit está contido em:
40 files changed
+3432
-1184
No files matched your search
@@ -1,3 +1,25 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
set(rocpd_sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/data_processor.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/json.cpp
|
||||
|
||||
@@ -69,8 +69,7 @@ data_processor::initialize_metadata()
|
||||
size_t
|
||||
data_processor::insert_string(const char* str)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
auto it = _string_map.find(str);
|
||||
auto it = _string_map.find(str);
|
||||
if(it != _string_map.end()) return _string_map.at(str);
|
||||
|
||||
data_storage::queries::table_insert_query query;
|
||||
@@ -242,24 +241,12 @@ data_processor::insert_sample(const char* track, uint64_t timestamp, size_t even
|
||||
}
|
||||
|
||||
size_t
|
||||
data_processor::insert_event(size_t category_id, size_t stack_id, size_t parent_stack_id,
|
||||
size_t correlation_id, const char* call_stack,
|
||||
const char* line_info, const char* extdata)
|
||||
data_processor::insert_event(size_t string_primary_key, size_t stack_id,
|
||||
size_t parent_stack_id, size_t correlation_id,
|
||||
const char* call_stack, const char* line_info,
|
||||
const char* extdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
auto it = _category_map.find(category_id);
|
||||
if(it == _category_map.end())
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "Insert event failed! Error: Unknown category id: " << category_id
|
||||
<< " for UPID: " << _upid;
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
|
||||
ROCPROFSYS_VERBOSE(3, "Insert event category id: %ld, string id: %ld\n", category_id,
|
||||
it->second);
|
||||
|
||||
_insert_event_statement(_upid.c_str(), it->second, stack_id, parent_stack_id,
|
||||
_insert_event_statement(_upid.c_str(), string_primary_key, stack_id, parent_stack_id,
|
||||
correlation_id, call_stack, line_info, extdata);
|
||||
return data_storage::database::get_instance().get_last_insert_id();
|
||||
}
|
||||
@@ -456,7 +443,6 @@ void
|
||||
data_processor::insert_args(size_t event_id, size_t position, const char* type,
|
||||
const char* name, const char* value, const char* extdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
_insert_args_statement(_upid.c_str(), event_id, position, type, name, value, extdata);
|
||||
}
|
||||
|
||||
@@ -464,40 +450,24 @@ void
|
||||
data_processor::insert_stream_info(size_t stream_id, size_t node_id, size_t process_id,
|
||||
const char* name, const char* extdata)
|
||||
{
|
||||
if(_stream_ids.count(stream_id) > 0)
|
||||
{
|
||||
// ROCPROFSYS_WARNING(
|
||||
// 1, "Insert stream info failed! Error: Stream ID %ld already exists!\n",
|
||||
// stream_id);
|
||||
return;
|
||||
}
|
||||
data_storage::queries::table_insert_query query;
|
||||
data_storage::database::get_instance().execute_query(
|
||||
query.set_table_name("rocpd_info_stream_" + _upid)
|
||||
.set_columns("id", "guid", "nid", "pid", "name", "extdata")
|
||||
.set_values(stream_id, _upid, node_id, process_id, name, extdata)
|
||||
.get_query_string());
|
||||
_stream_ids.insert(stream_id);
|
||||
}
|
||||
|
||||
void
|
||||
data_processor::insert_queue_info(size_t queue_id, size_t node_id, size_t process_id,
|
||||
const char* name, const char* extdata)
|
||||
{
|
||||
if(_queue_ids.count(queue_id) > 0)
|
||||
{
|
||||
// ROCPROFSYS_WARNING(
|
||||
// 1, "Insert queue info failed! Error: Queue ID %ld already exists!\n",
|
||||
// queue_id);
|
||||
return;
|
||||
}
|
||||
data_storage::queries::table_insert_query query;
|
||||
data_storage::database::get_instance().execute_query(
|
||||
query.set_table_name("rocpd_info_queue_" + _upid)
|
||||
.set_columns("id", "guid", "nid", "pid", "name", "extdata")
|
||||
.set_values(queue_id, _upid, node_id, process_id, name, extdata)
|
||||
.get_query_string());
|
||||
_queue_ids.insert(queue_id);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -506,20 +476,9 @@ data_processor::insert_code_object(size_t id, size_t node_id, size_t process_id,
|
||||
uint64_t ld_size, uint64_t ld_delta,
|
||||
const char* storage_type, const char* extdata)
|
||||
{
|
||||
if(_code_object_ids.count(id) > 0)
|
||||
{
|
||||
// ROCPROFSYS_WARNING(
|
||||
// 1,
|
||||
// "Insert code object info failed! Error: Code object ID %ld already
|
||||
// exists!\n", id);
|
||||
return;
|
||||
}
|
||||
ROCPROFSYS_VERBOSE(2, "Insert code object with ID: %ld\n", id);
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
_insert_code_object_statement(id, _upid.c_str(), node_id, process_id, agent_id, uri,
|
||||
ld_base, ld_size, ld_delta, storage_type, extdata);
|
||||
|
||||
_code_object_ids.insert(id);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -530,40 +489,11 @@ data_processor::insert_kernel_symbol(
|
||||
uint32_t private_segment_size, uint32_t sgrp_count, uint32_t arch_vgrp_count,
|
||||
uint32_t accum_vgrp_count, const char* extdata)
|
||||
{
|
||||
if(_kernel_sym_ids.count(id) > 0)
|
||||
{
|
||||
// ROCPROFSYS_WARNING(
|
||||
// 1,
|
||||
// "Insert kernel symbol failed! Error: Kernel symbol ID %ld already
|
||||
// exists!\n", id);
|
||||
return;
|
||||
}
|
||||
|
||||
ROCPROFSYS_VERBOSE(2, "Insert kernel symbol: %s with ID: %ld\n", name, id);
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
_insert_kernel_symbol_statement(
|
||||
id, _upid.c_str(), node_id, process_id, code_obj_id, name, display_name,
|
||||
kernel_obj, kernarg_segmnt_size, kernarg_segment_alignment, group_segment_size,
|
||||
private_segment_size, sgrp_count, arch_vgrp_count, accum_vgrp_count, extdata);
|
||||
|
||||
_kernel_sym_ids.insert(id);
|
||||
}
|
||||
|
||||
void
|
||||
data_processor::insert_category(size_t category_id, const char* name)
|
||||
{
|
||||
auto it = _category_map.find(category_id);
|
||||
if(it != _category_map.end())
|
||||
{
|
||||
// ROCPROFSYS_WARNING(
|
||||
// 1, "Insert category failed! Error: Category %s already exist!\n", name);
|
||||
return;
|
||||
}
|
||||
auto name_id = insert_string(name);
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
ROCPROFSYS_VERBOSE(2, "Insert category: name: %s, id: %ld, name id: %ld\n", name,
|
||||
category_id, name_id);
|
||||
_category_map.emplace(category_id, name_id);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -571,7 +501,6 @@ data_processor::insert_region(size_t node_id, size_t process_id, size_t thread_i
|
||||
uint64_t start, uint64_t end, size_t name_id,
|
||||
size_t event_id, const char* extdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
ROCPROFSYS_VERBOSE(2, "Insert region for event id: %ld\n", event_id);
|
||||
|
||||
_insert_region_statement(_upid.c_str(), node_id, process_id, thread_id, start, end,
|
||||
@@ -587,8 +516,6 @@ data_processor::insert_kernel_dispatch(
|
||||
size_t grid_size_x, size_t grid_size_y, size_t grid_size_z, size_t region_name_id,
|
||||
size_t event_id, const char* extdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
|
||||
ROCPROFSYS_VERBOSE(2, "Insert kernel dispatch for event id: %ld\n", event_id);
|
||||
|
||||
_insert_kernel_dispatch_statement(
|
||||
@@ -607,8 +534,6 @@ data_processor::insert_memory_copy(size_t node_id, size_t process_id, size_t thr
|
||||
size_t region_name_id, size_t event_id,
|
||||
const char* extdata)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_data_mutex);
|
||||
|
||||
_insert_memory_copy_statement(_upid.c_str(), node_id, process_id, thread_id, start,
|
||||
end, name_id, dst_agent_id, dst_addr, src_agent_id,
|
||||
src_addr, size, queue_id, stream_id, region_name_id,
|
||||
@@ -663,6 +588,18 @@ data_processor::insert_thread_info(size_t node_id, size_t parent_process_id,
|
||||
return thread_idx;
|
||||
}
|
||||
|
||||
size_t
|
||||
data_processor::map_thread_id_to_primary_key(size_t thread_id)
|
||||
{
|
||||
auto it = _thread_id_map.find(thread_id);
|
||||
|
||||
if(it == _thread_id_map.end())
|
||||
{
|
||||
throw std::invalid_argument("Given thread id don't exist");
|
||||
}
|
||||
return _thread_id_map.at(thread_id);
|
||||
}
|
||||
|
||||
void
|
||||
data_processor::flush()
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ struct data_processor
|
||||
using insert_event_stmt =
|
||||
std::function<void(const char*, size_t, size_t, size_t, size_t, const char*,
|
||||
const char*, const char*)>;
|
||||
using insert_pmc_event_stms =
|
||||
using insert_pmc_event_stmt =
|
||||
std::function<void(const char*, size_t, size_t, double, const char*)>;
|
||||
using insert_sample_stmt =
|
||||
std::function<void(const char*, size_t, uint64_t, size_t, const char*)>;
|
||||
@@ -124,9 +124,10 @@ public:
|
||||
void insert_track(const char* track_name, size_t node_id, size_t process_id,
|
||||
std::optional<size_t> thread_id, const char* extdata = "{}");
|
||||
|
||||
size_t insert_event(size_t category_id, size_t stack_id, size_t parent_stack_id,
|
||||
size_t correlation_id, const char* call_stack = "{}",
|
||||
const char* line_info = "{}", const char* extdata = "{}");
|
||||
size_t insert_event(size_t string_primary_key, size_t stack_id,
|
||||
size_t parent_stack_id, size_t correlation_id,
|
||||
const char* call_stack = "{}", const char* line_info = "{}",
|
||||
const char* extdata = "{}");
|
||||
|
||||
void insert_pmc_event(size_t event_id, size_t agent_id, const char* pmc_descriptor,
|
||||
double value, const char* extdata = "{}");
|
||||
@@ -143,8 +144,6 @@ public:
|
||||
void insert_sample(const char* track, uint64_t timestamp, size_t event_id,
|
||||
const char* extdata = "{}");
|
||||
|
||||
void insert_category(size_t category_id, const char* name);
|
||||
|
||||
void insert_region(size_t node_id, size_t process_id, size_t thread_id,
|
||||
uint64_t start, uint64_t end, size_t name_id, size_t event_id,
|
||||
const char* extdata = "{}");
|
||||
@@ -199,6 +198,8 @@ public:
|
||||
size_t stream_id, size_t event_id,
|
||||
const char* extdata = "{}");
|
||||
|
||||
size_t map_thread_id_to_primary_key(size_t thread_id);
|
||||
|
||||
void flush();
|
||||
|
||||
private:
|
||||
@@ -223,16 +224,10 @@ private:
|
||||
std::unordered_map<pmc_identifier, size_t, pmc_identifier_hash, pmc_identifier_equal>
|
||||
_pmc_descriptor_map;
|
||||
std::unordered_map<size_t, size_t> _thread_id_map;
|
||||
std::unordered_map<size_t, size_t> _category_map;
|
||||
std::unordered_map<std::string, size_t> _string_map;
|
||||
|
||||
std::set<uint64_t> _code_object_ids;
|
||||
std::set<uint64_t> _kernel_sym_ids;
|
||||
std::set<uint64_t> _stream_ids;
|
||||
std::set<uint64_t> _queue_ids;
|
||||
|
||||
insert_event_stmt _insert_event_statement;
|
||||
insert_pmc_event_stms _insert_pmc_event_statement;
|
||||
insert_pmc_event_stmt _insert_pmc_event_statement;
|
||||
insert_sample_stmt _insert_sample_statement;
|
||||
insert_region_stmt _insert_region_statement;
|
||||
insert_kernel_dispatch_stmt _insert_kernel_dispatch_statement;
|
||||
@@ -244,8 +239,6 @@ private:
|
||||
insert_memory_alloc_no_agent_stmt _insert_memory_alloc_no_agent_statement;
|
||||
|
||||
std::string _upid{};
|
||||
|
||||
std::mutex _data_mutex;
|
||||
};
|
||||
|
||||
} // namespace rocpd
|
||||
|
||||
@@ -93,9 +93,8 @@ database::initialize_schema()
|
||||
return new_file_path;
|
||||
}
|
||||
}
|
||||
return std::string(
|
||||
"rocprofiler-systems/source/lib/core/rocpd/data_storage/schema/")
|
||||
.append(filename);
|
||||
// TODO: Update to look for the system's rocpd schema
|
||||
return std::string("source/lib/core/rocpd/data_storage/schema/").append(filename);
|
||||
};
|
||||
|
||||
std::vector<std::string_view> schema_files = { "rocpd_tables.sql", "rocpd_views.sql",
|
||||
@@ -118,9 +117,11 @@ database::initialize_schema()
|
||||
std::string query = ss_query.str();
|
||||
|
||||
std::regex upid_pattern("\\{\\{uuid\\}\\}");
|
||||
std::regex guid_pattern("\\{\\{guid\\}\\}");
|
||||
std::regex view_upid_pattern("\\{\\{view_upid\\}\\}");
|
||||
|
||||
query = std::regex_replace(query, upid_pattern, "_" + get_upid());
|
||||
query = std::regex_replace(query, guid_pattern, get_upid());
|
||||
query = std::regex_replace(query, view_upid_pattern, "");
|
||||
|
||||
validate_sqlite3_result(
|
||||
|
||||
Reference in new issue
Bloquear um usuário