This example walks you through the creation of two new report types, based on Klocwork metrics:
- functions and methods with more than two returns
- the number of system includes per file
To add custom reports based on Klocwork metrics:
- Back up the following file:
- <projects_root>/config/metrics.xml
- Open the original metrics.xml file for editing.
- Our first custom report is a threshold metric, so it is under the EntityCountOverThreshold category.
- We need to find the ID for the "Number of Returns" metric. From Function- and method-level metrics, we find the ID, 134. This ID is used for the <kids> element.
- Now we need to find the IDs for the two entities Function and Method. From Supported entity types, we find the IDs, 5 and 48. These IDs are used for the <entityKids> element.
- We can now copy the entire default <metric> element under <category catid="EntityCountOverThreshold">, and paste it directly below.
- We edit the elements as follows:
- <metric>
- <name>Number of returns</name>
- <description>Number of Functions with returns over {threshold}</description>
- <kids>134</kids>
- <entityKids>5,48</entityKids>
- <default_threshold>2</default_threshold>
- <enable>true</enable>
- </metric>
- Our second custom report is a total value metric report, so it is under the TotalMetricValue category.
- We need to find the ID for the "Number of System Includes" metric. From File-level metrics, we find the ID, 16. This ID is used for the <kids> element.
Tip: The TotalMetricValue category does not require a list of Klocwork entity kinds (the <entityKids> element).
- We can now copy the entire default <metric> element under <category catid="TotalMetricValue">, and paste it directly below.
- We edit the elements as follows:
- <metric>
- <name>Number of system includes</name>
- <description>Number of system includes per file</description>
- <kids>16</kids>
- <enable>true</enable>
- </metric>
- Save the file.
- Restart the Klocwork Server with kwservice restart or Windows Services Administration.
- The changes you have made are visible to all Klocwork Static Code Analysis users when they log in, or when they refresh the Reports page. We now verify that our changes are appearing correctly.
-
Log in to Static Code Analysis.
- Click Reports for your project.
- Click Create a new report.
Note: If you were already viewing the report types, refresh your browser to pick up the changes to metrics.xml.
- The report types are displayed on the right. Scroll down and click see more.
- We see that our list now includes the Number of system includes and Number of returns report types.
- Click Number of returns to ensure that the default threshold is set at 2.