/*
 * Copyright (C) 2022 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 perfetto.protos;

import "protos/perfetto/metrics/android/process_metadata.proto";

message AndroidJankCujMetric {
  repeated Cuj cuj = 1;

  // Next id: 12
  message Cuj {
    // ID of the CUJ that is unique within the trace.
    optional int32 id = 1;

    // Name of the CUJ, extracted from the CUJ trace marker.
    // For example SHADE_EXPAND_COLLAPSE from J<SHADE_EXPAND_COLLAPSE>.
    optional string name = 2;

    // Details about the process (uid, version, etc)
    optional AndroidProcessMetadata process = 3;

    // ts of the CUJ trace marker slice.
    optional int64 ts = 4;

    // dur of the CUJ trace marker slice.
    optional int64 dur = 5;

    // Details about each of the frames within the CUJ.
    repeated Frame frame = 6;

    // Details about each of the SF frames within the CUJ.
    repeated Frame sf_frame = 10;

    // Metrics extracted from the counters output by FrameTracker
    // Does not contain the frame_dur percentile information.
    optional Metrics counter_metrics = 7;

    // Metrics extracted from the frame timeline.
    optional Metrics timeline_metrics = 8;

    // Metrics extracted from the trace slices.
    optional Metrics trace_metrics = 9;

    // Layer name of the surface where the cuj is drawn.
    optional string layer_name = 11;
  }

  // Next id: 11
  message Frame {
    // Index of the frame within the single user journey.
    optional int64 frame_number = 1;

    // VSYNC ID of the frame.
    optional int64 vsync = 2;

    optional int64 ts = 3;
    optional int64 dur = 4;
    optional int64 dur_expected = 7;

    // Whether the app process missed the frame deadline.
    // Only set for the App frames. Always left unset for SF frames.
    optional bool app_missed = 5;

    // Whether SF missed the frame deadline.
    optional bool sf_missed = 6;

    // Jank severity weight score for janky frames.
    optional double jank_score = 10;

    // Whether the SF callback missed before emitting jank metrics.
    // SF callback is used to get the jank classification.
    optional bool sf_callback_missed = 8;

    // Whether the HWUI callback missed before emitting jank metrics.
    // HWUI callback is used to get the frame duration.
    optional bool hwui_callback_missed = 9;
  }

  // Next id: 21
  message Metrics {
    // Overall number of frames within the CUJ.
    optional int64 total_frames = 1;

    // Number of missed frames.
    optional int64 missed_frames = 2;

    // Number of frames missed due to the app missing the deadline.
    optional int64 missed_app_frames = 3;

    // Number of frames missed due to SF.
    optional int64 missed_sf_frames = 4;

    // Weighted number of frames missed due to the app missing the deadline.
    optional double weighted_missed_app_frames = 19;

    // Weighted number of frames missed due to SF.
    optional double weighted_missed_sf_frames = 20;

    // Number of successive frames missed.
    // Not available in timeline_metrics and trace_metrics.
    optional int64 missed_frames_max_successive = 5;

    // Max frame duration in nanoseconds.
    optional int64 frame_dur_max = 6;

    // Duration in ns of the animation.
    optional int64 anim_duration = 18;

    // Average frame duration in nanoseconds.
    // Not available in counter_metrics.
    optional int64 frame_dur_avg = 7;

    // Median frame duration in nanoseconds.
    // Not available in counter_metrics.
    optional int64 frame_dur_p50 = 8;

    // P90 frame duration in nanoseconds.
    // Not available in counter_metrics.
    optional int64 frame_dur_p90 = 9;

    // P95 frame duration in nanoseconds.
    // Not available in counter_metrics.
    optional int64 frame_dur_p95 = 10;

    // P99 frame duration in nanoseconds.
    // Not available in counter_metrics.
    optional int64 frame_dur_p99 = 11;

    // Median frame duration in milliseconds.
    // Not available in counter_metrics.
    optional double frame_dur_ms_p50 = 12;

    // P90 frame duration in milliseconds.
    // Not available in counter_metrics.
    optional double frame_dur_ms_p90 = 13;

    // P95 frame duration in milliseconds.
    // Not available in counter_metrics.
    optional double frame_dur_ms_p95 = 14;

    // P99 frame duration in milliseconds.
    // Not available in counter_metrics.
    optional double frame_dur_ms_p99 = 15;

    // Number of frames with missed SF callback.
    optional int64 sf_callback_missed_frames = 16;

    // Number of frames with missed HWUI callback.
    optional int64 hwui_callback_missed_frames = 17;
  }
}
