Logo AND Algorithmique Numérique Distribuée

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