mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 05:50:14 +00:00
add custom profiling via Debug(Start|Stop)Profile
This commit is contained in:
1 parent
4347cb4af2
commit
946c1362e1
4 files changed
+14
No files matched your search
@@ -21,6 +21,7 @@ struct Stats {
|
|||||||
double stddev;
|
double stddev;
|
||||||
double min;
|
double min;
|
||||||
double max;
|
double max;
|
||||||
|
size_t n;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Calculates and stores the moving average over K samples of execution time data
|
/// Calculates and stores the moving average over K samples of execution time data
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ private:
|
|||||||
sol::table Lua_FS_ListDirectories(const std::string& Path);
|
sol::table Lua_FS_ListDirectories(const std::string& Path);
|
||||||
|
|
||||||
prof::UnitProfileCollection mProfile {};
|
prof::UnitProfileCollection mProfile {};
|
||||||
|
std::unordered_map<std::string, prof::TimePoint> mProfileStarts;
|
||||||
|
|
||||||
std::string mName;
|
std::string mName;
|
||||||
TLuaStateId mStateId;
|
TLuaStateId mStateId;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ prof::Stats prof::UnitExecutionTime::stats() const {
|
|||||||
if (measurements->size() == 0) {
|
if (measurements->size() == 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result.n = measurements->size();
|
||||||
result.max = std::numeric_limits<double>::min();
|
result.max = std::numeric_limits<double>::min();
|
||||||
result.min = std::numeric_limits<double>::max();
|
result.min = std::numeric_limits<double>::max();
|
||||||
Duration sum {};
|
Duration sum {};
|
||||||
|
|||||||
@@ -859,9 +859,20 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, TLuaStateI
|
|||||||
Result[name]["stddev"] = stat.stddev;
|
Result[name]["stddev"] = stat.stddev;
|
||||||
Result[name]["min"] = stat.min;
|
Result[name]["min"] = stat.min;
|
||||||
Result[name]["max"] = stat.max;
|
Result[name]["max"] = stat.max;
|
||||||
|
Result[name]["n"] = stat.n;
|
||||||
}
|
}
|
||||||
return Result;
|
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");
|
auto HttpTable = StateView.create_named_table("Http");
|
||||||
HttpTable.set_function("CreateConnection", [this](const std::string& host, uint16_t port) {
|
HttpTable.set_function("CreateConnection", [this](const std::string& host, uint16_t port) {
|
||||||
|
|||||||
Reference in new issue
Block a user