From: Frederic Suter Date: Wed, 9 May 2018 14:40:29 +0000 (+0200) Subject: also use ofstream for tracing_files X-Git-Tag: v3.20~262 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/88d8c7a64ca458f3e1a81fa3653eba880ae71fed also use ofstream for tracing_files --- diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 30ee13e5fe..2cea47fa07 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing event system (containers)"); extern std::ofstream tracing_file; -extern std::map tracing_files; // TI specific +std::map tracing_files; // TI specific double prefix = 0.0; // TI specific static container_t rootContainer = nullptr; /* the root container */ @@ -157,7 +157,7 @@ void Container::logCreation() tracing_file << stream.str() << std::endl; } else if (trace_format == simgrid::instr::TraceFormat::Ti) { // if we are in the mode with only one file - static FILE* ti_unique_file = nullptr; + static std::ofstream* ti_unique_file = nullptr; if (tracing_files.empty()) { // generate unique run id with time @@ -172,8 +172,8 @@ void Container::logCreation() #else mkdir(folder_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); #endif - ti_unique_file = fopen(filename.c_str(), "w"); - xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename.c_str(), strerror(errno)); + ti_unique_file = new std::ofstream(filename.c_str(), std::ofstream::out); + xbt_assert(not ti_unique_file->fail(), "Tracefile %s could not be opened for writing", filename.c_str()); tracing_file << filename << std::endl; } tracing_files.insert({this, ti_unique_file}); @@ -196,7 +196,8 @@ void Container::logDestruction() tracing_file << stream.str() << std::endl; } else if (trace_format == simgrid::instr::TraceFormat::Ti) { if (not simgrid::config::get_value("tracing/smpi/format/ti-one-file") || tracing_files.size() == 1) { - fclose(tracing_files.at(this)); + tracing_files.at(this)->close(); + delete tracing_files.at(this); } tracing_files.erase(this); } else { diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index 258b4e7a54..a22de7daa6 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -10,7 +10,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)"); extern std::ofstream tracing_file; -std::map tracing_files; // TI specific +extern std::map tracing_files; // TI specific namespace simgrid { namespace instr { @@ -104,7 +104,7 @@ void StateEvent::print() /* Subtract -1 because this is the process id and we transform it to the rank id */ stream_ << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print(); - fprintf(tracing_files.at(getContainer()), "%s\n", stream_.str().c_str()); + *tracing_files.at(getContainer()) << stream_.str() << std::endl; } else { THROW_IMPOSSIBLE; }