1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/progress_bar/progress_bar.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb.h"
12#include "duckdb/execution/executor.hpp"
13#include "duckdb/common/mutex.hpp"
14#include "duckdb/common/profiler.hpp"
15#include "duckdb/common/progress_bar/progress_bar_display.hpp"
16
17namespace duckdb {
18
19struct ClientConfig;
20typedef unique_ptr<ProgressBarDisplay> (*progress_bar_display_create_func_t)();
21
22class ProgressBar {
23public:
24 static unique_ptr<ProgressBarDisplay> DefaultProgressBarDisplay();
25 static void SystemOverrideCheck(ClientConfig &config);
26
27 explicit ProgressBar(
28 Executor &executor, idx_t show_progress_after,
29 progress_bar_display_create_func_t create_display_func = ProgressBar::DefaultProgressBarDisplay);
30
31 //! Starts the thread
32 void Start();
33 //! Updates the progress bar and prints it to the screen
34 void Update(bool final);
35 //! Gets current percentage
36 double GetCurrentPercentage();
37
38 void PrintProgressInternal(int percentage);
39 void PrintProgress(int percentage);
40 void FinishProgressBarPrint();
41 bool ShouldPrint(bool final) const;
42 bool PrintEnabled() const;
43
44private:
45 //! The executor
46 Executor &executor;
47 //! The profiler used to measure the time since the progress bar was started
48 Profiler profiler;
49 //! The time in ms after which to start displaying the progress bar
50 idx_t show_progress_after;
51 //! The current progress percentage
52 double current_percentage;
53 //! The display used to print the progress
54 unique_ptr<ProgressBarDisplay> display;
55 //! Whether or not profiling is supported for the current query
56 bool supported = true;
57 //! Whether the bar has already finished
58 bool finished = false;
59};
60} // namespace duckdb
61