Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f52b0cf9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use existing getProcessPid method to get pid of system_server."

parents 0b8b0ef6 d64bdbcc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
+7 −24
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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);