2022-01-19 01:07:49 +03:00
|
|
|
// Copyright (C) 2018-2022 Intel Corporation
|
2019-04-12 18:25:53 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2021-12-13 11:30:58 +03:00
|
|
|
|
|
|
|
|
#include "samples/console_progress.hpp"
|
2019-04-12 18:25:53 +03:00
|
|
|
|
|
|
|
|
/// @brief Responsible for progress bar handling within the benchmark_app
|
|
|
|
|
class ProgressBar {
|
|
|
|
|
public:
|
2019-08-09 19:02:42 +03:00
|
|
|
explicit ProgressBar(size_t totalNum, bool streamOutput = false, bool progressEnabled = false) {
|
|
|
|
|
_bar.reset(new ConsoleProgress(totalNum, streamOutput));
|
|
|
|
|
_streamOutput = streamOutput;
|
2019-04-12 18:25:53 +03:00
|
|
|
_isFinished = true;
|
2019-08-09 19:02:42 +03:00
|
|
|
_progressEnabled = progressEnabled;
|
2019-04-12 18:25:53 +03:00
|
|
|
}
|
|
|
|
|
|
2022-01-19 01:08:07 +03:00
|
|
|
void add_progress(size_t num) {
|
2019-04-12 18:25:53 +03:00
|
|
|
_isFinished = false;
|
2019-08-09 19:02:42 +03:00
|
|
|
if (_progressEnabled) {
|
|
|
|
|
_bar->addProgress(num);
|
|
|
|
|
}
|
2019-04-12 18:25:53 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-09 19:02:42 +03:00
|
|
|
void finish(size_t num = 0) {
|
|
|
|
|
if (num > 0) {
|
2022-01-19 01:08:07 +03:00
|
|
|
add_progress(num);
|
2019-08-09 19:02:42 +03:00
|
|
|
}
|
2019-04-12 18:25:53 +03:00
|
|
|
_isFinished = true;
|
|
|
|
|
_bar->finish();
|
2019-08-09 19:02:42 +03:00
|
|
|
if (_progressEnabled) {
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|
2019-04-12 18:25:53 +03:00
|
|
|
}
|
|
|
|
|
|
2022-01-19 01:08:07 +03:00
|
|
|
void new_bar(size_t totalNum) {
|
2019-04-12 18:25:53 +03:00
|
|
|
if (_isFinished) {
|
2019-08-09 19:02:42 +03:00
|
|
|
_bar.reset(new ConsoleProgress(totalNum, _streamOutput));
|
2019-04-12 18:25:53 +03:00
|
|
|
} else {
|
2019-08-09 19:02:42 +03:00
|
|
|
throw std::logic_error("Cannot create a new bar. Current bar is still in progress");
|
2019-04-12 18:25:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_ptr<ConsoleProgress> _bar;
|
2019-08-09 19:02:42 +03:00
|
|
|
bool _streamOutput;
|
2019-04-12 18:25:53 +03:00
|
|
|
bool _isFinished;
|
2019-08-09 19:02:42 +03:00
|
|
|
bool _progressEnabled;
|
|
|
|
|
};
|