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

feat(ProgressLogger): allow to change the refresh interval #1006

Closed
Closed
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
6 changes: 5 additions & 1 deletion include/geode/basic/progress_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <string>

#include <absl/time/clock.h>

#include <geode/basic/common.hpp>
#include <geode/basic/pimpl.hpp>

Expand All @@ -33,7 +35,9 @@ namespace geode
class opengeode_basic_api ProgressLogger
{
public:
ProgressLogger( const std::string& message, index_t nb_steps );
ProgressLogger( const std::string& message,
index_t nb_steps,
absl::Duration refresh_interval = absl::Seconds( 1 ) );
~ProgressLogger();

index_t increment();
Expand Down
25 changes: 12 additions & 13 deletions src/geode/basic/progress_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,22 @@

#include <mutex>

#include <absl/time/clock.h>

#include <geode/basic/logger.hpp>
#include <geode/basic/pimpl_impl.hpp>
#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
{
public:
Impl( const std::string& message, index_t nb_steps )
: nb_steps_( nb_steps ), current_time_{ absl::Now() }
Impl( const std::string& message,
index_t nb_steps,
absl::Duration refresh_interval )
: nb_steps_( nb_steps ),
current_time_{ absl::Now() },
refresh_interval_{ refresh_interval }
{
ProgressLoggerManager::start( id_, message, nb_steps_ );
}
Expand All @@ -65,7 +62,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 @@ -85,12 +82,14 @@ namespace geode
index_t nb_steps_;
index_t current_{ 0 };
absl::Time current_time_;
absl::Duration refresh_interval_;
std::mutex lock_;
};

ProgressLogger::ProgressLogger(
const std::string& message, index_t nb_steps )
: impl_( message, nb_steps )
ProgressLogger::ProgressLogger( const std::string& message,
index_t nb_steps,
absl::Duration refresh_interval )
: impl_( message, nb_steps, refresh_interval )
{
}

Expand Down
Loading