llScriptProfiler
void llScriptProfiler(integer State)Enables or disables script profiling options. Currently only supports PROFILE_SCRIPT_MEMORY (Mono only) and PROFILE_NONE.
May significantly reduce script performance.
Parameters
-
State(integer) - PROFILE_NONE or PROFILE_SCRIPT_MEMORY flags to control the state.
This function’s behavior is dependent upon the VM the script is using. Mono is the new VM, LSO is the old VM. The big difference between Mono and LSO is that Mono scripts run faster and can utilize four times more memory.
Use this function with PROFILE_SCRIPT_MEMORY to enable memory profiling at a severe script performance penalty. Use it with PROFILE_NONE to disable profiling. During and after a profiling run, llGetSPMaxMemory() will return the most memory used at any one time.
This function has no effect for scripts not compiled to Mono.
Examples
Section titled “Examples”Basic profiling usage:
llScriptProfiler(PROFILE_SCRIPT_MEMORY);my_func();llScriptProfiler(PROFILE_NONE);llOwnerSay("This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during my_func.");Complete example with memory limit:
workerMethod(){ float mathNumber = 3 * PI + 3 * llSin( PI ); llSetText( "Answer: " + (string)mathNumber, <1, 0, 0>, 1.0 );}
default{ state_entry() { llSetMemoryLimit( 5000 ); // set the memory limit
// call up the profiler, execute a method, stop profiler llScriptProfiler( PROFILE_SCRIPT_MEMORY ); workerMethod(); llScriptProfiler( PROFILE_NONE );
// display memory usage... llSay(0, "Memory used: " + (string)llGetSPMaxMemory() + " bytes, total memory: " + (string)llGetMemoryLimit() + " bytes." ); }}
// Output: Memory used: 4968 bytes, total memory: 5000 bytes.Caveats
Section titled “Caveats”- Scripts compiled to LSO cannot be profiled for memory use.
- The profile state will reset to
PROFILE_NONEif:- The object the script is in is de-rezzed, rezzed, or changes regions (via region cross or teleport)
- The region containing the object with the script shuts down or restarts
- The script is reset or taken to or from inventory
- There is up to 100x performance penalty to the script being profiled (but not the region).
See Also
Section titled “See Also”llGetSPMaxMemory()- Returns the most memory used during profilingllGetMemoryLimit()- Gets the current memory limitllSetMemoryLimit()- Sets the maximum memory available to the script