ATLAS Offline Software
Loading...
Searching...
No Matches
DebugInfoCollector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <sstream>
7#include <fstream>
8#include <cmath>
9
11 bool byTime):
12 m_name(name),
13 m_byTime(byTime),
14 m_timer(false) // false: units are us
15{
16 m_timer.start();
17}
18
20
21void DebugInfoCollector::collect(const std::string& key,
22 const std::string& info){
23 m_info[key].emplace_back(m_timer.elapsed_to_now(), info);
24}
25
27 /* print out messages in msg key order */
28
29 std::stringstream ss;
30 ss << "DEBUGInfoCollector: "
31 << m_name << " no of msgs: " << m_info.size() << "\n\n";
32
33 std::size_t msg_i {0};
34 for(const auto& i: m_info){
35 ss << "msg " << msg_i << ": " << i.first << '\n';
36 ++msg_i;
37 for(const auto& m : i.second){
38 // msg time followe by msg
39 ss << int(m.first) << " " << m.second << '\n';}
40 }
41 return ss.str();
42}
43
45 /* print out messages in time order */
46
47 std::map<unsigned long, std::string> by_time;
48
49 for(const auto& p : m_info){
50 for(const auto& tm : p.second){
51 // tm.first = time from vector of (time, msg)
52 // p.first = msg key
53 // tm.second = msg at time tm.first
54
55 auto timestamp = static_cast<unsigned long>(tm.first);
56 by_time[timestamp] = p.first + " " + tm.second;
57 }
58 }
59
60 std::stringstream ss;
61 ss << "DEBUGInfoCollector: "
62 << m_name << " no of msgs: " << m_info.size() << "\n\n";
63
64 for(const auto& i: by_time){
65 ss << i.first << " " << i.second << '\n';
66 }
67 return ss.str();
68}
69
70std::string DebugInfoCollector::toString() const {
72}
73
74
76 auto report = this->toString();
77 std::ofstream out(m_name+".log");
78 out << report;
79 out.close();
80}
81
static Double_t ss
virtual void collect(const std::string &, const std::string &) override
std::map< std::string, std::vector< std::pair< double, std::string > > > m_info
DebugInfoCollector(const std::string &name="Unknown", bool byTime=true)
virtual std::string toString() const override
std::string toStringByMsgKey() const
std::string toStringByTime() const
virtual void write() const override