Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
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#include <functional>
10
16
18 public:
19 ProgressMonitor(std::function<void(const std::string&, int, int)> report = nullptr, int report_level = 2);
20 virtual ~ProgressMonitor();
21
28 void group(std::string name = "", int total = 0, int level = -1);
29
34 void progress(); // Increment current step by 1
35 void progress(int n);
36 void progress(int n, int total);
37
39
40 void message(const std::string&);
41
43
44 void print() const;
45
47 std::function<void(const std::string&, int, int)> report;
48
49 // Level above which to report progress updates and not only add to totals
51
54
55 class Total {
56 public:
57 Total();
58
59 std::string name;
60 size_t call_count;
61 std::chrono::milliseconds time_spent;
63 std::vector<std::string> messages;
64
65 long time_spent_as_long() const;
66
67 bool operator==(const Total& other) const;
68
69 std::string str() const;
70 };
71
72 std::vector<Total> totals() const;
73
74 private:
82
83 class Block {
84 public:
85 Block(const std::string& name, int level);
86
87 std::string name;
88 std::chrono::milliseconds started;
90 std::vector<std::string> messages;
91 int level;
92 };
93
94 std::stack<Block> call_stack;
95 std::map<std::string, Total> call_totals;
96 };
97
98
100{
101public:
102 ScopedProgressGroup(ProgressMonitor* pm, const std::string& name, int total = 0, int level = -1);
104
105 void progress();
106 void progress(int n);
107 void progress(int n, int total);
108
109private:
111};
A single element of the nested group call stack.
Definition ProgressMonitor.hh:83
std::chrono::milliseconds started
Definition ProgressMonitor.hh:88
int step
Definition ProgressMonitor.hh:89
std::string name
Definition ProgressMonitor.hh:87
int level
Definition ProgressMonitor.hh:91
int total_steps
Definition ProgressMonitor.hh:89
std::vector< std::string > messages
Definition ProgressMonitor.hh:90
Object to accumulate total time and call counts for a particular named execution group.
Definition ProgressMonitor.hh:55
size_t call_count
Definition ProgressMonitor.hh:60
long time_spent_as_long() const
Definition ProgressMonitor.cc:118
std::string name
Definition ProgressMonitor.hh:59
std::chrono::milliseconds time_spent
Definition ProgressMonitor.hh:61
int total_steps
Definition ProgressMonitor.hh:62
Total()
Definition ProgressMonitor.cc:23
std::string str() const
Definition ProgressMonitor.cc:28
bool operator==(const Total &other) const
Definition ProgressMonitor.cc:145
std::vector< std::string > messages
Definition ProgressMonitor.hh:63
Object keeping track of time spent in nested execution blocks, and keeping track of out-of-band messa...
Definition ProgressMonitor.hh:17
virtual ~ProgressMonitor()
Definition ProgressMonitor.cc:13
std::map< std::string, Total > call_totals
Definition ProgressMonitor.hh:95
void group(std::string name="", int total=0, int level=-1)
Start a new named group, or close the innermost one in case the name argument is empty.
Definition ProgressMonitor.cc:39
std::function< void(const std::string &, int, int)> report
Callback for reporting a progress update.
Definition ProgressMonitor.hh:47
void message(const std::string &)
Log out-of-band messages to the current block.
Definition ProgressMonitor.cc:113
int report_level
Definition ProgressMonitor.hh:50
std::vector< Total > totals() const
Definition ProgressMonitor.cc:136
void print() const
Generate debug output on cerr.
Definition ProgressMonitor.cc:123
void progress()
Set the progress of the current top-level block to be n out of total steps.
Definition ProgressMonitor.cc:91
std::stack< Block > call_stack
Definition ProgressMonitor.hh:94
Definition ProgressMonitor.hh:100
~ScopedProgressGroup()
Definition ProgressMonitor.cc:161
void progress()
Definition ProgressMonitor.cc:167
ProgressMonitor * pm
Definition ProgressMonitor.hh:110