Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to compile when SMPI is compiled out
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "src/instr/instr_private.hpp"
8 #include "src/instr/instr_smpi.hpp"
9 #include "src/smpi/include/private.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12 extern FILE* tracing_file;
13 std::map<container_t, FILE*> tracing_files; // TI specific
14
15 namespace simgrid {
16 namespace instr {
17
18 NewEvent::NewEvent(double timestamp, container_t container, Type* type, EntityValue* val)
19     : simgrid::instr::PajeEvent::PajeEvent(container, type, timestamp, PAJE_NewEvent), val(val)
20 {
21   XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
22   insertIntoBuffer();
23 }
24
25 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
26                      std::string value, std::string key)
27     : LinkEvent(container, type, event_type, endpoint, value, key, -1)
28 {
29 }
30
31 LinkEvent::LinkEvent(container_t container, Type* type, e_event_type event_type, container_t endpoint,
32                      std::string value, std::string key, int size)
33     : PajeEvent(container, type, SIMIX_get_clock(), event_type)
34     , endpoint_(endpoint)
35     , value_(value)
36     , key_(key)
37     , size_(size)
38 {
39   XBT_DEBUG("%s: event_type=%u, timestamp=%f, value:%s", __FUNCTION__, eventType_, timestamp_, value_.c_str());
40   insertIntoBuffer();
41 }
42
43 VariableEvent::VariableEvent(double timestamp, Container* container, Type* type, e_event_type event_type, double value)
44     : PajeEvent::PajeEvent(container, type, timestamp, event_type), value(value)
45 {
46   XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
47   insertIntoBuffer();
48 }
49
50 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value)
51     : StateEvent(container, type, event_type, value, nullptr)
52 {
53 }
54
55 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
56     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
57 {
58 #if HAVE_SMPI
59   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
60     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
61     filename                        = loc->filename;
62     linenumber                      = loc->linenumber;
63   }
64 #else
65   filename   = "(null)";
66   linenumber = -1;
67 #endif
68
69   XBT_DEBUG("%s: event_type=%u, timestamp=%f", __FUNCTION__, eventType_, timestamp_);
70   insertIntoBuffer();
71 };
72
73 void NewEvent::print()
74 {
75   std::stringstream stream;
76   stream << std::fixed << std::setprecision(TRACE_precision());
77   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
78   if (instr_fmt_type != instr_fmt_paje)
79     return;
80
81   if (timestamp_ < 1e-12)
82     stream << eventType_ << " " << 0 << " ";
83   else
84     stream << eventType_ << " " << timestamp_ << " ";
85   stream << getType()->getId() << " " << getContainer()->getId() << " " << val->getId();
86   XBT_DEBUG("Dump %s", stream.str().c_str());
87   fprintf(tracing_file, "%s\n", stream.str().c_str());
88 }
89
90 void LinkEvent::print()
91 {
92   std::stringstream stream;
93   stream << std::fixed << std::setprecision(TRACE_precision());
94   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
95   if (instr_fmt_type != instr_fmt_paje)
96     return;
97   if (timestamp_ < 1e-12)
98     stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
99   else
100     stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
101
102   stream << " " << value_ << " " << endpoint_->getId() << " " << key_;
103
104   if (TRACE_display_sizes()) {
105     stream << " " << size_;
106   }
107   XBT_DEBUG("Dump %s", stream.str().c_str());
108   fprintf(tracing_file, "%s\n", stream.str().c_str());
109 }
110
111 void VariableEvent::print()
112 {
113   std::stringstream stream;
114   stream << std::fixed << std::setprecision(TRACE_precision());
115   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
116   if (instr_fmt_type != instr_fmt_paje)
117     return;
118
119   if (timestamp_ < 1e-12)
120     stream << eventType_ << " " << 0 << " ";
121   else
122     stream << eventType_ << " " << timestamp_ << " ";
123   stream << getType()->getId() << " " << getContainer()->getId() << " " << value;
124   XBT_DEBUG("Dump %s", stream.str().c_str());
125   fprintf(tracing_file, "%s\n", stream.str().c_str());
126 }
127
128 void StateEvent::print()
129 {
130   std::stringstream stream;
131   stream << std::fixed << std::setprecision(TRACE_precision());
132   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_);
133   if (instr_fmt_type == instr_fmt_paje) {
134     if (timestamp_ < 1e-12)
135       stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId();
136     else
137       stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId();
138
139     if (value != nullptr) // PAJE_PopState Event does not need to have a value
140       stream << " " << value->getId();
141
142     if (TRACE_display_sizes())
143       stream << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
144
145 #if HAVE_SMPI
146     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
147       stream << " \"" << filename << "\" " << linenumber;
148     }
149 #endif
150     XBT_DEBUG("Dump %s", stream.str().c_str());
151     fprintf(tracing_file, "%s\n", stream.str().c_str());
152   } else if (instr_fmt_type == instr_fmt_TI) {
153     if (extra_ == nullptr)
154       return;
155
156     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
157
158     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
159     if (getContainer()->getName().find("rank-") != 0)
160       stream << getContainer()->getName() << " " << extra_->print();
161     else
162       /* Subtract -1 because this is the process id and we transform it to the rank id */
163       stream << stoi(getContainer()->getName().erase(0, 5)) - 1 << " " << extra_->print();
164
165     fprintf(tracing_files.at(getContainer()), "%s\n", stream.str().c_str());
166   } else {
167     THROW_IMPOSSIBLE;
168   }
169
170   delete extra_;
171 }
172 }
173 }