summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2009-08-28 15:26:24 -0700
committerRoland McGrath <[email protected]>2009-08-28 15:26:24 -0700
commit7367eb6f3f7c386afcea85b80ca1c6c21b561832 (patch)
tree392fa78e3ca5d5cc9242728322deb6a8885f8ea8
parent785f2505c7ba0102e611fdbbaeac3f7629e85d53 (diff)
Fiddle stats output.
-rw-r--r--libdw/c++/dwarf_output61
-rw-r--r--tests/ChangeLog6
-rw-r--r--tests/print-die.cc10
-rwxr-xr-xtests/run-dwarfcmp-self.sh1
4 files changed, 62 insertions, 16 deletions
diff --git a/libdw/c++/dwarf_output b/libdw/c++/dwarf_output
index 5a8a58e2..747e8f8b 100644
--- a/libdw/c++/dwarf_output
+++ b/libdw/c++/dwarf_output
@@ -60,6 +60,7 @@
#include <deque>
#include <queue>
#include <bitset>
+#include <map>
#include <tr1/unordered_set>
/* Read the comments for elfutils::dwarf first.
@@ -252,7 +253,7 @@ namespace elfutils
inline const debug_info_entry &operator () (die_info_pair *) const;
};
- inline void reify_children () const;
+ inline void reify_children (unsigned int &total) const;
public:
friend class subr::hashed_hasher<children_type>;
@@ -803,8 +804,9 @@ namespace elfutils
}
inline void placed (const debug_info_entry::pointer &ref,
- bool have_sibling)
+ bool have_sibling, unsigned int &total)
{
+ ++total;
++_m_uses;
_m_with_sibling[have_sibling] = true;
@@ -837,7 +839,8 @@ namespace elfutils
/* This is called when a children_type is installed freshly in the collector.
Fill in its back pointers. */
inline void
- dwarf_output::debug_info_entry::children_type::reify_children () const
+ dwarf_output::debug_info_entry::children_type::
+ reify_children (unsigned int &total) const
{
_base::const_iterator i = _base::begin ();
bool have_sibling = i != _base::end ();
@@ -845,7 +848,7 @@ namespace elfutils
{
const const_iterator here (i, subr::nothing ());
have_sibling = ++i != _base::end ();
- (*here.base ())->second.placed (here, have_sibling);
+ (*here.base ())->second.placed (here, have_sibling, total);
}
}
@@ -905,7 +908,7 @@ namespace elfutils
if (p.second)
/* This candidate actually got inserted into the set.
Now fix up all the backpointers into the _m_broods copy. */
- result.reify_children ();
+ result.reify_children (_m_total);
return &result;
}
@@ -960,23 +963,44 @@ namespace elfutils
void add_shape (die_type &die, bool last_sibling);
+ typedef std::multimap<unsigned int,
+ const die_map::value_type *> die_stats_map;
+
+ struct die_stats_sorter
+ : public std::unary_function<die_map::value_type, void>
+ {
+ die_stats_map &_m_map;
+ inline die_stats_sorter (die_stats_map &m) : _m_map (m) {}
+
+ inline void operator () (const die_map::value_type &elt)
+ {
+ _m_map.insert (std::make_pair (elt.second._m_uses, &elt));
+ }
+ };
+
+ static void die_stats (const die_stats_map::value_type &v)
+ {
+ const die_map::value_type &elt = *v.second;
+ 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";
+ }
+
public:
inline dwarf_output_collector ()
: _m_total (0)
{}
- static void die_stats (const die_map::value_type &elt)
- {
- std::cout << to_string (elt.first) << " uses="
- << std::dec << elt.second._m_uses
- << " (" << elt.second._m_with_sibling.to_string () << ")\n";
- }
-
void stats () const
{
std::cout << "collected " << std::dec << _m_unique.size ()
<< " unique of " << _m_total << " total DIEs\n";
- std::for_each (_m_unique.begin (), _m_unique.end (), die_stats);
+
+ die_stats_map ordered;
+ std::for_each (_m_unique.begin (), _m_unique.end (),
+ die_stats_sorter (ordered));
+ std::for_each (ordered.rbegin (), ordered.rend (), die_stats);
}
};
@@ -1955,15 +1979,20 @@ namespace elfutils
}
};
- /* Create a whole CU in the output.
- */
+ // Create a whole CU in the output.
inline void
make_unit (const typename dw::compile_units::const_iterator &in,
const compile_units::iterator &out)
{
typename tracker::walk into (_m_tracker, in, out);
- *out = unit_copier (this, *in).final ()->first;
+ die_info_pair *cu = unit_copier (this, *in).final ();
+
+ *out = cu->first;
+
+ // This really just increments _m_total for us, but also _m_uses.
+ cu->second.placed (cu->first.children ().end (),
+ false, _m_collector->_m_total);
}
typedef std::tr1::unordered_map< ::Dwarf_Off, seen> seen_map;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 2a56063a..7316f5cd 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2009-08-28 Roland McGrath <[email protected]>
+
+ * run-dwarfcmp-self.sh: Test dwarfcmp-test binary too.
+
+ * print-die.cc: Grok --stats to dump collector stats.
+
2009-08-27 Roland McGrath <[email protected]>
* run-dwarfcmp-self.sh: Parameterize. Take out -T runs.
diff --git a/tests/print-die.cc b/tests/print-die.cc
index 728eb74a..6816632a 100644
--- a/tests/print-die.cc
+++ b/tests/print-die.cc
@@ -49,6 +49,7 @@ static bool sort_attrs;
static bool elide_refs;
static bool dump_refs;
static bool no_print;
+static bool output_stats;
static enum { copy_none, copy_edit, copy_output } make_copy;
@@ -107,6 +108,13 @@ print_die_main (int &argc, char **&argv, unsigned int &depth)
++argv;
}
+ if (argc > 1 && !strcmp (argv[1], "--stats"))
+ {
+ output_stats = true;
+ --argc;
+ ++argv;
+ }
+
if (argc > 1 && !strcmp (argv[1], "--silent"))
{
no_print = true;
@@ -315,6 +323,8 @@ print_file (const char *name, const file &dw, const unsigned int limit)
{
dwarf_output_collector c; // We'll just throw it away.
print_file (dwarf_output (dw, c), limit);
+ if (output_stats)
+ c.stats ();
}
break;
default:
diff --git a/tests/run-dwarfcmp-self.sh b/tests/run-dwarfcmp-self.sh
index c79ebb99..798558f6 100755
--- a/tests/run-dwarfcmp-self.sh
+++ b/tests/run-dwarfcmp-self.sh
@@ -49,6 +49,7 @@ runtest()
runtest ../src/addr2line
runtest ../src/dwarfcmp
+runtest ../src/dwarfcmp-test
runtest ../src/dwarflint
runtest ../src/elfcmp
runtest ../src/elflint