Skip to content

Commit dcf4d59

Browse files
committed
Improved progress bar display before diagram generation starts (#415)
1 parent 485a8a1 commit dcf4d59

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/common/generators/generators.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ auto make_generator(const std::string &name,
484484
runtime_config]() mutable -> std::unique_ptr<diagram_model> {
485485
try {
486486
std::unique_ptr<diagram_model> model;
487+
488+
if (indicator) {
489+
indicator->update(name);
490+
}
491+
487492
auto progress_fun = [&indicator, &name]() {
488493
if (indicator)
489494
indicator->increment(name);

src/common/generators/progress_indicator.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ void progress_indicator::add_progress_bar(
8686
progress_bars_mutex_.unlock();
8787
}
8888

89+
void json_logger_progress_indicator::update(const std::string &name)
90+
{
91+
inja::json j;
92+
j["diagram_name"] = name;
93+
94+
progress_bars_mutex_.lock();
95+
96+
if (progress_bar_index_.count(name) == 0) {
97+
progress_bars_mutex_.unlock();
98+
return;
99+
}
100+
101+
auto &p = progress_bar_index_.at(name);
102+
103+
j["progress"] = p.progress;
104+
j["max"] = p.max;
105+
j["status"] = "ongoing";
106+
107+
progress_bars_mutex_.unlock();
108+
109+
spdlog::get("json-progress-logger")
110+
->log(spdlog::level::info, "{}", j.dump());
111+
}
112+
89113
void json_logger_progress_indicator::increment(const std::string &name)
90114
{
91115
inja::json j;
@@ -112,6 +136,27 @@ void json_logger_progress_indicator::increment(const std::string &name)
112136
->log(spdlog::level::info, "{}", j.dump());
113137
}
114138

139+
void progress_indicator::update(const std::string &name)
140+
{
141+
const auto kASTTraverseProgressPercent = 95U;
142+
143+
progress_bars_mutex_.lock();
144+
145+
if (progress_bar_index_.count(name) == 0) {
146+
progress_bars_mutex_.unlock();
147+
return;
148+
}
149+
150+
auto &p = progress_bar_index_.at(name);
151+
auto &bar = progress_bars_[p.index];
152+
153+
bar.set_progress((p.progress * kASTTraverseProgressPercent) / p.max);
154+
bar.set_option(indicators::option::PostfixText{
155+
fmt::format("{}/{}", p.progress, p.max)});
156+
157+
progress_bars_mutex_.unlock();
158+
}
159+
115160
void progress_indicator::increment(const std::string &name)
116161
{
117162
const auto kASTTraverseProgressPercent = 95U;

src/common/generators/progress_indicator.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class progress_indicator_base {
5959
*/
6060
virtual void increment(const std::string &name) = 0;
6161

62+
/**
63+
* Update the display of the progress bar without modifying progress.
64+
*
65+
* @param name Name of the progress ba*
66+
*/
67+
virtual void update(const std::string &name) = 0;
68+
6269
/**
6370
* Stop all the progress bars.
6471
*/
@@ -92,6 +99,8 @@ class json_logger_progress_indicator : public progress_indicator_base {
9299
void add_progress_bar(
93100
const std::string &name, size_t max, indicators::Color color) override;
94101

102+
void update(const std::string &name) override;
103+
95104
void increment(const std::string &name) override;
96105

97106
void stop() override { }
@@ -115,6 +124,8 @@ class progress_indicator : public progress_indicator_base {
115124
void add_progress_bar(
116125
const std::string &name, size_t max, indicators::Color color) override;
117126

127+
void update(const std::string &name) override;
128+
118129
void increment(const std::string &name) override;
119130

120131
void stop() override;

0 commit comments

Comments
 (0)