Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:simgrid/simgrid into dev_7
[simgrid.git] / src / instr / instr_paje_events.cpp
1 /* Copyright (c) 2012-2020. 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
13 namespace simgrid {
14 namespace instr {
15
16 PajeEvent::PajeEvent(Container* container, Type* type, double timestamp, PajeEventType eventType)
17     : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType)
18 {
19   on_creation(*this);
20   insert_into_buffer();
21 }
22
23 PajeEvent::~PajeEvent()
24 {
25   on_destruction(*this);
26 }
27
28 StateEvent::StateEvent(Container* container, Type* type, PajeEventType event_type, EntityValue* value, TIData* extra)
29     : PajeEvent::PajeEvent(container, type, SIMIX_get_clock(), event_type), value(value), extra_(extra)
30 {
31 #if HAVE_SMPI
32   if (simgrid::config::get_value<bool>("smpi/trace-call-location")) {
33     const smpi_trace_call_location_t* loc = smpi_trace_get_call_location();
34     filename                        = loc->filename;
35     linenumber                      = loc->linenumber;
36   }
37 #endif
38 }
39
40 void NewEvent::print()
41 {
42   stream_ << " " << value->get_id();
43 }
44
45 void LinkEvent::print()
46 {
47   stream_ << " " << value_ << " " << endpoint_->get_id() << " " << key_;
48
49   if (TRACE_display_sizes() && size_ != -1)
50     stream_ << " " << size_;
51 }
52
53 void StateEvent::print()
54 {
55   if (trace_format == TraceFormat::Paje) {
56     if (value != nullptr) // PajeEventType::PopState Event does not need to have a value
57       stream_ << " " << value->get_id();
58
59     if (TRACE_display_sizes())
60       stream_ << " " << ((extra_ != nullptr) ? extra_->display_size() : "");
61
62 #if HAVE_SMPI
63     if (simgrid::config::get_value<bool>("smpi/trace-call-location"))
64       stream_ << " \"" << filename << "\" " << linenumber;
65 #endif
66   } else if (trace_format == TraceFormat::Ti) {
67     if (extra_ == nullptr)
68       return;
69
70     /* Unimplemented calls are: WAITANY, SENDRECV, SCAN, EXSCAN, SSEND, and ISSEND. */
71     std::string container_name(get_container()->get_name());
72     // FIXME: dirty extract "rank-" from the name, as we want the bare process id here
73     if (get_container()->get_name().find("rank-") == 0) {
74       /* Subtract -1 because this is the process id and we transform it to the rank id */
75       container_name=std::to_string(stoi(container_name.erase(0, 5)) - 1);
76     }
77 #if HAVE_SMPI
78     if (config::get_value<bool>("smpi/trace-call-location"))
79       stream_ << container_name << " location " << filename << " " << linenumber << std::endl ;
80 #endif
81     stream_ << container_name << " " << extra_->print();
82   } else {
83     THROW_IMPOSSIBLE;
84   }
85 }
86 } // namespace instr
87 } // namespace simgrid