+//------------------------------------------------------------------------------
+//------------------------------------- Module::RecordingGuard::RecordingGuard()
+//------------------------------------------------------------------------------
+anna::oam::Module::RecordingGuard::RecordingGuard(anna::oam::Module* module) :
+ a_module(module) {
+ module->a_counterRecording = true;
+}
+
+
+//------------------------------------------------------------------------------
+//------------------------------------ Module::RecordingGuard::~RecordingGuard()
+//------------------------------------------------------------------------------
+anna::oam::Module::RecordingGuard::~RecordingGuard() {
+ a_module->a_counterRecording = false;
+}
+
+
+//------------------------------------------------------------------------------
+//----------------------------------------------------- Module::recordCounters()
+//------------------------------------------------------------------------------
+void anna::oam::Module::recordCounters() throw(anna::RuntimeException) {
+ LOGMETHOD(anna::TraceMethod tttm("anna::oam::Module", "recordCounters", ANNA_FILE_LOCATION));
+
+ if(a_counterRecorder == NULL)
+ throw RuntimeException("anna::oam::Module has no counter recorder associated", ANNA_FILE_LOCATION);
+
+ LOGDEBUG(
+ std::string msg("Recording counters | ");
+ msg += a_counterRecorder->asString();
+ anna::Logger::write(Logger::Debug, msg, ANNA_FILE_LOCATION)
+ );
+ RecordingGuard guard(this);
+
+ a_counterRecorder->open();
+ CounterScope* cscope = NULL;
+
+ try {
+ for(scope_iterator scope_it = scope_begin(); scope_it != scope_end(); scope_it++) {
+ cscope = scope(scope_it);
+ if(cscope == NULL) continue;
+
+ Guard csGuard(cscope, "oam::CounterScope from oam::Module::record");
+
+ for(int icounter = 0; icounter < CounterScope::MaxCounter; icounter ++) {
+ Counter* counter = cscope->a_counters [icounter];
+
+ if(counter == NULL)
+ continue;
+
+ if(counter->getValue() == 0)
+ continue;
+
+ a_counterRecorder->apply(*counter);
+ counter->reset();
+ }
+ }
+
+ a_counterRecorder->close();
+ } catch(anna::RuntimeException&) {
+ a_counterRecorder->close();
+ throw;
+ }
+}
+