LLTrace

From Second Life Wiki
Jump to navigation Jump to search

What is it?

LLTrace is our system for capturing realtime statistic related to viewer performance and behavior and associating those statistics with certain actions or periods of time.

Most of the statistics that the viewer captures go through LLTrace. Examples include:

  • Frame rate
  • Bandwidth
  • Ping time
  • Object/Texture cache hit rate

In addition, LLTrace is used to capture detailed memory usage breakdown and time spent in various functions. By design, all of these metrics are available for run-time queries from the code, enabling detailed logging, in-client profiling, statistics reporting, and even self-tuning components and algorithms.

Usage

First, you need to declare a statistic that you are going to track. For example, let's say you want to create a pedometer for your avatar. If you want to know how many footsteps your avatar takes, you would declare a *count* statistic for footsteps like this:

static LLTrace::CountStatHandle<> sFootSteps ("footstepcount", "Number of footsteps I've taken");

This declares a handle to this particular statistic that you will use in all future reads/writes of that stat.

This object needs to be a global/static variable so that when we start running SL code, we have an accurate count of how many statistics we have. Support for dynamically adding/removing stats is under consideration for a future release.

The template parameter is used to specify the type of value the statistic is stored as. Here we are using the default, which is a double precision floating point value. All values are stored as double precision floats under the hood, so don't bother optimizing for integers, etc. The first parameter is the name of the stat, used for tagging in output and runtime lookup. The second parameter is a documentation string describing what this statistic means.

Next, you can record your data. For a count-like statistic, this is done through the add method:

// I took a step
add(sFootSteps, 1);

Recording statistics is useless unless you can read the values back. This is where the concept of a Recorder comes in. A recorder is