Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SIMIX_display_process_status becomes Global::display_all_actor_status
[simgrid.git] / src / instr / instr_paje_trace.cpp
1 /* Copyright (c) 2010-2019. 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 extern std::ofstream tracing_file;
18
19 static std::vector<simgrid::instr::PajeEvent*> buffer;
20
21 void dump_comment(const std::string& comment)
22 {
23   if (not comment.empty())
24     tracing_file << "# " << comment << std::endl;
25 }
26
27 void dump_comment_file(const std::string& filename)
28 {
29   if (filename.empty())
30     return;
31   std::ifstream fs(filename.c_str(), std::ifstream::in);
32
33   if (fs.fail())
34     throw simgrid::TracingError(
35         XBT_THROW_POINT,
36         simgrid::xbt::string_printf("Comment file %s could not be opened for reading.", filename.c_str()));
37
38   while (not fs.eof()) {
39     std::string line;
40     std::getline(fs, line);
41     tracing_file << "# " << line;
42   }
43   fs.close();
44 }
45
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)
49 {
50   if (not TRACE_is_enabled())
51     return;
52   XBT_DEBUG("%s: dump until %f. starts", __func__, TRACE_last_timestamp_to_dump);
53   if (force){
54     for (auto const& event : buffer) {
55       event->print();
56       delete event;
57     }
58     buffer.clear();
59   } else {
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)
64         break;
65       event->print();
66       delete event;
67       ++i;
68     }
69     buffer.erase(buffer.begin(), i);
70   }
71   XBT_DEBUG("%s: ends", __func__);
72 }
73
74 /* internal do the instrumentation module */
75 void simgrid::instr::PajeEvent::insert_into_buffer()
76 {
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_)
83       break;
84   }
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__);
89   else
90     XBT_DEBUG("%s: inserted at pos= %zd from its end", __func__, std::distance(buffer.rbegin(), i));
91   buffer.insert(i.base(), this);
92 }