Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customizable delay before displaying progress bar #3092

Merged
merged 12 commits into from
Mar 22, 2024
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ endif ()
if(${BUILD_KUZU})
add_definitions(-DKUZU_ROOT_DIRECTORY="${PROJECT_SOURCE_DIR}")
add_definitions(-DKUZU_CMAKE_VERSION="${CMAKE_PROJECT_VERSION}")
add_definitions(-DKUZU_EXTENSION_VERSION="0.2.2")
add_definitions(-DKUZU_EXTENSION_VERSION="0.2.3")

include_directories(src/include)
include_directories(third_party/antlr4_cypher/include)
Expand Down
28 changes: 24 additions & 4 deletions src/common/task_system/progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
return;
}
std::lock_guard<std::mutex> lock(progressBarLock);
queryTimer->start();
printProgressBar(0.0);
printing = true;
}

void ProgressBar::endProgress() {
std::lock_guard<std::mutex> lock(progressBarLock);
resetProgressBar();
printing = false;
queryTimer = std::make_unique<TimeMetric>(true);
}

void ProgressBar::addPipeline() {
Expand Down Expand Up @@ -46,10 +46,13 @@
std::cout << "\033[2A";
}
printProgressBar(curPipelineProgress);
printing = true;
}

void ProgressBar::printProgressBar(double curPipelineProgress) const {
void ProgressBar::printProgressBar(double curPipelineProgress) {
if (!shouldPrintProgress()) {
return;
}
printing = true;

Check warning on line 55 in src/common/task_system/progress_bar.cpp

View check run for this annotation

Codecov / codecov/patch

src/common/task_system/progress_bar.cpp#L55

Added line #L55 was not covered by tests
float pipelineProgress = 0.0;
if (numPipelines > 0) {
pipelineProgress = (float)numPipelinesFinished / (float)numPipelines;
Expand All @@ -71,11 +74,28 @@
numPipelines = 0;
numPipelinesFinished = 0;
prevCurPipelineProgress = 0.0;
printing = false;
if (queryTimer->isStarted) {
queryTimer->stop();
}
}

bool ProgressBar::shouldPrintProgress() const {
if (queryTimer->isStarted) {
queryTimer->stop();
}
bool shouldPrint = queryTimer->getElapsedTimeMS() > showProgressAfter;
queryTimer->start();
return shouldPrint;
}

void ProgressBar::toggleProgressBarPrinting(bool enable) {
trackProgress = enable;
}

void ProgressBar::setShowProgressAfter(uint64_t time) {
showProgressAfter = time;
}

} // namespace common
} // namespace kuzu
14 changes: 12 additions & 2 deletions src/include/common/task_system/progress_bar.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include <iostream>
#include <memory>
#include <mutex>

#include "common/metric.h"

