Wrote the beginnings of a new "stats" command.
This commit is contained in:
parent
bedadd03a0
commit
af3be5f964
3 changed files with 71 additions and 0 deletions
|
|
@ -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()
|
void format_entries::format_last_entry()
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
|
||||||
35
src/output.h
35
src/output.h
|
|
@ -78,6 +78,41 @@ public:
|
||||||
virtual void operator()(xact_t& xact);
|
virtual void operator()(xact_t& xact);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Brief
|
||||||
|
*
|
||||||
|
* 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
|
* @brief Brief
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -543,6 +543,11 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
|
||||||
(reporter<>(new format_xacts(*this, HANDLER(register_format_).str()),
|
(reporter<>(new format_xacts(*this, HANDLER(register_format_).str()),
|
||||||
*this));
|
*this));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
if (is_eq(p, "stats"))
|
||||||
|
return WRAP_FUNCTOR(reporter<>(new gather_statistics(*this), *this));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue