[rocprofiler-systems] Improve metadata parsing (#2238)
* Improve metadata JSON parsing * Fix string ownership
This commit is contained in:
committed by
GitHub
orang tua
5b241f3e61
melakukan
7da3275b42
@@ -29,6 +29,8 @@
|
||||
#include <fstream>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace rocprofsys
|
||||
{
|
||||
@@ -412,68 +414,55 @@ from_json(metadata_registry& _registry, std::vector<std::shared_ptr<agent>>& _ag
|
||||
auto process = from_json_process(process_json);
|
||||
_registry.set_process(process);
|
||||
|
||||
const auto& pmc_array = _json["pmc_infos"];
|
||||
for(const auto& pmc_json : pmc_array)
|
||||
{
|
||||
auto pmc = from_json_pmc(pmc_json);
|
||||
auto fill_from_json = [&_json](std::string_view field, auto transform_and_add) {
|
||||
if(_json.contains(field))
|
||||
{
|
||||
for(const auto& item : _json[field])
|
||||
{
|
||||
transform_and_add(item);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fill_from_json("pmc_infos", [&_registry](const auto& item) {
|
||||
auto pmc = from_json_pmc(item);
|
||||
_registry.add_pmc_info(pmc);
|
||||
}
|
||||
});
|
||||
|
||||
const auto& thread_array = _json["threads"];
|
||||
for(const auto& thread_json : thread_array)
|
||||
{
|
||||
auto thread = from_json_thread(thread_json);
|
||||
fill_from_json("threads", [&_registry](const auto& item) {
|
||||
auto thread = from_json_thread(item);
|
||||
_registry.add_thread_info(thread);
|
||||
}
|
||||
});
|
||||
|
||||
const auto& track_array = _json["tracks"];
|
||||
for(const auto& track_json : track_array)
|
||||
{
|
||||
auto track = from_json_track(track_json);
|
||||
fill_from_json("tracks", [&_registry](const auto& item) {
|
||||
auto track = from_json_track(item);
|
||||
_registry.add_track(track);
|
||||
}
|
||||
});
|
||||
|
||||
const auto& queue_array = _json["queues"];
|
||||
for(const auto& queue_json : queue_array)
|
||||
{
|
||||
auto handle = queue_json.get<long long>();
|
||||
fill_from_json("queues", [&_registry](const auto& item) {
|
||||
auto handle = item.template get<long long>();
|
||||
_registry.add_queue(static_cast<uint64_t>(handle));
|
||||
}
|
||||
});
|
||||
|
||||
const auto& stream_array = _json["streams"];
|
||||
for(const auto& stream_json : stream_array)
|
||||
{
|
||||
auto handle = stream_json.get<long long>();
|
||||
fill_from_json("streams", [&_registry](const auto& item) {
|
||||
auto handle = item.template get<long long>();
|
||||
_registry.add_stream(static_cast<uint64_t>(handle));
|
||||
}
|
||||
});
|
||||
|
||||
const auto& string_array = _json["strings"];
|
||||
for(const auto& string_json : string_array)
|
||||
{
|
||||
auto str = string_json.get<std::string>();
|
||||
_registry.add_string(str);
|
||||
}
|
||||
fill_from_json("strings", [&_registry](const auto& item) {
|
||||
_registry.add_string(item.template get<std::string>());
|
||||
});
|
||||
|
||||
#if ROCPROFSYS_USE_ROCM
|
||||
if(_json.contains("code_objects"))
|
||||
{
|
||||
const auto& code_object_array = _json["code_objects"];
|
||||
for(const auto& code_object_json : code_object_array)
|
||||
{
|
||||
auto code_object = from_json_code_object(code_object_json);
|
||||
_registry.add_code_object(code_object);
|
||||
}
|
||||
}
|
||||
fill_from_json("code_objects", [&_registry](const auto& item) {
|
||||
auto code_object = from_json_code_object(item);
|
||||
_registry.add_code_object(code_object);
|
||||
});
|
||||
|
||||
if(_json.contains("kernel_symbols"))
|
||||
{
|
||||
const auto& kernel_symbol_array = _json["kernel_symbols"];
|
||||
for(const auto& kernel_symbol_json : kernel_symbol_array)
|
||||
{
|
||||
auto kernel_symbol = from_json_kernel_symbol(kernel_symbol_json);
|
||||
_registry.add_kernel_symbol(kernel_symbol);
|
||||
}
|
||||
}
|
||||
fill_from_json("kernel_symbols", [&_registry](const auto& item) {
|
||||
auto kernel_symbol = from_json_kernel_symbol(item);
|
||||
_registry.add_kernel_symbol(kernel_symbol);
|
||||
});
|
||||
#endif
|
||||
|
||||
if(!_agents.empty())
|
||||
@@ -482,14 +471,10 @@ from_json(metadata_registry& _registry, std::vector<std::shared_ptr<agent>>& _ag
|
||||
_agents.clear();
|
||||
}
|
||||
|
||||
if(_json.contains("agents"))
|
||||
{
|
||||
const auto& agents_array = _json["agents"];
|
||||
for(const auto& agent_json : agents_array)
|
||||
{
|
||||
_agents.push_back(from_json_agent(agent_json));
|
||||
}
|
||||
}
|
||||
fill_from_json("agents", [&_agents](const auto& item) {
|
||||
auto agent = from_json_agent(item);
|
||||
_agents.push_back(agent);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -561,14 +546,14 @@ metadata_registry::add_stream(const uint64_t& stream_handle)
|
||||
}
|
||||
|
||||
void
|
||||
metadata_registry::add_string(const std::string_view& string_value)
|
||||
metadata_registry::add_string(const std::string_view string_value)
|
||||
{
|
||||
m_strings.wlock([&string_value](auto& _data) {
|
||||
if(_data.count(string_value) > 0)
|
||||
std::string str{ string_value };
|
||||
if(_data.count(str) == 0)
|
||||
{
|
||||
return;
|
||||
_data.emplace(std::move(str));
|
||||
}
|
||||
_data.emplace(string_value);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#if ROCPROFSYS_USE_ROCM > 0
|
||||
# include <rocprofiler-sdk/callback_tracing.h>
|
||||
# include <rocprofiler-sdk/cxx/name_info.hpp>
|
||||
@@ -192,7 +193,7 @@ struct metadata_registry
|
||||
void add_track(const info::track& track_info);
|
||||
void add_queue(const uint64_t& queue_handle);
|
||||
void add_stream(const uint64_t& stream_handle);
|
||||
void add_string(const std::string_view& string_value);
|
||||
void add_string(const std::string_view string_value);
|
||||
|
||||
info::process get_process_info() const;
|
||||
std::optional<info::pmc> get_pmc_info(const std::string_view& unique_name) const;
|
||||
@@ -236,9 +237,9 @@ private:
|
||||
common::synchronized<std::set<info::thread>> m_threads{};
|
||||
common::synchronized<std::set<info::track>> m_tracks{};
|
||||
|
||||
common::synchronized<std::set<uint64_t>> m_streams{};
|
||||
common::synchronized<std::set<uint64_t>> m_queues{};
|
||||
common::synchronized<std::unordered_set<std::string_view>> m_strings{};
|
||||
common::synchronized<std::set<uint64_t>> m_streams{};
|
||||
common::synchronized<std::set<uint64_t>> m_queues{};
|
||||
common::synchronized<std::unordered_set<std::string>> m_strings{};
|
||||
#if ROCPROFSYS_USE_ROCM > 0
|
||||
common::synchronized<std::set<rocprofiler_callback_tracing_code_object_load_data_t,
|
||||
info::code_object_less>>
|
||||
|
||||
Reference in New Issue
Block a user