Sim Restart Logger

From Second Life Wiki
Revision as of 05:46, 22 July 2009 by Huney Jewell (talk | contribs) (Published renewed script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Counts region restarts and displays log of last 9 restarts together with region FPS and dilation.

Updated version: Achieves accurate information about Sim restarts by checking the newly introduced CHANGED_REGION_START flag in 'changed' event to log data instead of previous version's method of approximating restarts by checking for poor script performance.


Requirements:

  • Place this script into a single prim and decorate to taste.

Operation:

  • No special instructions. It operates stand alone once installed.

<lsl> //******************************************************** // This Script was pulled out for you by YadNi Monde from the SL FORUMS at // http://forums.secondlife.com/showthread.php?t=275229, it is intended to stay FREE by it's author(s) // and all the comments here in ORANGE must NOT be deleted. They include notes on how to use it // and no help will be provided either by YadNi Monde or it's Author(s). // IF YOU DO NOT AGREE WITH THIS JUST DONT USE!!! //********************************************************

///////////////////////////////////////// // SIM CRASH/REBOOT LOGGER // by: Kyrah Abattoir // Updated by: Huney Jewell // Changed: Achieving more accurate information about Sim restarts to log data by checking the newly introduced // CHANGED_REGION_START flag in 'changed' event instead of approximation by checking for poor script performance // Added last FPS and dilation values to hover text /////////////////////////////////////////

// GLOBALS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// User adjustable settings

float timering = 120; //the polling rate, put the speed you wish, in seconds

// System settings - Do Not Change Anything Below!

string _buffer = ""; list log = []; string region_name; integer span; float fps_avg; float dilation_avg; integer restarts = 0; string date = ""; //2004-08-27T00:56:21.785886Z

// FUNCTIONS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

string FormatDecimal(float number, integer precision) {

   float roundingValue = llPow(10, -precision)*0.5;
   float rounded;
   if (number < 0) rounded = number - roundingValue;
   else            rounded = number + roundingValue;
   if (precision < 1) // Rounding integer value
   {
       integer intRounding = (integer)llPow(10, -precision);
       rounded = (integer)rounded/intRounding*intRounding;
       precision = -1; // Don't truncate integer value
   }
   string strNumber = (string)rounded;
   return llGetSubString(strNumber, 0, llSubStringIndex(strNumber, ".") + precision);

}


// CODE ENTRY ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

default {

   state_entry()
   {
       llSetTimerEvent(timering); //starting our timer
       llSetText("",<1.0,1.0,1.0>,1.0); // clear hover text
       region_name = llGetRegionName();
   }
   on_rez(integer num)
   {
       llResetScript();
   }
   changed(integer change)
   {
       if (change & CHANGED_REGION_START)
       { // log region restart
           restarts++;
           string timestamp = llGetTimestamp();
           list temp = llParseString2List(timestamp,["T",":","."],[]);
           log += llList2String(temp,0) + " - " + llList2String(temp,1) + ":"
               + llList2String(temp,2) + ":" + llList2String(temp,3);
           if(llGetListLength(log) > 9)
               log = llDeleteSubList(log,0,0);}
   }
   timer()
   {
       string _date = llGetDate();
       if(date == _date) //daily reset of the average FPS and dilation
           span++;
       else
       {
           span = 1;
           date = _date;
           fps_avg = 0;
           dilation_avg = 0;
       }
       float fps = llGetRegionFPS();
       fps_avg += fps;
       float dilation = llGetRegionTimeDilation();
       dilation_avg += dilation;
       string buffer = "";
       buffer += region_name + "\n Last FPS: " + FormatDecimal(fps, 0)
           + "\n Avg FPS: " + FormatDecimal(fps_avg/span, 0);
       buffer += "\n Last dilation: " + FormatDecimal(dilation, 2)
           + "\n Avg dilation: " + FormatDecimal(dilation_avg/span, 2);
       buffer += "\n Sim restarts: " + (string)restarts
           + "\n Last restarts (Timestamp is UTC): \n" + llDumpList2String(log,"\n");
       if(_buffer != buffer) //display
       {
           llSetText(buffer,<1.0,1.0,1.0>,1.0);
           _buffer = buffer;
       }
   }

} </lsl>

--Huney Jewell 12:46, 22 July 2009 (UTC)