Bug 28956 - [XA 5.1] "log:heapshot" option no longer produces "profile.mlpd" file
Summary: [XA 5.1] "log:heapshot" option no longer produces "profile.mlpd" file
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.1
Hardware: PC Mac OS
: Highest critical
Target Milestone: 5.1
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2015-04-09 18:32 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-04-17 10:24 UTC (History)
5 users (show)

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


Attachments
Test case (30.19 KB, application/zip)
2015-04-09 18:32 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Adb logcat output (38.93 KB, application/octet-stream)
2015-04-09 18:34 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 or GitHub 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 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-09 18:32:14 UTC
Created attachment 10699 [details]
Test case

[XA 5.1] "log:heapshot" option no longer produces "profile.mlpd" file


Regression status: REGRESSION between Xamarin.Android 4.20.0-37 (9e05e39) and 5.1.0-100 (7402e0b)


I didn't see anything about this in the XA 5.1 release notes, so I suspect the brekage might be unintentional. This profiling support may still be considered a preview feature, so I'm leaving the initial severity as "normal".


Note: this also appears to break profiling via the graphical Profiler app.



## Steps to reproduce

1. Ensure "log:heapshot" is set for the "debug.mono.profile" options:
> $adb shell setprop debug.mono.profile log:heapshot


2. Run the attached test case. (This is just a template app with `GC.Collect()` added in the button's Click event handler.)


3. Click the button a few times.


4. Try to pull down the `profile.mlpd` file.

> $ adb pull /data/data/com.companyname.androidapp1/files/.__override__/profile.mlpd



## Result

> remote object '/data/data/com.companyname.androidapp1/files/.__override__/profile.mlpd' does not exist



## Version information

### Devices tested
- Xamarin Android Player API 19
- LG Optimus L9 API 16


### OS X 10.9.5, MacBook Air

Mono 4.0.0 ((detached/21d849b)

=== Xamarin.Android ===

Version: 5.1.0.100 (Business Edition)
Android SDK: /Users/macuser/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /Users/macuser
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-09 18:34:51 UTC
Created attachment 10700 [details]
Adb logcat output

Ah ha. It appears the logcat output shows the problem fairly clearly.

> W/monodroid( 3189): Trying to load profiler: /data/data/com.companyname.androidapp1/files/.__override__/libmono-profiler-log.so: dlopen=0x0 error=No such file or directory
> W/monodroid( 3189): Trying to load profiler: /storage/emulated/0/Android/data/com.companyname.androidapp1/files/.__override__/libmono-profiler-log.so: dlopen=0x0 error=No such file or directory
> W/monodroid( 3189): Trying to load profiler: /data/app-lib/com.companyname.androidapp1-1/libmono-profiler-log.so: dlopen=0x0 error=dlopen failed: could not load library "libmonosgen-2.0.so" needed by "libmono-profiler-log.so"; caused by library "libmonosgen-2.0.so" not found
> W/monodroid( 3189): looking for embedded profiler within '/data/app-lib/com.companyname.androidapp1-1/libmonodroid.so': dlopen=0x9d849d54 error=<none>
> W/monodroid( 3189): Looking for profiler init symbol 'mono_profiler_startup_log'? 0x0
> W/monodroid( 3189): Trying to load profiler: /data/app-lib/Mono.Android.DebugRuntime-1/libmono-profiler-log.so: dlopen=0x0 error=No such file or directory
> W/monodroid( 3189): The 'log' profiler wasn't found in the main executable nor could it be loaded from 'libmono-profiler-log.so'.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-04-09 18:52:50 UTC
And `libmono-profiler-log.so` profiler _is_ installed on the device at:

> /data/data/com.companyname.androidapp1/lib/libmono-profiler-log.so


So...

## Workaround

(Maybe a bit "hacky", and not really advisable? But it did suffice in my quick experiments.)

> $ adb shell ln -s /data/data/com.companyname.androidapp1/lib/libmono-profiler-log.so /data/data/com.companyname.androidapp1/files/.__override__/libmono-profiler-log.so

> $ adb shell ln -s /data/data/Mono.Android.DebugRuntime/lib/libmonosgen-32bit-2.0.so /data/data/com.companyname.androidapp1/files/.__override__/libmonosgen-2.0.so
Comment 3 Jonathan Pryor 2015-04-09 21:50:33 UTC
Radek: I'm sorry; this was introduced by fixing Bug #28538 (monodroid/8763f662b), which renames libmonosgen-2.0.so to libmonosgen-{32,64}bits-2.0.so.

The problem is that libmono-profiler-log.so still has a NEEDED library reference to libmonosgen-2.0.so, which now no longer exists:

> $ arm-linux-androideabi-readelf -d libmono-profiler-log.armeabi-v7a.so  | grep NEED
   0x00000001 (NEEDED)                     Shared library: [libmonosgen-2.0.so]
   0x00000001 (NEEDED)                     Shared library: [libdl.so]
   0x00000001 (NEEDED)                     Shared library: [libc.so]
   0x00000001 (NEEDED)                     Shared library: [liblog.so]
   0x00000001 (NEEDED)                     Shared library: [libm.so]
   0x00000001 (NEEDED)                     Shared library: [libz.so]

We either need to fix the name used by libmono-profiler-log.so -- which may not be possible -- or come up with an alternative solution to Bug #28358. :-(
Comment 5 PJ 2015-04-16 16:25:06 UTC
After discussion with PJ and Adrian I believe we will keep this patch on 5.1-series for release with 5.1.0. I will file a new bug for the 64-bit related profiling issues to be tracked for C5SR1.
Comment 7 Ram Chandra 2015-04-17 10:24:10 UTC
@Peter: Thanks for the update peter.

I am able to verify this issue with Samsung S3 (android 4.1) and Moto E (4.4.4) device.

However, I am still getting this issue with Nexus 5 and Moto X (Android:5.0.1) but as Peter told to me that this is the known issue with android 5.0+. 

Workaround with 5.0+ 

> ./adb shell cp /data/data/com.companyname.androidapp1/files/.__override__/profile.mlpd /sdcard/

> ./adb pull /sdcard/profile.mlpd

This issue has been fixed. Hence I am closing this issue.

Environment Info: 

=== Xamarin Studio ===

Version 5.9 (build 429)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 4.0.0 ((detached/c8db1b0)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000144

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.10.0.258 (Enterprise Edition)
Hash: c2c0012
Branch: master
Build date: 2015-04-14 17:26:21-0400

=== Xamarin.Android ===

Version: 5.1.0.115 (Enterprise Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 1.12.0.14 (Enterprise Edition)

=== Build Information ===

Release ID: 509000429
Git revision: c2162733aaad35e9703eebc3121a8131306b2dde
Build date: 2015-04-16 13:10:53-04
Xamarin addins: 791954691dfbc403676a103e52a0bb9754b9af29

=== Operating System ===

Mac OS X 10.10.3
Darwin Dalvik.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64