phptools-docs
phptools-docs copied to clipboard
Excesive CPU Usage
I use this extension (free version) for all my open php projects.
One day ago I got an issue, my CPU was 100% workload. When I opened the Task Manager there it was, devsense.php.ls consuming nearly the 100% of the CPU.
I didn't encounter a solution so y ended up using other extensions. Finally i returned to this extension and everything looked good, but in 1 file the process would go to 100% and make impossible to program.
I ended up finding what causes this error: Imagine you have this heredoc (ignore the names):
$html = <<<HTML
{$this->getSelect($this->x->a,'A',MyClass::CONSTANT_A,isRequired: true)}
{$this->getSelect($this->x->b,'B',MyClass::CONSTANT_B,isRequired: true)}
{$this->getSelect($this->x->c,'C',MyClass::CONSTANT_C,isRequired: true)}
{$this->getSelect($this->x->d,'D',MyClass::CONSTANT_D,isRequired: false)}
HTML;
This won't make the process go to 100% but this:
$html = <<<HTML
{$this->getSelect(
$this->x->a,
'A',
MyClass::CONSTANT_A,
isRequired: true)}
{$this->getSelect(
$this->x->b,
'B',
MyClass::CONSTANT_B,
isRequired: true)}
{$this->getSelect(
$this->x->c,
'C',
MyClass::CONSTANT_C,
isRequired: true)}
{$this->getSelect(
$this->x->d,
'D',
MyClass::CONSTANT_D,
isRequired: false)}
HTML;
This will make the process go in a loop
I have nothing more to say, if you're reading this because your devsense.php.ls is at 100% load you can "fix" it this way, although your method will be larger.
Thank you for digging into it.
Sadly it's not happening to me with this code :/
In my case, after restarting extension host for whatever reason one core of vscode plugin hosts keeps 100% forever. Very annoying, tbh.
EDIT: seems not to be related to php tools, sorry for false positive (turns out it was the phpstan vscode extension, swordev/phpstan)
Have you seen what's the name of the process causing it?
I'm also experiencing this issue, which seems related to the devsense.php.ls command.
It essentially makes my VS Code unusable, as the PHP IntelliSense freezes. I cannot navigate to files through Ctrl + click, and there is no auto-completion.
Most of the time, it sits at 99 or 100%, but everything still works as expected. But a few times a day, it jumps to a crazy high CPU usage, like 1,300%+, as below.
Output of sudo htop
It's hard to pinpoint what is causing the issue, e.g. a specific piece of code, the number of files open, etc. What are your recommended steps to help troubleshoot this, @jakubmisek ?
@angus-mcritchie Thank you! Yes, this is wrong - there must be just ONE devsense.php.ls process for one VSCode Workspace. Also using two extensions for PHP intellisense at the same time is a bit killer.
So there are two issues actually
- processes not being closed when the user reloads/closes VSCode (I guess)
- process loops on something
Is it Linux/x64?
@angus-mcritchie Thank you! Yes, this is wrong - there must be just ONE
devsense.php.lsprocess for one VSCode Workspace. Also using two extensions for PHP intellisense at the same time is a bit killer.So there are two issues actually
- processes not being closed when the user reloads/closes VSCode (I guess)
- process loops on something
Is it Linux/x64?
@jakubmisek I only have one extension for PHP iltellisense which is DEVSENSE.phptools-vscode.
My machine is running WSL 2 inside Windows 11 - Ubuntu 20.04.6 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64).
If I close VS Code all the processes stop. When I open VS Code now it spawns 18 processes of .vscode-server/extensions/devsense.phptools-vscode-1.53.16379-linux-x64/out/server/devsense.php.ls and 18 processes of .vscode-server/extensions/devsense. intelli-php-vscode-0.12.15062-linux-x64/out/server/intelliphp.ls
I did some further testing to rules other things out like other extensions and specific code.
I set up a workspace with a single file index.php with the contents below.
<?php
echo 'Hello world';
Opened it with a fresh VS Code profile with only the DEVSENSE.phptools-vscode extension pack installed.
It also opens up 36 processes as soon as I open the index.php file. Here's a screenshot of that.
Any help is much appreciated 🙏
May I ask you what's in the OUTPUT window / PHP (Language Server)
and the VSCode console in Help / Toggle Developer Tools -> Console:
(as a text :))
There might be some errors; but it looks like VSCode opens the workspace 18 times
@jakubmisek Here's the output of the php language.
Output of the dev tools console on reload window.
Found out it was a false alarm;
they are not processes, they are background threads (and they don't consume additional resources).
In htop you can enable F2 -> Display Options -> Tree View
To see the threads owned by the single process.
The actual issue is the CPU Usage - there may be something in the user's code causing the code analysis to loop infinitely ...
Found out it was a false alarm;
they are not processes, they are background threads (and they don't consume additional resources).
In
htopyou can enable F2 -> Display Options -> Tree View To see the threads owned by the single process.
The actual issue is the CPU Usage - there may be something in the user's code causing the code analysis to loop infinitely ...
Okay, that makes sense. If you have any clues what kind of code might be causing the loop, I'm all ears.
When it happens again I'll take note what files I have open and try to get a minimal example to reproduce it 🙂
Thanks again for your help.
@angus-mcritchie, thank you for your help! Yes, please. If it happens again, I'll be glad to know some details.
We'll add some logging in the future update, so anything that takes too much time will be logged somewhere - working on it.
I had to stop using this extension because a file in my PHP project leads devsense.php.ls to use 100% of a single core of my CPU.
And this happens even if I close VSCode. I should kill it manually.
The extension is very useful, but I need that file open in my project, so my only option is to uninstall it.
@Digitalone1 Thank you for reporting the issue.
Is it possible to share that file with us? We'll be happy to fix it. Here, or at info{at}devsense.com
Thank you!
@Digitalone1 Thank you for reporting the issue.
Is it possible to share that file with us? We'll be happy to fix it. Here, or at info{at}devsense.com
Thank you!
Unfortunately not, it's too big (+6k lines) and contains sensible information. Thank you anyway.