Add feature: Cache check results for future runs: - #799
Conversation
nirbar
commented
May 24, 2016
- Add command line flag: --cache=path/to/cache.xml
- Each check is cached along side the file's pre-processed size, code hash (SHA-512), configuration, check results
- In subsequent runs, if a file with the same path, size, hash is found in cache- report the cached results rather than running the full check again.
- File hash and size are calculated on preprocessed code. This ensures that the file hasn't changed as well as the included files.
- Results are cached disregarding uniquity. This allows subsequent runs with different configuration-sets to have all the results available. Report output is still unique- just the cache isn't.
- File path must be exact across runs. (either use same relative paths or same full path)
- Add command line flag: --cache=path/to/cache.xml - Each check is cached along side the check file's size, preprocessed code hash (SHA-512), configuration, check results - In subsequent runs, if a file with the same path, size, hash is found in cache- report the cached results rather than running the full check again. - File hash and size are calculated on preprocessed code. This ensures that the file hasn't changed as well as the included files. - Results are cached disregarding uniquity. This allows subsequent runs with different configuration-sets to have all the results available. Report output is still unique- just the cache isn't. - File path must be exact across runs. (either use same relative paths or same full path)
- Each check is cached along side the file's pre-processed size, code hash (SHA-512), configuration, check results - In subsequent runs, if a file with the same path, size, hash is found in cache- report the cached results rather than running the full check again. - File hash and size are calculated on preprocessed code. This ensures that the file hasn't changed as well as the included files. - Results are cached disregarding uniquity. This allows subsequent runs with different configuration-sets to have all the results available. Report output is still unique- just the cache isn't. - File path must be exact across runs. (either use same relative paths or same full path)
|
I don't like that cryptopp dependency is added.. please remove that. We don't need to put this in cppcheck as far as I see. It is possible to use make to only check changed source files, isn't it? |
| * That is very sensitive to the operating system, hardware, compiler and runtime! | ||
| * The code is not meant for production environment, it's using functions not whitelisted for usage in a signal handler function. | ||
| */ | ||
| /* |
There was a problem hiding this comment.
It is hard to read the diff when you are making lots of redundant indentation changes like this one. Please remove all redundant indentation changes.
|
|
cryptopp is a quite large dependency just to calculate a checksum. We just need a function as far as I see. We have the TokenList::calculateChecksum btw it is very simplistic so feel free to update that. |
so you have the same problem with compilation. But maybe that is much faster anyway. I don't like to put this in Cppcheck. It's like a workaround for your build environment. If some external tool can be used I'd prefer that. But at the same time .. maybe this could be used for distributed analysis also? I think the cache file should contain FileInfo data also if possible so we can get whole-program-analysis. |
| } | ||
|
|
||
| // Cache file (--cache=) | ||
| else if (std::strncmp(argv[i], "--cache=", strlen("--cache=")) == 0) { |
|
Checking changes by midification time is VERY error prune in this case. It should be checked for the source file and for every file it recursively includes, and then for every file that the included' files include... Calculating a unique-enough hash plus the code size is much safer. |
|
@nirbar |
That is how make works. I would not say that make works badly. For users that can use modification time, we could create a script in cppcheck/tools that generates a makefile. And to run incremental analysis, the normal make is used. But I guess that you need a hash-based solution. I don't think it's optimal for performance reasons to calculate the hash after the cppcheck-preprocessing. At least it's possible, as far as I see, to create a script in tools/cppcheck that calculate such hashes and run Cppcheck on modified files and then creates a full report for all files. Do you think this is a bad choice for some reason?
that would be better. we don't fully require C++11 yet so I am not sure if that is available yet though. But if it isn't then maybe we can temporarily use something like djb2 here http://www.cse.yorku.ca/~oz/hash.html |
|
Calculating hash is indeed time consuming but much less so comparing to a full scan. On tests I ran on a pretty large code base, average full scan took 40 minuets and an average incremental run with no changes to code took 3 minutes. I am not too particular about which hash to use. I chose SHA-512 because it is widely used and known to be quite unique. If the hash you're referring to can be trusted with that than lets go for it. |
|
basically.. I am very careful about adding new command line flags. yes we need to allow incremental analysis. I don't want to add a special flag that is only intended for hash-based incremental analysis. I would like to see how "make" like incremental analysis are done using this flag also. And I think this flag should allow distributed analysis using standard tools (for instance dispy/rsh/etc). |
|
Distributes analysis is much different- you need to start processes on During builds, an object file is generated for each source file- this part About the cache feature- personally, I don't see a reason not to add it; Nir Bar
2016-05-28 21:55 GMT+03:00 Daniel Marjamäki notifications@github.com:
|
|
I am not opposed to your hash-based incremental analysis. I want full flexibility so it will work for more use cases. There are already tools for distributed computing and timestamp-based incremental builds.. I do not want to put that functionality into Cppcheck also. Distributed analysis: timestamp-based incremental builds: This "linking" should not read any sourcefiles, it should just read the xml files and create the report. |
I do no want to implement these mechanisms into Cppcheck.
Exactly. So I hope we can pretend that the cache file is an object file.
There is no technical reason to disallow this for those who wants it.
ok I am fine with that.
I am especially careful about adding command line flags. Imagine that we add hash-based object files now. And you start distributing this to your clients. And then later we want to have distributed analysis and we must change the object files. It will be a pain for you if I change the command line flags and object files later. |
|
have you considered to include configuration also in the hash;
I don't think we must implement that to start with. but it should be considered. |
|
I think it is risky to let the user perform all the distribution work- the About configuration management of cache- these indeed should be added. Nir Bar
2016-05-30 10:52 GMT+03:00 Daniel Marjamäki notifications@github.com:
|
|
On Monday, 30. May 2016 01:06:01 Nir Bar wrote:
distcc, a compile job distribution system, solved the header expansion Homepage: There's also a "pump" mode in distcc that sends the headers Interesting is the last paragraph in README.pump:The pump mode was developed to be used with large clusters of distcc workstation is fast enough to keep that many machines busy.Thomas |
|
That's what I had in mind too. Nir Bar
2016-05-30 11:39 GMT+03:00 Thomas Jarosch notifications@github.com:
|
…ple source files. This somewhat reduces unique repoting, but follows full-scan convention.
|
yes I agree the source code to analyse should be sent from the host to the client machine. cfg files and rule files should also be passed from the host to the client. How we do that is a future problem imho. I do not think it's impossible. Then as I see it, when the client has all source files, headers, cfg, etc then it should be possible to do the analysis on the client machine using this cache functionality. then the cache file can be returned to the host. when all cache files are returned to host then it should not be hard for the host to generate a full analysis report. |
|
If we forget about cfg files and rule files for a moment.. and since I don't recommend that system headers are included let's forget those too.. it should then be possible to use distcc in pump mode right? |
|
I'm not that familiar with distcc... Nir Bar
2016-06-02 11:26 GMT+03:00 Daniel Marjamäki notifications@github.com:
|
|
I am starting to think that we can add this. Can you create a commit that does not break appveyor and travis? |
|
I am working on this. See --cppcheck-build-dir in git head. It is unfinished and under work but it has the caching of error messages functionality. |