Script profiler for finding slow scripts

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1191 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-09-02 16:27:47 +00:00
parent 4ad8c9f813
commit 9709364ee7
4 changed files with 180 additions and 2 deletions
+18
View File
@@ -161,6 +161,10 @@ void CLISetInterface::handleCommand(const String& command) {
system(arg.c_str());
#endif
}
#if USE_SCRIPT_PROFILING
} else if (before == _(":profile")) {
showProfilingStats();
#endif
} else {
cli.showError(_("Unknown command, type :help for help."));
}
@@ -187,3 +191,17 @@ void CLISetInterface::handleCommand(const String& command) {
cli.showError(e.what());
}
}
#if USE_SCRIPT_PROFILING
DECLARE_TYPEOF_COLLECTION(FunctionProfileItem);
void CLISetInterface::showProfilingStats() {
vector<FunctionProfileItem> stats;
get_profile(stats);
sort(stats.begin(), stats.end());
cli << GRAY << _("Time(s) Avg (ms) Calls Function") << ENDL;
cli << _("======== ======== ====== ===============================") << NORMAL << ENDL;
FOR_EACH_REVERSE(s, stats) {
cli << String::Format(_("%8.5f %8.5f %6d %s"), s.time, 1000 * s.time / s.calls, s.calls, s.name.c_str()) << ENDL;
}
}
#endif