Bug 26122 - Debugging Android project causes real time antivirus to spike CPU
Summary: Debugging Android project causes real time antivirus to spike CPU
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger ()
Version: 3.9
Hardware: PC Windows
: High major
Target Milestone: 3.11
Assignee: Juan Marcelo Tondato
URL:
: 25976 ()
Depends on:
Blocks:
 
Reported: 2015-01-16 16:10 UTC by Cody Beyer (MSFT)
Modified: 2016-05-10 16:57 UTC (History)
15 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
XVS 3.9 CPU usage graph (30.10 KB, image/png)
2015-02-02 23:01 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
XVS 3.8 CPU usage graph (26.46 KB, image/png)
2015-02-02 23:01 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Cody Beyer (MSFT) 2015-01-16 16:10:49 UTC
### Description

When debugging certain Xamarin.Android projects within Visual Studio, the CPU utilization will spike to 100%. It appears that this spike occurs within installed Anti-Virus software, when real-time scanning is enabled

### Test Case

https://www.dropbox.com/s/t6ugezxzqk1zcxq/GertecBinding.zip?dl=0

### Steps to Reproduce

1. Download attached test case
2. Attempt to debug in Visual Studio

### Expected Results

App will build and run

### Actual Results

System will hang because AV has used all CPU Resources

### Version

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0447006-02904
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0447006-02904
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0447006-02904
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0447006-02904
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0447006-02904
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0447006-02904
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0447006-02904
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0447006-02904
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.236.0 (d6a2cae)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.6.0.0 (eb24bdcf5cba2c12b673a07e0a8cce368b9563b3)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 1 asimk 2015-01-19 06:54:50 UTC
As I have download the app attached in BUg description. But Unable to Build App because its showing ClassLibrary3 not found error as shown in Screencast. Can you please provide me updated App so that we can reproduce the same issue.


Screencast:
http://www.screencast.com/t/IPvC1Dq68f

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0446016-02372
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0446016-02372
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0446016-02372
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446016-02372
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446016-02372
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446016-02372
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0446016-02372
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0446016-02372
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.3.50717.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.20703.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.2
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.2
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.2
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.241.0 (927cb6a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.0.0.16 (8a272fe970de5e889f2f5e65b6e8bec9b679974a)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.6.0.0 (dfb682fa615491b012ed24198d2bdcd641e1874f)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-30 03:06:41 UTC
Regression status: suspected regression between 3.8.150 and 3.9.236.

## https://xamarin.desk.com/agent/case/118011

This is the original basis for the bug report. The customer mentioned Windows Defender as the program that was likely performing on-access scans.


## https://xamarin.desk.com/agent/case/118874

The customer reported very similar symptoms:

> Every 3 - 4 seconds a java process is spawned - (I assume to scan for an
> Android phone?), this is then grabbed by "McAfee On-Access scanner" which
> halts the process permanently. This is then repeated until 100% processor
> capacity is reached.

He observed this behavior on 3.9.274. After downgrading back to 3.8.150, the problem no longer occurred:

> I downgraded as you suggested, and it’s behaving as normal
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2015-01-30 18:47:16 UTC
## https://xamarin.desk.com/agent/case/121433

This customer also reported very similar symptoms to 118874:

> I've made a screenshot from Process Explorer
> As you can see it runs quite a huge amount of find_java64.exe processes

> It looks like Xamarin start an infinite loop of android.bat files that call
> the find_java64.exe that starts java.exe and then some process are killed,
> some other are left suspended, but the amount of process never decrease, once
> it came up to 300 process, it made my computer really laggy.


He reported that he was using an antivirus program written by Kaspersky.


Again, downgrading to XVS 3.8.150 stopped the problem:

> I downgraded successfully and I don't have the problem anymore.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-02 23:01:17 UTC
Created attachment 9612 [details]
XVS 3.9 CPU usage graph

## Regression status: regression

### Good
Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)

### Bad
Xamarin   3.9.289.0 (39a70ae)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)



## Steps to reproduce

1. Ensure Windows Defender has "Real-time protection" enabled.

2. Open a Xamarin.Android project in Visual Studio.

3. Launch Process Explorer [1].
[1] https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

4. Open "View -> System Information".

5. Wait a little while to collect some data on the average CPU usage.



## Results

### XVS 3.9.289 shows frequent CPU usage spikes to 100% (image attached)

The `devenv.exe` process tree in Process Explorer shows new `cmd.exe` child processes appearing frequently, each one invoking `android.bat list avd`.

In the Windows Task Manager, the "Antimalware Service Executable" appears at the top of the list of processes for CPU usage.

Apparently in some environments these repeated calls to `android.bat list avd` get "stuck" running, eventually consuming the CPU entirely. In addition to Windows Defender, I tried a couple quick experiments with a McAfee on-access antivirus scanner. I was unable to hit the particular form of the problem where `android.bat` gets stuck, but it's probably worth reducing the frequency of calls to `android.bat list avd` anyway, if possible.


### devenv*.log

The XamarinVS log shows each of the many (costly) invocations of `android.bat list avd`.

> Xamarin.VisualStudio.ProcessWrapper Verbose: 0 : [2015-02-02 21:45:12.1] Executable: C:\ANDROI~1\tools\android.bat
> Xamarin.VisualStudio.ProcessWrapper Verbose: 0 : [2015-02-02 21:45:12.3] Arguments: list avd
> Xamarin.VisualStudio.ProcessWrapper Verbose: 0 : [2015-02-02 21:45:13.2] -- Process Finished [-1] --
> Xamarin.VisualStudio.ProcessWrapper Verbose: 0 : [2015-02-02 21:45:16.9] -- Starting Process - 02/02/2015 21:45:16 --



## Expected results

### XVS 3.8.150 shows consistently low CPU Usage (image attached)

The `devenv.exe` process tree in Process Explorer shows NO new child processes.



## Partial workarounds

- Disable Windows Defender. This reduces the height of the CPU spikes.

- Backup `android.bat` and replace it with an empty file.


Neither of these workarounds is a full workaround. There are still periodic spikes in CPU usage compared to 3.8.150, but the spikes are lower.



## Additional version info

### Windows 8.1 64-bit, in VMWare Fusion 6.0.5 (2209127)
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641


Tested with both Java JRE 6 (32-bit) and Java JRE 8 (64-bit).


=== Xamarin.Android ===

Version: 4.20.0 (Business Edition)
Android SDK: C:\android-sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode, sharing)
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-02 23:01:47 UTC
Created attachment 9613 [details]
XVS 3.8 CPU usage graph
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-02 23:05:52 UTC
I can confirm the primary symptoms (see comment 4).
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-03 17:14:21 UTC
Just for bookkeeping, I'll note that I've created a forum announcement to help provide public visibility of this issue:

http://forums.xamarin.com/discussion/32208/android-projects-cause-high-cpu-usage-related-to-android-bat-list-avd-regression-in-3-9
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-16 17:40:07 UTC
*** Bug 25976 has been marked as a duplicate of this bug. ***