Removing cache of decoded lines and returning shared_ptr (#953)
[ROCm/rocprofiler-sdk commit: a045947a89]
This commit is contained in:
zatwierdzone przez
GitHub
rodzic
3327f10d81
commit
5a5e1f22a6
@@ -117,7 +117,7 @@ struct isa_map_elem_t
|
||||
{
|
||||
std::atomic<size_t> hitcount{0};
|
||||
std::atomic<size_t> latency{0};
|
||||
std::shared_ptr<Instruction> code_line{nullptr};
|
||||
std::unique_ptr<Instruction> code_line{nullptr};
|
||||
};
|
||||
|
||||
struct ToolData
|
||||
@@ -332,7 +332,7 @@ isa_callback(char* isa_instruction,
|
||||
C_API_BEGIN
|
||||
assert(userdata && "ISA callback passed null!");
|
||||
|
||||
std::shared_ptr<Instruction> instruction;
|
||||
std::unique_ptr<Instruction> instruction;
|
||||
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> unique_lock(tool->isa_map_mut);
|
||||
|
||||
@@ -152,10 +152,11 @@ tool_codeobj_tracing_callback(rocprofiler_callback_tracing_record_t record,
|
||||
<< std::dec << ". Printing first 64 bytes:" << std::endl;
|
||||
|
||||
std::unordered_set<std::string> references{};
|
||||
int num_waitcnts = 0;
|
||||
int num_scalar = 0;
|
||||
int num_vector = 0;
|
||||
int num_other = 0;
|
||||
|
||||
int num_waitcnts = 0;
|
||||
int num_scalar = 0;
|
||||
int num_vector = 0;
|
||||
int num_other = 0;
|
||||
|
||||
size_t vaddr = begin_end.first;
|
||||
while(vaddr < begin_end.second)
|
||||
|
||||
+14
-29
@@ -177,7 +177,7 @@ public:
|
||||
return {};
|
||||
};
|
||||
|
||||
std::shared_ptr<Instruction> disassemble_instruction(uint64_t faddr, uint64_t vaddr)
|
||||
std::unique_ptr<Instruction> disassemble_instruction(uint64_t faddr, uint64_t vaddr)
|
||||
{
|
||||
if(!disassembly) throw std::exception();
|
||||
|
||||
@@ -191,7 +191,7 @@ public:
|
||||
{}
|
||||
|
||||
auto pair = disassembly->ReadInstruction(faddr);
|
||||
auto inst = std::make_shared<Instruction>(std::move(pair.first), pair.second);
|
||||
auto inst = std::make_unique<Instruction>(std::move(pair.first), pair.second);
|
||||
inst->faddr = faddr;
|
||||
inst->vaddr = vaddr;
|
||||
|
||||
@@ -215,7 +215,7 @@ public:
|
||||
: load_addr(_load_addr)
|
||||
, load_end(_load_addr + _memsize)
|
||||
{
|
||||
if(!filepath) throw "Empty filepath.";
|
||||
if(!filepath) throw std::runtime_error("Empty filepath.");
|
||||
|
||||
std::string_view fpath(filepath);
|
||||
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
{
|
||||
std::ifstream file(filepath, std::ios::in | std::ios::binary);
|
||||
|
||||
if(!file.is_open()) throw "Invalid filename " + std::string(filepath);
|
||||
if(!file.is_open()) throw std::runtime_error("Invalid file " + std::string(filepath));
|
||||
|
||||
std::vector<char> buffer;
|
||||
file.seekg(0, file.end);
|
||||
@@ -247,33 +247,19 @@ public:
|
||||
decoder =
|
||||
std::make_unique<CodeobjDecoderComponent>(reinterpret_cast<const char*>(data), size);
|
||||
}
|
||||
std::shared_ptr<Instruction> add_to_map(uint64_t ld_addr)
|
||||
std::unique_ptr<Instruction> get(uint64_t ld_addr)
|
||||
{
|
||||
if(!decoder || ld_addr < load_addr) throw std::out_of_range("Addr not in decoder");
|
||||
if(!decoder || ld_addr < load_addr) return nullptr;
|
||||
|
||||
uint64_t voffset = ld_addr - load_addr;
|
||||
auto faddr = decoder->va2fo(voffset);
|
||||
if(!faddr) throw std::out_of_range("Could not find file offset");
|
||||
if(!faddr) return nullptr;
|
||||
|
||||
auto shared = decoder->disassemble_instruction(*faddr, voffset);
|
||||
shared->ld_addr = ld_addr;
|
||||
decoded_map[ld_addr] = shared;
|
||||
return shared;
|
||||
auto unique = decoder->disassemble_instruction(*faddr, voffset);
|
||||
unique->ld_addr = ld_addr;
|
||||
return unique;
|
||||
}
|
||||
|
||||
std::shared_ptr<Instruction> get(uint64_t addr)
|
||||
{
|
||||
if(decoded_map.find(addr) != decoded_map.end()) return decoded_map[addr];
|
||||
try
|
||||
{
|
||||
return add_to_map(addr);
|
||||
} catch(std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << " at addr " << std::hex << addr << std::dec << std::endl;
|
||||
}
|
||||
throw std::out_of_range("Invalid address");
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t begin() const { return load_addr; };
|
||||
uint64_t end() const { return load_end; }
|
||||
uint64_t size() const { return load_end - load_addr; }
|
||||
@@ -299,8 +285,7 @@ public:
|
||||
private:
|
||||
uint64_t load_end = 0;
|
||||
|
||||
std::unordered_map<uint64_t, std::shared_ptr<Instruction>> decoded_map;
|
||||
std::unique_ptr<CodeobjDecoderComponent> decoder{nullptr};
|
||||
std::unique_ptr<CodeobjDecoderComponent> decoder{nullptr};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -332,7 +317,7 @@ public:
|
||||
|
||||
virtual bool removeDecoderbyId(codeobj_marker_id_t id) { return decoders.erase(id) != 0; }
|
||||
|
||||
std::shared_ptr<Instruction> get(codeobj_marker_id_t id, uint64_t offset)
|
||||
std::unique_ptr<Instruction> get(codeobj_marker_id_t id, uint64_t offset)
|
||||
{
|
||||
auto& decoder = decoders.at(id);
|
||||
return decoder->get(decoder->begin() + offset);
|
||||
@@ -387,13 +372,13 @@ public:
|
||||
return table.remove(load_addr) && this->Super::removeDecoderbyId(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<Instruction> get(uint64_t vaddr)
|
||||
std::unique_ptr<Instruction> get(uint64_t vaddr)
|
||||
{
|
||||
auto& addr_range = table.find_codeobj_in_range(vaddr);
|
||||
return this->Super::get(addr_range.id, vaddr - addr_range.vbegin);
|
||||
}
|
||||
|
||||
std::shared_ptr<Instruction> get(codeobj_marker_id_t id, uint64_t offset)
|
||||
std::unique_ptr<Instruction> get(codeobj_marker_id_t id, uint64_t offset)
|
||||
{
|
||||
if(id == 0)
|
||||
return get(offset);
|
||||
|
||||
+3
-3
@@ -154,10 +154,10 @@ public:
|
||||
if(!(size = std::stoul(size_it->second, nullptr, 0))) return;
|
||||
}
|
||||
|
||||
if(protocol == "memory") throw protocol + " protocol not supported!";
|
||||
if(protocol == "memory") throw std::runtime_error(protocol + " protocol not supported!");
|
||||
|
||||
std::ifstream file(decoded_path, std::ios::in | std::ios::binary);
|
||||
if(!file || !file.is_open()) throw "could not open " + decoded_path;
|
||||
if(!file || !file.is_open()) throw std::runtime_error("could not open " + decoded_path);
|
||||
|
||||
if(!size)
|
||||
{
|
||||
@@ -165,7 +165,7 @@ public:
|
||||
size_t bytes = file.gcount();
|
||||
file.clear();
|
||||
|
||||
if(bytes < offset) throw "invalid uri " + decoded_path + " (file size < offset)";
|
||||
if(bytes < offset) throw std::runtime_error("invalid uri " + decoded_path);
|
||||
|
||||
size = bytes - offset;
|
||||
}
|
||||
|
||||
@@ -138,9 +138,9 @@ get_trace_data(rocprofiler_att_parser_data_type_t type, void* att_data, void* us
|
||||
auto ptr = std::make_unique<TrackedIsa>();
|
||||
try
|
||||
{
|
||||
auto shared_inst = codeobjTranslate->get(pc.marker_id, pc.addr);
|
||||
if(shared_inst == nullptr) return;
|
||||
ptr->inst = shared_inst->inst;
|
||||
auto unique_inst = codeobjTranslate->get(pc.marker_id, pc.addr);
|
||||
if(unique_inst == nullptr) return;
|
||||
ptr->inst = unique_inst->inst;
|
||||
} catch(...)
|
||||
{
|
||||
return;
|
||||
@@ -178,7 +178,7 @@ isa_callback(char* isa_instruction,
|
||||
assert(trace_data.tool && "ISA callback passed null!");
|
||||
ToolData& tool = *reinterpret_cast<ToolData*>(trace_data.tool);
|
||||
|
||||
std::shared_ptr<Instruction> instruction;
|
||||
std::unique_ptr<Instruction> instruction;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user