* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* 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 PROFILER_SERVER_MEM_SCOPE_DEFS_H
#define PROFILER_SERVER_MEM_SCOPE_DEFS_H
#include "pch.h"
#include "FileDef.h"
namespace Dic::Module::MemScope {
const char OWNER_STRING_DELIMITER = '@';
struct MEM_SCOPE_DUMP_EVENT {
inline const static std::string MALLOC = "MALLOC";
inline const static std::string FREE = "FREE";
inline const static std::string ACCESS = "ACCESS";
inline const static std::string OP_LAUNCH = "OP_LAUNCH";
inline const static std::string KERNEL_LAUNCH = "KERNEL_LAUNCH";
inline const static std::string SYSTEM = "SYSTEM";
};
struct MEM_SCOPE_DUMP_EVENT_TYPE {
inline const static std::string MALLOC_FREE_PTA = "PTA";
inline const static std::string MALLOC_FREE_MINDSPORE = "MINDSPORE";
inline const static std::string MALLOC_FREE_ATB = "ATB";
inline const static std::string MALLOC_FREE_HAL = "HAL";
inline const static std::string MALLOC_FREE_PTA_WORKSPACE = "PTA_WORKSPACE";
inline const static std::string MALLOC_FREE_HOST_PINNED = "HOST_PINNED";
inline const static std::string ACCESS_READ = "READ";
inline const static std::string ACCESS_WRITE = "WRITE";
inline const static std::string OP_LAUNCH_ATEN_START = "ATEN_START";
inline const static std::string OP_LAUNCH_ATEN_END = "ATEN_END";
inline const static std::string KERNEL_LAUNCH = "KERNEL_LAUNCH";
inline const static std::string KERNEL_LAUNCH_START = "KERNEL_EXECUTE_START";
inline const static std::string KERNEL_LAUNCH_END = "KERNEL_EXECUTE_END";
inline const static std::string SYSTEM_ACL_INIT = "ACL_INIT";
inline const static std::string SYSTEM_ACL_FINI = "ACL_FINI";
inline const static std::string SYSTEM_START_TRACE = "START_TRACE";
inline const static std::string SYSTEM_STOP_TRACE = "STOP_TRACE";
};
const std::unordered_map<std::string, std::set<std::string>> EVENT_TYPE_MAP = {
{MEM_SCOPE_DUMP_EVENT::MALLOC,
{MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_PTA, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_MINDSPORE,
MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_ATB, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_HAL,
MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_PTA_WORKSPACE, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_HOST_PINNED}},
{MEM_SCOPE_DUMP_EVENT::FREE,
{MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_PTA, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_MINDSPORE,
MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_ATB, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_HAL,
MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_PTA_WORKSPACE, MEM_SCOPE_DUMP_EVENT_TYPE::MALLOC_FREE_HOST_PINNED}},
{MEM_SCOPE_DUMP_EVENT::ACCESS, {MEM_SCOPE_DUMP_EVENT_TYPE::ACCESS_READ, MEM_SCOPE_DUMP_EVENT_TYPE::ACCESS_WRITE}},
{MEM_SCOPE_DUMP_EVENT::OP_LAUNCH,
{MEM_SCOPE_DUMP_EVENT_TYPE::OP_LAUNCH_ATEN_START, MEM_SCOPE_DUMP_EVENT_TYPE::OP_LAUNCH_ATEN_END}},
{MEM_SCOPE_DUMP_EVENT::KERNEL_LAUNCH,
{MEM_SCOPE_DUMP_EVENT_TYPE::KERNEL_LAUNCH, MEM_SCOPE_DUMP_EVENT_TYPE::KERNEL_LAUNCH_START,
MEM_SCOPE_DUMP_EVENT_TYPE::KERNEL_LAUNCH_END}},
{MEM_SCOPE_DUMP_EVENT::SYSTEM,
{MEM_SCOPE_DUMP_EVENT_TYPE::SYSTEM_ACL_INIT, MEM_SCOPE_DUMP_EVENT_TYPE::SYSTEM_ACL_FINI,
MEM_SCOPE_DUMP_EVENT_TYPE::SYSTEM_START_TRACE, MEM_SCOPE_DUMP_EVENT_TYPE::SYSTEM_STOP_TRACE}}};
struct MemScopeEvent {
uint64_t id{0};
std::string event;
std::string eventType;
std::string name;
uint64_t timestamp{0};
uint64_t processId{0};
uint64_t threadId{0};
std::string deviceId;
std::string ptr;
std::string attr;
int64_t size{0};
std::string callStackC;
std::string callStackPython;
};
struct MemoryAllocation {
uint64_t id{0};
uint64_t timestamp{0};
uint64_t totalSize{0};
std::string deviceId;
std::string eventType;
bool optimized{false};
MemoryAllocation() = default;
MemoryAllocation(
uint64_t timestamp, uint64_t totalSize, std::string deviceId, std::string eventType, bool optimized)
: id(0), timestamp(timestamp), totalSize(totalSize), deviceId(std::move(deviceId)),
eventType(std::move(eventType)), optimized(optimized) {}
};
struct MemoryBlock {
uint64_t id{0};
std::string ptr;
std::string deviceId;
uint64_t size{0};
uint64_t startTimestamp{0};
uint64_t endTimestamp{0};
std::string owner;
std::string eventType;
std::string attrJsonString;
uint64_t processId{0};
uint64_t threadId{0};
int64_t firstAccessTimestamp{-1};
int64_t lastAccessTimestamp{-1};
uint64_t maxAccessInterval{0};
bool lazyUsed{false};
bool delayedFree{false};
bool longIdle{false};
MemoryBlock() = default;
virtual ~MemoryBlock() = default;
MemoryBlock(std::string ptr, std::string deviceId, uint64_t size, uint64_t startTs, uint64_t endTs,
std::string owner, std::string eventType, std::string attrJsonString, uint64_t pid, uint64_t tid)
: id(0), ptr(std::move(ptr)), deviceId(std::move(deviceId)), size(size), startTimestamp(startTs),
endTimestamp(endTs), owner(std::move(owner)), eventType(std::move(eventType)),
attrJsonString(std::move(attrJsonString)), processId(pid), threadId(tid) {}
};
}
#endif