vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Microsoft.VSCode.CPP.Extension.darwin high CPU usage

Open antnsi opened this issue 8 years ago • 47 comments

screen shot 2018-04-10 at 21 57 16

Configuration:

  • macOS 10.12.6
  • VS code 1.22.1
  • plugin 0.16.1

DB icon says "Discovering files: xxxx". VS Code console is full of such logs below. Seems it's constantly scanning some Frameworks folders, but why it takes so much resources?

IntelliSense Engine = Tag Parser.
The extension will use the Tag Parser for IntelliSense when #includes don't resolve.
Autocomplete is enabled.
Error squiggles are disabled.
File exclude: **/.git
File exclude: **/.svn
File exclude: **/.hg
File exclude: **/CVS
File exclude: **/.DS_Store
File exclude: **/.vscode
Search exclude: **/node_modules
Search exclude: **/bower_components
Search exclude: **/.vscode
  Folder: xxxxxxxxx will be indexed
  Folder: /usr/local/include/ will be indexed
  Folder: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/ will be indexed
  Folder: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/ will be indexed
  Folder: /usr/include/ will be indexed
  Folder: /System/Library/Frameworks/ will be indexed
  Folder: /Library/Frameworks/ will be indexed
Discovering files...
.......
/System/Library/Frameworks/AppKit.framework/Versions/C/Resources/he.lproj/Spelling.strings
Unable to add file to database, error = 0x8064000a: /System/Library/Frameworks/AppKit.framework/Versions/C/Resources/he.lproj/TextFinder.strings
Unable to add file to database, error = 0x8064000a: /System/Library/Frameworks/AppKit.framework/Versions/C/Resources/he.lproj/TextSystem.strings
Unable to add file to database, error = 0x8064000a: /System/Library/Frameworks/AppKit.framework/Versions/C/Resources/he.lproj/TextTouchBar-BBBAA77A32-C4EBFEA440.strings

call stack: sample.txt

antnsi avatar Apr 11 '18 08:04 antnsi

This is generally expected the first time you open a folder. You can reduce the CPU usage by lowering the priority of the indexing. See the "C_Cpp.workspaceParsingPriority" setting. If your config sets the "browse.limitSymbolsToIncludedHeaders" property to true (which is the default), the extension will only stat the files in the folders it has marked for indexing unless they are in your workspace folder or included by some file that is open in the editor.

Some of the Framework folders on Mac can take a while to traverse, so if you're not using any frameworks, you might consider removing them from the macFrameworkPath property in c_cpp_properties.json or scoping the path to only include the folders you care about.

How long does it take you to get past the "Discovering files: xxx" part? There could be something else going on too... The "Discovering files" is supposed to be really fast.

bobbrow avatar Apr 11 '18 15:04 bobbrow

@bobbrow thank you for reply! Seems plugin tries to traverse /System/Library/Frameworks and I never finished the process as it takes hours. I have C_Cpp.workspaceParsingPriority: low (it still take 80% cpu load) and browse.limitSymbolsToIncludedHeaders: true.

Finally, I removed all default paths from macFrameworkPath and indeed scan completed in few seconds (basically only headers).

antnsi avatar Apr 13 '18 07:04 antnsi

"low" is supposed to set the background CPU usage to around 25%, so if you're seeing 80%, it could be another thread doing work (if you open a file, another thread will attempt to parse that, causing more CPU usage than the background processing amount). I'm not able to repro the issue (it finishes with 262k files processed using <25% CPU and processes the /System/Library/Frameworks and /Library/Frameworks/). We haven't gotten other complains from other users so maybe there's some special about your setup (I also used 10.12.6, on a very slow Mac), i.e. some particular framework installed with a symbolic link causing an infinite loop? If you set the loggingLevel to "7" you can (slowly) see all the files we search through to see if there's some bug in the "discovering" phase. The 0x806400a error is an e_pending (or SQLITE disk I/O) error...not sure why that's occurring but it shouldn't matter unless it occurs consistently with a file you want symbols to be parsed with. If you could attach a debugger to the high CPU process and provide the call stack of the big threads that might help diagnose this.

image

sean-mcmanus avatar Apr 14 '18 01:04 sean-mcmanus

I've also noticed incredibly high CPU usage even when closing any open instances of VS Code that contain C++ code.

For example, I'll have two VSCode windows open (one for Ruby and one for a C++ project). If I close the C++ project, the CPU usage will still be quite high and I resort to killing the process with SIGTERM.

cmazakas avatar Apr 23 '18 14:04 cmazakas

@LeonineKing1199 I don't understand -- what process is using the CPU? Is there a Microsoft.VSCode.Extension process started from the Ruby project or is there a dangling one? VS Code is supposed to kill any dangling extension processes after 5 seconds so I'm not sure what could cause that to not happen.

sean-mcmanus avatar Apr 23 '18 20:04 sean-mcmanus

Sorry for not being clear.

