-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce parameter to disable CxxSquidSensor #2080
Introduce parameter to disable CxxSquidSensor #2080
Conversation
0d37ed6
to
815e2cf
Compare
Hi @andreydanin, think that is not working because squid is also used for indexing, calculating metrics, syntax highlighting ... |
@guwirth probably you are right. I created this patch to avoid long squid scan for our pull request jobs (I disabled all cxx rules for that job in a Quality Profile). However I still can run squid if at least one cxx rule is enabled in a Quality Profile (for nightly builds in my case). Another solution that I had in mind is to implement an option that will stop squid from running. |
@andreydanin think squid in general is not slow, the problem is the preprocessor and the include files. Easiest to try is to set no (less) sonar.cxx.includeDirectories. Have you tried this? The general issue with this is, that SonarQube needs always all source files and reports, also for a PR. There is no „incremental analysis“. Maybe you can ask this as a general question here: https://community.sonarsource.com/. To understand this better. How big is your code base? What execution time we are talking about? |
2+ M lines of code. Execution time is 40+ minutes.
We use other analyzers for PR as well. SonarQube (with witsonar-cxx plugin) is one of the tools. It would be nice to be able exclude specific checks/ plugins.
Not yet. I will try different parameters as you suggested. |
Did you turn debug info on to see where exactly the time is used up?
That‘s slow. Guess it’s because of many includes or #1685 Which version of the cxx plugin and SonarQube are you using? |
Good suggestion. I will try.
No, squid for c/c++ is executed even if all rules are disabled.
Yes. This is how I found that squid for c/c++ is slowest part of check in our environment.
Thanks, I will check the discussion.
SonarQube 7.9.4.35981, cxx plugin - 1.3.2 (with my patch). |
@andreydanin in case you wanna proceed in this direction
|
@andreydanin maybe you can try and give feedback. Is this faster? sonar-cxx/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxSquidSensor.java Line 283 in 76e71ae
@Override
public void execute(SensorContext context) {
this.context = context;
// add vistor only if corresponding rule is active
var visitors = new ArrayList<SquidAstVisitor<Grammar>>();
for (var check : checks.all()) {
RuleKey key = checks.ruleKey(check);
if (key != null) {
if (context.activeRules().find(key) != null) {
visitors.add(check);
}
}
}
AstScanner<Grammar> scanner = CxxAstScanner.create(createConfiguration(),
visitors.toArray(new SquidAstVisitor[visitors.size()]));
... |
- add visitor only if corresponding rule is active - close SonarOpenCommunity#2080
@andreydanin see also #2082, will wait for you feedback... |
Thanks for the quick responses. I really appreciate it! |
@andreydanin any news? |
Sorry for the delay. It took more time than I expected. I've performed few tests and unfortunately I don't see big difference on full and empty CXX profile with "optimize squid sensor #2082" patch. Full test is much faster (~10 minutes vs ~36 minutes) on my machine (i7 with SSD) then on machine where I performed tests initially. "-Dsonar.exclusions=**/*.cpp" disables CXX (execution time is much faster than 8-9 minutes) but I haven't checked if cppcheck report is processed in this case. Please let me know if you need more information or have other ideas about things that I should check. |
@andreydanin thx for testing. It's hard for me to see from the log file which log is with/without the patch?
How big is the difference? |
Branch: Mode: Profile: CXX_time: Total_time:
|
@andreydanin thx Still wondering which are two comparable lines in the list for What is the time difference between full and empty?
|
I performed multiple tests in each configuration to eliminate interference with background tasks on my machine. |
Hi @andreydanin, I merged the PR #2082 to 2.0. Don‘t know if faster but can not hurt... |
Hi @guwirth I've rebased my patch on top of 2.0.5 and performed some tests on our projects. For tests I enabled debug log (-X parameter for scanner). Longes execution was found for "Sensor CXX". I checked output like this:
Note: for cppcheck related part we expect log line:
I checked 3 configurations: 1. Without "Sensor CXX"
2. With "Sensor CXX" (rule "Avoid too many code lines in source file" is enabled)
3. With "Sensor CXX" (rule "Avoid too many code lines in source file" is enabled, Preprocessor::handlePreprocessorDirective is disabled)
Do you have any ideas what should I check next? |
Hi @andreydanin, thx for testing. Like to understand it better:
Regards, |
Hi. Thanks for the quick response.
Yes. All three test cases are tested with the patch from this pull request applied. It should only have effect in test case 1 (when squid execution is skipped because it's rules are not active).
Yes.
Source code was changed. I can run all three test cases without my changes but I expect that test case 2 will be the same and case 1 will become same as 2 (squid will be active even rules are disabled).
Yes. I believe I disabled preprocessor in test case 3.
Rules were same as in test case 2. Test case 1 - only cppcheck rules are active. Squid ("Sensor CXX") was not executed as expected because patch from this pull request is applied. Test cases 2 and 3 - rules from 1 plus rule "Avoid too many code lines in source file". Additional rule activated squid ("Sensor CXX") in test cases 2 and 3. |
19ba6bb
to
b78dfa6
Compare
Hi @andreydanin, my main concern is still that the software metrics are not working with your patch? Did you compare the values, e.g. LoC, Complexity, … with the cases 1) to 3)… Regards |
Hi @guwirth
LoCs, complexity and other metrics will not be present if squid is disabled. The problem for me and some other users is that this estimations performed for a long time on big projects. Also we are focused on code defects that were reported by external scanner(s) (cppcheck, PVS Studio, clang analyzer, etc.). Probably we can split basic measures (like LoCs) and more advanced measures (that require file analysis) into different components. In this case we will have squid that calculates LoCs very fast and new component that performs code analysis in depth to identify issues, code duplication and so on. Code duplication, functions complexity and some other metrics are also important. But I think it's better to improve analysis speed for these measures in a separate patch. I didn't perform profiling and I'm still not very familiar with the codebase and sonar API to plan and design such improvements alone (at least yet :). Thanks. |
Hi @andreydanin, think there are still different ways:
If you can provide a solution for 2) I would merge it. If you could provide more detailed numbers with https://www.ej-technologies.com/products/jprofiler/overview.html it would help to take a better decision. If you ask them they will provide a free license for open source projects. Regards |
@andreydanin sorry typo: …provide a solution for 2) I would merge it. |
b78dfa6
to
2421d1c
Compare
Fix for SonarOpenCommunity#2228 SquidSensor can take significant amount of time on big projects. Skip execution if sonar.cxx.squid.disabled parameter is set to true.
2421d1c
to
38b726d
Compare
Hello @andreydanin, thx. I will merge it asap. Regards |
Fix for #2228
SquidSensor can take significant amount of time on big projects.
Skip execution if sonar.cxx.squid.disabled parameter is set to true.
This change is