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’;
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.
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.
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.
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.
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.