From: Roland McGrath Date: Mon, 14 Sep 2009 00:45:38 +0000 (-0700) Subject: dwarf_output stats hack. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=075c0ec58a2822d99b49af4e268bf7ac54bb6ae5;p=thirdparty%2Felfutils.git dwarf_output stats hack. --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 0327e7811..0760942d5 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -508,6 +508,8 @@ namespace elfutils { return (uintptr_t) _m_die.addr; } + + ::Dwarf_Off cost () const; }; // Container for raw list of child DIEs, intended to be a compatible with diff --git a/libdw/c++/dwarf_edit b/libdw/c++/dwarf_edit index 38a036e06..9b0936978 100644 --- a/libdw/c++/dwarf_edit +++ b/libdw/c++/dwarf_edit @@ -252,6 +252,11 @@ namespace elfutils return identity (); } + inline ::Dwarf_Off cost () const + { + return 0; + } + // Convenience entry point. inline pointer add_entry (int child_tag) { diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output index 434252d19..df2034915 100644 --- a/libdw/c++/dwarf_output +++ b/libdw/c++/dwarf_output @@ -385,6 +385,11 @@ namespace elfutils { return identity (); } + + inline ::Dwarf_Off cost () const + { + return 0; + } }; class attr_value @@ -694,11 +699,13 @@ namespace elfutils { die_info_pair *_m_parent; std::queue _m_refs; + ::Dwarf_Off _m_original_cost; std::bitset<2> _m_with_sibling; unsigned int _m_uses; inline die_info () - : _m_parent (NULL), _m_refs (), _m_with_sibling (), _m_uses (0) + : _m_parent (NULL), _m_refs (), + _m_original_cost (0), _m_with_sibling (), _m_uses (0) {} inline ~die_info () @@ -932,7 +939,13 @@ namespace elfutils std::cout << std::dec << elt.second._m_uses << "\thash=" << std::hex << subr::hash_this (elt.first) << "\t(" << elt.second._m_with_sibling.to_string () << ")\t" - << to_string (elt.first) << "\n"; + << std::dec << elt.second._m_original_cost; + if (elt.second._m_uses > 1) + std::cout << " (" + << (double (elt.second._m_original_cost) + / double (elt.second._m_uses - 1)) + << ")"; + std::cout << "\t" << to_string (elt.first) << "\n"; } public: @@ -1289,6 +1302,7 @@ namespace elfutils : public value::value_dispatch { ::Dwarf_Off _m_offset; // XXX debugging only + ::Dwarf_Off _m_cost; // For statistics only. // Set if we are building this in the copying walk right now. entry_copier *_m_building; @@ -1666,6 +1680,8 @@ namespace elfutils _m_building != NULL && refs_dangling); dump (false, true) << " final done\n"; + + _m_final->second._m_original_cost += _m_cost; } /* This is called from pending_entry::final when resolving @@ -1757,6 +1773,7 @@ namespace elfutils if (unlikely (_m_in->_m_building != NULL)) throw std::runtime_error ("detected cycle in logical DWARF tree"); _m_in->_m_building = this; + _m_in->_m_cost = in.cost (); } // On destruction, we clear _m_building. diff --git a/libdw/c++/values.cc b/libdw/c++/values.cc index b9e273056..8f97a98f7 100644 --- a/libdw/c++/values.cc +++ b/libdw/c++/values.cc @@ -688,3 +688,16 @@ namespace elfutils return dec_string (size (), "{", " line entries}"); } }; + +::Dwarf_Off +dwarf::debug_info_entry::cost () const +{ + Dwarf_Die next; + int result = dwarf_siblingof (thisdie (), &next); + xif (result < 0); + if (result == 0) + return (const char *) next.addr - (const char *) _m_die.addr; + if (next.addr != NULL) + return (const char *) next.addr - (const char *) _m_die.addr + 1; + return _m_die.cu->end - dwarf_dieoffset (thisdie ()); +}