Added a panel showing profiler timings

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1523 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2010-10-13 21:35:30 +00:00
parent 7bcb045668
commit 9735e24517
8 changed files with 230 additions and 10 deletions
+2 -1
View File
@@ -53,7 +53,7 @@ void FunctionProfile::get_children(vector<FunctionProfileP>& out) const {
sort(out.begin(), out.end(), compare_time);
}
// note: not thread safe
FunctionProfile profile_aggr(_("everywhere"));
void profile_aggregate(FunctionProfile& parent, int level, int max_level, const FunctionProfile& p);
@@ -135,6 +135,7 @@ Profiler::~Profiler() {
ProfileTime time = timer.time();
if (function == parent) return; // don't count
function->time_ticks += time;
function->time_ticks_max = max(function->time_ticks_max,time);
function->calls += 1;
function = parent; // pop
}
+25 -5
View File
@@ -75,11 +75,15 @@ class Timer {
/// How much time was spent in a function?
class FunctionProfile : public IntrusivePtrBase<FunctionProfile> {
public:
FunctionProfile(const String& name) : name(name), time_ticks(0), calls(0) {}
FunctionProfile(const String& name)
: name(name), time_ticks(0), time_ticks_max(0), calls(0)
{}
String name;
ProfileTime time_ticks;
UInt calls;
ProfileTime time_ticks_max;
int calls;
/// for each id, called children
/** we (ab)use the fact that all pointers are even to store both pointers and ids */
map<size_t,FunctionProfileP> children;
@@ -88,13 +92,15 @@ class FunctionProfile : public IntrusivePtrBase<FunctionProfile> {
void get_children(vector<FunctionProfileP>& out) const;
/// Time in seconds
inline double time() const { return time_ticks / (double)timer_resolution(); }
inline double avg_time() const { return time() / calls; }
inline double total_time() const { return time_ticks / (double)timer_resolution(); }
inline double avg_time() const { return total_time() / calls; }
inline double max_time() const { return time_ticks_max / (double)timer_resolution(); }
};
/// The root profile
extern FunctionProfile profile_root;
/// Return a simplified profile, where all things beyond a cerrain level are agragated
const FunctionProfile& profile_aggregated(int level = 1);
// ----------------------------------------------------------------------------- : Profiler
@@ -119,6 +125,20 @@ class Profiler {
FunctionProfile* parent;
};
// Profile the current function (all following code in the current block) under the given name
#define PROFILER(name) \
Timer profile_timer; \
Profiler profiler(profile_timer, name)
#define PROFILER2(name1,name2) \
Timer profile_timer; \
Profiler profiler(profile_timer, name1,name2)
#else // USE_SCRIPT_PROFILING
#define PROFILER(a)
#define PROFILER2(a,b)
#endif // USE_SCRIPT_PROFILING
// ----------------------------------------------------------------------------- : EOF
#endif
#endif
+1 -4
View File
@@ -295,10 +295,7 @@ void SetScriptManager::updateAll() {
Context& ctx = getContext(set.stylesheet);
FOR_EACH(v, set.data) {
try {
#if USE_SCRIPT_PROFILING
Timer t;
Profiler prof(t, v->fieldP.get(), _("update set.") + v->fieldP->name);
#endif
PROFILER2( v->fieldP.get(), _("update set.") + v->fieldP->name );
v->update(ctx);
} catch (const ScriptError& e) {
handle_error(ScriptError(e.what() + _("\n while updating set value '") + v->fieldP->name + _("'")), false, true);