void TimeBudgetWarningLogger::LogWarningIfOvertime()

in netcx/ec/lib/timebudgetwarninglogger.cpp [44:80]


void TimeBudgetWarningLogger::LogWarningIfOvertime(
    _In_ const TimeBudget& timeBudget
)
{
    const auto totalTimeInDispatch = timeBudget.TotalTimeInDispatch();
    if (m_watermarkTicks == 0 || totalTimeInDispatch == 0)
    {
        return;
    }

    if (totalTimeInDispatch >= m_watermarkTicks)
    {
        m_iterationsOverTimeCount++;
    }

    LARGE_INTEGER currentSystemTimeTicks;
    KeQueryTickCount(&currentSystemTimeTicks);

    if (currentSystemTimeTicks.QuadPart > m_nextReportingDeadlineTicks.QuadPart)
    {
        if (m_iterationsOverTimeCount != 0)
        {
            ULONG timeSinceLastReportMs = 0;
            if (m_nextReportingDeadlineTicks.QuadPart != 0)
            {
                auto overtimeTicks = static_cast<ULONG>(currentSystemTimeTicks.QuadPart - m_nextReportingDeadlineTicks.QuadPart);
                timeSinceLastReportMs = overtimeTicks * KeQueryTimeIncrement() / MS_TO_TIME_INCREMENT_MULT;
                timeSinceLastReportMs += m_dispatchTimeWarningIntervalMs;
            }

            ReportWarning(timeSinceLastReportMs);

            m_nextReportingDeadlineTicks.QuadPart = currentSystemTimeTicks.QuadPart + m_reportIntervalTicks;
            m_iterationsOverTimeCount = 0;
        }
    }
}