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

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

Merge "Fix checkstyle errors in SystemMemoryTest"

parents 9582e9e0 e9451112
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.tests.sysmem.host;
@@ -24,10 +24,10 @@ import com.android.tradefed.device.ITestDevice;
 * host.
 */
public class Cujs {
    private ITestDevice device;
    private ITestDevice mDevice;

    public Cujs(ITestDevice device) {
        this.device = device;
        this.mDevice = device;
    }

    /**
@@ -38,6 +38,6 @@ public class Cujs {
        // TODO: Consider exercising the system in other interesting ways as
        // well.
        String command = "am instrument -w com.android.tests.sysmem.device/.Cujs";
        device.executeShellCommand(command);
        mDevice.executeShellCommand(command);
    }
}
+21 −13
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.tests.sysmem.host;
@@ -22,46 +22,54 @@ import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestMetrics;
import com.android.tradefed.testtype.IDeviceTest;
import java.io.IOException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

/**
 * Runs a system memory test.
 */
@RunWith(DeviceJUnit4ClassRunner.class)
public class MemoryTest implements IDeviceTest {

    @Rule public TestMetrics testMetrics = new TestMetrics();
    @Rule public TestLogData testLogs = new TestLogData();

    private ITestDevice testDevice;
    private int iterations = 0;     // Number of times cujs have been run.
    private Metrics metrics;
    private Cujs cujs;
    private ITestDevice mTestDevice;
    private int mIterations = 0;     // Number of times cujs have been run.
    private Metrics mMetrics;
    private Cujs mCujs;

    @Override
    public void setDevice(ITestDevice device) {
        testDevice = device;
        metrics = new Metrics(device, testMetrics, testLogs);
        cujs = new Cujs(device);
        mTestDevice = device;
        mMetrics = new Metrics(device, testMetrics, testLogs);
        mCujs = new Cujs(device);
    }

    @Override
    public ITestDevice getDevice() {
        return testDevice;
        return mTestDevice;
    }

    // Invoke a single iteration of running the cujs.
    private void runCujs() throws DeviceNotAvailableException {
        cujs.run();
        iterations++;
        mCujs.run();
        mIterations++;
    }

    // Sample desired memory.
    private void sample()
            throws DeviceNotAvailableException, IOException, Metrics.MetricsException {
        metrics.sample(String.format("%03d", iterations));
        mMetrics.sample(String.format("%03d", mIterations));
    }

    /**
     * Runs the memory tests.
     */
    @Test
    public void run() throws Exception {
        sample();   // Sample before running cujs
+26 −23
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 * limitations under the License.
 */

package com.android.tests.sysmem.host;
@@ -22,6 +22,7 @@ import com.android.tradefed.result.FileInputStreamSource;
import com.android.tradefed.result.LogDataType;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestMetrics;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
@@ -33,15 +34,15 @@ import java.util.Scanner;
 */
class Metrics {

    private ITestDevice device;
    private TestMetrics metrics;
    private TestLogData logs;
    private ITestDevice mDevice;
    private TestMetrics mMetrics;
    private TestLogData mLogs;

    /**
     * Exception thrown in case of error sampling metrics.
     */
    public static class MetricsException extends Exception {
        public MetricsException(String msg) {
        MetricsException(String msg) {
            super(msg);
        }

@@ -59,10 +60,10 @@ class Metrics {
     * @param metrics where to log the high level metrics when taking a sample
     * @param logs where to log detailed breakdowns when taking a sample
     */
    public Metrics(ITestDevice device, TestMetrics metrics, TestLogData logs) {
        this.device = device;
        this.metrics = metrics;
        this.logs = logs;
    Metrics(ITestDevice device, TestMetrics metrics, TestLogData logs) {
        this.mDevice = device;
        this.mMetrics = metrics;
        this.mLogs = logs;
    }

    /**
@@ -73,7 +74,7 @@ class Metrics {
        PrintStream ps = new PrintStream(file);
        ps.print(text);
        try (FileInputStreamSource dataStream = new FileInputStreamSource(file)) {
        logs.addTestLog(label, LogDataType.TEXT, dataStream);
            mLogs.addTestLog(label, LogDataType.TEXT, dataStream);
        }
    }

@@ -82,7 +83,7 @@ class Metrics {
     */
    private int getPidForProcess(String name)
            throws DeviceNotAvailableException, IOException, MetricsException {
        String psout = device.executeShellCommand("ps -A -o PID,CMD");
        String psout = mDevice.executeShellCommand("ps -A -o PID,CMD");
        Scanner sc = new Scanner(psout);
        try {
            // ps output is of the form:
@@ -117,20 +118,22 @@ class Metrics {
     */
    void sample(String label) throws DeviceNotAvailableException, IOException, MetricsException {
        // adb root access is required to get showmap
        device.enableAdbRoot();
        mDevice.enableAdbRoot();

        int pid = getPidForProcess("system_server");

        // Read showmap for system server and add it as a test log
        String showmap = device.executeShellCommand("showmap " + pid);
        String showmap = mDevice.executeShellCommand("showmap " + pid);
        logText(label + ".system_server.showmap", showmap);

        // Extract VSS, PSS and RSS from the showmap and output them as metrics.
        // The last lines of the showmap output looks something like:
        // CHECKSTYLE:OFF Generated code
        // virtual                     shared   shared  private  private
        //    size      RSS      PSS    clean    dirty    clean    dirty     swap  swapPSS   # object
        //-------- -------- -------- -------- -------- -------- -------- -------- -------- ---- ------------------------------
        //  928480   113016    24860    87348     7916     3632    14120     1968     1968 1900 TOTAL
        // CHECKSTYLE:ON Generated code
        try {
            int pos = showmap.lastIndexOf("----");
            Scanner sc = new Scanner(showmap.substring(pos));
@@ -139,16 +142,16 @@ class Metrics {
            long rss = sc.nextLong();
            long pss = sc.nextLong();

            metrics.addTestMetric(String.format("%s.system_server.vss", label), Long.toString(vss));
            metrics.addTestMetric(String.format("%s.system_server.rss", label), Long.toString(rss));
            metrics.addTestMetric(String.format("%s.system_server.pss", label), Long.toString(pss));
            mMetrics.addTestMetric(label + ".system_server.vss", Long.toString(vss));
            mMetrics.addTestMetric(label + ".system_server.rss", Long.toString(rss));
            mMetrics.addTestMetric(label + ".system_server.pss", Long.toString(pss));
        } catch (InputMismatchException e) {
            throw new MetricsException("unexpected showmap format", e);
        }

        // Run debuggerd -j to get GC stats for system server and add it as a
        // test log
        String debuggerd = device.executeShellCommand("debuggerd -j " + pid);
        String debuggerd = mDevice.executeShellCommand("debuggerd -j " + pid);
        logText(label + ".system_server.debuggerd", debuggerd);

        // TODO: Experiment with other additional metrics.