📜 ⬆️ ⬇️

Integration of PVS-Studio with the IncrediBuild distributed assembly system



PVS-Studio performs analysis of C / C ++ code and prompts the programmer where errors are hidden, or points to areas of code that may become problematic in the future. If the developed project is large enough, the analysis can take a lot of time. To speed up the analysis of a large project, you can use the IncrediBuild tool. If you already have the PVS-Studio analyzer and the IncrediBuild tool installed, then you will learn from the article how you can make friends and speed up the analysis. In the future, the PVS-Studio analyzer will integrate even more closely with IncrediBuild. But once again we will repeat that it is possible to parallelize the launch of PVS-Studio on several machines now. It's simple. And in the article we will tell how to do it.


Introduction


Any developer who compiles a project for more than half an hour knows about the existence of IncrediBuild . This solution is designed to speed up compilation by distributing to multiple machines. As a result, several computers (for example, four) are simultaneously compiling the project. Each computer compiles its part of the files and as a result, the total assembly time is reduced several times.
')
Recently, users of PVS-Studio have begun to contact us with a request to add IncrediBuild support to our solution. We contacted the IncrediBuild development team and asked for assistance. The IncrediBuild team gladly responded, and now we are ready to share a way to share PVS-Studio and IncrediBuild together.

Now (in PVS-Studio version 5.25), the user who installed PVS-Studio on his machine will not see the item “check the project in PVS-Studio using IncrediBuild” in the menu of his IDE. It is possible that in the next versions of PVS-Studio such a menu item will appear. But already now, the user of IncrediBuild can benefit from this system when using PVS-Studio. All you need is a little bit of magic. And this article tells you what spells to cast.

How does PVS-Studio work?


What purpose can a person who wants to integrate PVS-Studio with IncrediBuild pursue? I think it is quite obvious that the ultimate goal of this should be to reduce the time required for analyzing the source files. Let's see what, in fact, is “code verification in PVS-Studio” and how to “connect it” to IncrediBuild.

IncrediBuild is primarily intended for the distribution of assembly tasks among the available computational resources, that is, between developers' computers. What exactly should be distributed in case of launching the PVS-Studio static analyzer?

PVS-Studio performs direct verification of the original C / C ++ files using the command line utility PVS-Studio.exe. This utility is the core of the analyzer. It is very close to the C ++ compiler in terms of its use. In particular, PVS-Studio.exe is required to be run each time to check each source file, passing all the compilation parameters of this file and additional parameters to this utility.

Note. The compilation parameters are needed by the analyzer, since it needs to first preprocess the file. Accordingly, he must know which preprocessor directives are declared, where to look for header files, and so on.

It should be noted that PVS-Studio.exe is not intended for “manual” use - it cannot simply be set on the directory with source files. Just to automate this launch procedure, the PVS-Studio plugin, which integrates into the Visual Studio development environment, serves. Alternatively, you can use the PVS-Studio Standalone shell.

Of course, in case of using an assembly system other than MSBuild, launching PVS-Studio.exe can be embedded in other assembly systems, however, this does not negate the principle that PVS-Studio.exe should not be used directly by the analyzer user.

I think that now it is obvious to us that in order to optimize the operation of the analyzer, it is necessary to distribute the analysis procedure at the stage of launching the PVS-Studio.exe processes. This situation is very similar to the way Incredibuild works during a normal project build - it distributes compiler launches (for example, cl.exe) and linkers.

In this case, IncrediBuild "deceives" the local assembly system. MSBuild.exe starts the processes of compilation and linking as if “locally”, and IncrediBuild “silently” spreads the actual work of these processes directly to the compute nodes (computers) accessible to it.

Needless to say, it is obvious that IncrediBuild is not limited in what specific processes can be distributed across compute nodes. How can we use it to “fool” PVS-Studio? In our case, to “deceive” we will need someone who is directly involved in launching the PVS-Studio.exe processes.

For example, let’s dwell on the fact that a user has a project in Microsoft Visual Studio, assembled in MSBuild. Then, in order to test this project, he will most likely use the PVS-Studio plugin for this IDE. The IDE plug-in is part of the IDE itself, so we can now call the one we have to “deceive” - devenv.exe - the process, which is the very Microsoft Visual Studio.

