espressif / idf-env

idf-env tool helps set up and manage ESP-IDF installations
29 stars 4 forks source link

【Exit code: 0x2a】Requesting elevation of privileges for idf-env.exe antivirus exclusion add -a #31

Closed xiaolongba closed 2 years ago

xiaolongba commented 2 years ago

Hi espressif experts,

I tried to improve the compilation speed and type in the following commands in the PowerShell, but it returned the Exit code: 0x2a. the details as below:

PS F:\Tools\Espressif\IDF_Tools\.espressif> .\idf-env.exe antivirus exclusion add -a
Requesting elevation of privileges for: F:\Tools\Espressif\IDF_Tools\.espressif\idf-env.exe antivirus exclusion add -a
Exit code: 0x2a

could you give me a hand?

thanks.

georgik commented 2 years ago

@xiaolongba That's correct exit code.

What you see is that the process is elevating privileges and then executes the same command under Administrator account in new Terminal Window. The tool prints this exit code. The new Terminal Windows which contains list of exclusions which are being added. All exclusions should be visible in Administrator's PowerShell. Just execute command:

(Get-MpPreference).ExclusionPath

I admit that the result message is not very user friendly and there is room for improvement.

@JurajSadel Would you like to look at this issue and make CLI for this command more user friendly?

xiaolongba commented 2 years ago

Just execute command:

(Get-MpPreference).ExclusionPath

Hi @georgik

big thanks. but I tried to type in the command (Get-MpPreference).ExclusionPath , Nothing happen. image

However, I tried to type in the same command I mentioned above in Administrator's PowerShell. it works, as below:

image

is it normal? does it mean that all tools are excluded by antivirus software?

georgik commented 2 years ago

@xiaolongba That's expected behaviour. Only Administrator is allowed to see and modify exclusions.

It's also correct that there are so many exclusions. Unfortunately this is limitation of Windows Defender which requires to list each and every executable which should be excluded.

If you do not like that so many binaries are excluded, you can use more fine grained approach. Here is example which adds just cmake (tool name corresponds the name in .espressif/tools)

idf-env antivirus exclusion remove --all
idf-env antivirus exclusion add --tool cmake

Commands are available here: https://github.com/espressif/idf-env#working-with-antivirus

Adding just one or two tools may result only in 2-5% gain. Excluding --all will yield about 30% of gain.

xiaolongba commented 2 years ago

Adding just one or two tools may result only in 2-5% gain. Excluding --all will yield about 30% of gain.

perfect, I have added all tools for excluding, the commands I used as shown as

PS F:\Tools\Espressif\IDF_Tools\.espressif> .\idf-env.exe antivirus exclusion add -a
Requesting elevation of privileges for: F:\Tools\Espressif\IDF_Tools\.espressif\idf-env.exe antivirus exclusion add -a
Exit code: 0x2a

but it still needs around 40 seconds for blink example project, but I tried to type in the test commands , it showed me that it is around 17seconds. it seems that this is a big difference? is it possible to match to 17 seconds or fewer seconds?

PS F:\Tools\Espressif\IDF_Tools\.espressif> .\idf-env.exe idf build --repeat 10
Number of CPU cores: 12
ESP-IDF Shell Initializer: F:\Tools\Espressif\IDF_Tools\.espressif/Initialize-Idf.ps1
ESP-IDF Path: F:/BLE_WIFI/Espressif/SDK/esp-idf/
Time elapsed in build: 17.9945627s
Time elapsed in build: 16.7224732s
Time elapsed in build: 15.7629186s
Time elapsed in build: 15.5797721s
Time elapsed in build: 15.5295627s
Time elapsed in build: 15.6766036s
Time elapsed in build: 16.1085269s
Time elapsed in build: 16.2525799s
Time elapsed in build: 15.8353592s
Time elapsed in build: 16.1477195s
georgik commented 2 years ago

@xiaolongba The first build takes the longest time. Subsequent rebuilds are faster mainly thanks to the Ccache.

xiaolongba commented 2 years ago

The first build takes the longest time. Subsequent rebuilds are faster mainly thanks to the Ccache.

indeed. so the 40 seconds for the first build is normal after adding all tools for the exclusion? can I consider it like this? but why does the test command shows me that it is only around 17 seconds? what is the difference between them? or how to identify the exclusion command is available?

sorry for lots of doubts, bro.

georgik commented 2 years ago

Without exclusion: 1st build can be about 90 seconds and rebuilds might reach about 50 seconds. With exclusions: 1st build should be around 40 seconds and rebuilds can reach about 20 seconds.

Test command is repeating same build over and over to get statistic information, so it belongs to the section of subsequent builds. Some antiviruses are giving here penalty on build time about 120 seconds. Your computer with Defender seems to be completely ok.

The code which seeks for exclusions for tools is here: https://github.com/espressif/idf-env/blob/main/src/antivirus/exclusion.rs#L10 It walks through all/selected tools and searches for .exe files which are then added to the exclusion list.

xiaolongba commented 2 years ago

clear, thanks bro. you can close this ticket now.