mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
let profiler trace 'get member' calls, because I suspect they might be slow (linear string lookup)
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1244 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user