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

Microsoft.VSCode.CPP.Extension.darwin pegging CPU for hours on end

Open DevSecTim opened this issue 10 years ago • 77 comments

Any reason why this happens? My Mac fan is going all the time while using VSCode and its annoying and hot! Surely IntelliSight (or whatever) doesn't constantly need to scan code?

screen shot 2016-10-13 at 23 04 04

DevSecTim avatar Oct 13 '16 22:10 DevSecTim

Yeah, that is not normal. How many CPU cores do you have? One? It should use most of the CPU on one core. Why are there 4 extensions processes running? There should only be 1 per VS Code instance. You should probably kill those if they're extra. If you have opened a big root folder it might take a long time to build the browse database. Are there processes running 32 hours?

sean-mcmanus avatar Oct 13 '16 22:10 sean-mcmanus

Oh, on Mac/Linux the near 100% CPU usage reported is actually for just 1 Core, unlike the Windows Task Manager which divides the usage by the number of cores. So the behavior of our extension is the same.

sean-mcmanus avatar Oct 13 '16 22:10 sean-mcmanus

Since this post I have actually realised that closing VSCode doesn't actually kill the helper processes, which is why there where four - so maybe thats a bug on Mac?

Also, my root folder is definitely not large enough to justify 32 hours!

Is there anything I can do to help you guys reproduce?

DevSecTim avatar Oct 14 '16 06:10 DevSecTim

Yeah, the helper process isn't supposed to go away until it's done processing stuff, but it still sound like something is going wrong. Can you find out how many files are in the workspace? Or how large the .browse.vc.db is after it's done processing? How long does it take to stop, if ever? If you can get a repro on an open source project that would be good.

sean-mcmanus avatar Oct 14 '16 14:10 sean-mcmanus

I'll see what I can do and get back to you on this thread, as far as my observations show it never finishes - but I wasn't properly paying attention.

Watch this space.

DevSecTim avatar Oct 14 '16 14:10 DevSecTim

I have this problem all the time. Everytime I close VS Code, another helper process will stay alive forever. If I load up VS code again, it'll launch another process. If I load VS Code 3-4 times w/o actively killing the process in activity monitor, all my CPUs will be taken. This only happens on two separate macs, both running macOS Sierra.

Steps to reproduce:

  1. Git clone this repo - https://github.com/mozilla/gecko-dev
  2. Load VS code with the C++ extension
  3. Load the directory
  4. See the process take CPU usage forever. It never seems to finish.

This also looks like issue 297 as well. Also, same repository using VS Code on Windows with the same repository does not have this issue. This only happens on macOS. Also, the little flame in the bottom right corner is not on, which I think means that the directory has already been processed.

This would be great to fix please! Thanks!

changm avatar Oct 26 '16 01:10 changm

