summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java2
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java31
-rw-r--r--tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java2
3 files changed, 9 insertions, 26 deletions
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
index 6500428253f6..18cdf96c7131 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Cujs.java
@@ -34,7 +34,7 @@ public class Cujs {
// Do an explicit GC in the system server process as part of the test
// case to reduce GC-related sources of noise.
// SIGUSR1 = 10 is the magic signal to trigger the GC.
- int pid = mDevice.getPidForProcess("system_server");
+ int pid = mDevice.getProcessPid("system_server");
mDevice.executeShellCommand("kill -10 " + pid);
// Invoke the Device Cujs instrumentation to run the cujs.
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java
index 03503cec5fec..26146ca0ea6c 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Device.java
@@ -19,9 +19,6 @@ package com.android.tests.sysmem.host;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
-import java.util.InputMismatchException;
-import java.util.Scanner;
-
/**
* Wrapper around ITestDevice exposing useful device functions.
*/
@@ -58,29 +55,15 @@ class Device {
/**
* Returns the pid for the process with the given name.
*/
- public int getPidForProcess(String name) throws TestException {
- String psout = executeShellCommand("ps -A -o PID,CMD");
- Scanner sc = new Scanner(psout);
+ public int getProcessPid(String name) throws TestException {
try {
- // ps output is of the form:
- // PID CMD
- // 1 init
- // 2 kthreadd
- // ...
- // 9693 ps
- sc.nextLine();
- while (sc.hasNextLine()) {
- int pid = sc.nextInt();
- String cmd = sc.next();
-
- if (name.equals(cmd)) {
- return pid;
- }
+ String pid = mDevice.getProcessPid(name);
+ if (pid == null) {
+ throw new TestException("failed to get pid for " + name);
}
- } catch (InputMismatchException e) {
- throw new TestException("unexpected ps output format: " + psout, e);
+ return Integer.parseInt(pid);
+ } catch (DeviceNotAvailableException e) {
+ throw new TestException(e);
}
-
- throw new TestException("failed to get pid for process " + name);
}
}
diff --git a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
index b408a81d8f93..b46e642b5e92 100644
--- a/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
+++ b/tests/SystemMemoryTest/host/src/com/android/tests/sysmem/host/Metrics.java
@@ -79,7 +79,7 @@ class Metrics {
// adb root access is required to get showmap
mDevice.enableAdbRoot();
- int pid = mDevice.getPidForProcess("system_server");
+ int pid = mDevice.getProcessPid("system_server");
// Read showmap for system server and add it as a test log
String showmap = mDevice.executeShellCommand("showmap " + pid);