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

fix(ProgressLogger): add refresh interval setter #1011

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile bindings/python/requirements.in
# pip-compile --pre bindings/python/requirements.in
#
7 changes: 7 additions & 0 deletions include/geode/basic/progress_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <geode/basic/common.hpp>
BotellaA marked this conversation as resolved.
Show resolved Hide resolved
#include <geode/basic/pimpl.hpp>

namespace absl
{
class Duration;
} // namespace absl

namespace geode
{
class opengeode_basic_api ProgressLogger
Expand All @@ -44,6 +49,8 @@ namespace geode

index_t increment_nb_steps( index_t nb_steps );

void set_refresh_interval( absl::Duration refresh_interval );

private:
IMPLEMENTATION_MEMBER( impl_ );
};
Expand Down
18 changes: 12 additions & 6 deletions src/geode/basic/progress_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
#include <geode/basic/progress_logger_manager.hpp>
#include <geode/basic/uuid.hpp>

namespace
{
constexpr absl::Duration SLEEP = absl::Seconds( 1 );
} // namespace

namespace geode
{
class ProgressLogger::Impl
Expand Down Expand Up @@ -65,7 +60,7 @@ namespace geode
const std::lock_guard< std::mutex > locking{ lock_ };
current_ += nb_increments;
auto now = absl::Now();
if( now - current_time_ > SLEEP )
if( now - current_time_ > refresh_interval_ )
{
current_time_ = now;
ProgressLoggerManager::update( id_, current_, nb_steps_ );
Expand All @@ -80,12 +75,18 @@ namespace geode
return nb_steps_;
}

void set_refresh_interval( absl::Duration refresh_interval )
{
refresh_interval_ = std::move( refresh_interval );
}

private:
uuid id_;
index_t nb_steps_;
index_t current_{ 0 };
absl::Time current_time_;
std::mutex lock_;
absl::Duration refresh_interval_{ absl::Seconds( 1 ) };
};

ProgressLogger::ProgressLogger(
Expand Down Expand Up @@ -115,4 +116,9 @@ namespace geode
{
return impl_->increment_nb_steps( nb_steps );
}

void ProgressLogger::set_refresh_interval( absl::Duration refresh_interval )
{
impl_->set_refresh_interval( std::move( refresh_interval ) );
}
} // namespace geode
Loading