PVS-Studio is a static analyzer that detects errors in source code of C/C++ applications. Like a compiler, the analyzer parses the project source files one by one. However, without the help of auxiliary tools, some projects may take several hours to build and even longer to analyze. When building large projects, some developers use the distributed build technology implemented in the IncrediBuild tool. We will not discuss the details of integrating PVS-Studio into IncrediBuild in this article; instead, I will tell you about the specifics of analyzing a large project, time measurements, and other interesting things.
PVS-Studio analyzes C/C++ code and points out to the programmer code fragments that contain potential errors.
The analyzer is comprised of several components, while the analysis as such of each source file is done by the PVS-Studio.exe process (the analyzer kernel). Further in this article, I will use the term "thread" to mean that one thread contains one running PVS-Studio.exe process analyzing one source file. And we are going to have lots of files....
IncrediBuild is a distributed build application that allows you to easily distribute processes among a number of computers, thus speeding up your software's work. At the same time, you don't have to worry about dependencies typical of ordinary concurrent processes.
We are going to use IncrediBuild to analyze our test project in a number of threads by using additional computers.
The authors of the project we are going to analyze didn't want us to reveal its name, but I can say that its size is about 7 million code lines. The code base size is 300 Mbytes in about 9000 files. It took us about 6 hours to analyze this project in 8 threads on a computer with Intel Core i7-4770 3.40 GHz CPU and 16 GB of RAM. Further in this article, I will tell you how we have managed to significantly boost the analysis speed by means of the IncrediBuild tool and a few additional computers.
In all the tests, we were using computers with about the same configuration, allowing us to run the analysis in 8 threads on each.
When setting up the IncrediBuild tool on several computers, one of them is set as a coordinator, while the others are set as agents connecting to the coordinator. Since the project analysis was run on one of the agents, we set the IncrediBuild copy installed on this computer to run the analysis in one thread only to avoid overloading which could interfere with the measuring process. The coordinator was also set to use 1 thread only.
For the first test run of PVS-Studio, we used 5 computers:
In total, it makes 1 + 1 + 8 + 8 + 8 = 26 threads to analyze 26 files at a time in parallel mode.
Figure 1 presents the scheme of project analysis parallelized into 26 threads.
Figure 1 - Analyzing a project in 26 threads
Now a few words for those of you who are not familiar with IncrediBuild. Each green stripe corresponds to 1 process that has successfully finished on a computer whose name is written in the left column. The stripe carries the process name, while the time bar at the bottom of the window allows monitoring the process' start and finish points so that you can check the working time of every process.
The figure above represents analysis of relatively large source files. Process distribution is highly even and efficient when threads stay loaded for a long time.
Figure 2 presents analysis of source files of varied sizes.
Figure 2 - Analyzing small and large project files in 26 threads
As you can see, quick thread termination causes certain overheads on creating new threads, so some of the computers may stay idle for a while. But generally the process distribution is pretty decent. It took us 2 hours 10 minutes to analyze this project, which makes a very nice difference compared to 6 hours.
For the second test run of PVS-Studio, we used 7 computers:
In total, it makes 1 + 2 + 8 + 8 + 8 + 8 + 8 = 43 threads to analyze 43 files at a time in parallel mode.
Figure 3 presents the project analysis parallelized into 43 threads.
Figure 3 - Analyzing a project in 43 threads.
You can't see the entire list of the 43 threads at once, but you can surely notice how greatly the delay time has grown for computers analyzing small files. Nevertheless, it still looks pretty nice, especially considering that it took us 1 hour 24 minutes instead of 6 hours to analyze the project, and the only effort we had made was to quickly install IncrediBuild on all the computers involved in the experiment. As for PVS-Studio, we only needed to change 1 settings option - i.e. define the thread number.
By using the IncrediBuild tool, usually used by developers to build especially heavy projects, we have managed to speed up the project analysis in PVS-Studio by 4.2 times, involving a few computers of the developers who were waiting nearby. All IncrediBuild's settings were set to default, and there are quite a number of them. I'm almost sure we could have obtained better performance, but we were interested in a "quick start".
So, once again, we needed to do the following to quickly launch the project analysis by PVS-Studio:
In this article you can read about how to use PVS-Studio and InccrediBuild in your project: "Integrating PVS-Studio with the IncrediBuild Distributed Build System".