CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/MIPS/MIPSTracer.h
Views: 1401
// Copyright (c) 2024- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <unordered_map>20#include <vector>21#include <string>2223#include "Common/CommonTypes.h"24#include "Core/Opcode.h"25#include "Core/MIPS/IR/IRJit.h"26#include "Common/Log.h"27#include "Common/File/Path.h"28#include "Common/Data/Collections/CyclicBuffer.h"293031struct TraceBlockInfo {32u32 virt_address;33u32 storage_index;34};3536struct TraceBlockStorage {37std::vector<u32> raw_instructions;38u32 cur_index;39u32* cur_data_ptr;4041TraceBlockStorage(u32 capacity):42raw_instructions(capacity, 0),43cur_index(0),44cur_data_ptr(raw_instructions.data())45{}4647TraceBlockStorage(): raw_instructions(), cur_index(0), cur_data_ptr(nullptr) {}4849bool save_block(const u32* instructions, u32 size);5051void initialize(u32 capacity);52void clear();5354u32 operator[](u32 index) {55return raw_instructions[index];56}57Memory::Opcode read_asm(u32 index) {58return Memory::Opcode(raw_instructions[index]);59}60};61626364// This system is meant for trace recording.65// A trace here stands for a sequence of instructions and their respective addresses in RAM.66// The register/memory changes (or thread switches) are not included!67// Note: the tracer stores the basic blocks inside, which causes the last block to be dumped as a whole,68// despite the fact that it may not have executed to its end by the time the tracer is stopped.69struct MIPSTracer {70std::vector<TraceBlockInfo> trace_info;7172// The trace might be very big, in that case I don't mind losing the oldest entries.73CyclicBuffer<u32> executed_blocks;7475std::unordered_map<u64, u32> hash_to_storage_index;7677TraceBlockStorage storage;7879Path logging_path;80FILE* output;81bool tracing_enabled = false;8283int in_storage_capacity = 0x10'0000;84int in_max_trace_size = 0x10'0000;8586void start_tracing();87void stop_tracing();8889void prepare_block(const MIPSComp::IRBlock* block, MIPSComp::IRBlockCache& blocks);90void set_logging_path(std::string path) {91logging_path = Path(path);92}93std::string get_logging_path() const {94return logging_path.ToString();95}9697bool flush_to_file();98void flush_block_to_file(const TraceBlockInfo& block);99100void initialize(u32 storage_capacity, u32 max_trace_size);101void clear();102103inline void print_stats() const;104105MIPSTracer(): trace_info(), executed_blocks(), hash_to_storage_index(), storage(), logging_path() {}106};107108extern MIPSTracer mipsTracer;109110111