diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/output.cc | 31 | ||||
-rw-r--r-- | src/output.h | 35 | ||||
-rw-r--r-- | src/report.cc | 5 |
3 files changed, 71 insertions, 0 deletions
diff --git a/src/output.cc b/src/output.cc index 593ce909..752d6dd2 100644 --- a/src/output.cc +++ b/src/output.cc @@ -84,6 +84,37 @@ void format_xacts::operator()(xact_t& xact) } } +void gather_statistics::flush() +{ + std::ostream& out(report.output_stream); + + out << "Statistics gathered for this report:" << std::endl + << " Total entries: " ; + + out << std::right; + out.width(6); + out << statistics.total_entries << std::endl + << " Total transactions: "; + + out << std::right; + out.width(6); + out << statistics.total_xacts << std::endl; + + out.flush(); +} + +void gather_statistics::operator()(xact_t& xact) +{ + if (last_entry != xact.entry) { + statistics.total_entries++; + last_entry = xact.entry; + } + if (last_xact != &xact) { + statistics.total_xacts++; + last_xact = &xact; + } +} + void format_entries::format_last_entry() { bool first = true; diff --git a/src/output.h b/src/output.h index fd462040..ada7b21c 100644 --- a/src/output.h +++ b/src/output.h @@ -83,6 +83,41 @@ public: * * Long. */ +class gather_statistics : public item_handler<xact_t> +{ +protected: + report_t& report; + entry_t * last_entry; + xact_t * last_xact; + + struct statistics_t { + std::size_t total_entries; + std::size_t total_xacts; + + statistics_t() + : total_entries(0), + total_xacts(0) {} + } + statistics; + +public: + gather_statistics(report_t& _report) + : report(_report), last_entry(NULL), last_xact(NULL) { + TRACE_CTOR(gather_statistics, "report&"); + } + virtual ~gather_statistics() { + TRACE_DTOR(gather_statistics); + } + + virtual void flush(); + virtual void operator()(xact_t& xact); +}; + +/** + * @brief Brief + * + * Long. + */ class format_entries : public format_xacts { public: diff --git a/src/report.cc b/src/report.cc index 9dea33db..97d7ba0c 100644 --- a/src/report.cc +++ b/src/report.cc @@ -543,6 +543,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name) (reporter<>(new format_xacts(*this, HANDLER(register_format_).str()), *this)); break; + + case 's': + if (is_eq(p, "stats")) + return WRAP_FUNCTOR(reporter<>(new gather_statistics(*this), *this)); + break; } } break; |