/*
 * Copyright (C) 2023 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/cpu_metric.proto";

// These metrices collects various function and thread
// usage within androd's codec framework. This can give an
// idea about performance and cpu usage when using codec
// framework
message AndroidCodecMetrics {
  // profile details in messages
  message Detail {
    // was thread_name
    reserved 1;
    // total time
    optional int64 total_cpu_ns = 2;
    // CPU time ( time 'Running' on cpu)
    optional int64 running_cpu_ns = 3;
    // avg running time for the trace duration
    optional int64 avg_running_cpu_ns = 9;
    // Total CPU cycles
    optional int64 total_cpu_cycles = 4;
    // avg CPU cycles per call
    optional int64 avg_cpu_cycles = 8;
    // avg time for this slice type
    optional int64 avg_time_ns = 5;
    optional int32 count = 6;
    message Latency {
      optional int64 max_us = 1;
      optional int64 min_us = 2;
      optional int64 avg_us = 3;
      optional int64 agg_us = 4;
      optional uint32 count = 5;
    }
    optional Latency self = 7;
  }

  // These are traces and could indicate framework queue latency
  // buffer-packing, buffer-preprocess, buffer post-process
  // latency etc. These metrics are monitored to track quality.
  // Same message can come from different
  // processes.
  message CodecFunction {
    // codec string
    optional string codec_string = 1;
    message Process {
      optional string name = 1;
      message Thread {
        optional string name = 1;
        optional Detail detail = 2;
      }
      optional Thread thread = 2;
    }
    optional Process process = 2;
  }

  // This message can indicate overall cpu
  // utilization of codec framework threads.
  message CpuUsage {
    // name of process using codec framework
    optional string process_name = 1;
    message ThreadInfo {
      // name of the codec thread
      optional string name = 1;
      message Details {
        // total cpu usage of the codec thread
        optional int64 thread_cpu_ns = 1;
        // can be number of codec framework thread
        optional uint32 num_threads = 2;
        // core type data info used by codec thread
        repeated AndroidCpuMetric.CoreTypeData core_data = 3;
      }
      optional Details info = 2;
    }
    optional ThreadInfo thread = 2;
    // was thread_cpu_us
    reserved 3;
  }

  // Rail details
  message Rail {
    // name of rail
    optional string name = 1;
    // energy and power details of this rail
    message Info {
      // energy from this rail for codec use
      optional double energy = 1;
      // power consumption in this rail for codec use
      optional double power_mw = 2;
    }
    optional Info info = 2;
  }

  // have the energy usage for the codec running time
  message Energy {
    // total energy taken by the system during this time
    optional double total_energy = 1;
    // total time for this energy is calculated
    optional int64 duration = 2;
    //  for this session
    optional double power_mw = 3;
    // enery breakdown by subsystem
    repeated Rail rail = 4;
  }

  repeated CpuUsage cpu_usage = 1;
  repeated CodecFunction codec_function = 2;
  optional Energy energy = 3;
}