I meant that it's a dangling process and it's quite CPU-heavy. I only know it's running because the fans on my MacBook sounds like they're gonna take off into space :P

I'll double-check to see if it persists beyond the 5 second window though.

cmazakas avatar Apr 23 '18 21:04 cmazakas

@sean-mcmanus I don't have anything unusual in /System/Library/Frameworks and /Library/Frameworks and I can't reproduce anymore high CPU process, after I excluded default frameworks from scanning. Now it's scans only headers and it takes about second: Discovering files: 3471 file(s) processed.

There is call stack sample.txt in original description of this ticket, is it something you are looking for? If this is not enough, then I can revert frameworks back to scan and investigate case more.

antnsi avatar Apr 24 '18 06:04 antnsi

I end up in the same situation where this process is stuck at consuming 100% cpu and it never quiets down, not even for hours on end. They also have a tendency to dangle if I quit VSCode and then I get multiple processes running at 100% "forever".

Attaching a stack trace of the process. Sample of Microsoft.VSCode.CPP.Extension.darwin.txt

danengelbrecht-king avatar May 23 '18 08:05 danengelbrecht-king

@danengelbrecht-king Thanks for those logs. I think I know what's going on. It appears to be caused by the new code that looks through the include path recursively...probably not handling cyclic symlinks correctly leading to an infinite loop. Can you confirm that doing an Edit Configuration and removing the "**" from the includePath's fixes the issue (you may need to "reload window" too)?

sean-mcmanus avatar May 23 '18 19:05 sean-mcmanus

@danengelbrecht-king Does this repro with 0.17.3? I don't repro any issue with cyclic symlinks so I'm not sure yet how to repro the issue yet. Are you able to repro the issue with some simple project you could share?

sean-mcmanus avatar May 24 '18 00:05 sean-mcmanus

@danengelbrecht-king Increasing the loggingLevel to something like the hidden value of "6" or higher might help us track down the cause.

@bobbrow Are you able to identify which method processing is getting stuck in? I assumed it was in parse_includes, but I could be wrong.

sean-mcmanus avatar May 24 '18 00:05 sean-mcmanus

@sean-mcmanus I do get it problems with 0.17.3, but I'm unsure what you mean by "Edit Configuration and removing the "**" from the includePath's" - I have "C_Cpp.default.includePath": null and "C_Cpp.default.systemIncludePath": null in my config.

However, after leaving the computer on over the weekend it seem to have stopped consuming lots of CPU (yay!) but on the other hand I have orphaned processes, sometimes they eat a lot of CPU as well, or as in this case just seem to be deadlocked - they remain after exiting Visual Studio Code.

Attaching logs for one orphaned process. orphaned-process-Microsoft.VSCode.CPP.Extension.darwin.txt

See also screenshot of what is a common occurrence on my machine... vccode cpp processes

danengelbrecht-king avatar May 28 '18 05:05 danengelbrecht-king

And here is a screenshot of what it look like after exiting Visual Studio Code...

vccode cpp processes-after-vscode-exit

danengelbrecht-king avatar May 28 '18 10:05 danengelbrecht-king

@danengelbrecht-king Thanks for that call stack. We understand the problem and are looking into a fix...

UPDATE: Actually, we're still not sure how that call stack is possible...maybe some of our pending fixes will address this.

sean-mcmanus avatar May 29 '18 20:05 sean-mcmanus

image image

I got same problem these days.

the default C_Cpp.workspaceParsingPriority value is highest and C_Cpp.default.macFrameworkPath value is null

colorhook avatar May 31 '18 06:05 colorhook

@sean-mcmanus I got the same problem. Everything is okie from first seven or eight hour. (I don't remember exactly) After that, the cpu usage increase very high because of this service.

p/s: I working on a customize of https://github.com/rtbkit/rtbkit on mac os. Build this project via docker. I just use vs code to edit and format my code, so don't install all the required lib for this project. update: I also include a big golang and a small python project also. Hope this help

hungminhtran avatar May 31 '18 08:05 hungminhtran

@colorhook, @hungminhtran, can you try the workaround in #2043 if it applies and let us know if that resolves your issue?

bobbrow avatar May 31 '18 15:05 bobbrow

@danengelbrecht-king, @colorhook, @hungminhtran, We released 0.17.4 with a fix for the livelock, so that issue should be resolved now. There are still some performance issues with recursive includes that we are working on, so you might still see some high CPU usage when opening files, but it should eventually catch up. We are going to track performance problems with recursive includes using issue #2068.

bobbrow avatar Jun 01 '18 03:06 bobbrow

@bobbrow the workaround not work for me. How to get 0.17.4?

hungminhtran avatar Jun 01 '18 08:06 hungminhtran

@hungminhtran Just restart Visual Studio Code and there should be un update indicator in the Extensions pane.

danengelbrecht-king avatar Jun 01 '18 08:06 danengelbrecht-king