SonarQube LOC reported does not match

I am using SonarQube 8.4.1.35646 and the number of line code reported is

1,488,520 lines currently analyzed

but checking this old documentation link I have executed the query to check the number of LOC and the number that it comes out is

1.027.637

This is the query that I am executing

SELECT Sum(pm.value) AS global_loc
FROM projects p
INNER JOIN snapshots s ON s.component_uuid = p.uuid
INNER JOIN project_measures pm ON pm.analysis_uuid = s.uuid
INNER JOIN metrics m ON m.uuid = pm.metric_uuid
WHERE s.islast = 1
AND p.qualifier = ‘TRK’
AND m.name = ‘ncloc’;

Hi,

What’s the question?

 
:slightly_smiling_face:
Ann

Hi!
What is the SQL query to do on the SonarQube database to check the number of LOCs used?

Before in the documentation, there was this query to extract the LOC, now I cannot find any more.

Thanks

Hi,

There isn’t one. The query you excavated from very old documentation was designed to help people understand where they would be license-wise when they upgraded & converted to the now-standard license model. It’s not relevant for current instances. We neither provide nor endorse SQL for digging around in the DB for figuring these things out.

Believe the UI.

 
:slightly_smiling_face:
Ann

It’s difficult to trust the UI when the sum of each project size does not match the number reported into the License Manager! Since we pay our license based on this number I think is fare to know how is it calculated.

Hi,

You’re right, it’s a fair question and while the answer is published it’s maybe not as findable as it should be:

How do we count Lines of Code (LOC)?

LOCs are computed by summing up the main/program LOCs of each project analyzed. Lines of test code are never included in this number. The LOCs used for a project are the LOCs found during the most recent analysis of this project. If you start using the branch analysis feature, then the counted LOCs of a project will be the ones of the biggest branch of that project.

So if you’re just summing what you see on the global Projects page, it’s quite likely that it doesn’t match the license LoC the Admin sees. And branches explain why.

 
HTH,
Ann

Thanks for reporting it, but I still don’t see an easy way to check the real size of a project in terms of LOC.

IMHO you should provide this information by the project (the effective one with the biggest branch) or at least the query to extract it from DB as calculate into the license manager.

Hi,

I don’t disagree with you.

 
:woman_shrugging:
Ann

Can you open a bug or a product improvement into your backlog?

I’ve flagged this thread internally

Hi,

As a followup, recent versions of SonarQube (starting in 9.4 IIRC) have a report you can download from the License page. It tells you which branch of each project is being counted for license LOC, and how many LOC the branch contributes.

 
HTH,
Ann

Hi
I cannot find this option into License Manager page. Could you provide me the link? We have last version of SonarQube installed

  • Developer Edition
  • Version 9.5 (build 56709)

Hi,

It looks like in 9.5 there’s only an API: api/projects/license_usage.

 
HTH,
Ann