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/Exception.hpp"
8 #include "simgrid/sg_config.hpp"
9 #include "src/instr/instr_private.hpp"
10 #include "src/instr/instr_smpi.hpp"
11 #include "src/smpi/include/private.hpp"
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
17 extern std::ofstream tracing_file;
19 static std::vector<simgrid::instr::PajeEvent*> buffer;
21 void dump_comment(const std::string& comment)
23 if (not comment.empty())
24 tracing_file << "# " << comment << std::endl;
27 void dump_comment_file(const std::string& filename)
31 std::ifstream fs(filename.c_str(), std::ifstream::in);
34 throw simgrid::TracingError(
36 simgrid::xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str()));
38 while (not fs.eof()) {
40 std::getline(fs, line);
41 tracing_file << "# " << line;
46 double TRACE_last_timestamp_to_dump = 0;
47 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
48 void TRACE_paje_dump_buffer(bool force)
50 if (not TRACE_is_enabled())
52 XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
54 for (auto const& event : buffer) {
60 std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
61 for (auto const& event : buffer) {
62 double head_timestamp = event->timestamp_;
63 if (head_timestamp > TRACE_last_timestamp_to_dump)
69 buffer.erase(buffer.begin(), i);
71 XBT_DEBUG("%s: ends", __func__);
74 /* internal do the instrumentation module */
75 void simgrid::instr::PajeEvent::insert_into_buffer()
77 XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size());
78 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
79 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
80 simgrid::instr::PajeEvent* e1 = *i;
81 XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_);
82 if (e1->timestamp_ <= timestamp_)
85 if (i == buffer.rend())
86 XBT_DEBUG("%s: inserted at beginning", __func__);
87 else if (i == buffer.rbegin())
88 XBT_DEBUG("%s: inserted at end", __func__);
90 XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
91 buffer.insert(i.base(), this);