From 92197c7e3516470da6ccee2253d0e515a70a70a9 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 9 May 2018 15:56:55 +0200 Subject: [PATCH] replace FILE* by ofstream for tracing_file --- src/instr/instr_config.cpp | 19 ++- src/instr/instr_paje_containers.cpp | 8 +- src/instr/instr_paje_events.cpp | 10 +- src/instr/instr_paje_header.cpp | 248 ++++++++++++++-------------- src/instr/instr_paje_trace.cpp | 11 +- src/instr/instr_paje_types.cpp | 6 +- src/instr/instr_paje_values.cpp | 4 +- src/instr/instr_private.hpp | 2 + 8 files changed, 156 insertions(+), 152 deletions(-) diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 7ea943f98a..20f4014f42 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -8,13 +8,14 @@ #include "src/instr/instr_private.hpp" #include "surf/surf.hpp" #include "xbt/virtu.h" /* sg_cmdline */ +#include #include #include XBT_LOG_NEW_CATEGORY(instr, "Logging the behavior of the tracing system (used for Visualization/Analysis of simulations)"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration"); -extern FILE* tracing_file; +std::ofstream tracing_file; #define OPT_TRACING_BASIC "tracing/basic" #define OPT_TRACING_BUFFER "tracing/buffer" @@ -97,8 +98,8 @@ static void TRACE_start() /* open the trace file(s) */ std::string filename = TRACE_get_filename(); - tracing_file = fopen(filename.c_str(), "w"); - if (tracing_file == nullptr) { + tracing_file.open(filename.c_str(), std::ofstream::out); + if (tracing_file.fail()) { THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str()); } @@ -106,15 +107,15 @@ static void TRACE_start() if (format == "Paje") { /* output generator version */ - fprintf(tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n", SIMGRID_VERSION_MAJOR, - SIMGRID_VERSION_MINOR, SIMGRID_VERSION_PATCH); - fprintf(tracing_file, "#["); + tracing_file << "#This file was generated using SimGrid-" << SIMGRID_VERSION_MAJOR << "." << SIMGRID_VERSION_MINOR + << "." << SIMGRID_VERSION_PATCH << std::endl; + tracing_file << "#["; unsigned int cpt; char* str; xbt_dynar_foreach (xbt_cmdline, cpt, str) { - fprintf(tracing_file, "%s ", str); + tracing_file << str << " "; } - fprintf(tracing_file, "]\n"); + tracing_file << "]" << std::endl; } /* output one line comment */ @@ -149,7 +150,7 @@ static void TRACE_end() delete root_type; /* close the trace files */ - fclose(tracing_file); + tracing_file.close(); XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str()); /* de-activate trace */ diff --git a/src/instr/instr_paje_containers.cpp b/src/instr/instr_paje_containers.cpp index 2b901348ea..30ee13e5fe 100644 --- a/src/instr/instr_paje_containers.cpp +++ b/src/instr/instr_paje_containers.cpp @@ -9,7 +9,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_containers, instr, "Paje tracing event system (containers)"); -extern FILE* tracing_file; +extern std::ofstream tracing_file; extern std::map tracing_files; // TI specific double prefix = 0.0; // TI specific @@ -154,7 +154,7 @@ void Container::logCreation() stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_CreateContainer << " "; stream << timestamp << " " << id_ << " " << type_->get_id() << " " << father_->id_ << " \"" << name_ << "\""; XBT_DEBUG("Dump %s", stream.str().c_str()); - fprintf(tracing_file, "%s\n", stream.str().c_str()); + 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; @@ -174,7 +174,7 @@ void Container::logCreation() #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)); - fprintf(tracing_file, "%s\n", filename.c_str()); + tracing_file << filename << std::endl; } tracing_files.insert({this, ti_unique_file}); } else { @@ -193,7 +193,7 @@ void Container::logDestruction() stream << std::fixed << std::setprecision(TRACE_precision()) << PAJE_DestroyContainer << " "; stream << timestamp << " " << type_->get_id() << " " << id_; XBT_DEBUG("Dump %s", stream.str().c_str()); - fprintf(tracing_file, "%s\n", stream.str().c_str()); + 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)); diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index 6373f40d06..258b4e7a54 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -9,7 +9,7 @@ #include "src/surf/surf_interface.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)"); -extern FILE* tracing_file; +extern std::ofstream tracing_file; std::map tracing_files; // TI specific namespace simgrid { @@ -46,7 +46,7 @@ void NewEvent::print() stream_ << " " << value->getId(); XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } void LinkEvent::print() @@ -60,7 +60,7 @@ void LinkEvent::print() stream_ << " " << size_; XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } void VariableEvent::print() @@ -71,7 +71,7 @@ void VariableEvent::print() stream_ << " " << value; XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } void StateEvent::print() @@ -90,7 +90,7 @@ void StateEvent::print() } #endif XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } else if (trace_format == simgrid::instr::TraceFormat::Ti) { if (extra_ == nullptr) return; diff --git a/src/instr/instr_paje_header.cpp b/src/instr/instr_paje_header.cpp index 01cd5bd12a..b3472d043c 100644 --- a/src/instr/instr_paje_header.cpp +++ b/src/instr/instr_paje_header.cpp @@ -9,180 +9,181 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_header, instr, "Paje tracing event system (header)"); -extern FILE *tracing_file; +extern std::ofstream tracing_file; static void TRACE_header_PajeDefineContainerType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineContainerType %u\n", simgrid::instr::PAJE_DefineContainerType); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineContainerType " << simgrid::instr::PAJE_DefineContainerType << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% ContainerType string\n"); + tracing_file << "% ContainerType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); + tracing_file << "% Type string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDefineVariableType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineVariableType %u\n", simgrid::instr::PAJE_DefineVariableType); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineVariableType " << simgrid::instr::PAJE_DefineVariableType << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% ContainerType string\n"); + tracing_file << "% ContainerType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); + tracing_file << "% Type string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%% Color color\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "% Color color" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDefineStateType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineStateType %u\n", simgrid::instr::PAJE_DefineStateType); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineStateType " << simgrid::instr::PAJE_DefineStateType << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% ContainerType string\n"); + tracing_file << "% ContainerType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); + tracing_file << "% Type string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDefineEventType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineEventType %u\n", simgrid::instr::PAJE_DefineEventType); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineEventType " << simgrid::instr::PAJE_DefineEventType << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% ContainerType string\n"); + tracing_file << "% ContainerType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); + tracing_file << "% Type string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDefineLinkType(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineLinkType %u\n", simgrid::instr::PAJE_DefineLinkType); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineLinkType " << simgrid::instr::PAJE_DefineLinkType << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% ContainerType string\n"); - fprintf(tracing_file, "%% SourceContainerType string\n"); - fprintf(tracing_file, "%% DestContainerType string\n"); + tracing_file << "% ContainerType string" << std::endl; + tracing_file << "% SourceContainerType string" << std::endl; + tracing_file << "% DestContainerType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% StartContainerType string\n"); - fprintf(tracing_file, "%% EndContainerType string\n"); + tracing_file << "% Type string" << std::endl; + tracing_file << "% StartContainerType string" << std::endl; + tracing_file << "% EndContainerType string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDefineEntityValue(bool basic) { - fprintf(tracing_file, "%%EventDef PajeDefineEntityValue %u\n", simgrid::instr::PAJE_DefineEntityValue); - fprintf(tracing_file, "%% Alias string\n"); + tracing_file << "%EventDef PajeDefineEntityValue " << simgrid::instr::PAJE_DefineEntityValue << std::endl; + tracing_file << "% Alias string" << std::endl; if (basic){ - fprintf(tracing_file, "%% EntityType string\n"); + tracing_file << "% EntityType string" << std::endl; }else{ - fprintf(tracing_file, "%% Type string\n"); + tracing_file << "% Type string" << std::endl; } - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%% Color color\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Name string" << std::endl; + tracing_file << "% Color color" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeCreateContainer() { - fprintf(tracing_file, "%%EventDef PajeCreateContainer %u\n", simgrid::instr::PAJE_CreateContainer); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Alias string\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeCreateContainer " << simgrid::instr::PAJE_CreateContainer << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Alias string" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeDestroyContainer() { - fprintf(tracing_file, "%%EventDef PajeDestroyContainer %u\n", simgrid::instr::PAJE_DestroyContainer); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Name string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeDestroyContainer " << simgrid::instr::PAJE_DestroyContainer << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Name string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeSetVariable() { - fprintf(tracing_file, "%%EventDef PajeSetVariable %u\n", simgrid::instr::PAJE_SetVariable); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value double\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeSetVariable " << simgrid::instr::PAJE_SetVariable << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value double" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeAddVariable() { - fprintf(tracing_file, "%%EventDef PajeAddVariable %u\n", simgrid::instr::PAJE_AddVariable); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value double\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeAddVariable " << simgrid::instr::PAJE_AddVariable << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value double" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeSubVariable() { - fprintf(tracing_file, "%%EventDef PajeSubVariable %u\n", simgrid::instr::PAJE_SubVariable); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value double\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeSubVariable " << simgrid::instr::PAJE_SubVariable << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value double" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeSetState() { - fprintf(tracing_file, "%%EventDef PajeSetState %u\n", simgrid::instr::PAJE_SetState); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeSetState " << simgrid::instr::PAJE_SetState << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajePushState(int size) { - fprintf(tracing_file, "%%EventDef PajePushState %u\n", simgrid::instr::PAJE_PushState); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value string\n"); - if (size) fprintf(tracing_file, "%% Size int\n"); + tracing_file << "%EventDef PajePushState " << simgrid::instr::PAJE_PushState << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value string" << std::endl; + if (size) + tracing_file << "% Size int" << std::endl; #if HAVE_SMPI if (simgrid::config::get_value("smpi/trace-call-location")) { /** * paje currently (May 2016) uses "Filename" and "Linenumber" as * reserved words. We cannot use them... */ - fprintf(tracing_file, "%% Fname string\n"); - fprintf(tracing_file, "%% Lnumber int\n"); + tracing_file << "% Fname string" << std::endl; + tracing_file << "% Lnumber int" << std::endl; } #endif - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajePopState() { - fprintf(tracing_file, "%%EventDef PajePopState %u\n", simgrid::instr::PAJE_PopState); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajePopState " << simgrid::instr::PAJE_PopState << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeResetState(bool basic) @@ -190,54 +191,55 @@ static void TRACE_header_PajeResetState(bool basic) if (basic) return; - fprintf(tracing_file, "%%EventDef PajeResetState %u\n", simgrid::instr::PAJE_ResetState); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeResetState " << simgrid::instr::PAJE_ResetState << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeStartLink(bool basic, int size) { - fprintf(tracing_file, "%%EventDef PajeStartLink %u\n", simgrid::instr::PAJE_StartLink); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value string\n"); + tracing_file << "%EventDef PajeStartLink " << simgrid::instr::PAJE_StartLink << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value string" << std::endl; if (basic){ - fprintf(tracing_file, "%% SourceContainer string\n"); + tracing_file << "% SourceContainer string" << std::endl; }else{ - fprintf(tracing_file, "%% StartContainer string\n"); + tracing_file << "% StartContainer string" << std::endl; } - fprintf(tracing_file, "%% Key string\n"); - if (size) fprintf(tracing_file, "%% Size int\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Key string" << std::endl; + if (size) + tracing_file << "% Size int" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeEndLink(bool basic) { - fprintf(tracing_file, "%%EventDef PajeEndLink %u\n", simgrid::instr::PAJE_EndLink); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value string\n"); + tracing_file << "%EventDef PajeEndLink " << simgrid::instr::PAJE_EndLink << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value string" << std::endl; if (basic){ - fprintf(tracing_file, "%% DestContainer string\n"); + tracing_file << "% DestContainer string" << std::endl; }else{ - fprintf(tracing_file, "%% EndContainer string\n"); + tracing_file << "% EndContainer string" << std::endl; } - fprintf(tracing_file, "%% Key string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "% Key string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } static void TRACE_header_PajeNewEvent() { - fprintf(tracing_file, "%%EventDef PajeNewEvent %u\n", simgrid::instr::PAJE_NewEvent); - fprintf(tracing_file, "%% Time date\n"); - fprintf(tracing_file, "%% Type string\n"); - fprintf(tracing_file, "%% Container string\n"); - fprintf(tracing_file, "%% Value string\n"); - fprintf(tracing_file, "%%EndEventDef\n"); + tracing_file << "%EventDef PajeNewEvent " << simgrid::instr::PAJE_NewEvent << std::endl; + tracing_file << "% Time date" << std::endl; + tracing_file << "% Type string" << std::endl; + tracing_file << "% Container string" << std::endl; + tracing_file << "% Value string" << std::endl; + tracing_file << "%EndEventDef" << std::endl; } void TRACE_header(bool basic, int size) diff --git a/src/instr/instr_paje_trace.cpp b/src/instr/instr_paje_trace.cpp index 4d55e557b0..3b8d752fe4 100644 --- a/src/instr/instr_paje_trace.cpp +++ b/src/instr/instr_paje_trace.cpp @@ -14,16 +14,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system"); static std::stringstream stream; -FILE *tracing_file = nullptr; +extern std::ofstream tracing_file; std::vector buffer; void buffer_debug(std::vector* buf); void dump_comment(std::string comment) { - if (comment.empty()) - return; - fprintf(tracing_file, "# %s\n", comment.c_str()); + if (not comment.empty()) + tracing_file << "# " << comment << std::endl; } void dump_comment_file(std::string filename) @@ -38,9 +37,9 @@ void dump_comment_file(std::string filename) } while (not fs->eof()) { std::string line; - fprintf (tracing_file, "# "); + tracing_file << "# "; std::getline(*fs, line); - fprintf(tracing_file, "%s", line.c_str()); + tracing_file << line; } fs->close(); } diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index aca269a3ff..952af67936 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -8,7 +8,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_types, instr, "Paje tracing event system (types)"); -extern FILE* tracing_file; +extern std::ofstream tracing_file; namespace simgrid { namespace instr { @@ -141,7 +141,7 @@ void Type::logDefinition(e_event_type event_type) if (isColored()) stream_ << " \"" << color_ << "\""; XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } void Type::logDefinition(simgrid::instr::Type* source, simgrid::instr::Type* dest) @@ -152,7 +152,7 @@ void Type::logDefinition(simgrid::instr::Type* source, simgrid::instr::Type* des stream_ << PAJE_DefineLinkType << " " << get_id() << " " << father_->get_id() << " " << source->get_id(); stream_ << " " << dest->get_id() << " " << get_name(); XBT_DEBUG("Dump %s", stream_.str().c_str()); - fprintf(tracing_file, "%s\n", stream_.str().c_str()); + tracing_file << stream_.str() << std::endl; } Type* Type::byName(std::string name) diff --git a/src/instr/instr_paje_values.cpp b/src/instr/instr_paje_values.cpp index 27ef1e1bbe..f4a2c4d745 100644 --- a/src/instr/instr_paje_values.cpp +++ b/src/instr/instr_paje_values.cpp @@ -7,7 +7,7 @@ #include "src/instr/instr_private.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_paje_values, instr, "Paje tracing event system (values)"); -extern FILE* tracing_file; +extern std::ofstream tracing_file; namespace simgrid { namespace instr { @@ -26,7 +26,7 @@ void EntityValue::print() if (not color_.empty()) stream << " \"" << color_ << "\""; XBT_DEBUG("Dump %s", stream.str().c_str()); - fprintf(tracing_file, "%s\n", stream.str().c_str()); + tracing_file << stream.str() << std::endl; } } diff --git a/src/instr/instr_private.hpp b/src/instr/instr_private.hpp index ce0ed557db..20aa187c61 100644 --- a/src/instr/instr_private.hpp +++ b/src/instr/instr_private.hpp @@ -18,7 +18,9 @@ #include "src/internal_config.h" #include "xbt/graph.h" +#include #include /** std::setprecision **/ +#include #include #include #include -- 2.20.1