
You can merge a set of measurements to form a new measurement that combines the merged measurements.
Example: Perhaps you have a set of related measurements that actually belong together. And you want a single aggregate coverage statistic for you upper-level management. Merging lets you get that aggregated result.
You can use the merged measurement exactly as you would any other measurement - you can calculate results from it, save it in the repository, and so on.
Merging combines the raw data of the measurements according to one of these three strategies:
CE_SCV_MERGE_STRATEGY=>UNION: Create a measurement that aggregates the coverage of all programs in the merged measurements. Answers the question: "What is the overall coverage resulting from my measurements?"
CE_SCV_MERGE_STRATEGY=>INTERSECTION: Create a measurement that aggregates the coverage of all programs that were executed during both measurements. Answers the question "What is the overall coverage of the objects executed in both measurements?"
CE_SCV_MERGE_STRATEGY=>DIFFERENCE: Create a measurement that reports the coverage only of programs that were executed during the first measurement and not in any of the other merged measurements. Answers the question "What is the coverage of the objects executed in only one measurement?"
Prerequisites for combining measurements are the following:
The raw data of each measurement to be merged is still available (has not been deleted or finalized)
The measurements to merge have been stopped (no more data is being collected).
You can merge as many measurements at a time as you wish.
Sample Code
Here is sample code for merging measurements.
* Source measurements
DATA: factory TYPE REF TO if_scv_factory,
users TYPE if_scv_measurement=>users,
measurement TYPE REF TO if_scv_measurement,
another_measurement TYPE REF TO if_scv_measurement.
* Merging of measurements
DATA: measurements TYPE if_scv_measurement=>tab,
merged_measurement TYPE REF TO if_scv_measurement.
* Results
DATA: result TYPE REF TO if_scv_result,
coverage TYPE REF TO if_scv_coverage,
text TYPE string.
* Create two measurements and measure two test programs
factory = cl_scv_coverage_api=>get_factory( ).
APPEND sy-uname TO users.
measurement = factory->create_measurement(
i_local_server_only = abap_true
i_users = users ).
another_measurement = factory->create_measurement(
i_local_server_only = abap_true
i_users = users ).
* First measurement
measurement->start( ).
SUBMIT rsdssmpl_performance AND RETURN.
measurement->stop( ).
* Second measurement
another_measurement->start( ).
SUBMIT rsdssmpl_status AND RETURN.
another_measurement->stop( ).
* Report the code coverage of the first measurement
result = measurement->build_package_result( 'SMOI' ).
coverage = result->get_coverage( if_scv_coverage=>con_statement ).
text = |Package SMOI has after measurement 1 a statement coverage of { coverage->get_percentage( ) }%|.
WRITE:/ text.
* Report the code coverage of the second measurement
result = another_measurement->build_package_result( 'SMOI' ).
coverage = result->get_coverage( if_scv_coverage=>con_statement ).
text = |Package SMOI has after measurement 2 a statement coverage of { coverage->get_percentage( ) }%|.
WRITE:/ text.
* Merge the measurements
* Insert the measurements to be merged into a parameter table
INSERT measurement INTO TABLE measurements.
INSERT another_measurement INTO TABLE measurements.
* Here are the constants for the supported merge strategies
* CE_SCV_MERGE_STRATEGY=>UNION Merge Coverage Measurements
* CE_SCV_MERGE_STRATEGY=>INTERSECTION Intersect Coverage Measurements
* CE_SCV_MERGE_STRATEGY=>DIFFERENCE Report Differences of Coverage Measurements
* We use the UNION strategy to aggregate the code coverages
merged_measurement = factory->merge_measurements(
i_name = 'myMerger'
i_measurements = measurements
i_strategy = ce_scv_merge_strategy=>union ).
* Report the merged code coverage
result = merged_measurement->build_package_result( 'SMOI' ).
coverage = result->get_coverage( if_scv_coverage=>con_statement ).
text = |Object SMOI has a merged statement coverage of { coverage->get_percentage( ) }%|.
WRITE: / text.
In the example, we combine two standalone measurements. But you can also merge measurements in measurement series. You can even merge merged measurements.