diff options
author | Frederick Mayle <fmayle@google.com> | 2024-03-28 16:45:58 -0700 |
---|---|---|
committer | Frederick Mayle <fmayle@google.com> | 2024-04-02 17:30:58 +0000 |
commit | 389c2c23dbcd55c5f761afe716ecb71e66fd8271 (patch) | |
tree | 332a8c4cacbb1aae20983916b7c084d12d81c480 | |
parent | 69716c29b62aaba285e4d87ab6371388788162fb (diff) | |
download | tradefederation-389c2c23dbcd55c5f761afe716ecb71e66fd8271.tar.gz |
use new cuttlefish options to simplify snapshot-restore integration
We now collect less detailed metrics, but I don't think we care too much
about that, there are other means of getting breakdowns.
Bug: 331853381, 325117136
Test: TODO
Change-Id: I70059314031a215e3778d7329df1e551ea134bc8
3 files changed, 5 insertions, 217 deletions
diff --git a/common_util/com/android/tradefed/invoker/logger/InvocationMetricLogger.java b/common_util/com/android/tradefed/invoker/logger/InvocationMetricLogger.java index f38fdc35c..5d28ca5ac 100644 --- a/common_util/com/android/tradefed/invoker/logger/InvocationMetricLogger.java +++ b/common_util/com/android/tradefed/invoker/logger/InvocationMetricLogger.java @@ -197,12 +197,6 @@ public class InvocationMetricLogger { DEVICE_SNAPSHOT_RESTORE_SUCCESS_COUNT("device_snapshot_restore_success_count", true), DEVICE_SNAPSHOT_RESTORE_FAILURE_COUNT("device_snapshot_restore_failure_count", true), DEVICE_SNAPSHOT_RESTORE_DURATIONS("device_snapshot_restore_durations", true), - DEVICE_SUSPEND_SUCCESS_COUNT("device_suspend_success_count", true), - DEVICE_SUSPEND_FAILURE_COUNT("device_suspend_failure_count", true), - DEVICE_SUSPEND_DURATIONS("device_suspend_durations", true), - DEVICE_RESUME_SUCCESS_COUNT("device_resume_success_count", true), - DEVICE_RESUME_FAILURE_COUNT("device_resume_failure_count", true), - DEVICE_RESUME_DURATIONS("device_resume_durations", true), DEVICE_STOP_SUCCESS_COUNT("device_stop_success_count", true), DEVICE_STOP_FAILURE_COUNT("device_stop_failure_count", true), DEVICE_STOP_DURATIONS("device_stop_durations", true), @@ -214,10 +208,6 @@ public class InvocationMetricLogger { OXYGEN_DEVICE_DIRECT_RELEASE_COUNT("oxygen_device_direct_release_count", true), OXYGEN_DEVICE_RELEASE_FAILURE_COUNT("oxygen_device_release_failure_count", true), OXYGEN_DEVICE_RELEASE_FAILURE_MESSAGE("oxygen_device_release_failure_message", true), - // Represents the time we spent deleting file on host - DELETE_SNAPSHOT_FILES("delete_host_file_time_ms", true), - // Represents how many times we call the delete host file method - DELETE_SNAPSHOT_FILES_COUNT("delete_host_file_count", true), DYNAMIC_FILE_RESOLVER_PAIR("tf_dynamic_resolver_pair_timestamp", true), ARTIFACTS_DOWNLOAD_SIZE("tf_artifacts_download_size_bytes", true), @@ -424,7 +414,6 @@ public class InvocationMetricLogger { INCREMENTAL_FLASHING_PATCHES_SIZE("incremental-flashing-patches-size", true), INCREMENTAL_FLASHING_TARGET_SIZE("incremental-flashing-target-size", true); - private final String mGroupName; // Whether or not to add the value when the key is added again. private final boolean mAdditive; diff --git a/javatests/com/android/tradefed/device/connection/AdbSshConnectionTest.java b/javatests/com/android/tradefed/device/connection/AdbSshConnectionTest.java index 6ff24a373..87fbf8844 100644 --- a/javatests/com/android/tradefed/device/connection/AdbSshConnectionTest.java +++ b/javatests/com/android/tradefed/device/connection/AdbSshConnectionTest.java @@ -610,48 +610,11 @@ public class AdbSshConnectionTest { Mockito.any(), Mockito.eq(avdConnectHost), Mockito.eq(cvdBin), - Mockito.eq("suspend"))) - .thenReturn(successCmdResult); - when(mMockRunUtil.runTimedCmd( - Mockito.anyLong(), - Mockito.eq(stdout), - Mockito.eq(stderr), - Mockito.eq("ssh"), - Mockito.eq("-o"), - Mockito.eq("LogLevel=ERROR"), - Mockito.eq("-o"), - Mockito.eq("UserKnownHostsFile=/dev/null"), - Mockito.eq("-o"), - Mockito.eq("StrictHostKeyChecking=no"), - Mockito.eq("-o"), - Mockito.eq("ServerAliveInterval=10"), - Mockito.eq("-i"), - Mockito.any(), - Mockito.eq(avdConnectHost), - Mockito.eq(cvdBin), Mockito.eq("snapshot_take"), + Mockito.eq("--force"), + Mockito.eq("--auto_suspend"), Mockito.eq(snapshotCommandPath))) .thenReturn(successCmdResult); - // Make sure the instance resumes - when(mMockRunUtil.runTimedCmd( - Mockito.anyLong(), - Mockito.eq(stdout), - Mockito.eq(stderr), - Mockito.eq("ssh"), - Mockito.eq("-o"), - Mockito.eq("LogLevel=ERROR"), - Mockito.eq("-o"), - Mockito.eq("UserKnownHostsFile=/dev/null"), - Mockito.eq("-o"), - Mockito.eq("StrictHostKeyChecking=no"), - Mockito.eq("-o"), - Mockito.eq("ServerAliveInterval=10"), - Mockito.eq("-i"), - Mockito.any(), - Mockito.eq(avdConnectHost), - Mockito.eq(cvdBin), - Mockito.eq("resume"))) - .thenReturn(successCmdResult); when(mMockRunUtil.runTimedCmd( Mockito.anyLong(), Mockito.eq(stdout), @@ -691,27 +654,6 @@ public class AdbSshConnectionTest { Mockito.eq("start"), Mockito.eq(restoreSnapshotCommandPath))) .thenReturn(successCmdResult); - // Make sure the instance resumes - when(mMockRunUtil.runTimedCmd( - Mockito.anyLong(), - Mockito.eq(stdout), - Mockito.eq(stderr), - Mockito.eq("ssh"), - Mockito.eq("-o"), - Mockito.eq("LogLevel=ERROR"), - Mockito.eq("-o"), - Mockito.eq("UserKnownHostsFile=/dev/null"), - Mockito.eq("-o"), - Mockito.eq("StrictHostKeyChecking=no"), - Mockito.eq("-o"), - Mockito.eq("ServerAliveInterval=10"), - Mockito.eq("-i"), - Mockito.any(), - Mockito.eq(avdConnectHost), - Mockito.eq("rm"), - Mockito.eq("-rf"), - Mockito.eq(snapshotPath))) - .thenReturn(successCmdResult); CommandResult adbResult = new CommandResult(); adbResult.setStatus(CommandStatus.SUCCESS); adbResult.setStdout("connected to"); diff --git a/src/com/android/tradefed/device/connection/AdbSshConnection.java b/src/com/android/tradefed/device/connection/AdbSshConnection.java index d14327b46..9a4439c6a 100644 --- a/src/com/android/tradefed/device/connection/AdbSshConnection.java +++ b/src/com/android/tradefed/device/connection/AdbSshConnection.java @@ -653,8 +653,6 @@ public class AdbSshConnection extends AdbTcpConnection { */ public CommandResult snapshotGce(String user, Integer offset, String snapshotId) throws TargetSetupError { - cleanupSnapshotGce(user, snapshotId); - suspendGce(user, offset); long startTime = System.currentTimeMillis(); if (mGceAvd == null) { @@ -673,7 +671,8 @@ public class AdbSshConnection extends AdbTcpConnection { commandBuilder( "cvd", String.format( - "snapshot_take --snapshot_path=/tmp/%s/snapshots/%s", + "snapshot_take --force --auto_suspend" + + " --snapshot_path=/tmp/%s/snapshots/%s", user, snapshotId), user, offset); @@ -710,115 +709,11 @@ public class AdbSshConnection extends AdbTcpConnection { getDevice().getDeviceDescriptor(), DeviceErrorIdentifier.DEVICE_FAILED_TO_SNAPSHOT); } - resumeGce(user, offset); return snapshotRes; } /** - * Attempt to suspend a Cuttlefish instance - * - * @param user the host running user of AVD, <code>null</code> if not applicable. - * @param offset the device num offset of the AVD in the host, <code>null</code> if not - * applicable - * @throws TargetSetupError - */ - private void suspendGce(String user, Integer offset) throws TargetSetupError { - long startTime = System.currentTimeMillis(); - - // Get the user from options instance-user if user is null. - if (user == null) { - user = getDevice().getOptions().getInstanceUser(); - } - - String suspendCommand = commandBuilder("cvd", "suspend", user, offset); - if (suspendCommand.length() == 0) { - throw new TargetSetupError( - "failed to set up suspend command, invalid path", - getDevice().getDeviceDescriptor(), - DeviceErrorIdentifier.DEVICE_FAILED_TO_SUSPEND); - } - - CommandResult suspendRes = - GceManager.remoteSshCommandExecution( - mGceAvd, - getDevice().getOptions(), - getRunUtil(), - // TODO(khei): explore shorter timeouts. - Math.max(30000L, getDevice().getOptions().getGceCmdTimeout()), - suspendCommand.split(" ")); - - if (CommandStatus.SUCCESS.equals(suspendRes.getStatus())) { - // Time taken for suspend this invocation - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_SUSPEND_DURATIONS, - Long.toString(System.currentTimeMillis() - startTime)); - - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_SUSPEND_SUCCESS_COUNT, 1); - } else { - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_SUSPEND_FAILURE_COUNT, 1); - CLog.e("%s", suspendRes.getStderr()); - throw new TargetSetupError( - String.format("failed to suspend device: %s", suspendRes.getStderr()), - getDevice().getDeviceDescriptor(), - DeviceErrorIdentifier.DEVICE_FAILED_TO_SUSPEND); - } - } - - /** - * Attempt to resume a Cuttlefish instance - * - * @param user the host running user of AVD, <code>null</code> if not applicable. - * @param offset the device num offset of the AVD in the host, <code>null</code> if not - * applicable - * @throws TargetSetupError - */ - private void resumeGce(String user, Integer offset) throws TargetSetupError { - long startTime = System.currentTimeMillis(); - - // Get the user from options instance-user if user is null. - if (user == null) { - user = getDevice().getOptions().getInstanceUser(); - } - - String resumeCommand = commandBuilder("cvd", "resume", user, offset); - if (resumeCommand.length() == 0) { - throw new TargetSetupError( - "failed to set up resume command, invalid path", - getDevice().getDeviceDescriptor(), - DeviceErrorIdentifier.DEVICE_FAILED_TO_RESUME); - } - - CommandResult resumeRes = - GceManager.remoteSshCommandExecution( - mGceAvd, - getDevice().getOptions(), - getRunUtil(), - Math.max(300000L, getDevice().getOptions().getGceCmdTimeout()), - resumeCommand.split(" ")); - - if (CommandStatus.SUCCESS.equals(resumeRes.getStatus())) { - // Time taken for resume this invocation - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_RESUME_DURATIONS, - Long.toString(System.currentTimeMillis() - startTime)); - - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_RESUME_SUCCESS_COUNT, 1); - } else { - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_RESUME_FAILURE_COUNT, 1); - CLog.e("%s", resumeRes.getStderr()); - throw new TargetSetupError( - String.format("failed to resume device: %s", resumeRes.getStderr()), - getDevice().getDeviceDescriptor(), - DeviceErrorIdentifier.DEVICE_FAILED_TO_RESUME); - } - } - - /** * Attempt to restore snapshot of a Cuttlefish instance * * @param user the host running user of AVD, <code>null</code> if not applicable. @@ -875,7 +770,7 @@ public class AdbSshConnection extends AdbTcpConnection { } // Time taken for restore this invocation InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DEVICE_RESUME_DURATIONS, + InvocationMetricKey.DEVICE_SNAPSHOT_RESTORE_DURATIONS, Long.toString(System.currentTimeMillis() - startTime)); InvocationMetricLogger.addInvocationMetrics( @@ -945,44 +840,6 @@ public class AdbSshConnection extends AdbTcpConnection { } /** - * Delete snapshot folder - * - * @param user the host running use of AVD, <code>null</code> if not applicable. - * @param snapshotId the id of the snapshot to delete. - */ - private void cleanupSnapshotGce(String user, String snapshotId) { - long startTime = System.currentTimeMillis(); - - // Get the user from options instance-user if user is null. - if (user == null) { - user = getDevice().getOptions().getInstanceUser(); - } - - String cleanupSnapshotCommand = - String.format("rm -rf /tmp/%s/snapshots/%s", user, snapshotId); - - CommandResult deleteRes = - GceManager.remoteSshCommandExecution( - mGceAvd, - getDevice().getOptions(), - getRunUtil(), - Math.max(3000L, getDevice().getOptions().getGceCmdTimeout()), - cleanupSnapshotCommand.split(" ")); - - if (CommandStatus.SUCCESS.equals(deleteRes.getStatus())) { - // Time taken for stop this invocation - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DELETE_SNAPSHOT_FILES, - Long.toString(System.currentTimeMillis() - startTime)); - - InvocationMetricLogger.addInvocationMetrics( - InvocationMetricKey.DELETE_SNAPSHOT_FILES_COUNT, 1); - } else { - CLog.e("failed to delete snapshot with ID: %s. Does the snapshot exist?", snapshotId); - } - } - - /** * Cuttlefish has a special feature that brings the tombstones to the remote host where we can * get them directly. */ |