* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This file is part of the MindStudio project.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------*/
#ifndef ANALYSIS_PARSER_ENVIRONMENT_CONTEXT_H
#define ANALYSIS_PARSER_ENVIRONMENT_CONTEXT_H
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include "analysis/csrc/infrastructure/utils/singleton.h"
#include "analysis/csrc/infrastructure/utils/time_utils.h"
#include "opensource/json/include/nlohmann/json.hpp"
namespace Analysis
{
namespace Domain
{
namespace Environment
{
const uint16_t HOST_ID = 64;
const uint16_t INVALID_DEVICE_ID = UINT16_MAX;
const uint16_t DEFAULT_DEVICE_ID = HOST_ID + 1;
enum class Chip : uint16_t
{
CHIP_V1_1_0 = 0,
CHIP_V2_1_0 = 1,
CHIP_V3_1_0 = 2,
CHIP_V3_2_0 = 3,
CHIP_V3_3_0 = 4,
CHIP_V4_1_0 = 5,
CHIP_V1_1_1 = 7,
CHIP_V1_1_2 = 8,
CHIP_V5_1_0 = 9,
CHIP_V1_1_3 = 11,
CHIP_V6_1_0 = 15,
CHIP_V6_2_0 = 16
};
class Context : public Utils::Singleton<Context>
{
public:
bool Load(const std::set<std::string> &profPaths);
bool IsAllExport();
void Clear();
public:
bool GetProfTimeRecordInfo(Utils::ProfTimeRecord &record, const std::string &profPath = "",
uint16_t deviceId = HOST_ID);
uint32_t GetPidFromInfoJson(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
std::string GetPidNameFromInfoJson(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
int64_t GetMsBinPid(const std::string &profPath);
std::string GetLLCProfiling(uint16_t deviceId, const std::string &profPath);
bool GetSyscntConversionParams(Utils::SyscntConversionParams ¶ms, uint16_t deviceId = DEFAULT_DEVICE_ID,
const std::string &profPath = "");
bool GetClockMonotonicRaw(uint64_t &monotonicRaw, bool isHost, uint16_t deviceId = DEFAULT_DEVICE_ID,
const std::string &profPath = "");
bool GetPmuFreq(double &freq, uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
bool GetMetricMode(std::string &metricMode, const std::string &profPath = "");
std::string GetHostUid(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
std::string GetHostName(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
std::vector<std::string> GetQosEvents(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
uint16_t GetAiCoreNum(uint16_t deviceId, const std::string &profPath);
uint64_t GetTotalMem(uint16_t deviceId, const std::string &profPath);
uint64_t GetNetCardTotalSpeed(uint16_t deviceId, const std::string &profPath);
bool IsLevel0(const std::string &profPath);
std::vector<uint16_t> GetCannVersion(uint16_t deviceId, const std::string &profPath);
public:
uint16_t GetPlatformVersion(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
static bool IsStarsChip(uint16_t platformVersion);
static bool IsChipV1(uint16_t platformVersion);
static bool IsChipV4(uint16_t platformVersion);
static bool IsChipV6(uint16_t platformVersion);
static bool IsFirstChipV1(uint16_t platformVersion);
private:
nlohmann::json GetInfoByDeviceId(uint16_t deviceId = DEFAULT_DEVICE_ID, const std::string &profPath = "");
bool LoadJsonData(const std::string &profPath, const std::string &deviceDir, uint16_t deviceId);
bool LoadLogData(const std::string &profPath, const std::string &deviceDir, uint16_t deviceId);
bool CheckInfoValueIsValid(const std::string &profPath, uint16_t deviceId);
std::unordered_map<std::string, std::map<uint16_t, nlohmann::json>> context_;
};
}
}
}
#endif