namespace kuzu {
namespace common {

Expand All @@ -15,7 +18,8 @@ class ProgressBar {
public:
ProgressBar()
: numPipelines{0}, numPipelinesFinished{0}, prevCurPipelineProgress{0.0},
trackProgress{false}, printing{false} {};
trackProgress{false}, printing{false}, queryTimer{std::make_unique<TimeMetric>(true)},
showProgressAfter{1000} {};

void addPipeline();

Expand All @@ -31,24 +35,30 @@ class ProgressBar {

void toggleProgressBarPrinting(bool enable);

void setShowProgressAfter(uint64_t showProgressAfter);

void updateProgress(double curPipelineProgress);

private:
inline void setGreenFont() const { std::cerr << "\033[1;32m"; }

inline void setDefaultFont() const { std::cerr << "\033[0m"; }

void printProgressBar(double curPipelineProgress) const;
void printProgressBar(double curPipelineProgress);

void resetProgressBar();

bool shouldPrintProgress() const;

private:
uint32_t numPipelines;
uint32_t numPipelinesFinished;
double prevCurPipelineProgress;
std::mutex progressBarLock;
bool trackProgress;
bool printing;
std::unique_ptr<TimeMetric> queryTimer;
uint64_t showProgressAfter;
};

} // namespace common
Expand Down
3 changes: 3 additions & 0 deletions src/include/main/client_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct ClientConfig {
uint32_t varLengthMaxDepth;
// If using progress bar
bool enableProgressBar;
// time before displaying progress bar
uint64_t showProgressAfter;
};

struct ClientConfigDefault {
Expand All @@ -29,6 +31,7 @@ struct ClientConfigDefault {
static constexpr uint32_t VAR_LENGTH_MAX_DEPTH = 30;
static constexpr bool ENABLE_SEMI_MASK = true;
static constexpr bool ENABLE_PROGRESS_BAR = true;
static constexpr uint64_t SHOW_PROGRESS_AFTER = 1000;
};

} // namespace main
Expand Down
13 changes: 13 additions & 0 deletions src/include/main/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ struct ProgressBarSetting {
}
};

struct ProgressBarTimerSetting {
static constexpr const char* name = "progress_bar_time";
static constexpr const common::LogicalTypeID inputType = common::LogicalTypeID::INT64;
static void setContext(ClientContext* context, const common::Value& parameter) {
KU_ASSERT(parameter.getDataType()->getLogicalTypeID() == common::LogicalTypeID::INT64);
context->getClientConfigUnsafe()->showProgressAfter = parameter.getValue<int64_t>();
context->getProgressBar()->setShowProgressAfter(parameter.getValue<int64_t>());
}
static common::Value getSetting(ClientContext* context) {
return common::Value(context->getClientConfig()->showProgressAfter);
}
};

struct VarLengthExtendMaxDepthSetting {
static constexpr const char* name = "var_length_extend_max_depth";
static constexpr const common::LogicalTypeID inputType = common::LogicalTypeID::INT64;
Expand Down
1 change: 1 addition & 0 deletions src/main/client_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ClientContext::ClientContext(Database* database) : database{database} {
config.timeoutInMS = ClientConfigDefault::TIMEOUT_IN_MS;
config.varLengthMaxDepth = ClientConfigDefault::VAR_LENGTH_MAX_DEPTH;
config.enableProgressBar = ClientConfigDefault::ENABLE_PROGRESS_BAR;
config.showProgressAfter = ClientConfigDefault::SHOW_PROGRESS_AFTER;
}

uint64_t ClientContext::getTimeoutRemainingInMS() const {
Expand Down
2 changes: 1 addition & 1 deletion src/main/db_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static ConfigurationOption options[] = { // NOLINT(cert-err58-cpp):
GET_CONFIGURATION(ThreadsSetting), GET_CONFIGURATION(TimeoutSetting),
GET_CONFIGURATION(VarLengthExtendMaxDepthSetting), GET_CONFIGURATION(EnableSemiMaskSetting),
GET_CONFIGURATION(HomeDirectorySetting), GET_CONFIGURATION(FileSearchPathSetting),
GET_CONFIGURATION(ProgressBarSetting)};
GET_CONFIGURATION(ProgressBarSetting), GET_CONFIGURATION(ProgressBarTimerSetting)};

ConfigurationOption* DBConfig::getOptionByName(const std::string& optionName) {
auto lOptionName = optionName;
Expand Down
12 changes: 12 additions & 0 deletions test/test_files/tinysnb/call/call.test
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ True
---- 1
False

-LOG SetGetProgressBarTime
-STATEMENT CALL progress_bar_time=4000
---- ok
-STATEMENT CALL current_setting('progress_bar_time') RETURN *
---- 1
4000
-STATEMENT CALL progress_bar_time=0
---- ok
-STATEMENT CALL current_setting('progress_bar_time') RETURN *
---- 1
0

-LOG disableSemihMaskOptimization
-STATEMENT CALL enable_semi_mask=true
---- ok
Expand Down
Loading