diff --git a/samples/advanced_thread_trace/client.cpp b/samples/advanced_thread_trace/client.cpp index c93d19e5..ee4b787b 100644 --- a/samples/advanced_thread_trace/client.cpp +++ b/samples/advanced_thread_trace/client.cpp @@ -117,7 +117,7 @@ struct isa_map_elem_t { std::atomic hitcount{0}; std::atomic latency{0}; - std::shared_ptr code_line{nullptr}; + std::unique_ptr 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; + std::unique_ptr instruction; { std::unique_lock unique_lock(tool->isa_map_mut); diff --git a/samples/code_object_isa_decode/client.cpp b/samples/code_object_isa_decode/client.cpp index 663f9eee..3ac1c2cb 100644 --- a/samples/code_object_isa_decode/client.cpp +++ b/samples/code_object_isa_decode/client.cpp @@ -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 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) diff --git a/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/code_printing.hpp b/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/code_printing.hpp index 0ed53389..c5471e38 100644 --- a/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/code_printing.hpp +++ b/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/code_printing.hpp @@ -177,7 +177,7 @@ class CodeobjDecoderComponent return {}; }; - std::shared_ptr disassemble_instruction(uint64_t faddr, uint64_t vaddr) + std::unique_ptr disassemble_instruction(uint64_t faddr, uint64_t vaddr) { if(!disassembly) throw std::exception(); @@ -191,7 +191,7 @@ class CodeobjDecoderComponent {} auto pair = disassembly->ReadInstruction(faddr); - auto inst = std::make_shared(std::move(pair.first), pair.second); + auto inst = std::make_unique(std::move(pair.first), pair.second); inst->faddr = faddr; inst->vaddr = vaddr; @@ -215,7 +215,7 @@ class LoadedCodeobjDecoder : 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 @@ class LoadedCodeobjDecoder { 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 buffer; file.seekg(0, file.end); @@ -247,33 +247,19 @@ class LoadedCodeobjDecoder decoder = std::make_unique(reinterpret_cast(data), size); } - std::shared_ptr add_to_map(uint64_t ld_addr) + std::unique_ptr 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 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 @@ class LoadedCodeobjDecoder private: uint64_t load_end = 0; - std::unordered_map> decoded_map; - std::unique_ptr decoder{nullptr}; + std::unique_ptr decoder{nullptr}; }; /** @@ -332,7 +317,7 @@ class CodeobjMap virtual bool removeDecoderbyId(codeobj_marker_id_t id) { return decoders.erase(id) != 0; } - std::shared_ptr get(codeobj_marker_id_t id, uint64_t offset) + std::unique_ptr get(codeobj_marker_id_t id, uint64_t offset) { auto& decoder = decoders.at(id); return decoder->get(decoder->begin() + offset); @@ -387,13 +372,13 @@ class CodeobjAddressTranslate : public CodeobjMap return table.remove(load_addr) && this->Super::removeDecoderbyId(id); } - std::shared_ptr get(uint64_t vaddr) + std::unique_ptr 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 get(codeobj_marker_id_t id, uint64_t offset) + std::unique_ptr get(codeobj_marker_id_t id, uint64_t offset) { if(id == 0) return get(offset); diff --git a/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/disassembly.hpp b/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/disassembly.hpp index 48b8c6d3..019cc7a7 100644 --- a/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/disassembly.hpp +++ b/source/include/rocprofiler-sdk/amd_detail/rocprofiler-sdk-codeobj/disassembly.hpp @@ -154,10 +154,10 @@ class CodeObjectBinary 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 @@ class CodeObjectBinary 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; } diff --git a/tests/thread-trace/trace_callbacks.cpp b/tests/thread-trace/trace_callbacks.cpp index bd0d5a29..531e0add 100644 --- a/tests/thread-trace/trace_callbacks.cpp +++ b/tests/thread-trace/trace_callbacks.cpp @@ -138,9 +138,9 @@ get_trace_data(rocprofiler_att_parser_data_type_t type, void* att_data, void* us auto ptr = std::make_unique(); 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(trace_data.tool); - std::shared_ptr instruction; + std::unique_ptr instruction; try {