Is there an API to retrieve metrics from polyspace access

16 views (last 30 days)
Olivier on 12 Feb 2021
Edited: Anirban on 16 Feb 2021
I have a polyspace server like url:9443
Inside it, with jenkins, I created a folder structure that looks like Public/project_name/branch_name.
I can access the server with my access license, and I see all the history and metrics from my jenkins builds in there (polyspace being triggered by jenkins).
For reporting, I have to recover the metrics of a specific project_name/branch_name. Is there an API to access it?
The url of the page where I see the metrics is like : url:9443/metrics/index.html?a=metrics&p=44&r=13
The other way I see is dumping the html page and analyzing it, but this is not a very "easy" way.

Accepted Answer

Anirban on 12 Feb 2021
Edited: Anirban on 12 Feb 2021
Hi Olivier,
You definitely have options besides dumping the full html page.
Just to clarify, when you say "metrics", do you mean "code complexity metrics" that Polyspace calculates or all the information that you see on a page like this:
Either way, you have to use the polyspace-access command with the -export option.
If you want the code complexity metrics, you have to use:
polyspace-access ... -export ...-code-metrics
This would export only the code complexity metrics to a tab-delimited text file and you can perform the calculations on the text file.
If you want all the info on the Polyspace Access dashboard exported, you have to first export results from a project to a text file with whatever filter you want and perform the computations on the text file. The polyspace-access command does not directly give out all the information that is on the Polyspace Access dashboard.
For syntax information and how to export only certain types of results, see polyspace-access.
If you use the Polyspace plugin in Jenkins, you can use some additional helper commands that does some of the computations. For instance, to get the number of results that are "To do" on the Polyspace Access dashboard, you can:
  • Apply a filter when exporting results to filter results that have the status "Unreviewed" (see the connection between "To do" and result statuses here)
  • Add up the number of results in the exported file using $ps_helper report_count_findings
That way, you can compute all the numbers that you see on the Polyspace Access dashboard without any heavy scripting. You can see an example script in Sample Scripts for Polyspace Analysis with Jenkins.

More Answers (1)

Olivier on 15 Feb 2021
I was able to retrieve the data thanks to your answer.
I did not use the polyspace plugin in jenkins, because I use a multibranch pipeline, so I used the JenkinsFile approach instead (using the example provided by mathworks).
One question:
Is there a way to retrieve the runId that I have to pass to the polyspace-access -export command without parsing the jenkins output (it's in here anyway, so it will be easy to parse, but maybe there is an easier/cleaner way)
  1 Comment
Anirban on 16 Feb 2021
Yes, you can use the polyspace-access -list-project with the project name as argument to get the last run ID of the project.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by