From 0c533bf948a63d134c8001e16b15194b197cb99a Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Testillano Date: Mon, 14 Mar 2016 03:49:45 +0100 Subject: [PATCH] Allow to log statistics samples as a event operation --- example/diameter/launcher/Launcher.cpp | 77 ++++++++++++++++---------- example/diameter/launcher/Launcher.hpp | 2 + example/diameter/launcher/main.cpp | 2 +- include/anna/statistics/Engine.hpp | 5 +- source/statistics/Engine.cpp | 21 ++++--- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/example/diameter/launcher/Launcher.cpp b/example/diameter/launcher/Launcher.cpp index 88e4c44..116c325 100644 --- a/example/diameter/launcher/Launcher.cpp +++ b/example/diameter/launcher/Launcher.cpp @@ -745,34 +745,11 @@ throw(anna::RuntimeException) { a_timeEngine->activate(a_counterRecorderClock); // start clock } - // Log statistics concepts - if(cl.exists("logStatisticSamples")) { - std::string list = cl.getValue("logStatisticSamples"); - anna::statistics::Engine &statEngine = anna::statistics::Engine::instantiate(); - - if(list == "all") { - if(statEngine.enableSampleLog(/* -1: all concepts */)) - LOGDEBUG(anna::Logger::debug("Sample log activation for all statistic concepts", ANNA_FILE_LOCATION)); - } else { - anna::Tokenizer lst; - lst.apply(cl.getValue("logStatisticSamples"), ","); - - if(lst.size() >= 1) { - anna::Tokenizer::const_iterator tok_min(lst.begin()); - anna::Tokenizer::const_iterator tok_max(lst.end()); - anna::Tokenizer::const_iterator tok_iter; - int conceptId; - - for(tok_iter = tok_min; tok_iter != tok_max; tok_iter++) { - conceptId = atoi(anna::Tokenizer::data(tok_iter)); - - if(statEngine.enableSampleLog(conceptId)) - LOGDEBUG(anna::Logger::debug(anna::functions::asString("Sample log activation for statistic concept id = %d", conceptId), ANNA_FILE_LOCATION)); - } - } - } - } - + ///////////////////////////// + // Log statistics concepts // + ///////////////////////////// + if(cl.exists("logStatisticSamples")) + logStatisticsSamples(cl.getValue("logStatisticSamples")); // Start client connections ////////////////////////////////////////////////////////////////////////////////// MyDiameterEntity *entity; @@ -1036,6 +1013,11 @@ std::string Launcher::help() const throw() { result += "\n This operation applies over all the registered host nodes"; result += "\n except if one specific working node has been set."; result += "\nforceCountersRecord Forces dump to file the current counters of the process."; + result += "\nlog-statistics-samples| Log statistics samples for the provided comma-separated concept id"; + result += "\n list, over './sample..csv' files. For example: \"1,2\""; + result += "\n will log concepts 1 and 2. Reserved words \"all\"/\"none\" activates/"; + result += "\n deactivates all registered statistics concept identifiers. That ids"; + result += "\n are shown at context dump."; result += "\nchange-dir[|directory] Changes the execution point which could be fine to ease some"; result += "\n file system interaction tasks. Be care about some requirements"; result += "\n (for example if you have a user defined counters directory as"; @@ -1476,6 +1458,38 @@ std::string Launcher::help() const throw() { return result; } + +void Launcher::logStatisticsSamples(const std::string &conceptsList) throw() { + anna::statistics::Engine &statEngine = anna::statistics::Engine::instantiate(); + + if(conceptsList == "all") { + if(statEngine.enableSampleLog(/* -1: all concepts */)) + LOGDEBUG(anna::Logger::debug("Sample log activation for all statistic concepts", ANNA_FILE_LOCATION)); + } + else if(conceptsList == "none") { + if(statEngine.disableSampleLog(/* -1: all concepts */)) + LOGDEBUG(anna::Logger::debug("Sample log deactivation for all statistic concepts", ANNA_FILE_LOCATION)); + } else { + anna::Tokenizer lst; + lst.apply(conceptsList, ","); + + if(lst.size() >= 1) { + anna::Tokenizer::const_iterator tok_min(lst.begin()); + anna::Tokenizer::const_iterator tok_max(lst.end()); + anna::Tokenizer::const_iterator tok_iter; + int conceptId; + + for(tok_iter = tok_min; tok_iter != tok_max; tok_iter++) { + conceptId = atoi(anna::Tokenizer::data(tok_iter)); + + if(statEngine.enableSampleLog(conceptId)) + LOGDEBUG(anna::Logger::debug(anna::functions::asString("Sample log activation for statistic concept id = %d", conceptId), ANNA_FILE_LOCATION)); + } + } + } +} + + void Launcher::eventOperation(const std::string &operation, std::string &response_content) throw(anna::RuntimeException) { LOGMETHOD(anna::TraceMethod tm("Launcher", "eventOperation", ANNA_FILE_LOCATION)); if (operation == "") return; // ignore @@ -1573,6 +1587,7 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons bool wrongBody = false; if((opType == "change-dir") && (numParams > 1)) wrongBody = true; + if((opType == "log-statistics-samples") && (numParams != 1)) wrongBody = true; if((opType == "node") && (numParams > 1)) wrongBody = true; if((opType == "node_auto") && (numParams > 0)) wrongBody = true; @@ -1603,6 +1618,12 @@ void Launcher::eventOperation(const std::string &operation, std::string &respons return; } + if(opType == "log-statistics-samples") { + logStatisticsSamples(param1); + response_content = anna::functions::asString("Log statistics samples for '%s' concepts", param1.c_str()); + return; + } + // Change execution directory: if(opType == "change-dir") { if (param1 == "") param1 = a_initialWorkingDirectory; diff --git a/example/diameter/launcher/Launcher.hpp b/example/diameter/launcher/Launcher.hpp index 14ea762..dcc684d 100644 --- a/example/diameter/launcher/Launcher.hpp +++ b/example/diameter/launcher/Launcher.hpp @@ -112,6 +112,8 @@ public: MyCommunicator *getCommunicator() throw() { return a_communicator; } void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException); void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); } + void logStatisticsSamples(const std::string &conceptsList) throw(); + anna::xml::Node* asXML(anna::xml::Node* parent) const throw(); void resetStatistics() throw(); diff --git a/example/diameter/launcher/main.cpp b/example/diameter/launcher/main.cpp index b603dee..6f2a653 100644 --- a/example/diameter/launcher/main.cpp +++ b/example/diameter/launcher/main.cpp @@ -34,7 +34,7 @@ int main(int argc, const char** argv) { commandLine.add("cntDir", anna::CommandLine::Argument::Optional, "Counters directory. By default is the current execution directory. Warning: a counter file will be dump per record period; take care about the possible accumulation of files"); commandLine.add("tmDir", anna::CommandLine::Argument::Optional, "Test manager directory. By default is the current execution directory. Warning: report files could be dump during system testing (see help for management operation 'test|report|result'); take care about the possible accumulation of files"); commandLine.add("cntRecordPeriod", anna::CommandLine::Argument::Optional, "Counters record procedure period in milliseconds. If missing, default value of 300000 (5 minutes) will be assigned. Value of 0 disables the record procedure."); - commandLine.add("logStatisticSamples", anna::CommandLine::Argument::Optional, "Log statistics samples for the provided concept id list, over './sample..csv' files. For example: \"1,2\" will log concepts 1 and 2. Reserved word \"all\" activates all registered statistics concept identifiers. That ids are shown at context dump (see help to get it)."); + commandLine.add("logStatisticSamples", anna::CommandLine::Argument::Optional, "Log statistics samples for the provided comma-separated concept id list, over './sample..csv' files. For example: \"1,2\" will log concepts 1 and 2. Reserved words \"all\"/\"none\" activates/deactivates all registered statistics concept identifiers. That ids are shown at context dump (see help to get it)."); commandLine.add("disableLogs", anna::CommandLine::Argument::Optional, "Overrides every node configuration regarding traffic log in order to disable it and ease production or system test startup.", false); // Communications diff --git a/include/anna/statistics/Engine.hpp b/include/anna/statistics/Engine.hpp index 5300cfa..1852e1a 100644 --- a/include/anna/statistics/Engine.hpp +++ b/include/anna/statistics/Engine.hpp @@ -115,11 +115,12 @@ public: /** * Disable sample log for statistics processings * - * @param id Concept identification. + * @param id Concept identification. If -1 value is provided, all concepts will be deactivated. * * @return @em false if not concept is registered with provided id + * @warning Many systems add concepts dynamically. This method only affects to current concepts registered at statistics engine. */ - bool disableSampleLog(const int & id) throw(); + bool disableSampleLog(const int & id = -1) throw(); // Gets diff --git a/source/statistics/Engine.cpp b/source/statistics/Engine.cpp index e804599..79a23ce 100644 --- a/source/statistics/Engine.cpp +++ b/source/statistics/Engine.cpp @@ -99,12 +99,9 @@ bool Engine::enableSampleLog(const int & id, const char *sampleFileName) throw() // For all concepts: _concept_identification_map_nc_iter it_min(a_concept_identification_map.begin()); _concept_identification_map_nc_iter it_max(a_concept_identification_map.end()); - for(it = it_min; it != it_max; it++) { realName = ""; - if(providedName != "") realName = anna::functions::asString("%s.%d.csv", providedName.c_str(), (*it).first); - SampleFile_ptr = &((*it).second.SampleFile); *SampleFile_ptr = realName; } @@ -117,14 +114,20 @@ bool Engine::enableSampleLog(const int & id, const char *sampleFileName) throw() //--------------------------------------------------- Engine::disableSampleLog() //------------------------------------------------------------------------------ bool Engine::disableSampleLog(const int & id) throw() { - _concept_identification_map_nc_iter it = a_concept_identification_map.find(id); - if(it == a_concept_identification_map.end()) return false; + if(id != -1) { + _concept_identification_map_nc_iter it = a_concept_identification_map.find(id); - // Access to map - std::string *SampleFile_ptr = &((*it).second.SampleFile); - *SampleFile_ptr = ""; - return true; + if(it == a_concept_identification_map.end()) return false; + + // Access to map + std::string *SampleFile_ptr = &((*it).second.SampleFile); + *SampleFile_ptr = ""; + return true; + } + + // For all concepts: + return enableSampleLog(id /* -1 */, ""); } -- 2.20.1