Cadabra
Computer algebra system for field theory problems
ProgressMonitor.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <string>
5 #include <chrono>
6 #include <stack>
7 #include <map>
8 #include <vector>
9 
15 
17  public:
19  virtual ~ProgressMonitor();
20 
27 
28  void group(std::string name="");
29 
34 
35  void progress(int n, int total);
36 
38 
39  void message(const std::string&);
40 
42 
43  void print() const;
44 
45 
48 
49  class Total {
50  public:
51  Total();
52 
53  std::string name;
54  size_t call_count;
55  std::chrono::milliseconds time_spent;
57  std::vector<std::string> messages;
58 
59  long time_spent_as_long() const;
60 
61  bool operator==(const Total& other) const;
62 
63  std::string str() const;
64  };
65 
66  std::vector<Total> totals() const;
67 
68  private:
69 
77 
78  class Block {
79  public:
80  Block();
81 
82  std::string name;
83  std::chrono::milliseconds started;
85  std::vector<std::string> messages;
86  };
87 
88  std::stack<Block> call_stack;
89  std::map<std::string, Total> call_totals;
90  };
91 
92 
std::chrono::milliseconds time_spent
Definition: ProgressMonitor.hh:55
size_t call_count
Definition: ProgressMonitor.hh:54
virtual ~ProgressMonitor()
Definition: ProgressMonitor.cc:10
ProgressMonitor()
Definition: ProgressMonitor.cc:6
int total_steps
Definition: ProgressMonitor.hh:56
std::vector< Total > totals() const
Definition: ProgressMonitor.cc:100
std::stack< Block > call_stack
Definition: ProgressMonitor.hh:88
std::string name
Definition: ProgressMonitor.hh:82
std::vector< std::string > messages
Definition: ProgressMonitor.hh:85
Object keeping track of time spent in nested execution blocks, and keeping track of out-of-band messa...
Definition: ProgressMonitor.hh:16
std::map< std::string, Total > call_totals
Definition: ProgressMonitor.hh:89
Object to accumulate total time and call counts for a particular named execution group.
Definition: ProgressMonitor.hh:49
void print() const
Generate debug output on cerr.
Definition: ProgressMonitor.cc:87
int total_steps
Definition: ProgressMonitor.hh:84
void progress(int n, int total)
Set the progress of the current top-level block to be n out of total steps.
Definition: ProgressMonitor.cc:71
std::vector< std::string > messages
Definition: ProgressMonitor.hh:57
std::string str() const
Definition: ProgressMonitor.cc:25
Total()
Definition: ProgressMonitor.cc:20
Block()
Definition: ProgressMonitor.cc:14
int step
Definition: ProgressMonitor.hh:84
long time_spent_as_long() const
Definition: ProgressMonitor.cc:82
void group(std::string name="")
Start a new named group, or close the innermost one in case the name argument is empty.
Definition: ProgressMonitor.cc:36
void message(const std::string &)
Log out-of-band messages to the current block.
Definition: ProgressMonitor.cc:77
bool operator==(const Total &other) const
Definition: ProgressMonitor.cc:109
A single element of the nested group call stack.
Definition: ProgressMonitor.hh:78
std::string name
Definition: ProgressMonitor.hh:53
std::chrono::milliseconds started
Definition: ProgressMonitor.hh:83