To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
RUB
* By clicking this button you agree to our Privacy Policy statement

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

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

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

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
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
What's new in PVS-Studio in 2021?

Date: Dec 31 2021

Author: Maxim Stefanov, Oleg Lisiy, Sergey Vasiliev

2021 is coming to an end, which means it's time to sum up the year! Today we'll tell you about the new features we added to PVS-Studio in the past year. Buckle up and let's go!
VSCode: how to view reports of static analyzers that support SARIF

Date: Aug 09 2021

Author: Nikolay Mironov

People increasingly start optimizing the process of finding code errors using static analyzers. Nowadays, we can choose from a variety of products to view analysis results. This post covers the ways …
PVS-Studio new features for notifying developers about errors found

Date: May 18 2021

Author: Maxim Stefanov

PVS-Studio user support often receives clients' suggestions on product improvement. We are happy to implement many of them. Recently one of the users suggested refining the automatic notification uti…
How to speed up building and analyzing of your project with IncrediBuild?

Date: May 17 2021

Author: Maxim Zvyagintsev

"How much longer are you going to build it?" - a phrase that every developer has uttered at least once in the middle of the night. Yes, a build can be long and there is no escaping it. One does not s…
Perl script instead of Blame-notifier on Linux OS

Date: Apr 08 2021

Author: Irina Polynkina

As you know, our clients are developers. Sometimes developers can surprise you. For example, one of our users wrote his own script. It allows configuring emails about errors found by PVS-Studio. The …

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept