syntax = "proto2";

package android.os.statsd.art;

import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/atom_field_options.proto";
import "frameworks/proto_logging/stats/enums/art/common_enums.proto";
import "frameworks/proto_logging/stats/enums/art/odrefresh_enums.proto";

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

extend Atom {
    optional OdrefreshReported odrefresh_reported = 366 [(module) = "art"];
    optional OdsignReported odsign_reported = 548 [(module) = "art"];
}

/*
 * Logs information about on-device refresh of ART AOT artifacts for boot classpath extensions
 * and system_server.
 *
 * Logged from:
 *   art/odrefresh/odrefresh.cc
 */
 message OdrefreshReported {
    optional int64 art_apex_version = 1;
    optional OdrefreshTrigger trigger = 2;
    optional OdrefreshStage stage_reached = 3;
    optional OdrefreshStatus status = 4;

    // Compilation time of the boot classpath for the primary architecture
    // ("primary boot classpath"), in seconds.
    optional int32 primary_bcp_compilation_seconds = 5;

    // Compilation time of the boot classpath for the secondary architecture
    // ("secondary boot classpath"), if any, in seconds.
    optional int32 secondary_bcp_compilation_seconds = 6;

    // Compilation time of system_server classpath, in seconds.
    optional int32 system_server_compilation_seconds = 7;

    // Cache space at start of update.
    optional int32 cache_space_free_start_mib = 8;

    // Cache space at end of update.
    optional int32 cache_space_free_end_mib = 9;

    // Compilation time of the boot classpath for the primary architecture
    // ("primary boot classpath"), in milliseconds.
    optional int32 primary_bcp_compilation_millis = 10;

    // Compilation time of the boot classpath for the secondary architecture
    // ("secondary boot classpath"), if any, in milliseconds.
    optional int32 secondary_bcp_compilation_millis = 11;

    // Compilation time of system_server classpath, in milliseconds.
    optional int32 system_server_compilation_millis = 12;

    // Status for the compilation of the boot
    // classpath for the primary architecture.
    optional ExecResultStatus primary_bcp_dex2oat_result_status = 13;

    // Exit code for the compilation of the boot classpath for the
    // primary architecture if status is EXEC_RESULT_STATUS_EXITED, else -1.
    optional int32 primary_bcp_dex2oat_result_exit_code = 14;

    // Signal for the compilation of the boot classpath for the
    // primary architecture if status is EXEC_RESULT_STATUS_SIGNALED, else 0.
    optional int32 primary_bcp_dex2oat_result_signal = 15;

    // Status for the compilation of the boot
    // classpath for the secondary architecture.
    optional ExecResultStatus secondary_bcp_dex2oat_result_status = 16;

    // Exit code for the compilation of the boot classpath for the
    // secondary architecture if status is EXEC_RESULT_STATUS_EXITED, else -1.
    optional int32 secondary_bcp_dex2oat_result_exit_code = 17;

    // Signal for the compilation of the boot classpath for the
    // secondary architecture if status is EXEC_RESULT_STATUS_SIGNALED, else 0.
    optional int32 secondary_bcp_dex2oat_result_signal = 18;

    // Status for the compilation of the boot classpath for the system_server.
    optional ExecResultStatus system_server_dex2oat_result_status = 19;

    // Exit code for the compilation of the boot classpath for the
    // system_server if status is EXEC_RESULT_STATUS_EXITED, else -1.
    optional int32 system_server_dex2oat_result_exit_code = 20;

    // Signal for the compilation of the boot classpath for the
    // system_server if status is EXEC_RESULT_STATUS_SIGNALED, else 0.
    optional int32 system_server_dex2oat_result_signal = 21;

    optional OdrefreshBcpCompilationType primary_bcp_compilation_type = 22;
    optional OdrefreshBcpCompilationType secondary_bcp_compilation_type = 23;
};

/**
 * Logs odsign metrics.
 *
 * Logged from:
 *   frameworks/base/services/core/java/com/android/server/pm/dex/OdsignStatsLogger.java
 */
 message OdsignReported {
    enum Status {
        // Unknown value.
        STATUS_UNSPECIFIED = 0;
        // All artifacts are generated and signed.
        STATUS_ALL_OK = 1;
        // Some artifacts are generated and signed, but odrefresh failed to generate the rest. See
        // odrefresh metrics for the odrefresh failure.
        STATUS_PARTIAL_OK = 2;
        // Odrefresh failed to generate any artifact. See odrefresh metrics for the odrefresh
        // failure.
        STATUS_ODREFRESH_FAILED = 3;
        // Odsign failed when interacting with Keystore.
        STATUS_KEYSTORE_FAILED = 4;
        // Odsign failed when initializing certificate.
        STATUS_CERT_FAILED = 5;
        // Odsign failed when cleaning up existing artifacts. Note that odrefresh may also clean up
        // existing artifacts, and failures about that are logged as `STATUS_ODREFRESH_FAILED`.
        STATUS_CLEANUP_FAILED = 6;
        // Odsign failed when signing artifacts.
        STATUS_SIGNING_FAILED = 7;
    }

    optional Status status = 1;
}
