diff --git a/src/script/profiler.cpp b/src/script/profiler.cpp index 1acf6e45..3780ecfe 100644 --- a/src/script/profiler.cpp +++ b/src/script/profiler.cpp @@ -104,6 +104,19 @@ Profiler::Profiler(Timer& timer, Variable function_name) timer.exclude_time(); } +// Enter a function +Profiler::Profiler(Timer& timer, const Char* function_name) + : timer(timer) + , parent(function) // push +{ + FunctionProfileP& fpp = parent->children[(size_t)function_name]; + if (!fpp) { + fpp = new_intrusive1(function_name); + } + function = fpp.get(); + timer.exclude_time(); +} + // Enter a function Profiler::Profiler(Timer& timer, void* function_object, const String& function_name) : timer(timer) diff --git a/src/script/profiler.hpp b/src/script/profiler.hpp index 237ce604..16d8cd85 100644 --- a/src/script/profiler.hpp +++ b/src/script/profiler.hpp @@ -70,6 +70,8 @@ class FunctionProfile : public IntrusivePtrBase { String name; ProfileTime time_ticks; UInt calls; + /// for each id, called children + /** we (ab)use the fact that all pointers are even to store both pointers and ids */ map children; /// The children, sorted by time @@ -90,8 +92,16 @@ const FunctionProfile& profile_aggregated(int level = 1); /// Profile a single function call class Profiler { public: + /// Log the fact that the function function_name is entered, ends when profiler goes out of scope. + /** Time between the construction of Timer and the construction of Profiler is excluded from ALL profiles. + */ Profiler(Timer& timer, Variable function_name); + /// As above, but with a constant name + Profiler(Timer& timer, const Char* function_name); + /// As above, but using a function object instead of a name, + /** if we haven't seen the object before, it gets the given name. */ Profiler(Timer& timer, void* function_object, const String& function_name); + /// Log the fact that the function is left ~Profiler(); private: Timer& timer; diff --git a/src/script/to_value.hpp b/src/script/to_value.hpp index d90d00b4..e40b74ca 100644 --- a/src/script/to_value.hpp +++ b/src/script/to_value.hpp @@ -11,6 +11,7 @@ #include