Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid into CRTP
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2019. 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 #include "src/surf/surf_interface.hpp"
10
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_events, instr, "Paje tracing event system (events)");
12 extern std::ofstream tracing_file;
13 extern std::map<container_t, std::ofstream*> tracing_files; // TI specific
14
15 namespace simgrid {
16 namespace instr {
17
18 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType)
19     : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
20 {
21   XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __func__, eventType_, TRACE_precision(), timestamp_);
22   if (trace_format == simgrid::instr::TraceFormat::Paje) {
23     stream_ << std::fixed << std::setprecision(TRACE_precision());
24     stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
25   }
26   insert_into_buffer();
27 };
28
29 void PajeEvent::print()
30 {
31   if (trace_format != simgrid::instr::TraceFormat::Paje)
32     return;
33
34   XBT_DEBUG("Dump %s", stream_.str().c_str());
35   tracing_file << stream_.str() << std::endl;
36 }
37
38 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
39     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
40 {
41 #if HAVE_SMPI
42   if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
43     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
44     filename                        = loc->filename;
45     linenumber                      = loc->linenumber;
46   }
47 #endif
48 }
49
50 void NewEvent::print()
51 {
52   if (trace_format != simgrid::instr::TraceFormat::Paje)
53     return;
54
55   stream_ << " " << value->get_id();
56
57   XBT_DEBUG("Dump %s", stream_.str().c_str());
58   tracing_file << stream_.str() << std::endl;
59 }
60
61 void LinkEvent::print()
62 {
63   if (trace_format != simgrid::instr::TraceFormat::Paje)
64     return;
65
66   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
67
68   if (TRACE_display_sizes() && size_ != -1)
69     stream_ << " " << size_;
70
71   XBT_DEBUG("Dump %s", stream_.str().c_str());
72   tracing_file << stream_.str() << std::endl;
73 }
74
75 void VariableEvent::print()
76 {
77   if (trace_format != simgrid::instr::TraceFormat::Paje)
78     return;
79
80   stream_ << " " << value_;
81
82   XBT_DEBUG("Dump %s", stream_.str().c_str());
83   tracing_file << stream_.str() << std::endl;
84 }
85
86 StateEvent::~StateEvent(){
87   delete extra_;
88 }
89
90 void StateEvent::print()
91 {
92   if (trace_format == simgrid::instr::TraceFormat::Paje) {
93
94     if (value != nullptr) // PAJE_PopState Event does not need to have a value
95       stream_ << " " << value->get_id();
96
97     if (TRACE_display_sizes())
98       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : "");
99
100 #if HAVE_SMPI
101     if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
102       stream_ << " \"" << filename << "\" " << linenumber;
103     }
104 #endif
105     XBT_DEBUG("Dump %s", stream_.str().c_str());
106     tracing_file << stream_.str() << std::endl;
107   } else if (trace_format == simgrid::instr::TraceFormat::Ti) {
108     if (extra_ == nullptr)
109       return;
110
111     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
112
113     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
114     if (get_container()->get_name().find("rank-") != 0) {
115       stream_ << get_container()->get_name() << " " << extra_->print();
116     } else {
117       /* Subtract -1 because this is the process id and we transform it to the rank id */
118       std::string container_name(get_container()->get_name());
119       stream_ << stoi(container_name.erase(0, 5)) - 1 << " " << extra_->print();
120     }
121     *tracing_files.at(get_container()) << stream_.str() << std::endl;
122   } else {
123     THROW_IMPOSSIBLE;
124   }
125
126 }
127 }
128 }