Commit bb5d72a4 by Maarten L. Hekkelman

remove dependency on boost::timer

parent 85d68b93
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <thread> #include <thread>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <map>
#include <chrono>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define TERM_WIDTH 80 #define TERM_WIDTH 80
...@@ -44,8 +46,6 @@ ...@@ -44,8 +46,6 @@
#endif #endif
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/timer/timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "cif++/CifUtils.hpp" #include "cif++/CifUtils.hpp"
...@@ -467,8 +467,7 @@ struct ProgressImpl ...@@ -467,8 +467,7 @@ struct ProgressImpl
{ {
ProgressImpl(int64_t inMax, const std::string& inAction) ProgressImpl(int64_t inMax, const std::string& inAction)
: mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction) : mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction)
, mThread(std::bind(&ProgressImpl::Run, this)) , mThread(std::bind(&ProgressImpl::Run, this)) {}
, mStart(boost::posix_time::second_clock::local_time()) {}
void Run(); void Run();
void Stop() void Stop()
...@@ -481,23 +480,20 @@ struct ProgressImpl ...@@ -481,23 +480,20 @@ struct ProgressImpl
void PrintProgress(); void PrintProgress();
void PrintDone(); void PrintDone();
int64_t mMax; int64_t mMax;
std::atomic<int64_t> mConsumed; std::atomic<int64_t>mConsumed;
int64_t mLastConsumed = 0; int64_t mLastConsumed = 0;
int mSpinnerIndex = 0; int mSpinnerIndex = 0;
std::string mAction, mMessage; std::string mAction, mMessage;
std::mutex mMutex; std::mutex mMutex;
std::thread mThread; std::thread mThread;
boost::timer::cpu_timer mTimer; std::chrono::time_point<std::chrono::system_clock>
boost::posix_time::ptime mStart; mStart = std::chrono::system_clock::now();
bool mStop = false; bool mStop = false;
}; };
void ProgressImpl::Run() void ProgressImpl::Run()
{ {
using namespace boost::posix_time;
// using namespace boost::local_time;
bool printedAny = false; bool printedAny = false;
try try
...@@ -511,7 +507,9 @@ void ProgressImpl::Run() ...@@ -511,7 +507,9 @@ void ProgressImpl::Run()
if (mStop or mConsumed == mMax) if (mStop or mConsumed == mMax)
break; break;
if (second_clock::local_time() - mStart < seconds(5)) auto elapsed = std::chrono::system_clock::now() - mStart;
if (elapsed < std::chrono::seconds(5))
continue; continue;
PrintProgress(); PrintProgress();
...@@ -612,9 +610,49 @@ void ProgressImpl::PrintProgress() ...@@ -612,9 +610,49 @@ void ProgressImpl::PrintProgress()
std::cout.flush(); std::cout.flush();
} }
namespace
{
std::ostream& operator<<(std::ostream& os, const std::chrono::duration<double>& t)
{
uint64_t s = static_cast<uint64_t>(std::trunc(t.count()));
if (s > 24 * 60 * 60)
{
uint32_t days = s / (24 * 60 * 60);
os << days << "d ";
s %= 24 * 60 * 60;
}
if (s > 60 * 60)
{
uint32_t hours = s / (60 * 60);
os << hours << "h ";
s %= 60 * 60;
}
if (s > 60)
{
uint32_t minutes = s / 60;
os << minutes << "m ";
s %= 60;
}
double ss = s + 1e-6 * (t.count() - s);
os << std::fixed << std::setprecision(1) << ss << 's';
return os;
}
}
void ProgressImpl::PrintDone() void ProgressImpl::PrintDone()
{ {
std::string msg = mAction + " done in " + mTimer.format(0, "%ts cpu / %ws wall"); std::chrono::duration<double> elapsed = std::chrono::system_clock::now() - mStart;
std::ostringstream msgstr;
msgstr << mAction << " done in " << elapsed << " cpu / %ws wall";
auto msg = msgstr.str();
uint32_t width = get_terminal_width(); uint32_t width = get_terminal_width();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment