tiagolr / dconsole

Haxe game-like console that provides runtime acess to methods, variables and more.
MIT License
169 stars 16 forks source link

Problems in recursive functions #41

Open larsiusprime opened 10 years ago

larsiusprime commented 10 years ago

I really like the profiler, but it seems to have trouble with codebases that have a lot of recursion (like Flixel-UI's _loadThing() function).

For instance:

function foo(iteration:Int = 0):Void
{
    DC.beginProfile("foo");
    if (iteration < 10)
    {
        foo(iteration++);
    }
    DC.endProfile("foo");
}

Call foo() from your code, and you will receive the error "foo already started." The problem is sometimes I want to be able to profile a recursive function but there's no easy way to do that if the profiler will throw an error if I begin another foo profile before I finish the last one.

If I do something like this:

private function foo(iteration:Int = 0):Void
{
    DC.beginProfile("foo:"+iteration);
    if (iteration < 10)
    {
        foo(iteration+1);
    }
    DC.endProfile("foo:"+iteration);
}

I can get around it, but it would be handy if the profiler would handle this case internally; it's a pretty common use-case.

tiagolr commented 10 years ago

I ran into the same problem very quickly using the profiler, I'll have a look soon.