* under the terms of the license (GNU LGPL) which comes with this package. */
#include "include/xbt/config.hpp"
+#include "simgrid/s4u/Engine.hpp"
#include "src/instr/instr_private.hpp"
#include "surf/surf.hpp"
+#include "xbt/virtu.h" /* sg_cmdline */
+#include <fstream>
#include <string>
#include <vector>
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");
+std::ofstream tracing_file;
+
#define OPT_TRACING_BASIC "tracing/basic"
#define OPT_TRACING_BUFFER "tracing/buffer"
#define OPT_TRACING_CATEGORIZED "tracing/categorized"
simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje;
-void TRACE_start()
+static void TRACE_start()
{
if (trace_active)
return;
XBT_DEBUG("Tracing starts");
/* init the tracing module to generate the right output */
-
- /* open the trace file(s) */
std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
XBT_DEBUG("Tracing format %s", format.c_str());
+
+ /* open the trace file(s) */
+ std::string filename = TRACE_get_filename();
+ 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());
+ }
+
+ XBT_DEBUG("Filename %s is open for writing", filename.c_str());
+
if (format == "Paje") {
- TRACE_paje_start();
- } else if (format == "TI") {
- simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
- TRACE_TI_start();
- }else{
- xbt_die("Unknown trace format :%s ", format.c_str());
+ /* output generator version */
+ 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) {
+ tracing_file << str << " ";
+ }
+ tracing_file << "]" << std::endl;
}
+ /* output one line comment */
+ dump_comment(TRACE_get_comment());
+
+ /* output comment file */
+ dump_comment_file(TRACE_get_comment_file());
+
+ if (format == "Paje") {
+ /* output Pajé header */
+ TRACE_header(TRACE_basic(), TRACE_display_sizes());
+ } else
+ simgrid::instr::trace_format = simgrid::instr::TraceFormat::Ti;
+
trace_active = true;
XBT_DEBUG("Tracing is on");
}
}
-void TRACE_end()
+static void TRACE_end()
{
if (not trace_active)
return;
delete root_type;
/* close the trace files */
- std::string format = simgrid::config::get_value<std::string>(OPT_TRACING_FORMAT);
- XBT_DEBUG("Tracing format %s\n", format.c_str());
- if (format == "Paje") {
- TRACE_paje_end();
- } else if (format == "TI") {
- TRACE_TI_end();
- } else {
- xbt_die("Unknown trace format :%s ", format.c_str());
- }
+ tracing_file.close();
+ XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
/* de-activate trace */
trace_active = false;
return;
is_initialised = true;
+
/* name of the tracefile */
simgrid::config::declare_flag<std::string>(OPT_TRACING_FILENAME, "Trace file created by the instrumented SimGrid.",
"simgrid.trace");
simgrid::config::declare_flag<int>(OPT_TRACING_PRECISION, "Numerical precision used when timestamping events "
"(expressed in number of digits after decimal point)",
6);
+
+ /* Connect callbacks */
+ simgrid::s4u::on_platform_creation.connect(TRACE_start);
+ simgrid::s4u::on_deadlock.connect(TRACE_end);
+ simgrid::s4u::on_simulation_end.connect(TRACE_end);
}
static void print_line (const char *option, const char *desc, const char *longdesc, int detailed)