* 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 <string>
simgrid::instr::TraceFormat simgrid::instr::trace_format = simgrid::instr::TraceFormat::Paje;
-int TRACE_start()
+static void TRACE_start()
{
+ if (trace_active)
+ return;
+
// tracing system must be:
// - enabled (with --cfg=tracing:yes)
// - already configured (TRACE_global_init already called)
if (TRACE_is_enabled()) {
- instr_routing_define_callbacks();
+ instr_define_callbacks();
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\n", format.c_str());
+ XBT_DEBUG("Tracing format %s", format.c_str());
if (format == "Paje") {
TRACE_paje_start();
} else if (format == "TI") {
xbt_die("Unknown trace format :%s ", format.c_str());
}
- /* activate trace */
- if (trace_active) {
- THROWF(tracing_error, 0, "Tracing is already active");
- }
trace_active = true;
XBT_DEBUG("Tracing is on");
}
- return 0;
}
-int TRACE_end()
+static void TRACE_end()
{
- int retval;
- if (not trace_active) {
- retval = 1;
- } else {
- retval = 0;
-
- /* dump trace buffer */
- TRACE_last_timestamp_to_dump = surf_get_clock();
- TRACE_paje_dump_buffer(true);
-
- simgrid::instr::Type* root_type = simgrid::instr::Container::getRoot()->type_;
- /* destroy all data structures of tracing (and free) */
- delete simgrid::instr::Container::getRoot();
- 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());
- }
+ if (not trace_active)
+ return;
- /* de-activate trace */
- trace_active = false;
- XBT_DEBUG("Tracing is off");
- XBT_DEBUG("Tracing system is shutdown");
+ /* dump trace buffer */
+ TRACE_last_timestamp_to_dump = surf_get_clock();
+ TRACE_paje_dump_buffer(true);
+
+ simgrid::instr::Type* root_type = simgrid::instr::Container::getRoot()->type_;
+ /* destroy all data structures of tracing (and free) */
+ delete simgrid::instr::Container::getRoot();
+ 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());
}
- return retval;
+
+ /* de-activate trace */
+ trace_active = false;
+ XBT_DEBUG("Tracing is off");
+ XBT_DEBUG("Tracing system is shutdown");
}
bool TRACE_needs_platform ()
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_config_in_platform_done.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)