Skip to content

Commit da80517

Browse files
committed
measure overlay framework time
separate from the widget time
1 parent 434b952 commit da80517

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

plugins/lua/overlay.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ local timers_start_ms = dfhack.getTickCount()
1717
function reset_timers()
1818
timers = {}
1919
timers_start_ms = dfhack.getTickCount()
20+
reset_framework_timer()
2021
end
2122
function print_timers()
2223
local elapsed = dfhack.getTickCount() - timers_start_ms
@@ -37,10 +38,14 @@ function print_timers()
3738
))
3839
end
3940
print()
40-
print(('elapsed time: %10d ms (%dm %ds)'):format(
41+
print(('elapsed time: %10d ms (%dm %ds)'):format(
4142
elapsed, elapsed // 60000, (elapsed % 60000) // 1000
4243
))
43-
print(('widget time: %10d ms (%.2f%% of elapsed time)'):format(
44+
local framework_time = get_framework_timer() - sum
45+
print(('framework time: %10d ms (%.2f%% of elapsed time)'):format(
46+
framework_time, (framework_time * 100) / elapsed
47+
))
48+
print(('widget time: %10d ms (%.2f%% of elapsed time)'):format(
4449
sum, (sum * 100) / elapsed
4550
))
4651
end

plugins/overlay.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "Debug.h"
2121
#include "LuaTools.h"
22+
#include "MemAccess.h"
2223
#include "PluginManager.h"
2324
#include "VTableInterpose.h"
2425

@@ -40,6 +41,11 @@ namespace DFHack {
4041

4142
static df::coord2d screenSize;
4243

44+
// instrumentation
45+
uint32_t total_overlay_ms = 0;
46+
static uint32_t get_framework_timer() { return total_overlay_ms; }
47+
static void reset_framework_timer() { total_overlay_ms = 0; }
48+
4349
static void call_overlay_lua(color_ostream *out, const char *fn_name,
4450
int nargs = 0, int nres = 0,
4551
Lua::LuaLambda && args_lambda = Lua::DEFAULT_LUA_LAMBDA,
@@ -48,6 +54,8 @@ static void call_overlay_lua(color_ostream *out, const char *fn_name,
4854

4955
CoreSuspender guard;
5056

57+
uint32_t start_ms = Core::getInstance().p->getTickCount();
58+
5159
auto L = Lua::Core::State;
5260
Lua::StackUnwinder top(L);
5361

@@ -57,6 +65,8 @@ static void call_overlay_lua(color_ostream *out, const char *fn_name,
5765
Lua::CallLuaModuleFunction(*out, L, "plugins.overlay", fn_name, nargs, nres,
5866
std::forward<Lua::LuaLambda&&>(args_lambda),
5967
std::forward<Lua::LuaLambda&&>(res_lambda));
68+
69+
total_overlay_ms += Core::getInstance().p->getTickCount() - start_ms;
6070
}
6171

6272
template<class T>
@@ -198,3 +208,9 @@ DFhackCExport command_result plugin_onupdate (color_ostream &out) {
198208
call_overlay_lua(&out, "update_hotspot_widgets");
199209
return CR_OK;
200210
}
211+
212+
DFHACK_PLUGIN_LUA_FUNCTIONS {
213+
DFHACK_LUA_FUNCTION(get_framework_timer),
214+
DFHACK_LUA_FUNCTION(reset_framework_timer),
215+
DFHACK_LUA_END
216+
};

0 commit comments

Comments
 (0)