Logo AND Algorithmique Numérique Distribuée

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