/*
 * Copyright (C) 2025 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.
 */

syntax = "proto2";

package android.os.statsd.virtualization;

import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/atom_field_options.proto";

option java_package = "com.android.os.virtualization";
option java_multiple_files = true;

extend Atom {
  optional FsckFailedReported fsck_failed_reported = 1150 [(module) = "virtualizationservice"];
  optional CgroupMemoryBreachReported cgroup_memory_breach_reported = 1151 [(module) = "virtualizationservice"];
  optional GetOrCreateSkSecretFailedReported get_or_create_sk_secret_failed_reported = 1152 [(module) = "virtualizationservice"];
  optional PsiMonitorFailedReported psi_monitor_failed_reported = 1159 [(module) = "virtualizationservice"];
}

/*
 * Reports that the an fsck program executed by a VM's encryptedstore binary exited with the given exit code.
 * Logged from: packages/modules/Virtualization/
 * This atom is pushed for a failure case that, ideally, should not happen.
 * Thus, average throughput will be <1 event per device per day.
 * Peak throughput (in the case of some bug) would be on the order of 100 per day due to VM restarts.
 */
message FsckFailedReported {
  // The exit code reported from the fsck (e.g. e2fsck) binary.
  optional int32 exit_code = 1;
  // The UID that requested a VM via AVF.
  optional int32 vm_requester_uid = 2 [(is_uid) = true];
  // Human readable name of the VM.
  optional string vm_identifier = 3;
}

/*
 * Reports that the cgroup monitor within microdroid had detected a high breach event.
 * Logged from: packages/modules/Virtualization/
 * This atom is pushed for a failure case that, ideally, should not happen.
 * Thus, average throughput will be <1 event per device per day.
 * Peak throughput (in the case of some bug) would be on the order of 100 per day.
 */
message CgroupMemoryBreachReported {
  // Count of high breach events detected.
  optional int64 high_breach_count = 1;
  // The peak high memory in megabytes.
  optional int64 high_memory_peak_mb = 2;
  // The UID that requested a VM via AVF.
  optional int32 vm_requester_uid = 3 [(is_uid) = true];
  // Human readable name of the VM.
  optional string vm_identifier = 4;
}

/*
 * Reports that a VM failed to get or create a secret in secretkeeper.
 * Logged from: packages/modules/Virtualization/
 * This atom is pushed for a failure case that, ideally, should not happen.
 * Thus, average throughput will be <1 event per device per day.
 * Peak throughput (in the case of some bug) would be on the order of 100 per day.
 */
message GetOrCreateSkSecretFailedReported {
  // How many times (for a given request) the failed operation was retried.
  optional int32 retry_count = 1;
  // The UID that requested a VM via AVF.
  optional int32 vm_requester_uid = 2 [(is_uid) = true];
  // Human readable name of the VM.
  optional string vm_identifier = 3;
}

/**
 * Reports that a crosvm psi thread failed, and will attempt restart.
 * Logged from: packages/modules/Virtualization/
 * This atom is pushed for a failure case that, ideally, should not happen.
 * Thus, average throughput will be <1 event per device per day.
 * Peak throughput (in the case of some bug) would be on the order of 100 per day.
 */
message PsiMonitorFailedReported {
  // The current exponential backoff for the next restart of the PSI monitor.
  optional int64 exponential_backoff_seconds = 1;
  // The UID that requested a VM via AVF.
  optional int32 vm_requester_uid = 2 [(is_uid) = true];
  // Human readable name of the VM.
  optional string vm_identifier = 3;
}
