profile.lsl

This is the source code of an included piece of LSL that I use frequently. It implements script memory profiling.

Normally, I’d say that if you aren’t using the Firestorm script preprocessor, copy the code between the opening and closing hash directives, but if you’re using this code, you’re probably sophisticated enough to figure it out 🙂

#ifndef __PROFILE_LSL
#define __PROFILE_LSL

#ifndef MEMLIMIT
#error MEMLIMIT not defined!
#endif // MEMLIMIT

#ifdef PROFILE
#ifndef DEBUG
#error define DEBUG to see profile info
#endif // DEBUG
#endif // PROFILE

#include "debug.lsl"    // See the source of debug.lsl

__profile_ml () {
    debug ("Memory limit: " + (string)MEMLIMIT);
    if (!llSetMemoryLimit (MEMLIMIT)) {
        debug ("MEMLIMIT = " + (string)MEMLIMIT + " too small");
    }
#ifndef PROFILE
    llScriptProfiler (PROFILE_NONE);
#endif // PROFILE
}

#ifdef PROFILE

init_profile () {
    __profile_ml ();
    llScriptProfiler (PROFILE_SCRIPT_MEMORY);
    debug ("Memory profile init: " + (string)llGetSPMaxMemory ());
}

show_profile (string id) {
    debug ("Memory profile show (" + id + "): " + (string)llGetSPMaxMemory ());
}

stop_profile () {
    debug ("Memory profile stop: " + (string)llGetSPMaxMemory ());
    llScriptProfiler (PROFILE_NONE);
}

#else // PROFILE

#define init_profile() __profile_ml()
#define show_profile(dummy)
#define stop_profile()

#endif // PROFILE

#endif // __PROFILE_LSL