add custom profiling via Debug(Start|Stop)Profile

This commit is contained in:
Lion Kortlepel
2024-01-24 13:50:11 +01:00
committed by Lion
parent 4347cb4af2
commit 946c1362e1
4 changed files with 14 additions and 0 deletions

View File

@@ -859,9 +859,20 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
Result[name]["stddev"] = stat.stddev;
Result[name]["min"] = stat.min;
Result[name]["max"] = stat.max;
Result[name]["n"] = stat.n;
}
return Result;
});
UtilTable.set_function("DebugStartProfile", [this](const std::string& name) {
mProfileStarts[name] = prof::now();
});
UtilTable.set_function("DebugStopProfile", [this](const std::string& name) {
if (!mProfileStarts.contains(name)) {
beammp_lua_errorf("DebugStopProfile('{}') failed, because a profile for '{}' wasn't started", name, name);
return;
}
mProfile.add_sample(name, prof::duration(mProfileStarts.at(name), prof::now()));
});
auto HttpTable = StateView.create_named_table("Http");
HttpTable.set_function("CreateConnection", [this](const std::string& host, uint16_t port) {