Commit 911fcd2a authored by twanvl's avatar twanvl

let profiler trace 'get member' calls, because I suspect they might be slow (linear string lookup)

parent c6e3cf56
......@@ -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<FunctionProfile>(function_name);
}
function = fpp.get();
timer.exclude_time();
}
// Enter a function
Profiler::Profiler(Timer& timer, void* function_object, const String& function_name)
: timer(timer)
......
......@@ -70,6 +70,8 @@ class FunctionProfile : public IntrusivePtrBase<FunctionProfile> {
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<size_t,FunctionProfileP> 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;
......
......@@ -11,6 +11,7 @@
#include <script/value.hpp>
#include <script/script.hpp>
#include <script/profiler.hpp>
#include <util/reflect.hpp>
#include <util/error.hpp>
#include <util/io/get_member.hpp>
......@@ -269,6 +270,10 @@ class ScriptObject : public ScriptValue {
ScriptValueP d = getDefault(); return d ? d->toImage(d) : ScriptValue::toImage(thisP);
}
virtual ScriptValueP getMember(const String& name) const {
#if USE_SCRIPT_PROFILING
Timer t;
Profiler prof(t, _("get member"));
#endif
GetMember gm(name);
gm.handle(*value);
if (gm.result()) return gm.result();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment