1 /* Copyright (c) 2010-2019. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "simgrid/sg_config.hpp"
8 #include "src/instr/instr_private.hpp"
9 #include "src/instr/instr_smpi.hpp"
10 #include "src/smpi/include/private.hpp"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
16 extern std::ofstream tracing_file;
18 static std::vector<simgrid::instr::PajeEvent*> buffer;
20 void dump_comment(const std::string& comment)
22 if (not comment.empty())
23 tracing_file << "# " << comment << std::endl;
26 void dump_comment_file(const std::string& filename)
30 std::ifstream fs(filename.c_str(), std::ifstream::in);
33 THROWF(system_error, 1, "Comment file %s could not be opened for reading.", filename.c_str());
35 while (not fs.eof()) {
37 std::getline(fs, line);
38 tracing_file << "# " << line;
43 double TRACE_last_timestamp_to_dump = 0;
44 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
45 void TRACE_paje_dump_buffer(bool force)
47 if (not TRACE_is_enabled())
49 XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
51 for (auto const& event : buffer) {
57 std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
58 for (auto const& event : buffer) {
59 double head_timestamp = event->timestamp_;
60 if (head_timestamp > TRACE_last_timestamp_to_dump)
66 buffer.erase(buffer.begin(), i);
68 XBT_DEBUG("%s: ends", __func__);
71 static void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf)
73 if (not XBT_LOG_ISENABLED(instr_paje_trace, xbt_log_priority_debug))
75 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
76 for (auto const& event : *buf) {
78 XBT_DEBUG("%p %s", event, event->stream_.str().c_str());
79 event->stream_.str("");
80 event->stream_.clear();
85 /* internal do the instrumentation module */
86 void simgrid::instr::PajeEvent::insert_into_buffer()
88 buffer_debug(&buffer);
90 XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size());
91 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
92 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
93 simgrid::instr::PajeEvent* e1 = *i;
94 XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_);
95 if (e1->timestamp_ <= timestamp_)
98 if (i == buffer.rend())
99 XBT_DEBUG("%s: inserted at beginning", __func__);
100 else if (i == buffer.rbegin())
101 XBT_DEBUG("%s: inserted at end", __func__);
103 XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
104 buffer.insert(i.base(), this);
106 buffer_debug(&buffer);