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 extern std::ofstream tracing_file;
18 std::vector<simgrid::instr::PajeEvent*> buffer;
20 void dump_comment(std::string comment)
22 if (not comment.empty())
23 tracing_file << "# " << comment << std::endl;
26 void dump_comment_file(std::string filename)
30 std::ifstream* fs = new std::ifstream();
31 fs->open(filename.c_str(), std::ifstream::in);
34 THROWF(system_error, 1, "Comment file %s could not be opened for reading.", filename.c_str());
36 while (not fs->eof()) {
39 std::getline(*fs, line);
45 double TRACE_last_timestamp_to_dump = 0;
46 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
47 void TRACE_paje_dump_buffer(bool force)
49 if (not TRACE_is_enabled())
51 XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
53 for (auto const& event : buffer) {
59 std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
60 for (auto const& event : buffer) {
61 double head_timestamp = event->timestamp_;
62 if (head_timestamp > TRACE_last_timestamp_to_dump)
68 buffer.erase(buffer.begin(), i);
70 XBT_DEBUG("%s: ends", __func__);
73 static void buffer_debug(std::vector<simgrid::instr::PajeEvent*>* buf)
75 if (not XBT_LOG_ISENABLED(instr_paje_trace, xbt_log_priority_debug))
77 XBT_DEBUG(">>>>>> Dump the state of the buffer. %zu events", buf->size());
78 for (auto const& event : *buf) {
80 XBT_DEBUG("%p %s", event, event->stream_.str().c_str());
81 event->stream_.str("");
82 event->stream_.clear();
87 /* internal do the instrumentation module */
88 void simgrid::instr::PajeEvent::insert_into_buffer()
90 if (not TRACE_buffer()) {
95 buffer_debug(&buffer);
97 XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size());
98 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
99 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
100 simgrid::instr::PajeEvent* e1 = *i;
101 XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_);
102 if (e1->timestamp_ <= timestamp_)
105 if (i == buffer.rend())
106 XBT_DEBUG("%s: inserted at beginning", __func__);
107 else if (i == buffer.rbegin())
108 XBT_DEBUG("%s: inserted at end", __func__);
110 XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
111 buffer.insert(i.base(), this);
113 buffer_debug(&buffer);