MCPcopy Create free account
hub / github.com/GameTechDev/PresentMon / ProcessEtwEventLatencyStats

Method ProcessEtwEventLatencyStats

PresentData/PresentMonTraceSession.cpp:715–771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

713}
714
715void PMTraceSession::ProcessEtwEventLatencyStats(uint64_t eventQpcTimestamp)
716{
717 const auto statsEnabled = pmon::util::log::GlobalPolicy::Get().GetLogLevel() >= pmon::util::log::Level::Debug;
718 if (!statsEnabled) {
719 if (mEtwEventLatencyStatsWindowStartQpc != 0) {
720 ResetEtwEventLatencyStats();
721 }
722 return;
723 }
724
725 if (eventQpcTimestamp == 0) {
726 return;
727 }
728
729 const auto now = pmon::util::GetCurrentTimestamp();
730 if (mEtwEventLatencyStatsWindowStartQpc == 0) {
731 mEtwEventLatencyStatsWindowStartQpc = now;
732 }
733
734 const auto periodSeconds = pmon::util::GetTimestampPeriodSeconds();
735 const auto eventLagMs = pmon::util::TimestampDeltaToSeconds(
736 static_cast<int64_t>(eventQpcTimestamp),
737 now,
738 periodSeconds) * 1000.0;
739 mEtwEventLatencyStatsMs.AddSample(eventLagMs);
740
741 const auto elapsedSeconds = pmon::util::TimestampDeltaToSeconds(
742 mEtwEventLatencyStatsWindowStartQpc,
743 now,
744 periodSeconds);
745 if (elapsedSeconds < 10.0) {
746 return;
747 }
748
749 mEtwEventLatencyStatsMs.Prepare();
750 const auto count = mEtwEventLatencyStatsMs.GetSampleCount();
751 if (count > 0) {
752 pmlog_(pmon::util::log::Level::Debug).note(std::format(
753 "ETW event latency stats [{} events] avg={:.3f} ms min={:.3f} ms p01={:.3f} ms p05={:.3f} ms p10={:.3f} ms p50={:.3f} ms p90={:.3f} ms p95={:.3f} ms p99={:.3f} ms max={:.3f} ms",
754 count,
755 mEtwEventLatencyStatsMs.GetMean(),
756 mEtwEventLatencyStatsMs.GetPercentile(0.00),
757 mEtwEventLatencyStatsMs.GetPercentile(0.01),
758 mEtwEventLatencyStatsMs.GetPercentile(0.05),
759 mEtwEventLatencyStatsMs.GetPercentile(0.10),
760 mEtwEventLatencyStatsMs.GetPercentile(0.50),
761 mEtwEventLatencyStatsMs.GetPercentile(0.90),
762 mEtwEventLatencyStatsMs.GetPercentile(0.95),
763 mEtwEventLatencyStatsMs.GetPercentile(0.99),
764 mEtwEventLatencyStatsMs.GetPercentile(1.00)));
765 } else {
766 pmlog_(pmon::util::log::Level::Debug).note("ETW event latency stats [0 events]");
767 }
768
769 mEtwEventLatencyStatsMs.Reset();
770 mEtwEventLatencyStatsWindowStartQpc = now;
771}
772

Callers 1

EventRecordCallbackFunction · 0.80

Calls 10

GetCurrentTimestampFunction · 0.85
TimestampDeltaToSecondsFunction · 0.85
GetLogLevelMethod · 0.80
PrepareMethod · 0.80
GetSampleCountMethod · 0.80
AddSampleMethod · 0.45
GetMeanMethod · 0.45
GetPercentileMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected