From c6b62fd814b6e5b4e3ba65b6f092f6aa4e1d298d Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Sat, 10 Oct 2015 14:28:45 +0200 Subject: [PATCH] Include accumulators on statistics engine in order to centralize and ease asXML. Fix setEngine(NULL) on TestStep.cpp --- .../diameter/launcher/testing/TestStep.cpp | 2 +- include/anna/diameter.comm/LocalServer.hpp | 2 +- include/anna/diameter.comm/Server.hpp | 2 +- include/anna/statistics/Accumulator.hpp | 21 ++++++++++++- include/anna/statistics/Engine.hpp | 4 ++- source/diameter.comm/Engine.cpp | 4 +-- source/diameter.comm/LocalServer.cpp | 31 ++++++++----------- source/diameter.comm/Server.cpp | 24 ++++++-------- source/statistics/Accumulator.cpp | 26 ++++++++++------ source/statistics/Engine.cpp | 18 ++++++++--- source/statistics/Meter.cpp | 2 +- 11 files changed, 81 insertions(+), 55 deletions(-) diff --git a/example/diameter/launcher/testing/TestStep.cpp b/example/diameter/launcher/testing/TestStep.cpp index 018dfcd..cb1b0f9 100644 --- a/example/diameter/launcher/testing/TestStep.cpp +++ b/example/diameter/launcher/testing/TestStep.cpp @@ -152,7 +152,7 @@ namespace { bool result = true; try { - messageCodec.setEngine(NULL); // perhaps we will need another codec engine ... + messageCodec.clear(); messageCodec.decode(message); } catch (anna::RuntimeException &ex) { diff --git a/include/anna/diameter.comm/LocalServer.hpp b/include/anna/diameter.comm/LocalServer.hpp index e97fb20..d83dd31 100644 --- a/include/anna/diameter.comm/LocalServer.hpp +++ b/include/anna/diameter.comm/LocalServer.hpp @@ -68,7 +68,7 @@ class LocalServer { int a_processing_time__StatisticConceptId; // request from local server (dpr's, etc.) int a_received_message_size__StatisticConceptId; anna::statistics::Accumulator *a_statisticsAccumulator; - void initializeStatisticConcepts() throw(); + void initializeStatisticResources() throw(); void resetStatistics() throw(); // void eraseServerSession(const anna::comm::ClientSocket& clientSocket) throw(); diff --git a/include/anna/diameter.comm/Server.hpp b/include/anna/diameter.comm/Server.hpp index 0484484..69f5e80 100644 --- a/include/anna/diameter.comm/Server.hpp +++ b/include/anna/diameter.comm/Server.hpp @@ -74,7 +74,7 @@ class Server { int a_processing_time__StatisticConceptId; int a_received_message_size__StatisticConceptId; anna::statistics::Accumulator *a_statisticsAccumulator; - void initializeStatisticConcepts() throw(); + void initializeStatisticResources() throw(); void resetStatistics() throw(); // Availability diff --git a/include/anna/statistics/Accumulator.hpp b/include/anna/statistics/Accumulator.hpp index 98d4624..c13bbf1 100644 --- a/include/anna/statistics/Accumulator.hpp +++ b/include/anna/statistics/Accumulator.hpp @@ -89,14 +89,31 @@ public: /** * Constructor. + * + * @param name Accumulator name */ - Accumulator(); + Accumulator(const std::string &name) : a_name(name) {}; /** * Destructor. */ ~Accumulator(); + /** + * Adds a new statistic concept through the accumulator, to ease the concept name creation, + * which will be a string defined by: concept name + ': ' + accumulator name. + * + * @param description Concept description; e.g.: processing time, messages size, etc. + * @param unit Concept unit description + * @param integerNatureSample Most of cases we will measure 'time' with the unit which force integer values + * (is more intuitive 850 msecs than 0,850 secs). Then, it is @em true by default. + * This is useful to advice better representation for some indicators like minimum/maximum + * within integer samples. + * + * @return Assigned concept identification number (sequence) + */ + int addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample = true) throw(); + /** * Process new value for the sample. @@ -189,6 +206,8 @@ public: private: + std::string a_name; + void initialize(const int & conceptId) throw(); _concept_data_t * getConcept(const int & conceptId) const throw(anna::RuntimeException); // Return NULL if no data is found for the concept Id diff --git a/include/anna/statistics/Engine.hpp b/include/anna/statistics/Engine.hpp index 8f59a2e..61a9fe6 100644 --- a/include/anna/statistics/Engine.hpp +++ b/include/anna/statistics/Engine.hpp @@ -142,9 +142,11 @@ public: * easily. Anyway, you could allocate this class objects without using this. Then, this is a helper to create accumulators * and centralize their reports. * + * @param name Accumulator name + * * @return New allocated accumulator, to be used by the client */ - Accumulator *createAccumulator() throw(); + Accumulator *createAccumulator(const std::string &name) throw(); /** * Class string representation diff --git a/source/diameter.comm/Engine.cpp b/source/diameter.comm/Engine.cpp index 489a093..88f78e2 100644 --- a/source/diameter.comm/Engine.cpp +++ b/source/diameter.comm/Engine.cpp @@ -274,7 +274,7 @@ throw(anna::RuntimeException) { result->setCategory(category); result->setDescription(description); result->setAllowedInactivityTime(allowedInactivityTime); - result->initializeStatisticConcepts(); + result->initializeStatisticResources(); // Los saco con metodos virtuales readXXX del motor: // if ((a_cea.isEmpty()) || (a_dwa.isEmpty())) // throw anna::RuntimeException("Must define valid CEA and DWA messages by mean setCEAandDWA()", ANNA_FILE_LOCATION); @@ -315,7 +315,7 @@ throw(anna::RuntimeException) { result->a_socket = socket; result->setMaxClientSessions(a_numberOfClientSessionsPerServer /* engine */); result->a_engine = this; - result->initializeStatisticConcepts(); + result->initializeStatisticResources(); for(int k = 0; k < a_numberOfClientSessionsPerServer; k++) result->addClientSession(k); diff --git a/source/diameter.comm/LocalServer.cpp b/source/diameter.comm/LocalServer.cpp index 67c35fc..b43a754 100644 --- a/source/diameter.comm/LocalServer.cpp +++ b/source/diameter.comm/LocalServer.cpp @@ -43,24 +43,19 @@ LocalServer::LocalServer() : a_category(0), a_lock(false), a_available(false), - a_lastUsedResource(NULL) { - a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(); -} - - -void LocalServer::initializeStatisticConcepts() throw() { - // Realm name - std::string realmName = a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer) - - // Statistics: - anna::statistics::Engine& statsEngine = anna::statistics::Engine::instantiate(); - // Concepts descriptions: - std::string serverAsString = anna::functions::socketLiteralAsString(a_key.first, a_key.second); - std::string c1desc = "Diameter processing time (for requests) at clients connected to "; c1desc += serverAsString; c1desc += " for realm '"; c1desc += realmName; c1desc += "'"; - std::string c2desc = "Diameter message sizes received from clients connected to "; c2desc += serverAsString; c2desc += " for realm '"; c2desc += realmName; c2desc += "'"; - // Registering - a_processing_time__StatisticConceptId = statsEngine.addConcept(c1desc.c_str(), "ms", true/* integer values */); - a_received_message_size__StatisticConceptId = statsEngine.addConcept(c2desc.c_str(), "bytes", true/* integer values */); + a_lastUsedResource(NULL), + a_statisticsAccumulator(NULL) {} + + +void LocalServer::initializeStatisticResources() throw() { + std::string accName = "local server '"; + accName += anna::functions::socketLiteralAsString(a_key.first, a_key.second); + accName += "' on realm '"; + accName += a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer) + accName += "'"; + a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(accName); + a_processing_time__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter requests processing time at clients connected to", "ms", true/* integer values */); + a_received_message_size__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter message sizes received from clients connected to", "bytes", true/* integer values */); } void LocalServer::resetStatistics() throw() { diff --git a/source/diameter.comm/Server.cpp b/source/diameter.comm/Server.cpp index 758ac2d..0b9bcd7 100644 --- a/source/diameter.comm/Server.cpp +++ b/source/diameter.comm/Server.cpp @@ -36,23 +36,19 @@ void Server::initialize() throw() { a_maxClientSessions = 1; // mono client connection a_lastIncomingActivityTime = (anna::Millisecond)0; a_lastOutgoingActivityTime = (anna::Millisecond)0; - a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(); + a_statisticsAccumulator = NULL; a_lastUsedResource = NULL; } -void Server::initializeStatisticConcepts() throw() { - // Realm name - std::string realmName = a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer) - - // Statistics: - anna::statistics::Engine& statsEngine = anna::statistics::Engine::instantiate(); - // Concepts descriptions: - std::string serverAsString = anna::functions::socketLiteralAsString(a_socket.first, a_socket.second); - std::string c1desc = "Diameter processing time (for requests) at servers on "; c1desc += serverAsString; c1desc += " for realm '"; c1desc += realmName; c1desc += "'"; - std::string c2desc = "Diameter message sizes received from servers on "; c2desc += serverAsString; c2desc += " for realm '"; c2desc += realmName; c2desc += "'"; - // Registering - a_processing_time__StatisticConceptId = statsEngine.addConcept(c1desc.c_str(), "ms", true/* integer values */); - a_received_message_size__StatisticConceptId = statsEngine.addConcept(c2desc.c_str(), "bytes", true/* integer values */); +void Server::initializeStatisticResources() throw() { + std::string accName = "remote server '"; + accName += anna::functions::socketLiteralAsString(a_socket.first, a_socket.second); + accName += "' from realm '"; + accName += a_engine ? a_engine->getRealm() : "unknown"; // it should be known (createServer) + accName += "'"; + a_statisticsAccumulator = anna::statistics::Engine::instantiate().createAccumulator(accName); + a_processing_time__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter requests processing time at", "ms", true/* integer values */); + a_received_message_size__StatisticConceptId = a_statisticsAccumulator->addConcept("Diameter message sizes received from", "bytes", true/* integer values */); } void Server::resetStatistics() throw() { diff --git a/source/statistics/Accumulator.cpp b/source/statistics/Accumulator.cpp index 1644700..358c87c 100644 --- a/source/statistics/Accumulator.cpp +++ b/source/statistics/Accumulator.cpp @@ -34,21 +34,13 @@ using namespace anna::time; //****************************************************************************** //------------------------------------------------------------------------------ -//--------------------------------------------------- Accumulator::Accumulator() +//-------------------------------------------------- Accumulator::~Accumulator() //------------------------------------------------------------------------------ - -// Default Constructor -Accumulator::Accumulator() { - //reset (); no sense -} - - Accumulator::~Accumulator() { // LOGMETHOD (TraceMethod tttm ("anna::statistics::Accumulator", "Destructor", ANNA_FILE_LOCATION)); + // TODO: anna::statistics::Engine::instantiate().releaseAccumulator(a_name); } - - // Private functions: @@ -62,6 +54,17 @@ void Accumulator::initialize(const int & conceptId) throw() { } +//------------------------------------------------------------------------------ +//---------------------------------------------------- Accumulator::addConcept() +//------------------------------------------------------------------------------ +int Accumulator::addConcept(const std::string & description, const std::string & unit, const bool & integerNatureSample) throw() { + std::string conceptName = description; + conceptName += ": "; + conceptName += a_name; + return anna::statistics::Engine::instantiate().addConcept(conceptName, unit, integerNatureSample); +} + + //------------------------------------------------------------------------------ //---------------------------------------------------- Accumulator::getConcept() //------------------------------------------------------------------------------ @@ -289,6 +292,8 @@ std::string Accumulator::asString(const int & numberOfDecimals) const throw() { trace = "\n====================="; trace += "\nStatistic Information"; trace += "\n====================="; + trace += "\nAccumulator name: "; + trace += a_name; trace += "\nCurrent Time: "; trace += time_now.asString(); @@ -370,6 +375,7 @@ std::string Accumulator::asString(const int & numberOfDecimals) const throw() { //------------------------------------------------------------------------------ anna::xml::Node* Accumulator::asXML(anna::xml::Node* parent, const int & numberOfDecimals) const throw() { anna::xml::Node* result = parent->createChild("anna.statistics.Accumulator"); + result->createAttribute("Name", a_name); _concept_data_map_iter iter; _concept_data_map_iter iter_min(a_concept_data_map.begin()); _concept_data_map_iter iter_max(a_concept_data_map.end()); diff --git a/source/statistics/Engine.cpp b/source/statistics/Engine.cpp index b90b609..ebde06c 100644 --- a/source/statistics/Engine.cpp +++ b/source/statistics/Engine.cpp @@ -158,10 +158,10 @@ bool Engine::logSample(const int & conceptId, const anna::Millisecond & unixTime //------------------------------------------------------------------------------ //----------------------------------------------------------- Engine::asString() //------------------------------------------------------------------------------ -Accumulator *Engine::createAccumulator() throw() { +Accumulator *Engine::createAccumulator(const std::string &name) throw() { Accumulator *result; - result = new Accumulator(); + result = new Accumulator(name); a_accumulators.push_back(result); return result; } @@ -201,6 +201,14 @@ std::string Engine::asString(void) const throw() { } trace += "\n"; + + // Accumulators: + trace += "\nNumber of accumulators= "; trace += anna::functions::asString(a_accumulators.size()); + for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) { + trace += "\n"; + trace += (*it)->asString(); + } + return (trace); } @@ -230,10 +238,10 @@ anna::xml::Node* Engine::asXML(anna::xml::Node* parent, const int & numberOfDeci } // Accumulators: - for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) { - anna::xml::Node* accumulators = result->createChild("anna.statistics.Accumulators"); + anna::xml::Node* accumulators = result->createChild("anna.statistics.Accumulators"); + accumulators->createAttribute("RegisteredAccumulators", a_accumulators.size()); + for (_accumulator_vector_it it = a_accumulators.begin(); it != a_accumulators.end(); it++) (*it)->asXML(accumulators); - } return result; } diff --git a/source/statistics/Meter.cpp b/source/statistics/Meter.cpp index feda763..9c9de5f 100644 --- a/source/statistics/Meter.cpp +++ b/source/statistics/Meter.cpp @@ -26,7 +26,7 @@ using namespace anna::statistics; //------------------------------------------------------------------------------ // Default Constructor -Meter::Meter(const std::string & description) { +Meter::Meter(const std::string & description) : a_accumulator(description) { Engine& statsEngine = Engine::instantiate(); a_single_accumulator_concept_id = statsEngine.addConcept(description, "ms", true); } -- 2.20.1