SonarScanner MsBuild sonar.showProfiling not working

  • SonarQube 7.9.1, Scanner.MsBuild 4.6.2.2108

I’m trying to enable profiling to find out why SonarScanner for MsBuild is making my build run slow. Build time without sonar scanner is 4-5min, with SonarScanner 20-25 minutes.

I set /d:sonar.showProfiling=true in the command line and it seems to be parsed as SonarQubeAnalysisConfig.xml shows this

<LocalSettings>
    <Property Name="sonar.cs.nunit.reportsPaths">testresults982.xml</Property>
    <Property Name="sonar.cs.opencover.reportsPaths">testcoverage982.xml</Property>
    <Property Name="sonar.exclusions">**/*.Designer.cs,**/*.resx,**/*.xaml.cs,**/Migrations/**/*.cs</Property>
    <Property Name="sonar.showProfiling">true</Property>
    <Property Name="sonar.verbose">true</Property>
    <Property Name="sonar.host.url">https://sonarqube.x.com</Property>
  </LocalSettings>

However, I cannot find any *profiler.xml file or indeed the /profiling/ subfolder in .sonarqube as described here https://docs.sonarqube.org/latest/analysis/analysis-parameters/#AnalysisParameters-AnalysisLogging

Any idea what I’m doing wrong?

Thanks!

Hi Adi,

Welcome to SonarSource community! It’s nice to see you here :slight_smile:

The parameter you are trying to use is not supported by the SonarScanner for MSBuild but you can use instead this msbuild /p:reportanalyzer=true /v:d > build.log to find more details about the analyzer execution time.

The results are part of the MsBuild output and you can find them by searching for: “Total analyzer execution time”.

If you do that, please share the results with us since we plan to do a few performance improvements in the future and any help counts :slight_smile:

Please let me know how it goes.

Thanks,
Costin

2 Likes

Hi Costin :slight_smile:

Thanks for the suggestion! Here’s what I found (the top 2 projects in the solution taking the most time to analyze):

Total analyzer execution time: 452.430 seconds.
NOTE: Elapsed time may be less than analyzer execution time because analyzers can run concurrently.
Time (s) % Analyzer
432.044 95 SonarAnalyzer.CSharp, Version=7.15.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244
20.908 4 SonarAnalyzer.Rules.CSharp.TokenTypeAnalyzer
17.668 3 SonarAnalyzer.Rules.CSharp.SymbolReferenceAnalyzer
17.318 3 SonarAnalyzer.Rules.CSharp.UnusedPrivateMember
17.262 3 SonarAnalyzer.Rules.CSharp.EmptyNullableValueAccess
16.382 3 SonarAnalyzer.Rules.CSharp.InvalidCastToInterface
15.990 3 SonarAnalyzer.Rules.CSharp.EmptyCollectionsShouldNotBeEnumerated
14.858 3 SonarAnalyzer.Rules.CSharp.ConditionEvaluatesToConstant
14.727 3 SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce
14.663 3 SonarAnalyzer.Rules.CSharp.NullPointerDereference
12.388 2 SonarAnalyzer.Rules.CSharp.PrivateFieldUsedAsLocalVariable
10.526 2 SonarAnalyzer.Rules.CSharp.CollectionQuerySimplification
6.205 1 SonarAnalyzer.Rules.CSharp.InsecureEncryptionAlgorithm
5.268 1 SonarAnalyzer.Rules.CSharp.DoNotCallGCCollectMethod
5.136 1 SonarAnalyzer.Rules.CSharp.PropertiesAccessCorrectField
5.003 1 SonarAnalyzer.Rules.CSharp.UseStringIsNullOrEmpty
4.968 1 SonarAnalyzer.Rules.CSharp.DangerousGetHandleShouldNotBeCalled
4.962 1 SonarAnalyzer.Rules.CSharp.DoNotCallAssemblyLoadInvalidMethods
4.946 1 SonarAnalyzer.Rules.CSharp.DoNotCallGCSuppressFinalizeMethod
4.900 1 SonarAnalyzer.Rules.CSharp.ThreadResumeOrSuspendShouldNotBeCalled
4.681 1 SonarAnalyzer.Rules.CSharp.StaticFieldInitializerOrder
4.308 <1 SonarAnalyzer.Rules.CSharp.DeadStores
4.253 <1 SonarAnalyzer.Rules.CSharp.BinaryOperationWithIdenticalExpressions
4.159 <1 SonarAnalyzer.Rules.CSharp.ParametersCorrectOrder
3.994 <1 SonarAnalyzer.Rules.CSharp.VariableUnused
3.979 <1 SonarAnalyzer.Rules.CSharp.PartialMethodNoImplementation
3.928 <1 SonarAnalyzer.Rules.CSharp.InvocationResolvesToOverrideWithParams
3.870 <1 SonarAnalyzer.Rules.CSharp.GetTypeWithIsAssignableFrom

Total analyzer execution time: 419.269 seconds.
NOTE: Elapsed time may be less than analyzer execution time because analyzers can run concurrently.
Time (s) % Analyzer
396.299 94 SonarAnalyzer.CSharp, Version=7.15.0.0, Culture=neutral, PublicKeyToken=c5b62af9de6d7244
62.316 14 SonarAnalyzer.Rules.CSharp.UnusedPrivateMember
18.257 4 SonarAnalyzer.Rules.CSharp.EmptyNullableValueAccess
17.572 4 SonarAnalyzer.Rules.CSharp.InvalidCastToInterface
17.242 4 SonarAnalyzer.Rules.CSharp.EmptyCollectionsShouldNotBeEnumerated
16.284 3 SonarAnalyzer.Rules.CSharp.NullPointerDereference
15.982 3 SonarAnalyzer.Rules.CSharp.ConditionEvaluatesToConstant
15.977 3 SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce
13.036 3 SonarAnalyzer.Rules.CSharp.TokenTypeAnalyzer
12.764 3 SonarAnalyzer.Rules.CSharp.SymbolReferenceAnalyzer
7.473 1 SonarAnalyzer.Rules.CSharp.PrivateFieldUsedAsLocalVariable
6.681 1 SonarAnalyzer.Rules.CSharp.CollectionQuerySimplification
6.144 1 SonarAnalyzer.Rules.CSharp.PropertiesAccessCorrectField
4.317 1 SonarAnalyzer.Rules.CSharp.InsecureEncryptionAlgorithm
4.057 <1 SonarAnalyzer.Rules.CSharp.UseStringIsNullOrEmpty
3.880 <1 SonarAnalyzer.Rules.CSharp.DeadStores
3.728 <1 SonarAnalyzer.Rules.CSharp.DoNotCallGCSuppressFinalizeMethod
3.667 <1 SonarAnalyzer.Rules.CSharp.VariableUnused

In the sonar qube dashboard I already have set “ignore issues on multiple criteria” to “csharpsquid:S1144” which I thought would cause the analysis to skip over the UnusedPrivateMember analyzer…maybe it only affects the server-side, i.e. the sonar scanner doesn’t locally take these ignore criteria into account?

Even so, it looks like there is no one single analyzer slowing down the build massively, it’s more like death by a thousand cuts. Not sure if there’s anything I can generally do, suggestions are very welcome.

Cheers!

I’m afraid not, if there isn’t a specific project that is taking a lot to analyze. We have #2429 and #2474 to investigate the performance issues

The easiest thing would be to remove the rule from your Quality Profile.

Update: we’ve fixed the performance problem we were having with the UnusedPrivateMember rule (#2474 ). The fix is included in the 8.13 release.