JadeProfiler Class
The JadeProfiler class encapsulates the behavior required to configure what is profiled and reported by the Jade Interpreter. Statistics are captured about the execution of methods, focusing on two types of information.
-
Execution times and number of times methods are called in an application
-
Code coverage of methods executed during testing
It is recommended that when investigating application performance, only one of the Jade Profiler, Jade Monitor, or method profiling is used at any one time, as the results reported when any of these are combined is undefined.
Code coverage details are not recorded for methods with no source or with encrypted source.
Information about the execution times of methods in an application and the number of times methods are called can help developers improve the performance of an application by:
-
Making a method that is executed frequently run faster resulting in a large cumulative saving of time
-
Improving the structure of the code by eliminating unnecessary method calls
The following example shows the use of the JadeProfiler class to produce a standard profiler report.
vars prof : JadeProfiler; begin prof := process.profiler; prof.fileName := "p:\profiling\dev\myprofile.log"; prof.methodCount := 25; prof.reportCacheStatistics := false; prof.start; // call user methods here ... prof.report; end;
Code coverage is a measure used in software testing to describe the degree to which the methods in a system have been executed. It is a useful measure to assure the quality of a set of tests, as opposed to directly reflecting the quality of the system under test. Code coverage can help testers and developers to:
-
Discover methods and blocks of code that are not exercised by a set of tests
-
Create tests that increase code coverage
-
Quantify the overall code coverage of a system, which is one measure of quality
The following example shows the use of the JadeProfiler class to perform code coverage.
vars prof : JadeProfiler; begin prof := process.profiler; prof.codeCoverageFileName:= "erewhonshop_20090312_074611.ccd"; prof.clearMethodCache; prof.startCodeCoverage; // call test methods here ... prof.reportCodeCoverage; end;
Alternatively, you can enable code coverage programmatically by declaring a new application that initiates a special initialize method, as shown in the following example.
initializeCodeCoverage() updating; begin create myCodeCoverage; // myCodeCoverage is a reference to JADEProfiler
// on app. myCodeCoverage.startCodeCoverage(); // start coverage myInitialize(); // call standard Application class initialize method end;
To turn off code coverage when it is on, use the Application class finalize method, as shown in the following example.
myFinalize() updating; begin if myCodeCoverage <> null then myCodeCoverage.stopCodeCoverage(); myCodeCoverage.reportCodeCoverage(); delete myCodeCoverage; endif; ... end;
Use the start method to start the recording of times spent in Jade and external methods. These statistics are recorded until the stop method is executed, and they are output to file only when the report method is executed. Use this method to optimize your Jade code, by analyzing the performance of your methods. For example:
-
Call the start method in your initialize method and then call the stop method after the methods whose performance you want to analyze have been called.
-
Call the report method to output the recorded profile statistics to a file.
-
Run the Jade application whose performance you want to monitor.
-
Analyze the Jade Profiler report and then make the appropriate changes to your Jade methods, to optimize performance.
-
Repeat steps 3 and 4 until you have made the performance improvements that you require.
Code coverage methods are used in testing Jade methods, as follows.
-
The startCodeCoverage method is called in the setup method before the testing starts.
-
The stopCodeCoverage method is called in the teardown method after the testing ends.
-
The reportCodeCoverage method is called to output the code coverage statistics to a file.
4. The resetCodeCoverage method is called to clear all code coverage data.
For details about analyzing a code coverage file, see "
(None)