![]() |
VR-Link API Documentation for DIS
|
VR-Link provides some classes to facilitate performace profiling of sections of code.
This functionality was added to VR-Link 3.12 for internal use, but may be used by customers. The provided classes use OS-dependent high performance counters to record the number of processor cycles between start() and stop() calls. The output is provided in seconds.
The performance statistics features are implemented in the following classes:
Here is an example of how the performance statistics classes can be used. This example contains two code sections, however there is no limit to the number of sections which can be created.
// Defines the classes DtPerformanceStats, DtTimeStatistic, and DtTimedSection #include <vlutil/vlPerformanceStats.h> // Defines DtInfo #include <vlutil/vlPrint.h> void foo() { // A dummy function } void measurePerformance() { // Create names (via enumerations) for each section of code you want // to measure. enum Stats { LoopTimeStat,FooTimeStat }; DtPerformanceStats reporter; // Create a DtTimedSection to measure, this could be // an initialization routine, or some computation DtTimedSection sectionOne; sectionOne.start(); // here is some code that you want to measure.... for (int i = 0; i < 100; ++i) { DtInfo << "some processing: " << i+10/34 << std::endl; } sectionOne.stop(); // Store the time for this section. You can measure this type of section // repeatedly, storing it each time. reporter.addTime(LoopTimeStat,sectionOne.duration()); // Create a new section to measure the time taken to call foo(). DtTimedSection sectionTwo; sectionTwo.start(); foo(); sectionTwo.stop(); reporter.addTime(FooTimeStat,sectionTwo.duration()); // Output the average render time. double aveTimeFoo = reporter.avg(FooTimeStat); DtInfo << "Iteration takes " << aveTimeFoo << std::endl; // Or, we could be outputting to a graphics package. //myGraph->addDataPoint(GetCurrentTime(),aveTimeFoo); }