Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
worker_statistics.hpp
Go to the documentation of this file.
1#pragma once
2
35
36#include <chrono>
37#include <cstdint>
38#include <vector>
39
41
42namespace orrery::backend {
43
49using Clock = std::chrono::steady_clock;
50
53using Duration = std::chrono::nanoseconds;
54
58 std::uint64_t chunks{};
59
68 std::uint64_t items{};
69
76 std::uint64_t steals{};
77
80
83};
84
94struct alignas(core::kCacheLineBytes) PaddedWorkerStatistics {
95 WorkerStatistics value;
96};
97
101 std::vector<WorkerStatistics> workers;
102
106
108 std::uint64_t regions{};
109
111 [[nodiscard]] Duration busy() const noexcept {
112 Duration total{};
113 for (const WorkerStatistics& worker : workers) {
114 total += worker.busy;
115 }
116 return total;
117 }
118
120 [[nodiscard]] Duration idle() const noexcept {
121 Duration total{};
122 for (const WorkerStatistics& worker : workers) {
123 total += worker.idle;
124 }
125 return total;
126 }
127
134 [[nodiscard]] double idle_fraction() const noexcept {
135 const Duration total = busy() + idle();
136 if (total.count() == 0) {
137 return 0.0;
138 }
139 return static_cast<double>(idle().count()) / static_cast<double>(total.count());
140 }
141};
142
143} // namespace orrery::backend
An allocator that starts every allocation on a cache line.
The whole pool's record.
Definition worker_statistics.hpp:99
double idle_fraction() const noexcept
The fraction of available worker time that was spent waiting.
Definition worker_statistics.hpp:134
Duration elapsed
Wall time spent inside parallel regions, measured by the submitting thread.
Definition worker_statistics.hpp:105
Duration idle() const noexcept
Idle time summed over workers.
Definition worker_statistics.hpp:120
Duration busy() const noexcept
Busy time summed over workers.
Definition worker_statistics.hpp:111
std::vector< WorkerStatistics > workers
One entry per worker, in worker order.
Definition worker_statistics.hpp:101
std::uint64_t regions
How many parallel regions have run.
Definition worker_statistics.hpp:108
One worker's record, on a cache line of its own.
Definition worker_statistics.hpp:94
One worker's record, accumulated over every region since the last reset.
Definition worker_statistics.hpp:56
Duration busy
Time spent inside the caller's work.
Definition worker_statistics.hpp:79
std::uint64_t chunks
How many chunks of work this worker executed.
Definition worker_statistics.hpp:58
std::uint64_t steals
How many of those chunks were taken from another worker's range.
Definition worker_statistics.hpp:76
Duration idle
Time inside a parallel region spent not working, as defined above.
Definition worker_statistics.hpp:82
std::uint64_t items
How many items those chunks covered, an item being one index of the range the caller asked to have di...
Definition worker_statistics.hpp:68
std::chrono::nanoseconds Duration
Durations are stored in nanoseconds so that they add without conversion and mean the same thing on ev...
Definition worker_statistics.hpp:53
std::chrono::steady_clock Clock
The clock every duration here is measured on.
Definition worker_statistics.hpp:49