mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-13 06:16:55 -04:00
More CPU usage stats
This commit is contained in:
parent
6fb4d341c8
commit
68cb857916
@ -72,6 +72,7 @@ class worker_group {
|
|||||||
bool add_job(job_t&& job) { return impl_->add_job(std::move(job)); }
|
bool add_job(job_t&& job) { return impl_->add_job(std::move(job)); }
|
||||||
size_t size() const { return impl_->size(); }
|
size_t size() const { return impl_->size(); }
|
||||||
size_t queue_size() const { return impl_->queue_size(); }
|
size_t queue_size() const { return impl_->queue_size(); }
|
||||||
|
double get_cpu_time() const { return impl_->get_cpu_time(); }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool add_job(std::packaged_task<T()>&& task) {
|
bool add_job(std::packaged_task<T()>&& task) {
|
||||||
@ -88,6 +89,7 @@ class worker_group {
|
|||||||
virtual bool add_job(job_t&& job) = 0;
|
virtual bool add_job(job_t&& job) = 0;
|
||||||
virtual size_t size() const = 0;
|
virtual size_t size() const = 0;
|
||||||
virtual size_t queue_size() const = 0;
|
virtual size_t queue_size() const = 0;
|
||||||
|
virtual double get_cpu_time() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -613,6 +613,8 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
|||||||
LOG_INFO << "waiting for background scanners...";
|
LOG_INFO << "waiting for background scanners...";
|
||||||
wg_.wait();
|
wg_.wait();
|
||||||
|
|
||||||
|
LOG_INFO << "scanning CPU time: " << time_with_unit(wg_.get_cpu_time());
|
||||||
|
|
||||||
LOG_INFO << "finalizing file inodes...";
|
LOG_INFO << "finalizing file inodes...";
|
||||||
uint32_t first_device_inode = first_file_inode;
|
uint32_t first_device_inode = first_file_inode;
|
||||||
fs.finalize(first_device_inode);
|
fs.finalize(first_device_inode);
|
||||||
@ -682,6 +684,9 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
|||||||
|
|
||||||
blockify.wait();
|
blockify.wait();
|
||||||
|
|
||||||
|
LOG_INFO << "segmenting/blockifying CPU time: "
|
||||||
|
<< time_with_unit(blockify.get_cpu_time());
|
||||||
|
|
||||||
bm.finish_blocks();
|
bm.finish_blocks();
|
||||||
wg_.wait();
|
wg_.wait();
|
||||||
|
|
||||||
|
@ -22,26 +22,44 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <folly/Conv.h>
|
#include <folly/Conv.h>
|
||||||
#include <folly/system/ThreadName.h>
|
#include <folly/system/ThreadName.h>
|
||||||
|
|
||||||
#include "dwarfs/error.h"
|
#include "dwarfs/error.h"
|
||||||
#include "dwarfs/semaphore.h"
|
#include "dwarfs/semaphore.h"
|
||||||
|
#include "dwarfs/util.h"
|
||||||
#include "dwarfs/worker_group.h"
|
#include "dwarfs/worker_group.h"
|
||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
pthread_t std_to_pthread_id(std::thread::id tid) {
|
||||||
|
static_assert(std::is_same_v<pthread_t, std::thread::native_handle_type>);
|
||||||
|
static_assert(sizeof(std::thread::id) ==
|
||||||
|
sizeof(std::thread::native_handle_type));
|
||||||
|
pthread_t id{0};
|
||||||
|
std::memcpy(&id, &tid, sizeof(id));
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
template <typename Policy>
|
template <typename Policy>
|
||||||
class basic_worker_group final : public worker_group::impl, private Policy {
|
class basic_worker_group final : public worker_group::impl, private Policy {
|
||||||
public:
|
public:
|
||||||
@ -55,6 +73,7 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
|||||||
if (num_workers < 1) {
|
if (num_workers < 1) {
|
||||||
DWARFS_THROW(runtime_error, "invalid number of worker threads");
|
DWARFS_THROW(runtime_error, "invalid number of worker threads");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!group_name) {
|
if (!group_name) {
|
||||||
group_name = "worker";
|
group_name = "worker";
|
||||||
}
|
}
|
||||||
@ -153,6 +172,22 @@ class basic_worker_group final : public worker_group::impl, private Policy {
|
|||||||
return jobs_.size();
|
return jobs_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get_cpu_time() const override {
|
||||||
|
std::lock_guard lock(mx_);
|
||||||
|
double t = 0.0;
|
||||||
|
|
||||||
|
for (auto const& w : workers_) {
|
||||||
|
::clockid_t cid;
|
||||||
|
struct ::timespec ts;
|
||||||
|
if (::pthread_getcpuclockid(std_to_pthread_id(w.get_id()), &cid) == 0 &&
|
||||||
|
::clock_gettime(cid, &ts) == 0) {
|
||||||
|
t += ts.tv_sec + 1e-9 * ts.tv_nsec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using jobs_t = std::queue<worker_group::job_t>;
|
using jobs_t = std::queue<worker_group::job_t>;
|
||||||
|
|
||||||
|
@ -865,6 +865,9 @@ int mkdwarfs(int argc, char** argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_INFO << "compression CPU time: "
|
||||||
|
<< time_with_unit(wg_compress.get_cpu_time());
|
||||||
|
|
||||||
ofs.close();
|
ofs.close();
|
||||||
|
|
||||||
if (ofs.bad()) {
|
if (ofs.bad()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user