Suppose also that the user of PVS-Studio uses a static analyzer, regularly launching it on its “build server”. Suppose also that the project is quite large (several thousand source files), because otherwise the user has no reason to speed up its verification.

All this means that the user will not run the test “manually” each time, choosing the 'Check Solution' menu item. What will he do then?
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" "D:\Test\OmniSample\OmniSample (vs2013).sln" /command "PVSStudio.CheckSolution Win32|Release|D:\Test\OmniSample\test.plog" 

Above is the launch string of the PVS-Studio analysis analysis for the OmniSample project (vs2013) .sln, Win32 | Release configuration. Upon completion of the analysis, the devenv.exe process will automatically terminate. The verification log will be saved to D: \ Test \ OmniSample \ test.plog. This is the “standard” way of using PVS-Studio from the command line, which you can read more about here.

Once again, this is not the only way to use PVS-Studio, but for clarity, we’ll dwell on it.

What happens when you run this command? The launched devenv.exe process will start running the PVS-Studio.exe processes in parallel, as we said earlier, one per source file. How many password processes will be launched is specified in the analyzer settings and this setting can be changed. By default, PVS-Studio will start simultaneously as many processes as there are logical cores in the system.

How can IncrediBuild help?


Suppose now that we have a project of 1000 files, and we run the analysis on a machine with 4 cores. This means that the devenv.exe analyzer will have to do 250 iterations (4 processes each) in order to successfully test the entire project. How can IncrediBuild help us?

Suppose that the PVS-Studio user has 3 more machines, and each also has 4 processor cores. If we could “spread” the PVS-Studio.exe launches on these 4 machines, then we would not need 250 “iterations”, but only 62.5 (after all, we have 16 cores).

In order to distribute the analyzer launches on different computers, we use the command line utility IBConsole :
 ibconsole /command=incredi.bat /profile=incredi.xml 

The incredi.xml file should have the following content:
 <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Profile FormatVersion="1"> <Tools> <Tool Filename="devenv" AllowIntercept="true" /> <Tool Filename="PVS-Studio" AllowRemote="true" /> </Tools> </Profile> 

As you can see, we “intercept” devenv activity and allow “distribute” the processes of PVS-Studio. In the file incredi.bat you need to register the launch string devenv.exe, given in the article earlier. Also, you need to remember to change the paralleling level in the settings of PVS-Studio from 4 to 16.

Suppose that IncrediBuild was pre-installed and correctly configured on 4 machines. Now, after launching the ibconsole command, we will see that the PVS-Studio.exe launches are distributed between these 4 computers, and the overall analysis time is reduced.

At the same time, on all machines, except the one on which this command is executed, there is no need to keep both PVS-Studio and Visual Studio, as well as the source code being checked. IncrediBuild will take care of this.

How much analysis time will be reduced? At first it may seem that it will be reduced exactly 4 times, because we now have 16 cores, not 4. In fact, this number will be less than four, and depends on very many factors. These factors include the performance of computers, their workload with other tasks, network bandwidth and much more. But we can say for sure that it will be less than 4, because in any case, the “bottleneck effect” will be observed. After all, the initiator of the analysis (devenv.exe) must process the results of the PVS-Studio.exe launches. In our experiments, with the use of 4 machines, we received an acceleration of 2.5-3.5 times.

If the user still wants to start the analysis manually by selecting the 'Check Solution' item, then simply change the contents of the incredi.bat file, registering a simple call to devenv.exe there - the Visual Studio window opens in which you can do all these actions, taking advantage of distributed launch analyzers. Of course, this is not at all as convenient as simply opening Visual Studio and selecting the menu item “check in IncrediBuild” there, and in the future such an item can actually appear in the PVS-Studio menu.

Conclusion


You can now use IncrediBuild and PVS-Studio together in current versions. If you have any difficulties, be sure to email us and we will help.


If you want to share this article with an English-speaking audience, then please use the link to the translation: Paul Eremeev. Integrating PVS-Studio with the IncrediBuild Distributed Build System .

Read the article and have a question?
Often our articles are asked the same questions. We collected answers to them here: Answers to questions from readers of articles about PVS-Studio, version 2015 . Please review the list.

Source: https://habr.com/ru/post/263369/


All Articles