Performance Profiler library
Release: |
4.6 • 5.0 • 5.1 • 5.2 • 5.3 • 5.4 • 6.0 • 6.1 • 6.2 • 6.3 • 6.4 • 6.5 |
---|
If your model takes a long time to run or uses a lot of memory, it's a good idea to find out which variables are using most of the time or memory. As experienced programmers know, the results are often a surprise. Usually, are just a few variables or functions that use the Lion's share of resources. The Performance Profiler is a standard library that shows the CPU time and memory used by every variable and function. With this information, you know where to focus your efforts to make the model faster or use less RAM.
This feature is available in Analytica Enterprise and Optimizer.
Load and view the Performance Profiler
From inside your model select Add library from the File menu, and select the Performance Profiler.ana to load the library. Or you can download a slightly updated version from Performance Profiler.ana into a folder, and import it uising Add module from the File menu.
Double click the module to open it:
Click the Performance profiles result button to see the profile for the variables and functions in your model:
This table lists the variables and functions by row, with columns:
.Objects
: The title of the object. Click it to open its Object window if you want to see why it's using so much time or memory.- Class' of the object, parent module
- Parent module: The module containing this object. You can click it to open the Diagram with the node highlighted.
- Bytes of RAM (random access memory),
- CPU msecs (milliseconds of time used by the central processing unit).
- msecs w ancestors, shows the CPU milliseconds to compute each variable or function including all its ancestors — i.e., the variables and functions it uses.
Select any of these columns from the Sort objects by menu to reorder the table by that column.
The Profiler omits variables and functions that use less than 24 bytes of RAM and take less than 1 millisecond to compute. Functions always show zero memory since they do not store their results, even though they may use substantial memory while they are evaluated.
Update profiles
After computing more results, click this button to update the performance profile to reflect the additional time and memory used.
Zero out times
If you want to look at the incremental time used by additional results, or another computation, first click this button to zero out the times already computed.
Understanding memory usage
A variable or function with a complex definitions may use much more RAM while computing than it needs to store the final result — the Profiler reports only the latter. The Bytes show the RAM used to store the value of each variable, mid, probabilistic, or both, depending on which it has computed. Typically, an array takes about 12 bytes per number to store. For example, an uncertain dynamic array of numbers, with an index I of 20 elements, Time has 30 elements, and SampleSize = 1000, would use about 20 x 30 x 1000 x12 = 7,200,000 bytes or 7.2 Megabytes. Analytica uses an efficient representation for arrays with many zeroes (sparse arrays) or many repeated values. A variable containing an array that is an exact or partial copy of an array in another variable may share slices. In that case, the memory used by both may be less than the sum of the memory reported for each one.
Understanding computation time
The CPU time listed is the time it took to evaluate the mid and/or prob value of each variable or function, depending on which type of evaluation it did. It is zero if the results computed did not cause evaluation of the variable or function. A variable is usually only computed at most once each for its mid and prob value. Rare exceptions include when the variable is referenced directly or indirectly in a parameter to Whatif or WhatIfall, which might cause multiple evaluations. A function can be called many times. The CPU time reported is the sum over all these evaluations.
Many computations utilize multiple CPU cores simultaneously, which makes the meaning of CPU time potentially ambiguous. CPU time normally refers to the actual number of computing cycles consumed. Your computation might take one minute of wall time, but if much of that time was spent waiting for a database to respond, or the process was competing for CPU resources with other active processes, the CPU time might be much less than real "clock" time. Conversely, a computation that completes in 1 minute using 8 cores effectively uses 8 minutes of CPU time. Performance Profiler's measure of CPU time coincides with the first example, but does not multi-count the concurrent thread usage. Hence will generally be close to wall-time for a multi-core computation that runs continuously. The metric was developed for the usual case where you care about the overall real-time speed of your computation, and not about the total CPU core resources consumed. In other words, you would be happy to have a higher core utilization if it speeds up the overall computation. In the less common case where you care more about total core cycles that real time to completion (e.g., an overtasked server with many simultaneous batch computations in different processes), a more appropriate metric during profiling can be obtained by turning off multithreading by setting MaxModelThreads to 1 and then use the resulting CPU time metric.
Time and virtual memory
Like most 32-bit applications on Windows, Analytica can use up to 3 GB of memory. If your computer doesn’t have that much RAM installed, and it needs more than is available, it can use virtual memory — that is, it saves data onto the hard disk. Since reading and writing a hard disk is usually much slower than RAM, using virtual memory often causes the application to slow down substantially. In this case, finding a way to reduce memory usage below the amount of physical RAM available can speed up the application considerably. Another approach is to install more RAM, up to 4 GB.
Performance profiling attributes and function
The Performance Profiler library uses a function, two attributes, and a command, which are also available for you to write your own functions using memory or time. For an example of how to use them, you can open up the library.
MemoryInUseBy(v)
This function returns the number of bytes in use by the cached result(s) for variable «v» — with the same disclaimer that shared memory can be counted more than once. It includes memory used by mid and prob values if those results have been computed and cached, but it doesn’t force them to be computed if they haven’t been. See MemoryInUseBy().
This function includes these two special read-only attributes:
EvaluationTime
This attribute returns the time in seconds to evaluate its variable or function, not including the time to evaluate any of its inputs.
EvaluationTimeAll
This attribute returns the time in seconds to evaluate its variable or function, including the time to compute any of its inputs that needed to be evaluated (and their inputs, and so on).
ResetElapsedTimings
This command sets these attributes back to zero. Like any command, you can use it in a button script, the Typescript, but not in a regular definition.
See Also
- Download: media:Performance Profiler.ana
- Performance Profiler
- MemoryInUseBy()
- Memory usage and management
- Managing Memory and CPU Time for large models
- Memory Usage Dialog
- Analytica Libraries and Templates
- Multithreaded evaluation
Enable comment auto-refresher