forked from mirrors/gecko-dev
		
	Bug 1821004 - Add summary.java-heap memory report. r=geckoview-reviewers,owlish
Android's memory profiler can show current java-heap size. Android M+ can get this usages from API. So this fix adds this entry to about:memory. Differential Revision: https://phabricator.services.mozilla.com/D172211
This commit is contained in:
		
							parent
							
								
									d9c9e6a248
								
							
						
					
					
						commit
						8eccde2927
					
				
					 2 changed files with 59 additions and 0 deletions
				
			
		|  | @ -40,6 +40,7 @@ import android.net.Network; | ||||||
| import android.net.NetworkInfo; | import android.net.NetworkInfo; | ||||||
| import android.os.Build; | import android.os.Build; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
|  | import android.os.Debug; | ||||||
| import android.os.LocaleList; | import android.os.LocaleList; | ||||||
| import android.os.Looper; | import android.os.Looper; | ||||||
| import android.os.PowerManager; | import android.os.PowerManager; | ||||||
|  | @ -1595,6 +1596,26 @@ public class GeckoAppShell { | ||||||
|     return id == 0 ? info.nonLocalizedLabel.toString() : context.getString(id); |     return id == 0 ? info.nonLocalizedLabel.toString() : context.getString(id); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   @WrapForJNI(calledFrom = "gecko") | ||||||
|  |   private static int getMemoryUsage(final String stateName) { | ||||||
|  |     if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | ||||||
|  |       // No API to get Java heap usages. | ||||||
|  |       return -1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     final Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); | ||||||
|  |     Debug.getMemoryInfo(memInfo); | ||||||
|  |     final String usage = memInfo.getMemoryStat(stateName); | ||||||
|  |     if (usage == null) { | ||||||
|  |       return -1; | ||||||
|  |     } | ||||||
|  |     try { | ||||||
|  |       return Integer.parseInt(usage); | ||||||
|  |     } catch (final NumberFormatException e) { | ||||||
|  |       return -1; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   @WrapForJNI |   @WrapForJNI | ||||||
|   public static native boolean isParentProcess(); |   public static native boolean isParentProcess(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -43,6 +43,11 @@ | ||||||
| #include "mozilla/ipc/UtilityProcessManager.h" | #include "mozilla/ipc/UtilityProcessManager.h" | ||||||
| #include "mozilla/ipc/FileDescriptorUtils.h" | #include "mozilla/ipc/FileDescriptorUtils.h" | ||||||
| 
 | 
 | ||||||
|  | #ifdef MOZ_WIDGET_ANDROID | ||||||
|  | #  include "mozilla/java/GeckoAppShellWrappers.h" | ||||||
|  | #  include "mozilla/jni/Utils.h" | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #ifdef XP_WIN | #ifdef XP_WIN | ||||||
| #  include "mozilla/MemoryInfo.h" | #  include "mozilla/MemoryInfo.h" | ||||||
| 
 | 
 | ||||||
|  | @ -1606,6 +1611,35 @@ NS_IMPL_ISUPPORTS(DMDReporter, nsIMemoryReporter) | ||||||
| 
 | 
 | ||||||
| #endif  // MOZ_DMD
 | #endif  // MOZ_DMD
 | ||||||
| 
 | 
 | ||||||
|  | #ifdef MOZ_WIDGET_ANDROID | ||||||
|  | class AndroidMemoryReporter final : public nsIMemoryReporter { | ||||||
|  |  public: | ||||||
|  |   NS_DECL_ISUPPORTS | ||||||
|  | 
 | ||||||
|  |   AndroidMemoryReporter() = default; | ||||||
|  | 
 | ||||||
|  |   NS_IMETHOD | ||||||
|  |   CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData, | ||||||
|  |                  bool aAnonymize) override { | ||||||
|  |     if (!jni::IsAvailable() || jni::GetAPIVersion() < 23) { | ||||||
|  |       return NS_OK; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     int32_t heap = java::GeckoAppShell::GetMemoryUsage("summary.java-heap"_ns); | ||||||
|  |     if (heap > 0) { | ||||||
|  |       MOZ_COLLECT_REPORT("java-heap", KIND_OTHER, UNITS_BYTES, heap * 1024, | ||||||
|  |                          "The private Java Heap usage"); | ||||||
|  |     } | ||||||
|  |     return NS_OK; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |  private: | ||||||
|  |   ~AndroidMemoryReporter() = default; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | NS_IMPL_ISUPPORTS(AndroidMemoryReporter, nsIMemoryReporter) | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  ** nsMemoryReporterManager implementation |  ** nsMemoryReporterManager implementation | ||||||
|  **/ |  **/ | ||||||
|  | @ -1695,6 +1729,10 @@ nsMemoryReporterManager::Init() { | ||||||
|   RegisterStrongReporter(new WindowsAddressSpaceReporter()); |   RegisterStrongReporter(new WindowsAddressSpaceReporter()); | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifdef MOZ_WIDGET_ANDROID | ||||||
|  |   RegisterStrongReporter(new AndroidMemoryReporter()); | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| #ifdef XP_UNIX | #ifdef XP_UNIX | ||||||
|   nsMemoryInfoDumper::Initialize(); |   nsMemoryInfoDumper::Initialize(); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Makoto Kato
						Makoto Kato