MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ~PerformanceMeasurer

Method ~PerformanceMeasurer

src/framerate_gui.cpp:256–282  ·  view source on GitHub ↗

Finish a cycle of a measured element and store the measurement taken. */

Source from the content-addressed store, hash-verified

254
255/** Finish a cycle of a measured element and store the measurement taken. */
256PerformanceMeasurer::~PerformanceMeasurer()
257{
258 if (this->elem == PFE_ALLSCRIPTS) {
259 /* Hack to not record scripts total when no scripts are active */
260 bool any_active = _pf_data[PFE_GAMESCRIPT].num_valid > 0;
261 for (uint e = PFE_AI0; e < PFE_MAX; e++) any_active |= _pf_data[e].num_valid > 0;
262 if (!any_active) {
263 PerformanceMeasurer::SetInactive(PFE_ALLSCRIPTS);
264 return;
265 }
266 }
267 if (this->elem == PFE_SOUND) {
268 /* PFE_SOUND measurements are made from the mixer thread.
269 * _pf_data cannot be concurrently accessed from the mixer thread
270 * and the main thread, so store the measurement results in a
271 * mutex-protected queue which is drained by the main thread.
272 * See: ProcessPendingPerformanceMeasurements() */
273 TimingMeasurement end = GetPerformanceTimer();
274 std::lock_guard lk(_sound_perf_lock);
275 if (_sound_perf_measurements.size() >= NUM_FRAMERATE_POINTS * 2) return;
276 _sound_perf_measurements.push_back(this->start_time);
277 _sound_perf_measurements.push_back(end);
278 _sound_perf_pending.store(true, std::memory_order_release);
279 return;
280 }
281 _pf_data[this->elem].Add(this->start_time, GetPerformanceTimer());
282}
283
284/** Set the rate of expected cycles per second of a performance element. */
285void PerformanceMeasurer::SetExpectedRate(double rate)

Callers

nothing calls this directly

Calls 4

GetPerformanceTimerFunction · 0.85
push_backMethod · 0.80
sizeMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected