1 /* Copyright (c) 2010-2020. 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_file(const std::string& filename)
25 std::ifstream fs(filename.c_str(), std::ifstream::in);
28 throw simgrid::TracingError(
30 simgrid::xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str()));
32 while (not fs.eof()) {
34 std::getline(fs, line);
35 tracing_file << "# " << line;
40 double TRACE_last_timestamp_to_dump = 0;
41 //dumps the trace file until the timestamp TRACE_last_timestamp_to_dump
42 void TRACE_paje_dump_buffer(bool force)
44 if (not TRACE_is_enabled())
46 XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
48 for (auto const& event : buffer) {
54 std::vector<simgrid::instr::PajeEvent*>::iterator i = buffer.begin();
55 for (auto const& event : buffer) {
56 double head_timestamp = event->timestamp_;
57 if (head_timestamp > TRACE_last_timestamp_to_dump)
63 buffer.erase(buffer.begin(), i);
65 XBT_DEBUG("%s: ends", __func__);
68 /* internal do the instrumentation module */
69 void simgrid::instr::PajeEvent::insert_into_buffer()
71 XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, eventType_, timestamp_, buffer.size());
72 std::vector<simgrid::instr::PajeEvent*>::reverse_iterator i;
73 for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
74 simgrid::instr::PajeEvent* e1 = *i;
75 XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, e1->eventType_, e1->timestamp_);
76 if (e1->timestamp_ <= timestamp_)
79 if (i == buffer.rend())
80 XBT_DEBUG("%s: inserted at beginning", __func__);
81 else if (i == buffer.rbegin())
82 XBT_DEBUG("%s: inserted at end", __func__);
84 XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
85 buffer.insert(i.base(), this);