Talk:Resource Tracking for FlightGear: Difference between revisions

Jump to navigation Jump to search
m
→‎Nasal GC: PMs to wiki
(+ Article Notes, section)
m (→‎Nasal GC: PMs to wiki)
Line 155: Line 155:


{{WIP}}
{{WIP}}
ThorstenB once posted a patch that tracks GC invocations over time (printf) which should be easy to also expose to the property tree and log/plot accordingly.
Also, it shows "GC pressure" (=symbols/references) per namespace.
you don't need a new/dedicated subsystem for tracking GC stuff: The Nasal GC is invoked as part of Nasal, which already is a subsystem, and which will be invoked by other subsystems, too (via listeners & timers).
So, you could patch nasal (in SimGear) to accept an option callback pointer to log this type of stuff, and then register a C++ static method in FGNasalSys that receives the corresponding notifications and logs those via SG_LOG() and/or fgSetDouble()
For instance, The Nasal C engine needs to be initialized via something like naInitNasal() - for details, refer to FGNasalSys::FGNasalSys() (the constructor) and/or the ::init() method.
The corresponding code could be extended to also accept a callback that tracks GC invocations, i.e. total references/symbols per namespace.
ThorstenB's patch should be a good start for this, i.e. the location would remain "as is", but the callback would be registered from FGNasalSys, so that this could be something like static void FGNasalSys::trackGC()
with &FGNasalSys::trackGC being registed then.
looking at the code, there's something called initGlobals at: http://sourceforge.net/p/flightgear/simgear/ci/next/tree/simgear/nasal/code.c#l161
with the globals struct being defined at: http://sourceforge.net/p/flightgear/simgear/ci/next/tree/simgear/nasal/code.h#l40
So this could be easily extended to also hold a void (*gc_callback)() pointer
The C++ constructor for wrapping the Nasal C engine already sets up some C++ stuff: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l210
the whole initGlobals() thing happens when a new context is created: http://sourceforge.net/p/flightgear/simgear/ci/next/tree/simgear/nasal/code.c#l196
So will be automatically invoked by the C++ code at: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l819
The ::init() method contains additional setup logic: http://sourceforge.net/p/flightgear/flightgear/ci/next/tree/src/Scripting/NasalSys.cxx#l812
I would do it like this:
* change the Globals struct to add a new pointer for an optional callback
* edit code.c/code.h to add an optional registerGCTracker() that sets the globals->gc_track_cb
* edit FGNasalSys to add a static method there like "trackGC" use SG_LOG(SG_GENERAL, SG_ALERT, "GC tracker invoked !");
* edit FGNasalSys::FGNasalSys() (the ctor) to set up the globals->gc_track_cb to point at this "trackGC" method
That way, you are registering a C++ callback with the Nasal engine, which can be invoked by checking via:
<syntaxhighlight lang="cpp">
    if (globals->gc_track_cb!=NULL) {
    gc_track_cb();
    }
</syntaxhighlight>
to make it process useful information, just change the signature to accept either a naContext or a naGlobals pointer, so that the C++ routine you registered, can access everything.
And then the C++ code can do stuff like fgSetInt(), SG_LOG() etc easily


== Article Notes ==
== Article Notes ==
Feel free to edit any changes i make that you think is misleading from a coder standpoint -- [[User:Hamzaalloush|Hamzaalloush]] ([[User talk:Hamzaalloush|talk]]) 07:46, 24 August 2015 (EDT)
Feel free to edit any changes i make that you think is misleading from a coder standpoint -- [[User:Hamzaalloush|Hamzaalloush]] ([[User talk:Hamzaalloush|talk]]) 07:46, 24 August 2015 (EDT)

Navigation menu