// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. #include "element_impl.hpp" #include #include #include using namespace gras; struct GetStatsReceiver : Theron::Receiver { GetStatsReceiver(void) { this->RegisterHandler(this, &GetStatsReceiver::handle_get_stats); } void handle_get_stats(const GetStatsMessage &message, const Theron::Address) { this->messages.push_back(message); } std::vector messages; }; std::string TopBlock::get_stats(const std::string &) { //get stats with custom receiver and set high prio GetStatsReceiver receiver; size_t outstandingCount(0); BOOST_FOREACH(Apology::Worker *worker, (*this)->executor->get_workers()) { dynamic_cast(worker)->highPrioPreNotify(); worker->Push(GetStatsMessage(), receiver.GetAddress()); outstandingCount++; } while (outstandingCount) outstandingCount -= receiver.Wait(outstandingCount); //now format the xml result std::string xml; xml += str(boost::format(" %llu\n") % time_now()); xml += str(boost::format(" %llu\n") % time_tps()); BOOST_FOREACH(const GetStatsMessage &message, receiver.messages) { const BlockStats &stats = message.stats; std::string block_xml; block_xml += str(boost::format(" %llu\n") % time_tps()); block_xml += str(boost::format(" %llu\n") % message.stats_time); block_xml += str(boost::format(" %llu\n") % stats.start_time); block_xml += str(boost::format(" %llu\n") % stats.stop_time); block_xml += str(boost::format(" %llu\n") % stats.work_count); block_xml += str(boost::format(" %llu\n") % stats.time_last_work); block_xml += str(boost::format(" %llu\n") % stats.total_time_prep); block_xml += str(boost::format(" %llu\n") % stats.total_time_work); block_xml += str(boost::format(" %llu\n") % stats.total_time_post); block_xml += str(boost::format(" %llu\n") % stats.total_time_input); block_xml += str(boost::format(" %llu\n") % stats.total_time_output); for (size_t i = 0; i < stats.items_consumed.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.items_consumed[i]); } for (size_t i = 0; i < stats.tags_consumed.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.tags_consumed[i]); } for (size_t i = 0; i < stats.msgs_consumed.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.msgs_consumed[i]); } for (size_t i = 0; i < stats.items_produced.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.items_produced[i]); } for (size_t i = 0; i < stats.tags_produced.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.tags_produced[i]); } for (size_t i = 0; i < stats.msgs_produced.size(); i++) { block_xml += str(boost::format(" %llu\n") % stats.msgs_produced[i]); } xml += str(boost::format(" \n%s\n") % message.block_id % block_xml); } return str(boost::format("\n%s") % this->to_string() % xml); }