Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

Walk-through: Adding custom reports based on Klocwork metrics

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:

  1. Back up the following file:
    <projects_root>/config/metrics.xml
  2. Open the original metrics.xml file for editing.
  3. Our first custom report is a threshold metric, so it is under the EntityCountOverThreshold category.
  4. 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.
  5. 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.
  6. We can now copy the entire default <metric> element under <category catid="EntityCountOverThreshold">, and paste it directly below.
  7. 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>
  8. Our second custom report is a total value metric report, so it is under the TotalMetricValue category.
  9. 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).
  10. We can now copy the entire default <metric> element under <category catid="TotalMetricValue">, and paste it directly below.
  11. 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>
  12. Save the file.
  13. 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.
  14. Log in to Static Code Analysis.
  15. Click Reports for your project.
  16. 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.
  17. 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.
  18. Click Number of returns to ensure that the default threshold is set at 2.