diff options
author | Michael Rosenfeld <mrosenfeld@google.com> | 2016-04-12 14:18:19 -0700 |
---|---|---|
committer | Michael Rosenfeld <mrosenfeld@google.com> | 2016-04-12 18:18:41 -0700 |
commit | 1099692bdce43f406c80a2cc92bc75a7aebaa9c1 (patch) | |
tree | 9412bb19f7736f5e2debddd5986a417bb163143c /src/com/android/tradefed/targetprep | |
parent | aa734dc9e986c6c28bcf76be1b2e5de618efc97a (diff) | |
download | tradefederation-1099692bdce43f406c80a2cc92bc75a7aebaa9c1.tar.gz |
TargetCleaner that uploads unreachable native memory
* Calls 'dumpsys meminfo --unreachable -a'
Bug: 28121919
Change-Id: Iadca031a869d5a3e1c41ef05ef9b50cefe06360f
Diffstat (limited to 'src/com/android/tradefed/targetprep')
-rw-r--r-- | src/com/android/tradefed/targetprep/NativeLeakCollector.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/com/android/tradefed/targetprep/NativeLeakCollector.java b/src/com/android/tradefed/targetprep/NativeLeakCollector.java new file mode 100644 index 000000000..1659181ad --- /dev/null +++ b/src/com/android/tradefed/targetprep/NativeLeakCollector.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * 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. + */ +package com.android.tradefed.targetprep; + +import com.android.tradefed.build.IBuildInfo; +import com.android.tradefed.build.IDeviceBuildInfo; +import com.android.tradefed.config.Option; +import com.android.tradefed.config.OptionClass; +import com.android.tradefed.device.BackgroundDeviceAction; +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.device.ITestDevice; +import com.android.tradefed.device.LargeOutputReceiver; +import com.android.tradefed.log.ITestLogger; +import com.android.tradefed.log.LogUtil.CLog; +import com.android.tradefed.result.ByteArrayInputStreamSource; +import com.android.tradefed.result.ITestLoggerReceiver; +import com.android.tradefed.result.InputStreamSource; +import com.android.tradefed.result.LogDataType; +import com.android.tradefed.util.StreamUtil; + +/** + * A {@link ITargetCleaner} that runs 'dumpsys meminfo --unreachable -a' to identify the unreachable + * native memory currently held by each process. + * <p> + * Note: this preparer requires N platform or newer. + */ +@OptionClass(alias = "native-leak-collector") +public class NativeLeakCollector implements ITestLoggerReceiver, ITargetCleaner { + private static final String UNREACHABLE_MEMINFO_CMD = + "dumpsys -t 60 meminfo --unreachable -a"; + + private ITestLogger mTestLogger; + + @Option(name = "disable", description = "If this preparer should be disabled.") + private boolean mDisable = false; + + @Option(name = "log-filename", description = "The filename to give this log.") + private String mLogFilename = "unreachable-meminfo"; + + /** + * {@inheritDoc} + */ + @Override + public void setUp(ITestDevice device, IBuildInfo buildInfo) + throws TargetSetupError, BuildError, DeviceNotAvailableException { + // No-op + } + + /** + * {@inheritDoc} + */ + @Override + public void tearDown(ITestDevice device, IBuildInfo buildInfo, Throwable e) + throws DeviceNotAvailableException { + if (mDisable || (e instanceof DeviceNotAvailableException)) { + return; + } + + String output = device.executeShellCommand(UNREACHABLE_MEMINFO_CMD); + if (output != null && !output.isEmpty()) { + ByteArrayInputStreamSource byteOutput = + new ByteArrayInputStreamSource(output.getBytes()); + mTestLogger.testLog(mLogFilename, LogDataType.TEXT, byteOutput); + StreamUtil.cancel(byteOutput); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setTestLogger(ITestLogger testLogger) { + mTestLogger = testLogger; + } +} |