From 38b24b7ef6e3d82c1a14b93c4ffafadbc2f1ae9b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 26 Mar 2013 00:41:12 -0500 Subject: gras: rename stats to query --- lib/CMakeLists.txt | 2 +- lib/top_block_query.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/top_block_stats.cpp | 85 ------------------------------------------------- 3 files changed, 86 insertions(+), 86 deletions(-) create mode 100644 lib/top_block_query.cpp delete mode 100644 lib/top_block_stats.cpp (limited to 'lib') diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e667570..fa15efa 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -55,7 +55,7 @@ list(APPEND GRAS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/output_handlers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hier_block.cpp ${CMAKE_CURRENT_SOURCE_DIR}/top_block.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/top_block_stats.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/top_block_query.cpp ${CMAKE_CURRENT_SOURCE_DIR}/register_messages.cpp ${CMAKE_CURRENT_SOURCE_DIR}/theron_allocator.cpp ) diff --git a/lib/top_block_query.cpp b/lib/top_block_query.cpp new file mode 100644 index 0000000..1a6376c --- /dev/null +++ b/lib/top_block_query.cpp @@ -0,0 +1,85 @@ +// 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::query(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.init_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); +} diff --git a/lib/top_block_stats.cpp b/lib/top_block_stats.cpp deleted file mode 100644 index 04fc7ae..0000000 --- a/lib/top_block_stats.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// 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.init_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); -} -- cgit