MATLAB: Is there any way to exclude certain function calls from being counted for Code Metrics in Polyspace Bug Finder R2019a

Polyspace Bug Finder

I am using a macro in my code to add several function calls to log debug information and I would like to avoid these calls being counted for the Polyspace Code Metric "Number of called functions".
Is there a way to exclude those function calls?

Best Answer

  • There is no way to manipulate metrics - if there is a function call it will get counted.
    As you mentioned your concern is about a macro for logging debug information. Possibly it is or could be encapsulated with a preprocessor definition like this:
    #ifdef DEBUG_ON 
      #define MYMACRO(a) callloggingfunction(a);
      #define MYMACRO(a)
    In such an example, relaunching the Polyspace analysis by removing the macro using
    -D DEBUG_ON in the analysis configuration
    will provide a different count since the callloggingfunction() function will not be counted in the Metric "Number of called functions" anymore because now it is no longer part of the analyzed code.
    If your macro is not encapsulated with a preprocessor definition another possibility could be using the -post-preprocessing-command option to call a Perl script that puts the call to callloggingfunction() in comments. Which will also make it irrelevant for the metrics counts.
    More details regarding this option can be found here:
    (Still, the first option is the preferable way to handle this.)