8806be162c
* Change how cache manager handles child process trace cache * Sampling and backtrace metrics to cache * Apply cmake formatting * Fix parsing of metadata json * Code clean up * Fix build nlohmann json from source * Fix storage parsed finished callback * Revert sampling for child process * Change cache file name generating * Fix thread start stop * Fix process start end timestamp * Applied suggestions from code review * Try with late start of flushing task thread * Change dockerfiles for ci * Revert changes on github workflows * Remove json_fwd.hpp include * fix dump * Build nlohmann/json by default Signed-off-by: David Galiffi <David.Galiffi@amd.com> * Update location of build artifacts for nlohmann/json Signed-off-by: David Galiffi <David.Galiffi@amd.com> * Revert use_output_suffix * Remove unused logs * Fix cache store inside counter due to structure change * Remove decode tests from debian ci * Fix issue where all databases have the same UUID (#1499) Co-authored-by: Aleksandar Djordjevic <adjordje@amd.com> * Removing the cpack and install steps to save space * Revert "Remove decode tests from debian ci" This reverts commit ddabf6dd142dcf438e6b8997b8abe86f2c868468. * Revert "Removing the cpack and install steps to save space" This reverts commit 973da3a1ba99d99d529af5269d30e177092f9bfa. * Add prepare-runner job as dependency to clean up the space * Fix formatting * Free up even more space * Remove verbose for workflows * remove hw_counters from ext_data * move space clean up inside container * try to remove external folder to free up space * Check space * Refactor Cleanup to it's own step --------- Signed-off-by: David Galiffi <David.Galiffi@amd.com> Co-authored-by: David Galiffi <David.Galiffi@amd.com> Co-authored-by: Aleksandar Djordjevic <aleksandar.djordjevic@amd.com> Co-authored-by: Aleksandar Djordjevic <adjordje@amd.com>
192 строки
5.6 KiB
C++
192 строки
5.6 KiB
C++
// MIT License
|
|
//
|
|
// Copyright (c) 2022-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.
|
|
|
|
#include "cpu.hpp"
|
|
#include "agent_manager.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <unordered_map>
|
|
|
|
namespace rocprofsys
|
|
{
|
|
namespace cpu
|
|
{
|
|
std::vector<cpu_info>
|
|
process_cpu_info_data()
|
|
{
|
|
std::vector<cpu_info> cpu_data;
|
|
std::ifstream cpuinfo_file("/proc/cpuinfo");
|
|
|
|
if(!cpuinfo_file.is_open())
|
|
{
|
|
return cpu_data;
|
|
}
|
|
|
|
std::string line;
|
|
cpu_info current_cpu;
|
|
bool has_processor_entry = false;
|
|
|
|
auto parse_long = [](const std::string& value) -> long {
|
|
try
|
|
{
|
|
return std::stol(value);
|
|
} catch(const std::exception&)
|
|
{
|
|
return -1;
|
|
}
|
|
};
|
|
|
|
auto trim_whitespace = [](const std::string& str) -> std::string {
|
|
size_t start = str.find_first_not_of(" \t");
|
|
if(start == std::string::npos) return "";
|
|
size_t end = str.find_last_not_of(" \t");
|
|
return str.substr(start, end - start + 1);
|
|
};
|
|
|
|
static const std::unordered_map<std::string,
|
|
std::function<void(cpu_info&, const std::string&)>>
|
|
field_parsers = {
|
|
{ "processor",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.processor = parse_long(val);
|
|
} },
|
|
{ "cpu family",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.family = parse_long(val);
|
|
} },
|
|
{ "model",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.model = parse_long(val);
|
|
} },
|
|
{ "physical id",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.physical_id = parse_long(val);
|
|
} },
|
|
{ "core id",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.core_id = parse_long(val);
|
|
} },
|
|
{ "apicid",
|
|
[&parse_long](cpu_info& cpu, const std::string& val) {
|
|
cpu.apicid = parse_long(val);
|
|
} },
|
|
{ "vendor_id",
|
|
[](cpu_info& cpu, const std::string& val) { cpu.vendor_id = val; } },
|
|
{ "model name",
|
|
[](cpu_info& cpu, const std::string& val) { cpu.model_name = val; } }
|
|
};
|
|
|
|
while(std::getline(cpuinfo_file, line))
|
|
{
|
|
if(line.empty())
|
|
{
|
|
if(has_processor_entry)
|
|
{
|
|
cpu_data.push_back(current_cpu);
|
|
return cpu_data; // Return immediately after first core
|
|
}
|
|
continue;
|
|
}
|
|
|
|
size_t colon_pos = line.find(':');
|
|
if(colon_pos == std::string::npos)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
std::string key = trim_whitespace(line.substr(0, colon_pos));
|
|
std::string value = trim_whitespace(line.substr(colon_pos + 1));
|
|
|
|
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
|
|
|
|
auto it = field_parsers.find(key);
|
|
if(it != field_parsers.end())
|
|
{
|
|
it->second(current_cpu, value);
|
|
if(key == "processor")
|
|
{
|
|
has_processor_entry = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(has_processor_entry)
|
|
{
|
|
cpu_data.push_back(current_cpu);
|
|
}
|
|
|
|
return cpu_data;
|
|
}
|
|
|
|
std::vector<cpu_info>
|
|
get_cpu_info()
|
|
{
|
|
static auto _v = process_cpu_info_data();
|
|
return _v;
|
|
}
|
|
|
|
size_t
|
|
device_count()
|
|
{
|
|
auto cpu_data = get_cpu_info();
|
|
return cpu_data.size();
|
|
}
|
|
|
|
void
|
|
query_cpu_agents()
|
|
{
|
|
int32_t id_count = 0;
|
|
uint32_t node_count = 0;
|
|
uint32_t cpu_count = 0;
|
|
|
|
if(device_count() == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto& _agent_manager = get_agent_manager_instance();
|
|
auto cpu_data = get_cpu_info();
|
|
|
|
for(auto& cpu : cpu_data)
|
|
{
|
|
auto node_id = node_count++;
|
|
auto logical_id = id_count++;
|
|
auto id = cpu_count++;
|
|
auto cur_agent = agent{ agent_type::CPU,
|
|
0,
|
|
id,
|
|
node_id,
|
|
logical_id,
|
|
static_cast<int32_t>(id),
|
|
cpu.model_name,
|
|
cpu.model_name,
|
|
cpu.vendor_id,
|
|
"" };
|
|
_agent_manager.insert_agent(cur_agent);
|
|
}
|
|
}
|
|
} // namespace cpu
|
|
} // namespace rocprofsys
|