Talk:Resource Tracking for FlightGear: Difference between revisions

Jump to navigation Jump to search
m
→‎Nasal GC Tracking: archive code snippets
mNo edit summary
m (→‎Nasal GC Tracking: archive code snippets)
Line 204: Line 204:


And then the C++ code can do stuff like fgSetInt(), SG_LOG() etc easily
And then the C++ code can do stuff like fgSetInt(), SG_LOG() etc easily
SimGear: http://codepad.org/xqOoW7rB
<syntaxhighlight lang="cpp">
diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx
index 8e7622e..ea6890d 100644
--- a/src/Scripting/NasalSys.cxx
+++ b/src/Scripting/NasalSys.cxx
@@ -60,6 +60,11 @@ void postinitNasalGUI(naRef globals, naContext c);
static FGNasalSys* nasalSys = 0;
+static
+void TrackGarbageCollectionCallback(unsigned int refs, unsigned int objs) {
+ SG_LOG(SG_NASAL, SG_ALERT, "Nasal GC: References:"<<refs<< " Objects:"<<objs);
+}
+
// Listener class for loading Nasal modules on demand
class FGNasalModuleListener : public SGPropertyChangeListener
{
@@ -819,6 +824,9 @@ void FGNasalSys::init()
    _context = naNewContext();
+    // register a custom GC tracking callback
+    registerGCTracker(&TrackGarbageCollectionCallback);
+
    // Start with globals.  Add it to itself as a recursive
    // sub-reference under the name "globals".  This gives client-code
    // write access to the namespace if someone wants to do something
@@ -875,6 +883,7 @@ void FGNasalSys::init()
    simgear::PathList directories = nasalDir.children(simgear::Dir::TYPE_DIR+
            simgear::Dir::NO_DOT_OR_DOTDOT, "");
    for (unsigned int i=0; i<directories.size(); ++i) {
+ SG_LOG(SG_NASAL, SG_ALERT, "Adding Nasal module:" << directories[i].file() );
        simgear::Dir dir(directories[i]);
        simgear::PathList scripts = dir.children(simgear::Dir::TYPE_FILE, ".nas");
        addModule(directories[i].file(), scripts);
</syntaxhighlight>
FlightGear: http://codepad.org/xqOoW7rB
<syntaxhighlight lang="cpp">
diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx
index 8e7622e..ea6890d 100644
--- a/src/Scripting/NasalSys.cxx
+++ b/src/Scripting/NasalSys.cxx
@@ -60,6 +60,11 @@ void postinitNasalGUI(naRef globals, naContext c);
static FGNasalSys* nasalSys = 0;
+static
+void TrackGarbageCollectionCallback(unsigned int refs, unsigned int objs) {
+ SG_LOG(SG_NASAL, SG_ALERT, "Nasal GC: References:"<<refs<< " Objects:"<<objs);
+}
+
// Listener class for loading Nasal modules on demand
class FGNasalModuleListener : public SGPropertyChangeListener
{
@@ -819,6 +824,9 @@ void FGNasalSys::init()
    _context = naNewContext();
+    // register a custom GC tracking callback
+    registerGCTracker(&TrackGarbageCollectionCallback);
+
    // Start with globals.  Add it to itself as a recursive
    // sub-reference under the name "globals".  This gives client-code
    // write access to the namespace if someone wants to do something
@@ -875,6 +883,7 @@ void FGNasalSys::init()
    simgear::PathList directories = nasalDir.children(simgear::Dir::TYPE_DIR+
            simgear::Dir::NO_DOT_OR_DOTDOT, "");
    for (unsigned int i=0; i<directories.size(); ++i) {
+ SG_LOG(SG_NASAL, SG_ALERT, "Adding Nasal module:" << directories[i].file() );
        simgear::Dir dir(directories[i]);
        simgear::PathList scripts = dir.children(simgear::Dir::TYPE_FILE, ".nas");
        addModule(directories[i].file(), scripts);
</syntaxhighlight>

Navigation menu