summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Sehr <sehr@google.com> 2019-11-27 16:24:06 -0800
committer David Sehr <sehr@google.com> 2019-12-09 13:52:38 -0800
commit8f3eee0466657cef3321fd119a4fe85bf09577cb (patch)
tree6c263c88072065892a58ce91b3d8cb778cf384bb
parent0e3e2a73c653f3497afd670f7dfb8db4cda25167 (diff)
Add hook for JVMTI agent in system server
Add a place to attach a jvmti agent into the system server in debug builds. This allows profiling and other investigations for performance improvements. Bug: none Test: attach agent, collect result Change-Id: I299dffb1774fdce48b9b695a614b7ab60f1307e2 Merged-In: I299dffb1774fdce48b9b695a614b7ab60f1307e2 (cherry picked from commit 1a88539df2279286695018c86485e4eb89357629)
-rw-r--r--services/java/com/android/server/SystemServer.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 2e4f1e39ce87..2528063f0bf8 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -40,12 +40,12 @@ import android.database.sqlite.SQLiteCompatibilityWalFlags;
import android.database.sqlite.SQLiteGlobal;
import android.hardware.display.DisplayManagerInternal;
import android.net.ConnectivityModuleConnector;
-import android.net.Network;
import android.net.NetworkStackClient;
import android.net.TetheringManager;
import android.os.BaseBundle;
import android.os.Binder;
import android.os.Build;
+import android.os.Debug;
import android.os.Environment;
import android.os.FactoryTest;
import android.os.FileUtils;
@@ -497,6 +497,24 @@ public final class SystemServer {
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
// Prepare the thread pool for init tasks that can be parallelized
SystemServerInitThreadPool.get();
+ // Attach JVMTI agent if this is a debuggable build and the system property is set.
+ if (Build.IS_DEBUGGABLE) {
+ // Property is of the form "library_path=parameters".
+ String jvmtiAgent = SystemProperties.get("persist.sys.dalvik.jvmtiagent");
+ if (!jvmtiAgent.isEmpty()) {
+ int equalIndex = jvmtiAgent.indexOf('=');
+ String libraryPath = jvmtiAgent.substring(0, equalIndex);
+ String parameterList =
+ jvmtiAgent.substring(equalIndex + 1, jvmtiAgent.length());
+ // Attach the agent.
+ try {
+ Debug.attachJvmtiAgent(libraryPath, parameterList, null);
+ } catch (Exception e) {
+ Slog.e("System", "*************************************************");
+ Slog.e("System", "********** Failed to load jvmti plugin: " + jvmtiAgent);
+ }
+ }
+ }
} finally {
traceEnd(); // InitBeforeStartServices
}