OsGetSimulatorMemoryKB
From OpenSimulator
(Difference between revisions)
(Created page with "{{osslfunc |threat_level=Moderate |function_syntax=integer osGetSimulatorMemoryKB(); |ossl_example=Simple Script (displays only the integer such as 234652064) <source lang="ls...") |
|||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{osslfunc | {{osslfunc | ||
|threat_level=Moderate | |threat_level=Moderate | ||
+ | |permissions=${OSSL}|osslParcelO}ESTATE_MANAGER,ESTATE_OWNER | ||
+ | |delay=0 | ||
|function_syntax=integer osGetSimulatorMemoryKB(); | |function_syntax=integer osGetSimulatorMemoryKB(); | ||
|ossl_example=Simple Script (displays only the integer such as 234652064) | |ossl_example=Simple Script (displays only the integer such as 234652064) | ||
<source lang="lsl"> | <source lang="lsl"> | ||
// Simple Unformatted Output | // Simple Unformatted Output | ||
− | + | ||
integer TotMemUsed; | integer TotMemUsed; | ||
+ | |||
default | default | ||
{ | { | ||
− | + | state_entry() | |
− | + | { | |
− | + | TotMemUsed = osGetSimulatorMemoryKB(); | |
− | + | llSetText( (string)TotMemUsed+" Memory by the OpenSimulator Instance", <0.0, 1.0, 0.0>, 1.0 ); | |
− | + | } | |
− | + | ||
− | + | touch(integer number) | |
− | + | { | |
− | + | TotMemUsed = osGetSimulatorMemoryKB(); | |
− | + | llSetText( (string)TotMemUsed+" Memory by the OpenSimulator Instance", <0.0, 1.0, 0.0>, 1.0 ); | |
+ | } | ||
} | } | ||
</source> | </source> | ||
− | |||
Extended with some formatting: (displays as 234.652 Mb) | Extended with some formatting: (displays as 234.652 Mb) | ||
− | |||
<source lang="lsl"> | <source lang="lsl"> | ||
− | // Simple formatted Output | + | // Simple formatted Output shows either MB or GB as applicable |
− | + | ||
− | + | ||
// ==== GET Memory Integer and Format for Display ==== | // ==== GET Memory Integer and Format for Display ==== | ||
GenStats() | GenStats() | ||
{ | { | ||
− | + | // Get Memory and format it | |
− | + | string TotalMem; | |
− | + | string TotMemUsed; | |
− | + | string TxtTail =" used by OpenSimulator Instance"; | |
− | + | ||
− | + | TotMemUsed = (string)osGetSimulatorMemoryKB(); | |
− | + | integer Len = llStringLength(TotMemUsed); | |
− | + | ||
− | + | if (Len == 5) // ##.### MB | |
− | + | { | |
− | + | string Mem1 = llGetSubString(TotMemUsed, 0, 1); | |
− | + | string Mem2 = llGetSubString(TotMemUsed, 2, 4); | |
− | + | TotalMem = Mem1 + "." + Mem2 + "\nMb"+TxtTail; | |
− | + | } | |
− | + | ||
− | + | else if (Len == 6) //###.### MB | |
− | + | { | |
− | + | string Mem1 = llGetSubString(TotMemUsed, 0, 2); | |
− | + | string Mem2 = llGetSubString(TotMemUsed, 3, 5); | |
− | + | TotalMem = Mem1 + "." + Mem2 + "\nMb"+TxtTail; | |
− | + | } | |
− | + | ||
− | + | else if (Len == 7) //#.### GB | |
− | + | { | |
− | + | string Mem1 = llGetSubString(TotMemUsed, 0, 0); | |
− | + | string Mem2 = llGetSubString(TotMemUsed, 1, 3); | |
− | + | TotalMem = Mem1 + "." + Mem2 + "\nGb"+TxtTail; | |
− | + | } | |
− | + | ||
− | + | else if(Len == 8) //##.### GB | |
− | + | { | |
− | + | string Mem1 = llGetSubString(TotMemUsed, 0, 1); | |
− | + | string Mem2 = llGetSubString(TotMemUsed, 2, 4); | |
− | + | TotalMem = Mem1 + "." + Mem2 + "\nGb"+TxtTail; | |
+ | } | ||
+ | |||
+ | llSetText(TotalMem, <0.0, 1.0, 0.0>, 1.0 ); | ||
} | } | ||
default | default | ||
{ | { | ||
− | + | state_entry() // display @ start | |
− | + | { | |
− | + | GenStats(); | |
− | + | } | |
− | + | ||
− | + | touch(integer number) // refresh on touch | |
− | + | { | |
− | + | GenStats(); | |
− | + | } | |
+ | } | ||
+ | </source> | ||
+ | More accurate conversion from KB to MB. | ||
+ | |||
+ | GB that way, tested against actual usage reported by the system. | ||
+ | <source lang="lsl"> | ||
+ | // Simple Formatted Output | ||
+ | |||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSetTimerEvent(5.0); | ||
+ | } | ||
+ | |||
+ | timer() | ||
+ | { | ||
+ | float TotMemUsed = osGetSimulatorMemoryKB(); | ||
+ | |||
+ | if (TotMemUsed > (1024*1024)) | ||
+ | { | ||
+ | TotMemUsed = TotMemUsed / (1024 * 1024); | ||
+ | llSetText("~" + (string)TotMemUsed + " GB", <1.0, 1.0, 1.0>, 1.0); | ||
+ | } | ||
+ | |||
+ | else if (TotMemUsed > 1024) | ||
+ | { | ||
+ | TotMemUsed = TotMemUsed / 1024; | ||
+ | llSetText("~" + (string)TotMemUsed + " MB", <1.0, 1.0, 1.0>, 1.0); | ||
+ | } | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
− | |||
'''Informations'''<br /> | '''Informations'''<br /> | ||
− | This allows | + | This allows working around the fact that osGetSimulatorMemory() reports at most 2GB. This one limit is now 2TB, should be enough for a while |
− | + | ||
+ | Implemented October 15,2017 version 0.9.0.1 | ||
| | | | ||
}} | }} |
Latest revision as of 06:17, 7 November 2019
integer osGetSimulatorMemoryKB();
| |
No descriptions provided | |
Threat Level | Moderate |
Permissions | ${OSSL}|osslParcelO}ESTATE_MANAGER,ESTATE_OWNER |
Extra Delay | 0 seconds |
Example(s) | |
Simple Script (displays only the integer such as 234652064)
// Simple Unformatted Output integer TotMemUsed; default { state_entry() { TotMemUsed = osGetSimulatorMemoryKB(); llSetText( (string)TotMemUsed+" Memory by the OpenSimulator Instance", <0.0, 1.0, 0.0>, 1.0 ); } touch(integer number) { TotMemUsed = osGetSimulatorMemoryKB(); llSetText( (string)TotMemUsed+" Memory by the OpenSimulator Instance", <0.0, 1.0, 0.0>, 1.0 ); } } Extended with some formatting: (displays as 234.652 Mb) // Simple formatted Output shows either MB or GB as applicable // ==== GET Memory Integer and Format for Display ==== GenStats() { // Get Memory and format it string TotalMem; string TotMemUsed; string TxtTail =" used by OpenSimulator Instance"; TotMemUsed = (string)osGetSimulatorMemoryKB(); integer Len = llStringLength(TotMemUsed); if (Len == 5) // ##.### MB { string Mem1 = llGetSubString(TotMemUsed, 0, 1); string Mem2 = llGetSubString(TotMemUsed, 2, 4); TotalMem = Mem1 + "." + Mem2 + "\nMb"+TxtTail; } else if (Len == 6) //###.### MB { string Mem1 = llGetSubString(TotMemUsed, 0, 2); string Mem2 = llGetSubString(TotMemUsed, 3, 5); TotalMem = Mem1 + "." + Mem2 + "\nMb"+TxtTail; } else if (Len == 7) //#.### GB { string Mem1 = llGetSubString(TotMemUsed, 0, 0); string Mem2 = llGetSubString(TotMemUsed, 1, 3); TotalMem = Mem1 + "." + Mem2 + "\nGb"+TxtTail; } else if(Len == 8) //##.### GB { string Mem1 = llGetSubString(TotMemUsed, 0, 1); string Mem2 = llGetSubString(TotMemUsed, 2, 4); TotalMem = Mem1 + "." + Mem2 + "\nGb"+TxtTail; } llSetText(TotalMem, <0.0, 1.0, 0.0>, 1.0 ); } default { state_entry() // display @ start { GenStats(); } touch(integer number) // refresh on touch { GenStats(); } } More accurate conversion from KB to MB. GB that way, tested against actual usage reported by the system. // Simple Formatted Output default { state_entry() { llSetTimerEvent(5.0); } timer() { float TotMemUsed = osGetSimulatorMemoryKB(); if (TotMemUsed > (1024*1024)) { TotMemUsed = TotMemUsed / (1024 * 1024); llSetText("~" + (string)TotMemUsed + " GB", <1.0, 1.0, 1.0>, 1.0); } else if (TotMemUsed > 1024) { TotMemUsed = TotMemUsed / 1024; llSetText("~" + (string)TotMemUsed + " MB", <1.0, 1.0, 1.0>, 1.0); } } } Informations Implemented October 15,2017 version 0.9.0.1 |