|
@@ -31,7 +31,13 @@
|
|
#ifndef dataset_hpp
|
|
#ifndef dataset_hpp
|
|
#define dataset_hpp
|
|
#define dataset_hpp
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
+#include <functional>
|
|
|
|
+
|
|
#include <sys/time.h>
|
|
#include <sys/time.h>
|
|
|
|
+#include <signal.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+#include <stdio.h>
|
|
|
|
+
|
|
#include "value.hpp"
|
|
#include "value.hpp"
|
|
#include "container.hpp"
|
|
#include "container.hpp"
|
|
#include "memtrack.hpp"
|
|
#include "memtrack.hpp"
|
|
@@ -42,6 +48,10 @@
|
|
|
|
|
|
namespace fv {
|
|
namespace fv {
|
|
|
|
|
|
|
|
+ void request_stop_callback(int); // Forward Declaration
|
|
|
|
+ class DataSet; // Forward Declaration
|
|
|
|
+ DataSet* the_dataset;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* A DataSet is a generic source of data that is used to populate
|
|
* A DataSet is a generic source of data that is used to populate
|
|
* ObservedValues. For each ObservedValue, it is recommended that the DataSet
|
|
* ObservedValues. For each ObservedValue, it is recommended that the DataSet
|
|
@@ -57,6 +67,7 @@ namespace fv {
|
|
}
|
|
}
|
|
|
|
|
|
timeval start_time;
|
|
timeval start_time;
|
|
|
|
+ bool stop_requested;
|
|
|
|
|
|
void print_status() {
|
|
void print_status() {
|
|
size_t m_used = fv_util::getCurrentRSS() / 1024 / 1024;
|
|
size_t m_used = fv_util::getCurrentRSS() / 1024 / 1024;
|
|
@@ -110,11 +121,16 @@ namespace fv {
|
|
virtual void save_config() = 0;
|
|
virtual void save_config() = 0;
|
|
|
|
|
|
public:
|
|
public:
|
|
- DataSet() {
|
|
|
|
|
|
+ DataSet() : stop_requested(false){
|
|
max_events = fv_util::the_config->get_max_events();
|
|
max_events = fv_util::the_config->get_max_events();
|
|
|
|
+ the_dataset = this;
|
|
|
|
+
|
|
|
|
+ signal(SIGINT, request_stop_callback);
|
|
|
|
+ signal(SIGTERM, request_stop_callback);
|
|
}
|
|
}
|
|
|
|
|
|
bool next(bool verbose=true) {
|
|
bool next(bool verbose=true) {
|
|
|
|
+ if (stop_requested) return false;
|
|
int current_event = get_current_event();
|
|
int current_event = get_current_event();
|
|
if (current_event == 0) gettimeofday(&start_time, nullptr);
|
|
if (current_event == 0) gettimeofday(&start_time, nullptr);
|
|
if (verbose and (((current_event + 1) % 500) == 0 or current_event+1 == get_events())) print_status();
|
|
if (verbose and (((current_event + 1) % 500) == 0 or current_event+1 == get_events())) print_status();
|
|
@@ -130,6 +146,10 @@ namespace fv {
|
|
return this->max_events;
|
|
return this->max_events;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void request_stop() {
|
|
|
|
+ stop_requested = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
virtual void save_all() {
|
|
virtual void save_all() {
|
|
for (auto container : containers)
|
|
for (auto container : containers)
|
|
container.second->save();
|
|
container.second->save();
|
|
@@ -140,7 +160,7 @@ namespace fv {
|
|
C *register_container(ArgTypes... args) {
|
|
C *register_container(ArgTypes... args) {
|
|
C *container = new C(args...);
|
|
C *container = new C(args...);
|
|
if (containers[container->get_name()] != nullptr) {
|
|
if (containers[container->get_name()] != nullptr) {
|
|
- CRITICAL("Container with name \"" + container->get_name() + "\" already exists.", -1);
|
|
|
|
|
|
+ CRITICAL("Container with name \"" + container->get_name() + "\" already exists.");
|
|
}
|
|
}
|
|
containers[container->get_name()] = container;
|
|
containers[container->get_name()] = container;
|
|
return container;
|
|
return container;
|
|
@@ -149,11 +169,15 @@ namespace fv {
|
|
GenContainer *get_container(std::string container_name) {
|
|
GenContainer *get_container(std::string container_name) {
|
|
GenContainer *c = containers[container_name];
|
|
GenContainer *c = containers[container_name];
|
|
if (c == nullptr) {
|
|
if (c == nullptr) {
|
|
- CRITICAL("Request for container \"" << container_name << "\" failed. Doesn't exist.", -1);
|
|
|
|
|
|
+ CRITICAL("Request for container \"" << container_name << "\" failed. Doesn't exist.");
|
|
}
|
|
}
|
|
return c;
|
|
return c;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ void request_stop_callback(int) {
|
|
|
|
+ std::cout << std::endl << "SIGINT/SIGTERM caught, stopping after current event" << std::endl;
|
|
|
|
+ the_dataset->request_stop();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
#endif // dataset_hpp
|
|
#endif // dataset_hpp
|