X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;ds=sidebyside;f=example%2Fdiameter%2Flauncher%2FMyCounterRecorder.cpp;h=dd326523efa24037b1bed8c8a243f2029d19b74d;hb=97a93101fb874a3237083d72c6d6f8c8df8dcfba;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=705d780f70b3596a222479ec7ad0dc3b3ab192cf;p=anna.git diff --git a/example/diameter/launcher/MyCounterRecorder.cpp b/example/diameter/launcher/MyCounterRecorder.cpp index e69de29..dd32652 100644 --- a/example/diameter/launcher/MyCounterRecorder.cpp +++ b/example/diameter/launcher/MyCounterRecorder.cpp @@ -0,0 +1,73 @@ +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // + + +// Process +#include + + +MyCounterRecorder::MyCounterRecorder(const std::string &fnp) : a_stream(-1), a_fileNamePrefix(fnp) { + a_previousTime = ::time(NULL); +} + +// pure virtual definitions: +void MyCounterRecorder::open() throw(anna::RuntimeException) { + static char str [256]; + const time_t now = ::time(NULL); + struct tm tmNow; + struct tm tmPrevious; + anna_memcpy(&tmNow, localtime(&now), sizeof(tmNow)); + anna_memcpy(&tmPrevious, localtime(&a_previousTime), sizeof(tmPrevious)); + sprintf( + str, ".Date%04d%02d%02d.Time%02d%02d%02d", + 1900 + (tmNow.tm_year), (tmNow.tm_mon) + 1, + tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min, tmNow.tm_sec); + a_fileName = a_fileNamePrefix; + a_fileName += str; + LOGDEBUG( + std::string msg("Flush counters | "); + msg += a_fileName; + anna::Logger::debug(msg, ANNA_FILE_LOCATION); + ); + + if((a_stream = ::open(a_fileName.c_str(), O_WRONLY | O_CREAT, S_IWUSR)) == -1) + throw RuntimeException(anna::functions::asString("Error opening file '%s'; errno = %d", a_fileName.c_str(), errno), ANNA_FILE_LOCATION); + + sprintf(str, "%04d-%02d-%02d %02d:%02d|%04d-%02d-%02d %02d:%02d", + 1900 + (tmPrevious.tm_year), (tmPrevious.tm_mon) + 1, + tmPrevious.tm_mday, tmPrevious.tm_hour, tmPrevious.tm_min, + 1900 + (tmNow.tm_year), (tmNow.tm_mon) + 1, + tmNow.tm_mday, tmNow.tm_hour, tmNow.tm_min + ); + a_fixedLine = str; +} + +void MyCounterRecorder::apply(const anna::oam::Counter& counter) throw(anna::RuntimeException) { + static char line [356]; + anna::oam::Counter::type_t value = counter; + sprintf(line, "%s|%06d|%07u|%s\n", a_fixedLine.c_str(), counter.getReference(), value, counter.getName().c_str()); + + if(write(a_stream, line, anna_strlen(line)) == -1) + throw RuntimeException(anna::functions::asString("Error writting to file '%s'; errno = %d", a_fileName.c_str(), errno), ANNA_FILE_LOCATION); +} + +void MyCounterRecorder::close() throw() { + if(a_stream != -1) { + ::close(a_stream); + a_stream = -1; + } + +chmod(a_fileName.c_str(), S_IWUSR | S_IRUSR); +a_previousTime = ::time(NULL); +} + +std::string MyCounterRecorder::asString() const throw() { + std::string result = "Physical counters dump at file '"; + result += a_fileName; + result += "'. Another way to see counters: context dump (kill -10 "; + return result; +}