+// Print information when destroyed, iff command line option is specified.
+StatisticInfo::~StatisticInfo() {
+ // Statistics not enabled?
+ if (Stats.empty()) return;
+
+ // Get the stream to write to.
+ std::ostream &OutStream = *GetLibSupportInfoOutputFile();
+
+ // Figure out how long the biggest Value and Name fields are.
+ unsigned MaxNameLen = 0, MaxValLen = 0;
+ for (unsigned i = 0, e = Stats.size(); i != e; ++i) {
+ MaxValLen = std::max(MaxValLen,
+ (unsigned)utostr(Stats[i]->getValue()).size());
+ MaxNameLen = std::max(MaxNameLen,
+ (unsigned)std::strlen(Stats[i]->getName()));
+ }
+
+ // Sort the fields by name.
+ std::stable_sort(Stats.begin(), Stats.end(), NameCompare());
+
+ // Print out the statistics header...
+ OutStream << "===" << std::string(73, '-') << "===\n"
+ << " ... Statistics Collected ...\n"
+ << "===" << std::string(73, '-') << "===\n\n";
+
+ // Print all of the statistics.
+ for (unsigned i = 0, e = Stats.size(); i != e; ++i) {
+ std::string CountStr = utostr(Stats[i]->getValue());
+ OutStream << std::string(MaxValLen-CountStr.size(), ' ')
+ << CountStr << " " << Stats[i]->getName()
+ << std::string(MaxNameLen-std::strlen(Stats[i]->getName()), ' ')
+ << " - " << Stats[i]->getDesc() << "\n";
+