Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / instr / instr_paje_trace.cpp
1 /* Copyright (c) 2010-2023. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
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"
12 #include <fstream>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(instr_paje_trace, instr, "tracing event system");
15
16 namespace simgrid::instr {
17 static std::vector<PajeEvent*> buffer;
18
19 double last_timestamp_to_dump = 0;
20 // dumps the trace file until the last_timestamp_to_dump
21 void dump_buffer(bool force)
22 {
23   if (not TRACE_is_enabled())
24     return;
25   XBT_DEBUG("%s: dump until %f. starts", __func__, last_timestamp_to_dump);
26   if (force || (trace_format == TraceFormat::Ti)){
27     for (auto const& event : buffer) {
28       event->print();
29       delete event;
30     }
31     buffer.clear();
32   } else {
33     auto i = buffer.begin();
34     for (auto const& event : buffer) {
35       if (event->timestamp_ > last_timestamp_to_dump)
36         break;
37       event->print();
38       delete event;
39       ++i;
40     }
41     buffer.erase(buffer.begin(), i);
42   }
43   XBT_DEBUG("%s: ends", __func__);
44 }
45
46 /* internal do the instrumentation module */
47 void PajeEvent::insert_into_buffer()
48 {
49   XBT_DEBUG("%s: insert event_type=%u, timestamp=%f, buffersize=%zu)", __func__, static_cast<unsigned>(eventType_),
50             timestamp_, buffer.size());
51   std::vector<PajeEvent*>::reverse_iterator i;
52   for (i = buffer.rbegin(); i != buffer.rend(); ++i) {
53     PajeEvent* e1 = *i;
54     XBT_DEBUG("compare to %p is of type %u; timestamp:%f", e1, static_cast<unsigned>(e1->eventType_), e1->timestamp_);
55     if (e1->timestamp_ <= timestamp_)
56       break;
57   }
58   if (i == buffer.rend())
59     XBT_DEBUG("%s: inserted at beginning", __func__);
60   else if (i == buffer.rbegin())
61     XBT_DEBUG("%s: inserted at end", __func__);
62   else
63     XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
64   buffer.insert(i.base(), this);
65 }
66
67 } // namespace simgrid::instr