Menu

Does Cppcheck take more time when more included paths are there

Krishna
2021-04-23
2023-09-08
1 2 > >> (Page 1 of 2)
  • Krishna

    Krishna - 2021-04-23

    I'm parsing compilation_commands.json to cppcheck with --project. In this each having the minimum 8 included paths provided(using -I). For each on average it is taking 3-4 secs and total it is taking 12 mins for 220 files.

    Is this expected behavior when more included paths provided?

     
  • Daniel Marjamäki

    It sounds expected. If a -I is not provided then the headers are probably not included and there will be less code to parse. Cppcheck is designed to check the code even without all headers.
    I would recommend that you don't include 3rd party headers, use --library instead.
    I would recommend that the internal headers are included by -I.

     
  • Krishna

    Krishna - 2021-04-27

    Hi Daniel,

    In that case is it possible below any. My concern is to decrease execution time.

    a. Incremental checking - means calling cppcheck for only modified files. So that no need to do for all files everytime.

    b. Duplicate includes - means there are 220 files in my database file. There is a high chance of included paths getting repeated. If cppcheck ignore checking already check path the time will be saved.

    Thanks.

     
  • Daniel Marjamäki

    We have incremental analysis, use --cppcheck-build-dir.

    I can't understand why we are not writing about this in the manual. :-(

     
    • john borland

      john borland - 2021-10-03

      Maybe something should be put in the help output to better draw peoples attention to it.

      Performance options
      -j, --cppcheck-build-dir

       
  • Krishna

    Krishna - 2021-04-27

    I tried giving --cppcheck-build-dir, Hardly it is saving 15-20 seconds.
    Can be saved more time?

     
    • Daniel Marjamäki

      it should save ~95% time or so.
      do you get various files in the cppcheck build dir.. if you have 100 source files then the cppcheck build dir should contain 100+ files..

       
  • Krishna

    Krishna - 2021-04-28

    Hi Daniel,

    Yes, I see files in cppcheck build dir. I have total 208 source files and in cppcheck build dir i'm seeing total 208 files. And if I rebuild without changing any source file, 36 files(A1) are getting updated to latest timestamp.

     
  • Daniel Marjamäki

    hmm that is unexpected. Not sure .. does it help if you provide -D flag(s) and don't say --force ?

     
  • Daniel Marjamäki

    Can you also try to run cppcheck with --showtime=summary option.. what is the output from that when you recheck a unchanged folder? Also stupid question.. you did use the exact same arguments when you rechecked the code right?

     
  • Mads Brix

    Mads Brix - 2021-04-28

    I have some cases where addition of just one more include path (leading to more header files being found) will lead to a huge increase in analysis time.
    No path to system headers, only my own headers.

    "Cppcheck is designed to check the code even without all headers".
    But I guess that without my headers the Class checks (missing member variable initialization etc.) are not possible?

     
  • Daniel Marjamäki

    But I guess that without my headers the Class checks (missing member variable initialization etc.) are not possible?

    Yes. I do recommend that you include your headers. In theory it would have been good to always use configuration files that had deeper information also but Cppcheck is not good enough and the work for users would have been too much.

     

    Last edit: Daniel Marjamäki 2021-04-29
  • Mads Brix

    Mads Brix - 2021-04-29

    Thanks - for the answer, and for the work with Cppcheck.

     
  • Krishna

    Krishna - 2021-09-21

    Hi Daniel,

    I see recursively passing project root directory is executing very quickly instead of passing with database file i.e., --project option.

    But I see with the recursive solution it is not finding errors in some header files. Intentionally added array out of bound error and run cppcheck. Strangely it is not at all reporting if header file located in a folder named with include.

    I'm giving -D flags, some excluded paths with -i option, and only one included path(cppcheck unable to find one macro, so had to provide this path), --enable=warning, --enable=style, -j 16 --enable=performance, --library=compiler.cfg, --xml, --quiet, --inline-suppr, --suppress=preprocessorErrorDirective --suppress=:projectRoot/vendor/*.h

    Using cppcheck 2.4.1 version

    We really want to speed up cppcheck exection as it is taking 10 mins with database file. With recursive method only executing in 20 sec.

    Any suggestions is really helpful.

     
    • Daniel Marjamäki

      But I see with the recursive solution it is not finding errors in some header files. Intentionally added array out of bound error and run cppcheck. Strangely it is not at all reporting if header file located in a folder named with include.

      Very strange! Of course that should work.

      Any suggestions is really helpful.

      I will suggest that you use --cppcheck-build-dir that can really speed up the analysis. However we discovered that option has been broken for some time. It will be fixed in cppcheck-2.6 that is released soonish.

       
      • Krishna

        Krishna - 2021-09-27

        Ok. When can we expect v2.6 release on worst case.

        Thanks.

         
  • Krishna

    Krishna - 2021-09-28

    Downloaded version 2.6-rc1 from github and tried the --cppcheck-build-dir, but it is not saving time at all. Creating the folder cppcheck-build-dir before running the cppcheck, PFA for complete command. I see .a1 and .snalyzerinfo are creating in cppcheck-build-dir.

    Do I miss anything here?

     
    • Daniel Marjamäki

      you need to run cppcheck at least twice to see the speedup..

      cppcheck --cppcheck-build-dir=cppcheck-build-dir ...
      cppcheck --cppcheck-build-dir=cppcheck-build-dir ...
      

      the first "cppcheck" will be as slow as before.
      the second "cppcheck" should be a lot faster.

       
  • Krishna

    Krishna - 2021-09-28

    Yes, I'm expecting time save for 2nd run while not changing anything.
    But it is not happening like that.

     
    • Daniel Marjamäki

      It's hard to trouble shoot without seeing any code. is there any code you could share? A single file. Maybe some kind of example code that includes public API?

      would it be possible to download the code in D:/Test/shared/source/cmsis somewhere and test on just that to start with?

       
      • Daniel Marjamäki

        you can download cppcheck source code here: https://github.com/danmar/cppcheck/archive/refs/heads/main.zip

        if you for testing purposes unpack that and run this command twice:

        cppcheck --cppcheck-build-dir=b -D__CPPCHECK__ -j4 lib
        

        Can you reproduce that the second command is faster?

         
  • Krishna

    Krishna - 2021-09-29

    Thanks for the reply Daniel.

    Yes, I ran cppcheck on the lib folder and it is saving time greatly for 2nd time run.
    In our case we are using compile_comands.json(Attached the json info for a single file which includes many included paths and -D flags) with --project option

    For us also passing project directory recursively is quick but we see some missing errors in header files. And with --cppcheck-build-dir I see .a1 and .snalyzerinfo files are generating and not creating/updating for 2nd run, only files.txt is getting updated still it is saving hardly 2 mins.

     
    • Krishna

      Krishna - 2021-09-30

      @danielmarjamaki

      Could you please suggest a solution?

       
      • Daniel Marjamäki

        It would help if I could reproduce this.

        With a compile database I get a speedup:

        danielm@debian:~/cppcheck$ rm b/*
        danielm@debian:~/cppcheck$ time ./cppcheck --project=build/compile_commands.json --cppcheck-build-dir=b --file-filter=lib/token.cpp
        Checking lib/token.cpp ...
        Checking lib/token.cpp: FILESDIR="/usr/local/share/Cppcheck";_GLIBCXX_DEBUG=1;__cplusplus=201103L...
        
        real    0m10,316s
        user    0m10,067s
        sys     0m0,024s
        danielm@debian:~/cppcheck$ time ./cppcheck --project=build/compile_commands.json --cppcheck-build-dir=b --file-filter=lib/token.cpp
        Checking lib/token.cpp ...
        
        real    0m0,144s
        user    0m0,137s
        sys     0m0,004s
        

        I guess that your compile command file does not matter.

        If you use --file-filter on some file as I did here can you see if it goes faster?

        If it does not go faster I wonder if you can validate the generated *.a1 file. Check if it is valid xml. For instance: xmllint --noout b/token.a1

         
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.