Skip to content

Commit cf52edd

Browse files
committed
ITSMFT: reuse capacity estimator statistics storage
1 parent 6229d42 commit cf52edd

1 file changed

Lines changed: 14 additions & 23 deletions

File tree

Detectors/ITSMFT/common/tracking/src/CapacityEstimator.cxx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ struct CapacityEstimator::Impl {
3131
float ratio{0.f};
3232
float margin{0.f};
3333
size_t maxEmitted{0};
34-
uint32_t nSamples{0};
3534
uint32_t nLowStreak{0};
36-
uint32_t nOverflows{0};
37-
size_t requested{0};
38-
size_t granted{0};
39-
size_t emitted{0};
40-
size_t spilled{0};
35+
Statistics statistics{};
4136
};
4237

4338
struct UndoRecord {
@@ -75,27 +70,28 @@ struct CapacityEstimator::Impl {
7570
// transaction without observing a partial update.
7671
checkpointBeforeUpdate(key);
7772
auto& e = entries[key];
78-
e.requested += requested;
79-
e.granted += granted;
80-
e.emitted += emitted;
81-
e.spilled += spilled;
73+
auto& statistics = e.statistics;
74+
statistics.requested += requested;
75+
statistics.granted += granted;
76+
statistics.emitted += emitted;
77+
statistics.spilled += spilled;
8278

83-
const bool firstSample = e.nSamples == 0;
79+
const bool firstSample = statistics.samples == 0;
8480
if (firstSample) {
8581
e.margin = cfg.marginInit;
8682
}
8783
const auto sample = static_cast<float>(double(emitted) / scale);
8884
e.ratio = firstSample ? sample : (cfg.alpha * sample) + ((1.f - cfg.alpha) * e.ratio);
8985
e.maxEmitted = std::max(e.maxEmitted, emitted);
90-
++e.nSamples;
86+
++statistics.samples;
9187

9288
if (memoryLimited) {
9389
e.nLowStreak = 0;
9490
e.margin = std::max(cfg.marginMin, e.margin * cfg.marginDown);
9591
return;
9692
}
9793
if (overflowed) {
98-
++e.nOverflows;
94+
++statistics.overflowEvents;
9995
e.nLowStreak = 0;
10096
if (!firstSample) {
10197
const float shortfall = granted ? static_cast<float>(double(emitted) / double(granted)) : cfg.marginUp;
@@ -172,7 +168,7 @@ size_t CapacityEstimator::capacity(uint64_t key, double scale) const
172168
}
173169
std::lock_guard lock{mImpl->mutex};
174170
const auto it = mImpl->entries.find(key);
175-
if (it == mImpl->entries.end() || it->second.nSamples == 0) {
171+
if (it == mImpl->entries.end() || it->second.statistics.samples == 0) {
176172
return mImpl->cfg.floorSlots;
177173
}
178174
const auto& e = it->second;
@@ -213,7 +209,7 @@ double CapacityEstimator::expected(uint64_t key, double scale) const
213209
}
214210
std::lock_guard lock{mImpl->mutex};
215211
const auto it = mImpl->entries.find(key);
216-
if (it == mImpl->entries.end() || it->second.nSamples == 0) {
212+
if (it == mImpl->entries.end() || it->second.statistics.samples == 0) {
217213
return 0.;
218214
}
219215
const double raw = double(it->second.ratio) * scale;
@@ -227,13 +223,7 @@ CapacityEstimator::Statistics CapacityEstimator::statistics(uint64_t key) const
227223
if (it == mImpl->entries.end()) {
228224
return {};
229225
}
230-
const auto& e = it->second;
231-
return {.requested = e.requested,
232-
.granted = e.granted,
233-
.emitted = e.emitted,
234-
.spilled = e.spilled,
235-
.samples = e.nSamples,
236-
.overflowEvents = e.nOverflows};
226+
return it->second.statistics;
237227
}
238228

239229
void CapacityEstimator::update(uint64_t key, double scale, size_t emitted, size_t capacityUsed, bool overflowed, bool memoryLimited)
@@ -277,8 +267,9 @@ void CapacityEstimator::print() const
277267
LOGP(info, "Printing CapacityEstimators:");
278268
for (const auto key : keys) {
279269
const auto& value = mImpl->entries.at(key);
270+
const auto& statistics = value.statistics;
280271
const auto decoded = decodeKey(key);
281-
LOGP(info, "\tSite:{} | iter:{} | var:({},{}) | slot:{} | ratio:{} | margin:{} | maxEmitted:{} | samples:{} | low:{} | requested:{} | granted:{} | emitted:{} | spilled:{} | overflows:{}", SlabSiteNames[decoded.site], decoded.iteration, getVariantHigh(decoded.variant), getVariantLow(decoded.variant), decoded.slot, value.ratio, value.margin, value.maxEmitted, value.nSamples, value.nLowStreak, value.requested, value.granted, value.emitted, value.spilled, value.nOverflows);
272+
LOGP(info, "\tSite:{} | iter:{} | var:({},{}) | slot:{} | ratio:{} | margin:{} | maxEmitted:{} | samples:{} | low:{} | requested:{} | granted:{} | emitted:{} | spilled:{} | overflows:{}", SlabSiteNames[decoded.site], decoded.iteration, getVariantHigh(decoded.variant), getVariantLow(decoded.variant), decoded.slot, value.ratio, value.margin, value.maxEmitted, statistics.samples, value.nLowStreak, statistics.requested, statistics.granted, statistics.emitted, statistics.spilled, statistics.overflowEvents);
282273
}
283274
}
284275

0 commit comments

Comments
 (0)