18 #include <flecsi-config.h> 20 #if defined(FLECSI_ENABLE_FLOG) 22 #include "flecsi/log/packet.hh" 24 #include "flecsi/log/utils.hh" 30 #include <unordered_map> 78 int initialize(std::string active =
"none",
80 std::size_t one_process = -1) {
81 #if defined(FLOG_ENABLE_DEBUG) 82 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: initializing runtime" 83 << FLOG_COLOR_PLAIN << std::endl;
88 #if defined(FLOG_ENABLE_TAGS) 105 tag_reverse_map_[0] =
"all";
107 if(active ==
"all") {
111 else if(active !=
"none") {
113 std::istringstream is(active);
115 while(std::getline(is, tag,
',')) {
116 if(tag_map_.find(tag) != tag_map_.end()) {
117 tag_bitset_.set(tag_map_[tag]);
120 std::cerr <<
"FLOG WARNING: tag " << tag
121 <<
" has not been registered. Ignoring this group..." 127 #if defined(FLOG_ENABLE_DEBUG) 128 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: active tags (" << active <<
")" 129 << FLOG_COLOR_PLAIN << std::endl;
132 #endif // FLOG_ENABLE_TAGS 134 #if defined(FLOG_ENABLE_MPI) 136 #if defined(FLOG_ENABLE_DEBUG) 137 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: initializing mpi state" 138 << FLOG_COLOR_PLAIN << std::endl;
143 MPI_Comm_rank(MPI_COMM_WORLD, &p);
144 MPI_Comm_size(MPI_COMM_WORLD, &np);
149 if(one_process + 1 && one_process >= processes_) {
151 std::cerr <<
"flog process " << one_process <<
" out-of-bounds (" 152 << processes_ <<
" processes)" << std::endl;
158 one_process_ = one_process;
161 std::thread flusher(flush_packets);
162 instance().flusher_thread().swap(flusher);
164 #endif // FLOG_ENABLE_MPI 172 #if defined(FLOG_ENABLE_MPI) 178 flusher_thread_.join();
182 #endif // FLOG_ENABLE_MPI 185 int verbose()
const {
193 const std::unordered_map<std::string, size_t> &
tag_map() {
202 return buffer_stream_;
220 return active ? buffer_stream_ : null_stream_;
247 if(tag_map_.find(tag) != tag_map_.end()) {
248 return tag_map_[tag];
251 const size_t id = ++tag_id_;
252 assert(
id < FLOG_TAG_BITS &&
"Tag bits overflow! Increase FLOG_TAG_BITS");
253 #if defined(FLOG_ENABLE_DEBUG) 254 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: registering tag " << tag <<
": " 255 <<
id << FLOG_COLOR_PLAIN << std::endl;
258 tag_reverse_map_[id] = tag;
283 assert(tag_reverse_map_.find(
id) != tag_reverse_map_.end());
284 return tag_reverse_map_[id];
292 assert(tag_reverse_map_.find(active_tag_) != tag_reverse_map_.end());
293 return tag_reverse_map_[active_tag_];
297 #if defined(FLOG_ENABLE_TAGS) 299 #if defined(FLOG_ENABLE_DEBUG) 300 auto active_set = tag_bitset_.test(active_tag_) == 1 ?
"true" :
"false";
301 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: tag " << active_tag_ <<
" is " 302 << active_set << FLOG_COLOR_PLAIN << std::endl;
308 #if defined(FLOG_ENABLE_EXTERNAL) 315 return tag_bitset_.test(active_tag_);
318 #endif // FLOG_ENABLE_TAGS 321 size_t lookup_tag(
const char *
tag) {
322 if(tag_map_.find(tag) == tag_map_.end()) {
323 std::cerr << FLOG_COLOR_YELLOW <<
"FLOG: !!!WARNING " << tag
324 <<
" has not been registered. Ignoring this group..." 325 << FLOG_COLOR_PLAIN << std::endl;
329 return tag_map_[tag];
336 #if defined(FLOG_ENABLE_MPI) 337 bool one_process()
const {
338 return one_process_ < processes_;
341 size_t output_process()
const {
345 std::size_t process() {
349 std::size_t processes() {
353 std::thread & flusher_thread() {
354 return flusher_thread_;
357 std::mutex & packets_mutex() {
358 return packets_mutex_;
361 void buffer_output() {
365 if(tmp.size() > FLOG_MAX_MESSAGE_SIZE) {
366 tmp.resize(FLOG_MAX_MESSAGE_SIZE - 100);
368 stream << tmp << FLOG_COLOR_LTRED <<
" OUTPUT BUFFER TRUNCATED " 369 << FLOG_MAX_MESSAGE_SIZE <<
"(" <<
buffer_stream().str().size()
370 <<
")" << FLOG_COLOR_PLAIN << std::endl;
374 packets_.push_back({tmp.c_str()});
377 std::vector<packet_t> & packets() {
386 run_flusher_ =
false;
389 void set_serialized() {
403 flog_t() : null_stream_(0), tag_id_(0), active_tag_(0) {}
406 #if defined(FLOG_ENABLE_DEBUG) 407 std::cerr << FLOG_COLOR_LTGRAY <<
"FLOG: flog_t destructor" << std::endl;
411 bool initialized_ =
false;
415 std::stringstream buffer_stream_;
416 std::ostream null_stream_;
420 std::bitset<FLOG_TAG_BITS> tag_bitset_;
421 std::unordered_map<std::string, size_t> tag_map_;
422 std::unordered_map<size_t, std::string> tag_reverse_map_;
424 #if defined(FLOG_ENABLE_MPI) 425 std::size_t one_process_, process_, processes_;
426 std::thread flusher_thread_;
427 std::mutex packets_mutex_;
428 std::vector<packet_t> packets_;
429 bool run_flusher_ =
true;
430 bool serialized_ =
false;
438 #endif // FLECSI_ENABLE_FLOG std::ostream & severity_stream(bool active=true)
Definition: state.hh:219
tee_stream_t & config_stream()
Definition: state.hh:236
std::stringstream & buffer_stream()
Definition: state.hh:201
size_t register_tag(const char *tag)
Definition: state.hh:244
static flog_t & instance()
Definition: state.hh:73
std::ostream & null_stream()
Definition: state.hh:227
std::string active_tag_name()
Definition: state.hh:291
std::ostream & stream()
Definition: state.hh:209
std::string tag_name(size_t id)
Definition: state.hh:282
flog_t & operator=(const flog_t &)=delete
size_t & active_tag()
Definition: state.hh:274
const std::unordered_map< std::string, size_t > & tag_map()
Definition: state.hh:193
Definition: control.hh:31
const size_t & active_tag() const
Definition: state.hh:266