Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
Integrating PVS-Studio with the Incredi…

Integrating PVS-Studio with the Incredibuild Distributed Build System

Jul 23 2015
Author:

PVS-Studio performs analysis of C/C++ code and highlights for the programmer various hidden errors and code fragments that may cause troubles in future. If your project is a large-scale one, its analysis may take quite a while. To speed it up, you can use the Incredibuild tool. If you already have the PVS-Studio analyzer and the Incredibuild tool installed on your computer, you will learn from this article how to make them friends and achieve analysis acceleration. In time, we are going to provide an even tighter integration of PVS-Studio with Incredibuild. But let me point this out once again that it is already possible to parallelize a PVS-Studio launch to a number of machines. It's simple. In this article, we will tell you how to do this.

The contents of this post are outdated. Please refer to the corresponding section of documentation for latest description of using PVS-Studio with Incredibuild.

0338_IncrediBuild/image1.png

Introduction

Any developer whose projects take over half an hour to compile, knows of the Incredibuild product. This solution is designed to accelerate compilation by distributing the building process among several machines. As a result, you have your project simultaneously compiled by a number of computers (for example four), each of which compiles its own portion of files, which leads to reducing the general build time by several times.

Since recently, we've been asked by PVS-Studio users to add support of Incredibuild into our product. We contacted the Incredibuild developer team and asked for assistance. They were glad to help and now we can tell you how to use PVS-Studio and Incredibuild together.

In PVS-Studio's current version (5.25), you won't yet see a new item "analyze project in PVS-Studio with Incredibuild" in your IDE's menu after installing PVS-Studio on your machine. We may add it in the next PVS-Studio versions. But an Incredibuild user can already start benefitting from this tool while using PVS-Studio. You just need a bit of magic. In this article, we will tell you what spells to speak.

How does PVS-Studio work?

What's the goal of anyone who wants to integrate PVS-Studio with Incredibuild? Obviously, it is to reduce the time of source code analysis. Let's figure out what "code analysis in PVS-Studio" actually is and how to "link" it to Incredibuild.

Incredibuild is first of all designed to distribute build tasks among available computational resources, i.e. developers' computers. What exactly do we need to distribute in the case of PVS-Studio?

Analysis of source C/C++ files as such is done by PVS-Studio through the command line utility PVS-Studio.exe. This utility is the analyzer kernel and its working principle is quite similar to that of a C++ compiler. In particular, PVS-Studio.exe has to be launched every time for each source file to be analyzed, by passing all of the file's compilation and other parameters into this utility.

Note. The analyzer needs the compilation parameters because it first needs to preprocess the file before analyzing it. Therefore, it needs to know which preprocessor directives are declared, where the header files are located, and so on.

Note that PVS-Studio.exe is not designed for "manual" use - you can't simply "set" it "on" the source folder. It is to automate this launch procedure that the PVS-Studio plugin is used as it integrates into the Visual Studio IDE. As an alternative, you can also use the PVS-Studio Standalone shell.

Of course, you can integrate a PVS-Studio.exe launch into any other build system different from MSBuild, but it doesn't cancel the requirement that PVS-Studio.exe must not be used directly by the user.

I suppose it is clear now that in order to optimize the analyzer's workflow, we need to distribute the analysis procedure at the stage of launching PVS-Studio.exe processes. It is very similar to the regular use of Incredibuild when building a project: it distributes the launches of compilers (for example cl.exe) and linkers.

While doing this, Incredibuild "cheats" the local build system. MSBuild.exe launches compilation and linking processes as if "locally", while Incredibuild "stealthily" distributes the real workflow of these processes among the available computational nodes (computers).

Obviously, Incredibuild has no restrictions as for what processes exactly can be distributed. So how can we use it to "cheat" PVS-Studio? In our case, we need to "cheat" the direct caller of PVS-Studio.exe processes.

Let's imagine, for example, there is a user who has a Microsoft Visual Studio project built in MSBuild. Then, in order to check this project, the user will most likely use the PVS-Studio plugin for this IDE. An IDE plugin is a part of the IDE itself, so we can now name the target we need to "cheat" - devenv.exe - the process which is actually Microsoft Visual Studio itself.

Let's assume also that the user regularly runs the analyzer on a "build server". Besides, the project must be large enough (a few thousand source files), otherwise there would be no need to speed up its analysis.

All this means that the user won't launch the analysis "manually" each time, selecting the 'Check Solution' menu item. So what will they 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"

The text above is the PVS-Studio analysis launch line for the OmniSample (vs2013).sln project with the Win32|Release configuration. Once the analysis is over, the devenv.exe process will automatically terminate. The analysis log will be saved into the file D:\Test\OmniSample\test.plog. This is a "standard" way of using PVS-Studio from the command line. Look here to learn more about it.

Note that this is not the only way to use PVS-Studio, but I have chosen it just because it is clearest of all.

So what will happen when executing this command? The launched devenv.exe process will start calling PVS-Studio.exe processes in parallel, one per source file, as discussed earlier. How many parallel processes will be launched is determined by the analyzer's settings option, which can be altered. By default, PVS-Studio launches as many processes at a time as the number of logical cores available in the system.

How can Incredibuild help us?

Suppose now that we have a project of 1000 files and we analyze it on a 4-core machine. It means that the devenv.exe analyzer will have to run 250 iterations (with 4 processes in each) to successfully check the entire project. So how can Incredibuild help us with that?

Suppose we have 3 more machines, each of which also carries 4 processor cores. If we could "distribute" PVS-Studio.exe launches among these 4 machines, we would need only 62.5 "iterations" instead of 250 (for we would have 16 cores available in this case).

To distribute analyzer launches among several computers, let's use the command line utility IBConsole:

ibconsole /command=incredi.bat /profile=incredi.xml

The incredi.xml file should contain the following text:

<?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 are "intercepting" the activity of devenv to enable "distribution" of PVS-Studio processes. In the incredi.bat file, we need to insert the launch line for devenv.exe, as described earlier. Also, we should remember to change the parallelizing level from 4 to 16 in PVS-Studio's settings.

Suppose Incredibuild was installed and correctly set up in advance on 4 machines. Now, after launching the ibconsole command, we will see that PVS-Studio.exe launches are distributed among these 4 computers, and the general analysis time will decrease.

Moreover, you don't need to keep either PVS-Studio or Visual Studio or the source files to be analyzed on all the other machines except the one this command is run on. Incredibuild will take care of it all.

So how much will the analysis time decrease? Your first guess is probably 4 times, for we now have 16 cores instead of 4, don't we? However, it will actually be less than four, and the exact figure will depend on a variety of factors, among which there are the computers' performance, their workload, network capacity, etc. But you can be sure it will be less than 4 because the "bottleneck effect" is inevitable anyway as the analysis initializer (devenv.exe) has to process the results of PVS-Studio.exe launches. In our experiments with 4 machines, we got a 2.5-3.5 time analysis acceleration.

If the user still wants to launch analysis manually by selecting the 'Check Solution' menu item, they will only need to change the contents of the incredi.bat file by inserting there a regular devenv.exe call: it will result in opening the Visual Studio window where you can perform all of the above described actions benefitting from the distributed analyzer launch. Of course, it's far not as convenient as just open Visual Studio and select the menu item "Run analysis in Incredibuild", so I think we will probably add this item into PVS-Studio's menu later.

Conclusion

It is already possible to use the current versions of Incredibuild and PVS-Studio together. If you face any troubles, please do not hesitate to let us know, and we'll be glad to help you.

Popular related articles


Comments (0)

Next comments next comments
close comment form
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam