From 490ea4c37de7f66316948477b6b52365cf0fa8d9 Mon Sep 17 00:00:00 2001 From: Giovanni LB Date: Wed, 13 Dec 2023 19:26:44 -0300 Subject: [PATCH] SWDEV-432445: ATT - Adding fixes for symbolic stitch and source reference numbering Change-Id: I31d63bd2500155697129c29d7e0bc857e48cad8e --- plugin/att/code_printing.cpp | 40 ++++++--- plugin/att/code_printing.hpp | 11 ++- plugin/att/segment.hpp | 97 +++++++++++++--------- plugin/att/stitch.py | 6 +- src/core/isa_capture/code_object_track.cpp | 2 +- src/core/isa_capture/code_object_track.hpp | 4 +- src/core/session/att/continuous.cpp | 1 - 7 files changed, 101 insertions(+), 60 deletions(-) diff --git a/plugin/att/code_printing.cpp b/plugin/att/code_printing.cpp index dc87022f37..74b6d08514 100644 --- a/plugin/att/code_printing.cpp +++ b/plugin/att/code_printing.cpp @@ -107,6 +107,8 @@ CodeObjDecoderComponent::CodeObjDecoderComponent( Dwarf_Off cu_offset{0}, next_offset; size_t header_size; + std::unordered_set used_addrs; + while (!dwarf_nextcu(dbg.get(), cu_offset, &next_offset, &header_size, nullptr, nullptr, nullptr)) { Dwarf_Die die; @@ -116,7 +118,6 @@ CodeObjDecoderComponent::CodeObjDecoderComponent( size_t line_count; if (dwarf_getsrclines(&die, &lines, &line_count)) continue; - std::shared_ptr dwarf_line_number{nullptr}; for (size_t i = 0; i < line_count; ++i) { Dwarf_Addr addr; int line_number; @@ -125,19 +126,36 @@ CodeObjDecoderComponent::CodeObjDecoderComponent( if (line && !dwarf_lineaddr(line, &addr) && !dwarf_lineno(line, &line_number) && line_number) { std::string src = dwarf_linesrc(line, nullptr, nullptr); - dwarf_line_number = std::make_shared(src + ':' + std::to_string(line_number)); - } + auto dwarf_line = src + ':' + std::to_string(line_number); - if (dwarf_line_number.get()) - m_line_number_map[addr] = dwarf_line_number; + if (used_addrs.find(addr) != used_addrs.end()) + { + size_t pos = m_line_number_map.lower_bound(addr); + m_line_number_map.data()[pos].str += ' ' + dwarf_line; + continue; + } + + used_addrs.insert(addr); + m_line_number_map.insert(DSourceLine{addr, 0, std::move(dwarf_line)}); + } } cu_offset = next_offset; } - // load_symbol_map(); } // Can throw disassembly = std::make_unique(codeobj_data, codeobj_size, gpu_id); + if (m_line_number_map.size()) + { + size_t total_size = 0; + for (size_t i=0; iGetKernelMap(); // Can throw } catch(...) {} @@ -145,7 +163,6 @@ CodeObjDecoderComponent::CodeObjDecoderComponent( //disassemble_kernels(); } - CodeObjDecoderComponent::~CodeObjDecoderComponent() { if (m_fd) ::close(m_fd); } @@ -178,11 +195,12 @@ CodeObjDecoderComponent::disassemble_instruction(uint64_t faddr, uint64_t vaddr) if (!disassembly) throw std::exception(); - char* cpp_line = nullptr; + const char* cpp_line = nullptr; - auto it = m_line_number_map.find(vaddr); - if (it != m_line_number_map.end()) - cpp_line = it->second->data(); + try { + const DSourceLine& it = m_line_number_map.find_obj(vaddr); + cpp_line = it.str.data(); + } catch(...) {} size_t size = disassembly->ReadInstruction(faddr, vaddr, cpp_line); return {disassembly->last_instruction, size}; diff --git a/plugin/att/code_printing.hpp b/plugin/att/code_printing.hpp index a9861a04a1..2c34cee283 100644 --- a/plugin/att/code_printing.hpp +++ b/plugin/att/code_printing.hpp @@ -32,6 +32,15 @@ #include "disassembly.hpp" #include "segment.hpp" +struct DSourceLine +{ + uint64_t vaddr; + uint64_t size; + std::string str; + uint64_t begin() const { return vaddr; } + bool inrange(uint64_t addr) const { return addr >= vaddr && addr < vaddr+size; } +}; + class CodeObjDecoderComponent { public: @@ -48,7 +57,7 @@ public: int m_fd; - std::map> m_line_number_map{}; + cached_ordered_vector m_line_number_map; std::map m_symbol_map{}; std::string m_uri; diff --git a/plugin/att/segment.hpp b/plugin/att/segment.hpp index 58da1a1093..3a2cc3ad43 100644 --- a/plugin/att/segment.hpp +++ b/plugin/att/segment.hpp @@ -78,6 +78,59 @@ public: const Type& get(size_t i) const { return this->operator[](i); } }; +/** + * @brief Finds a candidate codeobj for the given vaddr +*/ +template +class cached_ordered_vector : public ordered_vector +{ + using Super = ordered_vector; +public: + cached_ordered_vector() { reset(); } + + const Type& find_obj(uint64_t addr) + { + if (testCache(addr)) + return get(cached_segment); + + size_t lb = this->lower_bound(addr); + if (lb >= this->size() || !get(lb).inrange(addr)) + throw std::string("segment addr out of range"); + + cached_segment = lb; + return get(cached_segment); + } + + uint64_t find_addr(uint64_t addr) { + return find_obj(addr).begin(); + } + + bool testCache(uint64_t addr) const { + return this->cached_segment < this->size() && get(cached_segment).inrange(addr); + } + + const Type& get(size_t index) const { return this->data()[index]; } + + void insert(const Type& elem) { this->Super::insert(elem); } + void insert_list(std::vector arange) + { + for (auto& elem : arange) push_back(elem); + std::sort( + this->begin(), + this->end(), + [](const Type& a, const Type& b) { return a.begin() < b.begin(); } + ); + }; + + void reset() { cached_segment = ~0; } + void clear() { reset(); this->Super::clear(); } + bool remove(uint64_t addr) { reset(); return this->Super::remove(addr); } + +private: + size_t cached_segment = ~0; +}; + + struct address_range_t { uint64_t vbegin; @@ -94,46 +147,8 @@ struct address_range_t /** * @brief Finds a candidate codeobj for the given vaddr */ -class CodeobjTableTranslator : protected ordered_vector +class CodeobjTableTranslator : public cached_ordered_vector { - using Super = ordered_vector; -public: - CodeobjTableTranslator() { reset(); } - - const address_range_t& find_codeobj_in_range(uint64_t addr) - { - if (cached_segment < size() && get(cached_segment).inrange(addr)) - return get(cached_segment); - - size_t lb = lower_bound(addr); - if (lb >= size() || !get(lb).inrange(addr)) - throw std::string("segment addr out of range"); - - cached_segment = lb; - return get(cached_segment); - } - - uint64_t find_codeobj_addr_in_range(uint64_t addr) { - return find_codeobj_in_range(addr).vbegin; - } - - const address_range_t& get(size_t index) const { return data()[index]; } - - void insert(const address_range_t& elem) { this->Super::insert(elem); } - void insert_list(std::vector arange) - { - for (auto& elem : arange) push_back(elem); - std::sort( - this->begin(), - this->end(), - [](const address_range_t& a, const address_range_t& b) { return a < b; } - ); - }; - - void reset() { cached_segment = ~0; } - void clear() { reset(); this->Super::clear(); } - bool remove(uint64_t addr) { reset(); return this->Super::remove(addr); } - -private: - size_t cached_segment = ~0; + public: + const address_range_t& find_codeobj_in_range(uint64_t addr) { return this->find_obj(addr); } }; diff --git a/plugin/att/stitch.py b/plugin/att/stitch.py index c388dc1bbd..e51097ebb2 100644 --- a/plugin/att/stitch.py +++ b/plugin/att/stitch.py @@ -96,11 +96,11 @@ class RegisterWatchList: dst = line.split(" ")[1].strip() label_dests = [] try: - label_dests = next_line.split(", ") + label_dests = next_line[0].split(", ") except: pass try: - label_dests.append(next_line.split(", ")[-1].split("@")[0]) + label_dests.append(next_line[0].split(", ")[-1].split("@")[0]) except: pass @@ -540,7 +540,7 @@ def stitch(insts, raw_code, jumps, gfxv, bIsAuto, codeservice): print('WARNING: Parsing terminated at:', as_line) break - if as_line[1] != DONT_KNOW: + if matched or as_line[1] != DONT_KNOW or 's_barrier' in as_line[0]: if matched: inst.asmline = reverse_map[line] result.append(inst) diff --git a/src/core/isa_capture/code_object_track.cpp b/src/core/isa_capture/code_object_track.cpp index cf3b6c5d2e..6ad313dcff 100644 --- a/src/core/isa_capture/code_object_track.cpp +++ b/src/core/isa_capture/code_object_track.cpp @@ -91,7 +91,7 @@ void codeobj_capture_instance::Unload(uint64_t addr) { if (codeobj_record::codeobjs.find(addr) == codeobj_record::codeobjs.end()) return; - eventcount.fetch_add(1, std::memory_order_relaxed)+1; + eventcount.fetch_add(1, std::memory_order_relaxed); auto time = rocprofiler::ROCProfiler_Singleton::GetInstance().timestamp_ns().value; codeobj_record::codeobjs.at(addr)->end_time = time; codeobj_record::codeobjs.erase(addr); diff --git a/src/core/isa_capture/code_object_track.hpp b/src/core/isa_capture/code_object_track.hpp index 66b1ef3d16..fbba7b4506 100644 --- a/src/core/isa_capture/code_object_track.hpp +++ b/src/core/isa_capture/code_object_track.hpp @@ -43,8 +43,8 @@ class codeobj_capture_instance { uint64_t start_time, uint32_t id ) - : addr(_addr), load_size(_load_size), start_time(start_time), URI(_uri), - mem_addr(mem_addr), mem_size(mem_size), load_id(id) {}; + : addr(_addr), load_size(_load_size), start_time(start_time), + load_id(id), URI(_uri), mem_addr(mem_addr), mem_size(mem_size) {}; void setmode(rocprofiler_codeobj_capture_mode_t mode); diff --git a/src/core/session/att/continuous.cpp b/src/core/session/att/continuous.cpp index 020650d671..23e455ea6f 100644 --- a/src/core/session/att/continuous.cpp +++ b/src/core/session/att/continuous.cpp @@ -221,7 +221,6 @@ bool AttTracer::ATTContiguousWriteInterceptor( std::lock_guard lk(att_enable_disable_mutex); // If att_start already exists, don't start again bool bIsActive = this->HasActiveTracerATT(agent_handle); - auto agent_pending_packets = pending_stop_packets.find(agent_handle); if (bIsActive) insertStart = {};