Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename simgrid::config::get_config -> simgrid::config::get_value.
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <xbt/config.hpp>
7
8 #include "src/instr/instr_private.hpp"
9 #include "src/instr/instr_smpi.hpp"
10 #include "src/smpi/include/private.hpp"
11 #include "src/surf/surf_interface.hpp"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
14 extern FILE* tracing_file;
15 std::map<container_t, FILE*> tracing_files; // TI specific
16
17 namespace simgrid {
18 namespace instr {
19
20 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
21     : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
22 {
23   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
24   if (trace_format == simgrid::instr::TraceFormat::Paje) {
25     stream_ << std::fixed << std::setprecision(TRACE_precision());
26     stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
27   }
28   insertIntoBuffer();
29 };
30
31 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
32     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
33 {
34 #if HAVE_SMPI
35   if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
36     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
37     filename                        = loc->filename;
38     linenumber                      = loc->linenumber;
39   }
40 #endif
41 }
42
43 void NewEvent::print()
44 {
45   if (trace_format != simgrid::instr::TraceFormat::Paje)
46     return;
47
48   stream_ << " " << value->getId();
49
50   XBT_DEBUG("Dump %s", stream_.str().c_str());
51   fprintf(tracing_file, "%s\n", stream_.str().c_str());
52 }
53
54 void LinkEvent::print()
55 {
56   if (trace_format != simgrid::instr::TraceFormat::Paje)
57     return;
58
59   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
60
61   if (TRACE_display_sizes())
62     stream_ << " " << size_;
63
64   XBT_DEBUG("Dump %s", stream_.str().c_str());
65   fprintf(tracing_file, "%s\n", stream_.str().c_str());
66 }
67
68 void VariableEvent::print()
69 {
70   if (trace_format != simgrid::instr::TraceFormat::Paje)
71     return;
72
73   stream_ << " " << value;
74
75   XBT_DEBUG("Dump %s", stream_.str().c_str());
76   fprintf(tracing_file, "%s\n", stream_.str().c_str());
77 }
78
79 void StateEvent::print()
80 {
81   if (trace_format == simgrid::instr::TraceFormat::Paje) {
82
83     if (value != nullptr) // PAJE_PopState Event does not need to have a value
84       stream_ << " " << value->getId();
85
86     if (TRACE_display_sizes())
87       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
88
89 #if HAVE_SMPI
90     if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
91       stream_ << " \"" << filename << "\" " << linenumber;
92     }
93 #endif
94     XBT_DEBUG("Dump %s", stream_.str().c_str());
95     fprintf(tracing_file, "%s\n", stream_.str().c_str());
96   } else if (trace_format == simgrid::instr::TraceFormat::Ti) {
97     if (extra_ == nullptr)
98       return;
99
100     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
101
102     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
103     if (getContainer()->get_name().find("rank-") != 0)
104       stream_ << getContainer()->get_name() << " " << extra_->print();
105     else
106       /* Subtract -1 because this is the process id and we transform it to the rank id */
107       stream_ << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
108
109     fprintf(tracing_files.at(getContainer()), "%s\n", stream_.str().c_str());
110   } else {
111     THROW_IMPOSSIBLE;
112   }
113
114   delete extra_;
115 }
116 }
117 }