Difference between revisions of "LlScriptProfiler"

From Second Life Wiki
Jump to navigation Jump to search
m
m (remove repeated word)
 
(9 intermediate revisions by 8 users not shown)
Line 8: Line 8:
|func_footer
|func_footer
|spec=
|spec=
This function's behavior is dependent upon the VM the script is using. [[#Mono|Mono]] is the new VM, [[#LSO|LSO]] is the old VM. The big difference between between Mono and LSO is that Mono scripts run faster and can utilize four times more memory.
This function's behavior is dependent upon the VM the script is using. [[#Mono|Mono]] is the new VM, [[#LSO|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.


===Mono===
===Mono===


Use this function with [[PROFILE_SCRIPT_MEMORY]] to enable memory profiling at a sever 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.
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.


===LSO===
===LSO===
Line 19: Line 19:


|caveats=
|caveats=
*Scripts compiled to LSL can not be profiled for memory use.
*Scripts compiled to LSO can not be profiled for memory use.
*The profile state will reset to [[PROFILE_NONE]] if:
*The profile state will reset to [[PROFILE_NONE]] if:
** the object the script is in is de-rezed, rezed or changes regions (via region cross or teleport)
** the object the script is in is de-rezed, rezed or changes regions (via region cross or teleport)
Line 28: Line 28:
{{!}}- {{hl2}}
{{!}}- {{hl2}}
! Constant
! Constant
! Val
! Description
! Description
{{!}}-
{{!}}-
{{!}} [[PROFILE_NONE]]
{{!}} [[PROFILE_NONE]]
{{!}} 0
{{!}} Disables profiling
{{!}} Disables profiling
{{!}}-
{{!}}-
{{!}} [[PROFILE_SCRIPT_MEMORY]]
{{!}} [[PROFILE_SCRIPT_MEMORY]]
{{!}} 1
{{!}} Enables memory profiling
{{!}} Enables memory profiling
{{!}}}
{{!}}}
|examples=
|examples=
Calling llScriptProfiler can look like this:
Calling llScriptProfiler can look like this:
<lsl>
<source lang="lsl2">
llScriptProfiler(PROFILE_SCRIPT_MEMORY)
llScriptProfiler(PROFILE_SCRIPT_MEMORY);
my_func();
my_func();
llScriptProfiler(PROFILE_NONE)
llScriptProfiler(PROFILE_NONE);
llOwnerSay("This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during my_func.");
llOwnerSay("This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during my_func.");
</lsl>
</source>
 
This is how it looks in a script as an example:
<source lang="lsl2">// need to run something for the profile to register...
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." );
    }
}
 
// outputs
// Object: Memory used: 4968 bytes, total memory: 5000 bytes.</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llGetSPMaxMemory]]}}
|also_functions=
{{LSL DefineRow||[[llGetSPMaxMemory]]}}
{{LSL DefineRow||[[llGetMemoryLimit]]|}}
{{LSL DefineRow||[[llSetMemoryLimit]]|}}
|also_events
|also_events
|also_tests
|also_tests
Line 52: Line 86:
|lso
|lso
|cat1=Script
|cat1=Script
|cat2
|cat2=Memory
|cat3
|cat3=Script Profiler
|cat4
|cat4
|history = Date of Release  [[ Release_Notes/Second_Life_Server/11#11.06.17.233176 | 17/06/2011 ]]
}}
}}

Latest revision as of 09:16, 31 March 2015

Summary

Function: llScriptProfiler( integer flags );

Enables or disables the scripts profiling state.

• integer flags PROFILE_* flags

Specification

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.

Mono

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.

LSO

This function has no effect for scripts not compiled to Mono.

Constant Val Description
PROFILE_NONE 0 Disables profiling
PROFILE_SCRIPT_MEMORY 1 Enables memory profiling

Caveats

  • Scripts compiled to LSO can not be profiled for memory use.
  • The profile state will reset to PROFILE_NONE if:
    • the object the script is in is de-rezed, rezed or changes regions (via region cross or teleport)
    • the region that object with the script is in shuts down or restarts
    • if 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).
All Issues ~ Search JIRA for related Bugs

Examples

Calling llScriptProfiler can look like this:

llScriptProfiler(PROFILE_SCRIPT_MEMORY);
my_func();
llScriptProfiler(PROFILE_NONE);
llOwnerSay("This script used at most " + (string)llGetSPMaxMemory() + " bytes of memory during my_func.");

This is how it looks in a script as an example:

// need to run something for the profile to register... 
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." );
    }
}

// outputs 
// Object: Memory used: 4968 bytes, total memory: 5000 bytes.

See Also

Functions

•  llGetSPMaxMemory
•  llGetMemoryLimit
•  llSetMemoryLimit

Deep Notes

History

Date of Release 17/06/2011

Search JIRA for related Issues

Signature

function void llScriptProfiler( integer flags );