mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Stop calculating unused stats
This commit is contained in:
parent
f036b730f6
commit
837f7da035
@ -9,7 +9,7 @@ namespace Config
|
||||
class StatsColumns : public EnumListSetting
|
||||
{
|
||||
public:
|
||||
enum Values { CUR, AVG, MIN, MAX, LABEL };
|
||||
enum Values { CUR, AVG, MIN, MAX, LABEL, VALUE_COUNT };
|
||||
|
||||
StatsColumns()
|
||||
: EnumListSetting("StatsColumns", "label, cur, avg, min, max", { "cur", "avg", "min", "max", "label" })
|
||||
|
@ -25,7 +25,8 @@ namespace Config
|
||||
LOCKTIME,
|
||||
DDIUSAGE,
|
||||
GDIOBJECTS,
|
||||
DEBUG
|
||||
DEBUG,
|
||||
VALUE_COUNT
|
||||
};
|
||||
|
||||
StatsRows()
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <Common/Log.h>
|
||||
#include <Common/Hook.h>
|
||||
#include <Config/Settings/ConfigHotKey.h>
|
||||
#include <Config/Settings/StatsHotKey.h>
|
||||
#include <D3dDdi/ScopedCriticalSection.h>
|
||||
#include <Dll/Dll.h>
|
||||
#include <DDraw/RealPrimarySurface.h>
|
||||
@ -79,11 +81,17 @@ namespace
|
||||
return 0;
|
||||
}
|
||||
|
||||
Overlay::StatsWindow statsWindow;
|
||||
g_statsWindow = &statsWindow;
|
||||
if (0 != Config::statsHotKey.get().vk)
|
||||
{
|
||||
static Overlay::StatsWindow statsWindow;
|
||||
g_statsWindow = &statsWindow;
|
||||
}
|
||||
|
||||
Overlay::ConfigWindow configWindow;
|
||||
g_configWindow = &configWindow;
|
||||
if (0 != Config::configHotKey.get().vk)
|
||||
{
|
||||
static Overlay::ConfigWindow configWindow;
|
||||
g_configWindow = &configWindow;
|
||||
}
|
||||
|
||||
{
|
||||
D3dDdi::ScopedCriticalSection lock;
|
||||
|
@ -9,12 +9,6 @@ StatsEventCount::StatsEventCount()
|
||||
{
|
||||
}
|
||||
|
||||
void StatsEventCount::add(TickCount tickCount)
|
||||
{
|
||||
setTickCount(tickCount);
|
||||
m_sampleCount++;
|
||||
}
|
||||
|
||||
void StatsEventCount::finalize(SampleCount& sampleCount, Stat& sum, Stat& min, Stat& max)
|
||||
{
|
||||
const uint32_t index = getCurrentTickCount() % s_update_rate;
|
||||
|
@ -7,7 +7,14 @@ class StatsEventCount : public StatsQueue
|
||||
public:
|
||||
StatsEventCount();
|
||||
|
||||
void add(TickCount tickCount);
|
||||
void add(TickCount tickCount)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
setTickCount(tickCount);
|
||||
m_sampleCount++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void finalize(SampleCount& sampleCount, Stat& sum, Stat& min, Stat& max) override;
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
StatsEventGroup::StatsEventGroup()
|
||||
: m_rate(m_time)
|
||||
, m_isEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
void StatsEventGroup::add()
|
||||
void StatsEventGroup::addImpl()
|
||||
{
|
||||
auto qpcNow = Time::queryPerformanceCounter();
|
||||
auto tickCount = StatsQueue::getTickCount(qpcNow);
|
||||
@ -13,3 +14,13 @@ void StatsEventGroup::add()
|
||||
m_count.add(tickCount);
|
||||
m_time.add(tickCount, qpcNow);
|
||||
}
|
||||
|
||||
void StatsEventGroup::enable()
|
||||
{
|
||||
if (m_rate.isEnabled())
|
||||
{
|
||||
m_time.enable();
|
||||
}
|
||||
|
||||
m_isEnabled = m_count.isEnabled() || m_time.isEnabled() || m_rate.isEnabled();
|
||||
}
|
||||
|
@ -9,9 +9,15 @@ class StatsEventGroup
|
||||
public:
|
||||
StatsEventGroup();
|
||||
|
||||
void add();
|
||||
void add() { if (m_isEnabled) { addImpl(); } }
|
||||
void enable();
|
||||
|
||||
StatsEventCount m_count;
|
||||
StatsEventTime m_time;
|
||||
StatsEventRate m_rate;
|
||||
|
||||
private:
|
||||
void addImpl();
|
||||
|
||||
bool m_isEnabled;
|
||||
};
|
||||
|
@ -7,7 +7,7 @@ StatsEventTime::StatsEventTime()
|
||||
{
|
||||
}
|
||||
|
||||
void StatsEventTime::add(TickCount tickCount, long long qpcNow)
|
||||
void StatsEventTime::addImpl(TickCount tickCount, long long qpcNow)
|
||||
{
|
||||
if (0 != m_qpcLast && qpcNow - m_qpcLast < s_history_time * Time::g_qpcFrequency)
|
||||
{
|
||||
|
@ -7,11 +7,13 @@ class StatsEventTime : public StatsQueue
|
||||
public:
|
||||
StatsEventTime();
|
||||
|
||||
void add(TickCount tickCount, long long qpcNow);
|
||||
void add(TickCount tickCount, long long qpcNow) { if (isEnabled()) { addImpl(tickCount, qpcNow); } }
|
||||
|
||||
private:
|
||||
friend class StatsEventRate;
|
||||
|
||||
void addImpl(TickCount tickCount, long long qpcNow);
|
||||
|
||||
virtual double convert(double stat) override;
|
||||
|
||||
long long m_qpcLast;
|
||||
|
@ -1,9 +1,14 @@
|
||||
#include <array>
|
||||
|
||||
#include <Config/Settings/StatsAggregateTime.h>
|
||||
#include <Config/Settings/StatsColumns.h>
|
||||
#include <Config/Settings/StatsUpdateRate.h>
|
||||
#include <Overlay/StatsQueue.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::array<bool, Config::Settings::StatsColumns::VALUE_COUNT> g_isColumnEnabled = {};
|
||||
|
||||
bool greaterEqual(StatsQueue::Stat a, StatsQueue::Stat b)
|
||||
{
|
||||
return a >= b;
|
||||
@ -17,9 +22,23 @@ namespace
|
||||
|
||||
StatsQueueInitializer::StatsQueueInitializer()
|
||||
{
|
||||
for (auto statsColumnIndex : Config::statsColumns.get())
|
||||
{
|
||||
g_isColumnEnabled[statsColumnIndex] = true;
|
||||
}
|
||||
|
||||
s_update_rate = Config::statsUpdateRate.get();
|
||||
s_history_time = Config::statsAggregateTime.get();
|
||||
s_history_size = s_history_time * s_update_rate;
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::AVG] ||
|
||||
g_isColumnEnabled[Config::Settings::StatsColumns::MIN] ||
|
||||
g_isColumnEnabled[Config::Settings::StatsColumns::MAX])
|
||||
{
|
||||
s_history_size = s_history_time * s_update_rate;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_history_size = 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t StatsQueueInitializer::s_history_size = 0;
|
||||
@ -36,6 +55,7 @@ StatsQueue::StatsQueue()
|
||||
, m_max(0)
|
||||
, m_totalSampleCount(0)
|
||||
, m_totalSum(0)
|
||||
, m_isEnabled(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -71,8 +91,14 @@ StatsQueue::Stats StatsQueue::getRawStats(TickCount tickCount)
|
||||
setTickCount(tickCount);
|
||||
Stats stats = {};
|
||||
const uint32_t index = (m_currentTickCount - 1) % s_history_size;
|
||||
stats.cur = getAvg(m_sums[index], m_sampleCounts[index]);
|
||||
stats.avg = getAvg(m_totalSum, m_totalSampleCount);
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::CUR])
|
||||
{
|
||||
stats.cur = getAvg(m_sums[index], m_sampleCounts[index]);
|
||||
}
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::AVG])
|
||||
{
|
||||
stats.avg = getAvg(m_totalSum, m_totalSampleCount);
|
||||
}
|
||||
stats.min = m_minQueue.empty() ? NAN : m_minQueue.front().stat;
|
||||
stats.max = m_maxQueue.empty() ? NAN : m_maxQueue.front().stat;
|
||||
return stats;
|
||||
@ -86,10 +112,22 @@ StatsQueue::SampleCount StatsQueue::getSampleCount(TickCount tickCount) const
|
||||
StatsQueue::Stats StatsQueue::getStats(TickCount tickCount)
|
||||
{
|
||||
Stats stats = getRawStats(tickCount);
|
||||
stats.cur = convert(stats.cur);
|
||||
stats.avg = convert(stats.avg);
|
||||
stats.min = convert(stats.min);
|
||||
stats.max = convert(stats.max);
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::CUR])
|
||||
{
|
||||
stats.cur = convert(stats.cur);
|
||||
}
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::AVG])
|
||||
{
|
||||
stats.avg = convert(stats.avg);
|
||||
}
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::MIN])
|
||||
{
|
||||
stats.min = convert(stats.min);
|
||||
}
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::MAX])
|
||||
{
|
||||
stats.max = convert(stats.max);
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
@ -105,8 +143,14 @@ void StatsQueue::push()
|
||||
m_sampleCounts[index] = m_sampleCount;
|
||||
m_sums[index] = m_sum;
|
||||
|
||||
pushToMinMaxQueue(m_minQueue, m_min, lessEqual);
|
||||
pushToMinMaxQueue(m_maxQueue, m_max, greaterEqual);
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::MIN])
|
||||
{
|
||||
pushToMinMaxQueue(m_minQueue, m_min, lessEqual);
|
||||
}
|
||||
if (g_isColumnEnabled[Config::Settings::StatsColumns::MAX])
|
||||
{
|
||||
pushToMinMaxQueue(m_maxQueue, m_max, greaterEqual);
|
||||
}
|
||||
|
||||
m_sampleCount = 0;
|
||||
m_sum = 0;
|
||||
|
@ -35,7 +35,9 @@ public:
|
||||
void addSample(TickCount tickCount, Stat stat);
|
||||
Stats getStats(TickCount tickCount);
|
||||
|
||||
void enable() { m_isEnabled = true; }
|
||||
TickCount getCurrentTickCount() const { return m_currentTickCount; }
|
||||
bool isEnabled() const { return m_isEnabled; }
|
||||
|
||||
static long long getQpc(TickCount tickCount)
|
||||
{
|
||||
@ -79,4 +81,5 @@ private:
|
||||
Stat m_max;
|
||||
SampleCount m_totalSampleCount;
|
||||
Stat m_totalSum;
|
||||
bool m_isEnabled;
|
||||
};
|
||||
|
@ -36,14 +36,14 @@ void StatsTimer::resetTickCount()
|
||||
m_qpcSum = 0;
|
||||
}
|
||||
|
||||
void StatsTimer::start()
|
||||
void StatsTimer::startImpl()
|
||||
{
|
||||
auto qpcStart = Time::queryPerformanceCounter();
|
||||
setTickCount(getTickCount(qpcStart));
|
||||
m_qpcStart = qpcStart;
|
||||
}
|
||||
|
||||
void StatsTimer::stop()
|
||||
void StatsTimer::stopImpl()
|
||||
{
|
||||
auto qpcEnd = Time::queryPerformanceCounter();
|
||||
setTickCount(getTickCount(qpcEnd));
|
||||
|
@ -7,14 +7,17 @@ class StatsTimer : public StatsQueue
|
||||
public:
|
||||
StatsTimer();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void start() { if (isEnabled()) { startImpl(); } }
|
||||
void stop() { if (isEnabled()) { stopImpl(); } }
|
||||
|
||||
private:
|
||||
virtual double convert(double stat) override;
|
||||
virtual void finalize(SampleCount& sampleCount, Stat& sum, Stat& min, Stat& max) override;
|
||||
virtual void resetTickCount() override;
|
||||
|
||||
void startImpl();
|
||||
void stopImpl();
|
||||
|
||||
long long m_qpcStart;
|
||||
long long m_qpcSum;
|
||||
};
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <Config/Settings/StatsHotKey.h>
|
||||
#include <Config/Settings/StatsPosX.h>
|
||||
#include <Config/Settings/StatsPosY.h>
|
||||
#include <Config/Settings/StatsRows.h>
|
||||
#include <Config/Settings/StatsTransparency.h>
|
||||
#include <Gdi/GuiThread.h>
|
||||
#include <Input/Input.h>
|
||||
@ -94,34 +93,48 @@ namespace Overlay
|
||||
{ 0, 0, getWidth(), static_cast<int>(Config::statsRows.get().size()) * ROW_HEIGHT + BORDER },
|
||||
0, Config::statsTransparency.get(), Config::statsHotKey.get())
|
||||
, m_presentCount(0)
|
||||
, m_isRowEnabled{}
|
||||
, m_tickCount(0)
|
||||
{
|
||||
m_statsRows.push_back({ "", [](auto) { return std::array<std::string, 4>{ "cur", "avg", "min", "max" }; },
|
||||
WS_VISIBLE | WS_DISABLED });
|
||||
m_statsRows.push_back({ "Present count", UpdateStats(m_present.m_count) });
|
||||
m_statsRows.push_back({ "Present rate", UpdateStats(m_present.m_rate) });
|
||||
m_statsRows.push_back({ "Present time", UpdateStats(m_present.m_time) });
|
||||
m_statsRows.push_back({ "Flip count", UpdateStats(m_flip.m_count) });
|
||||
m_statsRows.push_back({ "Flip rate", UpdateStats(m_flip.m_rate) });
|
||||
m_statsRows.push_back({ "Flip time", UpdateStats(m_flip.m_time) });
|
||||
m_statsRows.push_back({ "Blit count", UpdateStats(m_blit.m_count) });
|
||||
m_statsRows.push_back({ "Blit rate", UpdateStats(m_blit.m_rate) });
|
||||
m_statsRows.push_back({ "Blit time", UpdateStats(m_blit.m_time) });
|
||||
m_statsRows.push_back({ "Lock count", UpdateStats(m_lock.m_count) });
|
||||
m_statsRows.push_back({ "Lock rate", UpdateStats(m_lock.m_rate) });
|
||||
m_statsRows.push_back({ "Lock time", UpdateStats(m_lock.m_time) });
|
||||
m_statsRows.push_back({ "DDI usage", UpdateStats(m_ddiUsage) });
|
||||
m_statsRows.push_back({ "GDI objects", UpdateStats(m_gdiObjects) });
|
||||
m_statsRows.push_back({ "", &getDebugInfo, WS_VISIBLE | WS_GROUP });
|
||||
nullptr, WS_VISIBLE | WS_DISABLED });
|
||||
m_statsRows.push_back({ "Present count", UpdateStats(m_present.m_count), &m_present.m_count });
|
||||
m_statsRows.push_back({ "Present rate", UpdateStats(m_present.m_rate), &m_present.m_rate });
|
||||
m_statsRows.push_back({ "Present time", UpdateStats(m_present.m_time), &m_present.m_time });
|
||||
m_statsRows.push_back({ "Flip count", UpdateStats(m_flip.m_count), &m_flip.m_count });
|
||||
m_statsRows.push_back({ "Flip rate", UpdateStats(m_flip.m_rate), &m_flip.m_rate });
|
||||
m_statsRows.push_back({ "Flip time", UpdateStats(m_flip.m_time), &m_flip.m_time });
|
||||
m_statsRows.push_back({ "Blit count", UpdateStats(m_blit.m_count), &m_blit.m_count });
|
||||
m_statsRows.push_back({ "Blit rate", UpdateStats(m_blit.m_rate), &m_blit.m_rate });
|
||||
m_statsRows.push_back({ "Blit time", UpdateStats(m_blit.m_time), &m_blit.m_time });
|
||||
m_statsRows.push_back({ "Lock count", UpdateStats(m_lock.m_count), &m_lock.m_count });
|
||||
m_statsRows.push_back({ "Lock rate", UpdateStats(m_lock.m_rate), &m_lock.m_rate });
|
||||
m_statsRows.push_back({ "Lock time", UpdateStats(m_lock.m_time), &m_lock.m_time });
|
||||
m_statsRows.push_back({ "DDI usage", UpdateStats(m_ddiUsage), &m_ddiUsage });
|
||||
m_statsRows.push_back({ "GDI objects", UpdateStats(m_gdiObjects), &m_gdiObjects });
|
||||
m_statsRows.push_back({ "", &getDebugInfo, nullptr, WS_VISIBLE | WS_GROUP });
|
||||
|
||||
for (auto statsRowIndex : Config::statsRows.get())
|
||||
{
|
||||
auto& statsRow = m_statsRows[statsRowIndex];
|
||||
auto& statsControl = addControl(statsRow.name, statsRow.updateFunc, statsRow.style);
|
||||
|
||||
m_isRowEnabled[statsRowIndex] = true;
|
||||
if (statsRow.statsQueue)
|
||||
{
|
||||
statsRow.statsQueue->enable();
|
||||
}
|
||||
|
||||
if (statsRow.style & WS_DISABLED)
|
||||
{
|
||||
statsControl.update(0);
|
||||
}
|
||||
}
|
||||
|
||||
m_present.enable();
|
||||
m_flip.enable();
|
||||
m_blit.enable();
|
||||
m_lock.enable();
|
||||
}
|
||||
|
||||
StatsControl& StatsWindow::addControl(const std::string& name, StatsControl::UpdateFunc updateFunc, DWORD style)
|
||||
@ -163,17 +176,24 @@ namespace Overlay
|
||||
m_tickCount = StatsQueue::getTickCount();
|
||||
if (m_tickCount == prevTickCount)
|
||||
{
|
||||
for (auto& statsControl : m_statsControls)
|
||||
if (isRowEnabled(Config::Settings::StatsRows::DEBUG))
|
||||
{
|
||||
if (statsControl.getStyle() & WS_GROUP)
|
||||
for (auto& statsControl : m_statsControls)
|
||||
{
|
||||
statsControl.update(m_tickCount);
|
||||
if (statsControl.getStyle() & WS_GROUP)
|
||||
{
|
||||
statsControl.update(m_tickCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_gdiObjects.addSample(m_tickCount, GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS));
|
||||
if (isRowEnabled(Config::Settings::StatsRows::GDIOBJECTS))
|
||||
{
|
||||
m_gdiObjects.addSample(m_tickCount, GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS));
|
||||
}
|
||||
|
||||
for (auto& statsControl : m_statsControls)
|
||||
{
|
||||
if (statsControl.isEnabled())
|
||||
|
@ -1,10 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Config/Settings/StatsRows.h>
|
||||
#include <Overlay/StatsControl.h>
|
||||
#include <Overlay/StatsEventGroup.h>
|
||||
#include <Overlay/StatsQueue.h>
|
||||
@ -18,6 +20,7 @@ namespace Overlay
|
||||
public:
|
||||
StatsWindow();
|
||||
|
||||
bool isRowEnabled(Config::Settings::StatsRows::Values row) const { return m_isRowEnabled[row]; }
|
||||
void updateStats();
|
||||
|
||||
uint32_t m_presentCount;
|
||||
@ -33,6 +36,7 @@ namespace Overlay
|
||||
{
|
||||
const char* name;
|
||||
StatsControl::UpdateFunc updateFunc;
|
||||
StatsQueue* statsQueue;
|
||||
DWORD style;
|
||||
};
|
||||
|
||||
@ -43,6 +47,7 @@ namespace Overlay
|
||||
|
||||
static LONG getWidth();
|
||||
|
||||
std::array<bool, Config::Settings::StatsRows::VALUE_COUNT> m_isRowEnabled;
|
||||
std::list<StatsControl> m_statsControls;
|
||||
std::vector<StatsRow> m_statsRows;
|
||||
uint64_t m_tickCount;
|
||||
|
Loading…
x
Reference in New Issue
Block a user