1 /* Copyright (c) 2010-2018. 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 static std::stringstream stream;
17 extern std::ofstream tracing_file;
19 std::vector<simgrid::instr::PajeEvent*> buffer;
20 void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf);
22 void dump_comment(std::string comment)
24 if (not comment.empty())
25 tracing_file << "# " << comment << std::endl;
28 void dump_comment_file(std::string filename)
32 std::ifstream* fs = new std::ifstream();
33 fs->open(filename.c_str(), std::ifstream::in);
36 THROWF(system_error, 1, "Comment file %s could not be opened for reading.", filename.c_str());
38 while (not fs->eof()) {
41 std::getline(*fs, line);
47 double TRACE_last_timestamp_to_dump = 0;
48 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
49 void TRACE_paje_dump_buffer(bool force)
51 if (not TRACE_is_enabled())
53 XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
55 for (auto const& event : buffer) {
61 std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
62 for (auto const& event : buffer) {
63 double head_timestamp = event->timestamp_;
64 if (head_timestamp > TRACE_last_timestamp_to_dump)
70 buffer.erase(buffer.begin(), i);
72 XBT_DEBUG("%s: ends", __func__);
75 void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf)
77 if (not XBT_LOG_ISENABLED(instr_paje_trace, xbt_log_priority_debug))
79 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
80 for (auto const& event : *buf) {
82 XBT_DEBUG("%p %s", event, stream.str().c_str());
89 /* internal do the instrumentation module */
90 void simgrid::instr::PajeEvent::insertIntoBuffer()
92 if (not TRACE_buffer()) {
97 buffer_debug(&buffer);
99 XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size());
100 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
101 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
102 simgrid::instr::PajeEvent* e1 = *i;
103 XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_);
104 if (e1->timestamp_ <= timestamp_)
107 if (i == buffer.rend())
108 XBT_DEBUG("%s: inserted at beginning", __func__);
109 else if (i == buffer.rbegin())
110 XBT_DEBUG("%s: inserted at end", __func__);
112 XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
113 buffer.insert(i.base(), this);
115 buffer_debug(&buffer);