Hi! @sean-mcmanus What would it take to get this fixed? This is making VS Code unusable for me :(. Thanks!

changm avatar Nov 02 '16 17:11 changm

I just wait for the fans on my Mac to kick off and then go to Activity Monitor and kill the processes each time!

DevSecTim avatar Nov 03 '16 09:11 DevSecTim

Same problem. Can you guys fix it ASAP??? c42c0158-baa5-4258-b66e-684ccaafebbf

gangliao avatar Nov 15 '16 05:11 gangliao

Thanks everybody for the continued feedback. As was noted previously, the fact that our C++ tag parsing service is CPU bound is expected. We expect modern OS's to ensure that CPU resources are fairly distributed across all running processes. Also, since the tag parser is single threaded, at most we will fully utilize one CPU on the system. That alone may indeed cause PC or Mac fans to kick on.

Note that while it seems like a no-brainer, we don't recommend terminating this process manually. While the database we're writing to should be robust enough to handle this situation (sqllite), there could be bugs that wind up persisting a corrupted state, causing lots of potential for undefined behavior.

That being said, there are two other important things to note. First, it is currently by design that our extension continues to run after VSCode itself is closed. It will end when all discovered C++ files for the opened folder are parsed.

Second, we do recognize that this can indeed be problematic in two situations:

  1. There are a large number of files to parse.
  2. There is a undiscovered bug that causes the extension to never finish parsing.

Barring finding and fixing the root cause of any situation that results in #2, we believe there is a solution for handling both of these scenarios. This general solution isn't something we'll likely get for our next release, but I expect we'll have it for a subsequent one.

Finally, if you are only interested in the debugging functionality of this extension and you're desperate, you can actually delete (or rename) the extension executable (i.e. Microsoft.VSCode.CPP.Extension.exe, Microsoft.VSCode.CPP.Extension.linux, or Microsoft.VSCode.CPP.Extension.darwin). This will allow debugging to continue to work, but you'll lose all the C++ editing functionality normally provided.

@changm , we will investigate your repro scenario specifically and see if we can't provide a fix, asap.

Hope this helps!

greazer avatar Nov 15 '16 21:11 greazer

Got hit by the exact same problem, now that I finally figured out how to get the includes working on OSX 10.10. (pro tip: the default includePath in your c_cpp_properties.json does not work). The OSX C++ setup page really needs more work. About nothing works out of the box and needs some arcane setup steps before hand, but that is another story.

First, it is currently by design that our extension continues to run after VSCode itself is closed.

I don't really like that design, but ok. Then you should at least take care that not another process is started when I reopen VSCode. I had 4 processes pegging my CPU and only realised that my fan started spinning...

I am also wondering why it is going through a lot of files outside of my includes. I saw it reading my mailboxes, my bootcamp partition, etc in Activity Monitor -> Open Files and Ports. That seems unnecessary at best and dangerous and unacceptable at worst.

didito avatar Nov 20 '16 21:11 didito

@didito, thanks for the extra information, and for the record, I don't like the design we have for continuing to index files after VS Code closes either. :) I'd like to get this addressed asap.

I'll also take note to review the OSX C++ setup page and we'll take a look at the potential that we're reading outside the scope of known workspace or include paths. This definitely isn't expected!

greazer avatar Nov 22 '16 01:11 greazer

@greazer Thank you, sounds good! Let me know if I can help with any additional information.

FWIW I let the thing run for more than 12 hours and it still was not done. I had to force quit it. It resulted in a ~2 GB browse.VC.db file. I checked it with some SQLite browser and it has entries with file paths of headers from all over my hard disk. It did not seem to respect my config at all:

   "configurations": [
        {
            "name": "Mac",
            "includePath": [
				".",
				"../..",
				"../../../../myotherproject/src",
				"/usr/local/include",
				"/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/v1",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include",
                "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/local/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/Library/Frameworks"
			],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Linux",
            "includePath": ["/usr/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        },
        {
            "name": "Win32",
            "includePath": ["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"],
            "browse" : {
                "limitSymbolsToIncludedHeaders" : true,
                "databaseFilename" : ""
            }
        }
    ]

didito avatar Nov 22 '16 08:11 didito

Same issue on a Linux machine (8 CPUs)

Even one hour after VS code was started, the process still eats a LOT of CPU runtime. lsof doesn't show the process opening any source files.

radubacaran avatar Dec 01 '16 00:12 radubacaran

I'm on a Linux machine, and I can confirm this bug is happening. Some info on my system:

[flisboac@sonic adl]$ uname -a
Linux sonic 4.8.13-1-ARCH #1 SMP PREEMPT Fri Dec 9 07:24:34 CET 2016 x86_64 GNU/Linux
[flisboac@sonic adl]$ lsb_release -a
LSB Version:	1.4
Distributor ID:	Arch
Description:	Arch Linux
Release:	rolling
Codename:	n/a

If the process must be alive even after closing the editor that started it, I think the extension should at least do one of the following:

  1. Check if there is another process running; if there is, the scanner process just finishes itself, or is not started to begin with. Perhaps this can be done with a lockfile, or something similar.
  2. Give the user some option to run the scanner process externally -- as in NOT inside the editor, or not started after opening the editor. Also, processes started from inside the editor should behave as we expect: they are finalized, at most, as soon as the editor is closed.

Another suggestion: could the scanning be done per-project? Forgive me if I'm wrong, but AFAIK it scans everything in the user/global configuration. It would be nice to be able to tell which folders/files to scan on a per-project basis, or perhaps deduce which files to scan by analyzing the source code (e.g. scanning as needed by any project ever opened by the current user). Scanning the whole /usr/include will surely take an awful lot of space and time (specially for a single-threaded process, as per design) for no real benefit, considering:

  • The event of a system update or package removal;
  • Projects that use just a small portion of what is available on the user/global include path (e.g. a handful of system-wide header files); or
  • Projects that use all but system and local (project-only) headers.

I also think that it should treat system headers in a special way; having to specify where the C++ headers are is kind of annoying and unnecessary, IMHO.

flisboac avatar Dec 20 '16 04:12 flisboac

I'm on macOS Sierra on a MBP 2015 and having the same issue here. System Specs

teknogeek avatar Jan 17 '17 14:01 teknogeek

When Microsoft.VSCode.CPP.Extension.linux pegs a CPU on my Linux system, it appears to be related to displaying the hover popup for the text under the cursor. I've been experimenting and I don't initially see the process peg the CPU. It is only after hovering the cursor over numerous items in the source code that it will eventually get into the situation. Another symptom of the problem is that the hover that is displayed includes the text "Loading..." which seems to indicate that the extension is attempting to look up the symbol.

I've run an strace on both the Extension.linux process and its child process Microsoft.VSCode.CPP.IntelliSense.Msvc.linux. When the hover is working normally and the CPU isn't pegged, hovers result in system calls in both processes.

Once the CPU pegs, only the Extension.linux continues to register system calls. The IntellliSense process never issues any additional system calls.

Hovering alone did not recreate the problem. I had to perform hovers with the Control key held down to add the hyperlink and give the summary of the number of references. Here is the strace output for Extension.linux: utex(0x7ffcce8f606c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7ffcce8f6068, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 read(0, "Content-Length: 227\r\n\r\n{\"jsonrpc"..., 4096) = 250 futex(0x7ffcce8f606c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7ffcce8f6068, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 read(0, "Content-Length: 227\r\n\r\n{\"jsonrpc"..., 4096) = 250 futex(0x7ffcce8f606c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7ffcce8f6068, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 read(0, "Content-Length: 17555\r\n\r\n{\"jsonr"..., 4096) = 4096 read(0, "NLINE TAO_Request_Dispatcher *\\n"..., 4096) = 4096 read(0, "n timeout = this->thread_per_co"..., 4096) = 4096 read(0, "MUTEX, mon, this->lock_,\\n "..., 4096) = 4096 read(0, "llowed to be nil then check for "..., 4096) = 1219 futex(0x7ffcce8f606c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7ffcce8f6068, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 read(0, "{\"jsonrpc\":\"2.0\",\"method\":\"textD"..., 4096) = 129 read(0, "Content-Length: 227\r\n\r\n{\"jsonrpc"..., 4096) = 250 read(0, "Content-Length: 222\r\n\r\n{\"jsonrpc"..., 4096) = 245 read(0, "Content-Length: 64\r\n\r\n", 4096) = 22 read(0, "{\"jsonrpc\":\"2.0\",\"method\":\"$/can"..., 4096) = 64 brk(0x217e000) = 0x217e000 read(0, "Content-Length: 222\r\n\r\n{\"jsonrpc"..., 4096) = 245 read(0, "Content-Length: 64\r\n\r\n", 4096) = 22 read(0, "{\"jsonrpc\":\"2.0\",\"method\":\"$/can"..., 4096) = 64 read(0, "Content-Length: 222\r\n\r\n", 4096) = 23 read(0, "{\"jsonrpc\":\"2.0\",\"id\":366,\"metho"..., 4096) = 222 brk(0x21ae000) = 0x21ae000 read(0, "Content-Length: 64\r\n\r\n{\"jsonrpc\""..., 4096) = 86 read(0, "Content-Length: 222\r\n\r\n{\"jsonrpc"..., 4096) = 245 read(0, "Content-Length: 64\r\n\r\n{\"jsonrpc\""..., 4096) = 86 brk(0x21de000) = 0x21de000 read(0, "Content-Length: 222\r\n\r\n", 4096) = 23 read(0, "{\"jsonrpc\":\"2.0\",\"id\":368,\"metho"..., 4096) = 222 read(0, "Content-Length: 64\r\n\r\n", 4096) = 22 read(0, "{\"jsonrpc\":\"2.0\",\"method\":\"$/can"..., 4096) = 64 brk(0x21ff000) = 0x21ff000 read(0, "Content-Length: 222\r\n\r\n{\"jsonrpc"..., 4096) = 245 read(0, "Content-Length: 64\r\n\r\n{\"jsonrpc\""..., 4096) = 86 read(0, "Content-Length: 222\r\n\r\n{\"jsonrpc"..., 4096) = 245 brk(0x222f000) = 0x222f000

Here is the trace from Intellisense. Note that the output stopped after Extensions pegged and the output started registering the brk() calls. ettid() = 27236 futex(0x7f8398002a3c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8398002a38, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 futex(0x1c9e920, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1c9e8a8, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1ca1d9c, FUTEX_WAIT_PRIVATE, 1, NULL) = 0 futex(0x1ca1d70, FUTEX_WAKE_PRIVATE, 1) = 0 gettid() = 27236 futex(0x7f8398002abc, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8398002ab8, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 futex(0x1c9f90c, FUTEX_WAIT_PRIVATE, 1, NULL) = 0 futex(0x1c9f8e0, FUTEX_WAKE_PRIVATE, 1) = 0 gettid() = 27236 futex(0x7f8398002a3c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8398002a38, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 futex(0x1c9e920, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1c9e8a8, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1ca1d9c, FUTEX_WAIT_PRIVATE, 1, NULL) = 0 futex(0x1ca1d70, FUTEX_WAKE_PRIVATE, 1) = 0 gettid() = 27236 futex(0x7f8398002abc, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f8398002ab8, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1 futex(0x1c9e920, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1c9e8a8, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x1c9f90c, FUTEX_WAIT_PRIVATE, 1, NULL

dpwegener avatar May 21 '17 19:05 dpwegener

I've got a reproducible scenario on my system.

>lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.04
Release:        17.04
Codename:       zesty

You have to install the ACE/TAO orb from http://download.dre.vanderbilt.edu/previous_versions/ACE+TAO-6.4.0.tar.gz

  1. Extract ACE/TAO to your home directory ~/ACE_wrappers.
  2. Follow the ACE install procedures and make install ACE with an INSTALL_PREFIX of /usr/local
  3. Follow the TAO install procedures and make install TAO with an INSTALL_PREFIX of /usr/local
  4. Open vscode on the folder ~/ACE_wrappers/TAO/DevGuideExamples/GettingStarted
  5. Open the file MessengerServer.cpp
  6. Scroll to around line 40 and look for the line: CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
  7. Press Control and hover over the variable name orb. This displays a hover with the text Loading... and the Extensions.linux process pegs a CPU.

dpwegener avatar May 21 '17 20:05 dpwegener

@dpwegener What version of cpptools do you have? I'm not able to repro the issue. Ctrl+Hover shows the definition. Can you attach to the process and give us a call stack?

sean-mcmanus avatar May 22 '17 19:05 sean-mcmanus

Sorry for the delay in responding. I was running version 0.11.1. This morning I noticed that there was an update to 0.11.2. After installing the update, I'm not seeing the issue. Ctrl Hovers are working just fine. It appears that what ever was causing the issue has been fixed in the latest release.

dpwegener avatar May 27 '17 16:05 dpwegener