Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
22faeb5d1ae7b6d4a6c8dcfbcce7d699fec20990
[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 #include "src/surf/surf_interface.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 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 (instr_fmt_type == instr_fmt_paje) {
23     stream_ << std::fixed << std::setprecision(TRACE_precision());
24     stream_ << eventType_ << " " << timestamp_ << " " << type_->get_id() << " " << container_->get_id();
25   }
26   insertIntoBuffer();
27 };
28
29 StateEvent::StateEvent(Container* container, Type* type, e_event_type event_type, EntityValue* value, TIData* extra)
30     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
31 {
32 #if HAVE_SMPI
33   if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
34     smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
35     filename                        = loc->filename;
36     linenumber                      = loc->linenumber;
37   }
38 #endif
39 }
40
41 void NewEvent::print()
42 {
43   if (instr_fmt_type != instr_fmt_paje)
44     return;
45
46   stream_ << " " << value->getId();
47
48   XBT_DEBUG("Dump %s", stream_.str().c_str());
49   fprintf(tracing_file, "%s\n", stream_.str().c_str());
50 }
51
52 void LinkEvent::print()
53 {
54   if (instr_fmt_type != instr_fmt_paje)
55     return;
56
57   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
58
59   if (TRACE_display_sizes())
60     stream_ << " " << size_;
61
62   XBT_DEBUG("Dump %s", stream_.str().c_str());
63   fprintf(tracing_file, "%s\n", stream_.str().c_str());
64 }
65
66 void VariableEvent::print()
67 {
68   if (instr_fmt_type != instr_fmt_paje)
69     return;
70
71   stream_ << " " << value;
72
73   XBT_DEBUG("Dump %s", stream_.str().c_str());
74   fprintf(tracing_file, "%s\n", stream_.str().c_str());
75 }
76
77 void StateEvent::print()
78 {
79   if (instr_fmt_type == instr_fmt_paje) {
80
81     if (value != nullptr) // PAJE_PopState Event does not need to have a value
82       stream_ << " " << value->getId();
83
84     if (TRACE_display_sizes())
85       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : 0);
86
87 #if HAVE_SMPI
88     if (xbt_cfg_get_boolean("smpi/trace-call-location")) {
89       stream_ << " \"" << filename << "\" " << linenumber;
90     }
91 #endif
92     XBT_DEBUG("Dump %s", stream_.str().c_str());
93     fprintf(tracing_file, "%s\n", stream_.str().c_str());
94   } else if (instr_fmt_type == instr_fmt_TI) {
95     if (extra_ == nullptr)
96       return;
97
98     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
99
100     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
101     if (getContainer()->get_name().find("rank-") != 0)
102       stream_ << getContainer()->get_name() << " " << extra_->print();
103     else
104       /* Subtract -1 because this is the process id and we transform it to the rank id */
105       stream_ << stoi(getContainer()->get_name().erase(0, 5)) - 1 << " " << extra_->print();
106
107     fprintf(tracing_files.at(getContainer()), "%s\n", stream_.str().c_str());
108   } else {
109     THROW_IMPOSSIBLE;
110   }
111
112   delete extra_;
113 }
114 }
115 }