mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
refactor: remove dependency on folly::Expected
This commit is contained in:
parent
29e09d94c7
commit
bfa17289b6
@ -28,9 +28,9 @@
|
||||
#include <future>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include <folly/Expected.h>
|
||||
#include <folly/Function.h>
|
||||
|
||||
namespace dwarfs {
|
||||
@ -87,10 +87,15 @@ class worker_group {
|
||||
|
||||
size_t size() const { return impl_->size(); }
|
||||
size_t queue_size() const { return impl_->queue_size(); }
|
||||
folly::Expected<std::chrono::nanoseconds, std::error_code>
|
||||
get_cpu_time() const {
|
||||
return impl_->get_cpu_time();
|
||||
|
||||
std::chrono::nanoseconds get_cpu_time(std::error_code& ec) const {
|
||||
return impl_->get_cpu_time(ec);
|
||||
}
|
||||
|
||||
std::optional<std::chrono::nanoseconds> try_get_cpu_time() const {
|
||||
return impl_->try_get_cpu_time();
|
||||
}
|
||||
|
||||
bool set_affinity(std::vector<int> const& cpus) {
|
||||
return impl_->set_affinity(cpus);
|
||||
}
|
||||
@ -111,8 +116,10 @@ class worker_group {
|
||||
virtual bool add_moveonly_job(moveonly_job_t&& job) = 0;
|
||||
virtual size_t size() const = 0;
|
||||
virtual size_t queue_size() const = 0;
|
||||
virtual folly::Expected<std::chrono::nanoseconds, std::error_code>
|
||||
get_cpu_time() const = 0;
|
||||
virtual std::chrono::nanoseconds
|
||||
get_cpu_time(std::error_code& ec) const = 0;
|
||||
virtual std::optional<std::chrono::nanoseconds>
|
||||
try_get_cpu_time() const = 0;
|
||||
virtual bool set_affinity(std::vector<int> const& cpus) = 0;
|
||||
};
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <system_error>
|
||||
|
||||
namespace dwarfs {
|
||||
@ -66,6 +67,7 @@ class thread_pool {
|
||||
void stop();
|
||||
void wait();
|
||||
bool running() const;
|
||||
std::optional<std::chrono::nanoseconds> try_get_cpu_time() const;
|
||||
std::chrono::nanoseconds get_cpu_time() const;
|
||||
std::chrono::nanoseconds get_cpu_time(std::error_code& ec) const;
|
||||
|
||||
|
@ -168,22 +168,28 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
||||
return jobs_.size();
|
||||
}
|
||||
|
||||
folly::Expected<std::chrono::nanoseconds, std::error_code>
|
||||
get_cpu_time() const override {
|
||||
std::chrono::nanoseconds get_cpu_time(std::error_code& ec) const override {
|
||||
ec.clear();
|
||||
|
||||
std::lock_guard lock(mx_);
|
||||
std::chrono::nanoseconds t{};
|
||||
|
||||
for (auto const& w : workers_) {
|
||||
std::error_code ec;
|
||||
t += os_.thread_get_cpu_time(w.get_id(), ec);
|
||||
if (ec) {
|
||||
return folly::makeUnexpected(ec);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
std::optional<std::chrono::nanoseconds> try_get_cpu_time() const override {
|
||||
std::error_code ec;
|
||||
auto t = get_cpu_time(ec);
|
||||
return ec ? std::nullopt : std::make_optional(t);
|
||||
}
|
||||
|
||||
bool set_affinity(std::vector<int> const& cpus) override {
|
||||
if (cpus.empty()) {
|
||||
return false;
|
||||
|
@ -647,7 +647,7 @@ void scanner_<LoggerPolicy>::scan(
|
||||
wg_.wait();
|
||||
|
||||
LOG_INFO << "scanning CPU time: "
|
||||
<< time_with_unit(wg_.get_cpu_time().value_or(0ns));
|
||||
<< time_with_unit(wg_.try_get_cpu_time().value_or(0ns));
|
||||
|
||||
dump_state(kEnvVarDumpFilesRaw, "raw files", fa,
|
||||
[&fs](auto& os) { fs.dump(os); });
|
||||
@ -827,10 +827,10 @@ void scanner_<LoggerPolicy>::scan(
|
||||
wg_ordering.wait();
|
||||
|
||||
LOG_INFO << "total ordering CPU time: "
|
||||
<< time_with_unit(wg_ordering.get_cpu_time().value_or(0ns));
|
||||
<< time_with_unit(wg_ordering.try_get_cpu_time().value_or(0ns));
|
||||
|
||||
LOG_INFO << "total segmenting CPU time: "
|
||||
<< time_with_unit(wg_blockify.get_cpu_time().value_or(0ns));
|
||||
<< time_with_unit(wg_blockify.try_get_cpu_time().value_or(0ns));
|
||||
}
|
||||
|
||||
// seg.finish();
|
||||
|
@ -43,13 +43,7 @@ void thread_pool::wait() { wg_->wait(); }
|
||||
bool thread_pool::running() const { return wg_->running(); }
|
||||
|
||||
std::chrono::nanoseconds thread_pool::get_cpu_time(std::error_code& ec) const {
|
||||
auto rv = wg_->get_cpu_time();
|
||||
if (rv) {
|
||||
ec.clear();
|
||||
return rv.value();
|
||||
}
|
||||
ec = rv.error();
|
||||
return {};
|
||||
return wg_->get_cpu_time(ec);
|
||||
}
|
||||
|
||||
std::chrono::nanoseconds thread_pool::get_cpu_time() const {
|
||||
@ -61,4 +55,8 @@ std::chrono::nanoseconds thread_pool::get_cpu_time() const {
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::optional<std::chrono::nanoseconds> thread_pool::try_get_cpu_time() const {
|
||||
return wg_->try_get_cpu_time();
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
||||
|
Loading…
x
Reference in New Issue
Block a user