/*
 * Copyright (C) 2019 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/ad_services_metric.proto";
import "protos/perfetto/metrics/android/android_boot.proto";
import "protos/perfetto/metrics/android/android_boot_unagg.proto";
import "protos/perfetto/metrics/android/android_garbage_collection_stats.proto";
import "protos/perfetto/metrics/android/android_garbage_collection_unagg_metric.proto";
import "protos/perfetto/metrics/android/auto_metric.proto";
import "protos/perfetto/metrics/android/sysui_notif_shade_list_builder_metric.proto";
import "protos/perfetto/metrics/android/sysui_update_notif_on_ui_mode_changed_metric.proto";
import "protos/perfetto/metrics/android/android_frame_timeline_metric.proto";
import "protos/perfetto/metrics/android/anr_metric.proto";
import "protos/perfetto/metrics/android/batt_metric.proto";
import "protos/perfetto/metrics/android/android_sysui_notifications_blocking_calls_metric.proto";
import "protos/perfetto/metrics/android/android_blocking_calls_cuj_metric.proto";
import "protos/perfetto/metrics/android/android_blocking_calls_cuj_per_frame_metric.proto";
import "protos/perfetto/metrics/android/android_blocking_calls_unagg.proto";
import "protos/perfetto/metrics/android/codec_metrics.proto";
import "protos/perfetto/metrics/android/cpu_metric.proto";
import "protos/perfetto/metrics/android/camera_metric.proto";
import "protos/perfetto/metrics/android/camera_unagg_metric.proto";
import "protos/perfetto/metrics/android/display_metrics.proto";
import "protos/perfetto/metrics/android/dma_heap_metric.proto";
import "protos/perfetto/metrics/android/dvfs_metric.proto";
import "protos/perfetto/metrics/android/fastrpc_metric.proto";
import "protos/perfetto/metrics/android/g2d_metric.proto";
import "protos/perfetto/metrics/android/gpu_metric.proto";
import "protos/perfetto/metrics/android/hwcomposer.proto";
import "protos/perfetto/metrics/android/hwui_metric.proto";
import "protos/perfetto/metrics/android/io_metric.proto";
import "protos/perfetto/metrics/android/io_unagg_metric.proto";
import "protos/perfetto/metrics/android/ion_metric.proto";
import "protos/perfetto/metrics/android/irq_runtime_metric.proto";
import "protos/perfetto/metrics/android/jank_cuj_metric.proto";
import "protos/perfetto/metrics/android/java_heap_histogram.proto";
import "protos/perfetto/metrics/android/java_heap_class_stats.proto";
import "protos/perfetto/metrics/android/java_heap_stats.proto";
import "protos/perfetto/metrics/android/lmk_metric.proto";
import "protos/perfetto/metrics/android/lmk_reason_metric.proto";
import "protos/perfetto/metrics/android/mem_metric.proto";
import "protos/perfetto/metrics/android/mem_unagg_metric.proto";
import "protos/perfetto/metrics/android/multiuser_metric.proto";
import "protos/perfetto/metrics/android/network_metric.proto";
import "protos/perfetto/metrics/android/package_list.proto";
import "protos/perfetto/metrics/android/powrails_metric.proto";
import "protos/perfetto/metrics/android/profiler_smaps.proto";
import "protos/perfetto/metrics/android/rt_runtime_metric.proto";
import "protos/perfetto/metrics/android/simpleperf.proto";
import "protos/perfetto/metrics/android/startup_metric.proto";
import "protos/perfetto/metrics/android/surfaceflinger.proto";
import "protos/perfetto/metrics/android/trace_quality.proto";
import "protos/perfetto/metrics/android/unsymbolized_frames.proto";
import "protos/perfetto/metrics/android/binder_metric.proto";
import "protos/perfetto/metrics/android/monitor_contention_metric.proto";
import "protos/perfetto/metrics/android/monitor_contention_agg_metric.proto";
import "protos/perfetto/metrics/android/app_process_starts_metric.proto";
import "protos/perfetto/metrics/android/android_oom_adjuster_metric.proto";
import "protos/perfetto/metrics/android/android_broadcasts_metric.proto";
import "protos/perfetto/metrics/android/wattson_in_time_period.proto";
import "protos/perfetto/metrics/android/android_anomaly_metric.proto";
import "protos/perfetto/metrics/android/wattson_tasks_attribution.proto";
import "protos/perfetto/metrics/common/clone_duration.proto";

// Trace processor metadata
// Next id: 21
message TraceMetadata {
  reserved 1;
  optional int64 trace_duration_ns = 2;
  optional string trace_uuid = 3;
  optional string android_build_fingerprint = 4;
  optional string android_incremental_build = 20;
  optional string android_device_manufacturer = 16;
  optional int64 android_profile_boot_classpath = 18;
  optional int64 android_profile_system_server = 19;
  optional int64 statsd_triggering_subscription_id = 5;
  optional int64 trace_size_bytes = 6;
  repeated string trace_trigger = 7;
  optional string trace_causal_trigger = 17;
  optional string unique_session_name = 8;
  optional string trace_config_pbtxt = 9;
  optional int64 sched_duration_ns = 10;
  optional int64 tracing_started_ns = 11;
  optional int64 android_sdk_version = 12;
  optional int64 suspend_count = 13;
  optional int64 data_loss_count = 14;
  optional int64 error_count = 15;
}

// Stats counters for the trace.
// Defined in src/trace_processor/storage/stats.h
message TraceAnalysisStats {
  enum Severity {
    SEVERITY_UNKNOWN = 0;
    SEVERITY_INFO = 1;
    SEVERITY_DATA_LOSS = 2;
    SEVERITY_ERROR = 3;
  }

  enum Source {
    SOURCE_UNKNOWN = 0;
    SOURCE_TRACE = 1;
    SOURCE_ANALYSIS = 2;
  }

  message Stat {
    optional string name = 1;
    optional uint32 idx = 2;
    optional Severity severity = 3;
    optional Source source = 4;

    optional int64 count = 5;
  }

  repeated Stat stat = 1;
}

// Root message for all Perfetto-based metrics (v1 metrics only).
//
// NOTE: the v1 system is "soft" deprecated: no new metrics are allowed but
// we still fully support any existing metrics written using this system.
//
// DO NOT ADD ANY OTHER FIELDS HERE. ADDITION OF NEW v1 METRICS WITH
// IS NO LONGER ALLOWED. PLEASE USE METRICS v2 INSTEAD.
message TraceMetrics {
  // Metrics which were later removed.
  reserved 4, 10, 13, 14, 16, 19;

  // Battery counters metric on Android.
  optional AndroidBatteryMetric android_batt = 5;

  // CPU usage per trace, process and thread.
  optional AndroidCpuMetric android_cpu = 6;

  // Memory metrics on Android (owned by the Android Telemetry team).
  optional AndroidMemoryMetric android_mem = 1;

  // Memory metrics on Android in unaggregated form. (owned by the Android
  // Telemetry team).
  // Note: this generates a lot of data so should not be requested unless it
  // is clear that this data is necessary.
  optional AndroidMemoryUnaggregatedMetric android_mem_unagg = 11;

  // Package list.
  optional AndroidPackageList android_package_list = 12;

  // ion buffer memory metrics.
  optional AndroidIonMetric android_ion = 9;

  // fastrpc subsystem memory metrics.
  optional AndroidFastrpcMetric android_fastrpc = 31;

  // Statistics about low memory kills.
  optional AndroidLmkMetric android_lmk = 8;

  // Power Rails metrics on Android.
  optional AndroidPowerRails android_powrails = 7;

  // Startup metrics on Android (owned by the Android Telemetry team).
  optional AndroidStartupMetric android_startup = 2;

  // Trace metadata (applicable to all traces).
  optional TraceMetadata trace_metadata = 3;

  // Trace stats (applicable to all traces).
  optional TraceAnalysisStats trace_stats = 33;

  // Returns stack frames missing symbols.
  optional UnsymbolizedFrames unsymbolized_frames = 15;

  // If the trace contains a heap graph, output allocation statistics.
  optional JavaHeapStats java_heap_stats = 17;

  // If the trace contains a heap graph, output histogram.
  optional JavaHeapHistogram java_heap_histogram = 21;

  // If the trace contains a heap graph, output stats per heap class.
  optional JavaHeapClassStats java_heap_class_stats = 67;

  // Metrics used to find potential culprits of low-memory kills.
  optional AndroidLmkReasonMetric android_lmk_reason = 18;

  optional AndroidHwuiMetric android_hwui_metric = 20;

  optional AndroidDisplayMetrics display_metrics = 22;

  // Deprecated was AndroidTaskNames
  reserved 23;

  // Deprecated was AndroidThreadTimeInStateMetric
  reserved 24;

  // Metric associated with surfaceflinger.
  optional AndroidSurfaceflingerMetric android_surfaceflinger = 25;

  // GPU metrics on Android.
  optional AndroidGpuMetric android_gpu = 26;

  // Deprecated AndroidSysUiCujMetrics.
  reserved 27;

  // Interaction and frame timings for CUJs (important UI transitions).
  optional AndroidJankCujMetric android_jank_cuj = 48;

  // Metric associated with hwcomposer.
  optional AndroidHwcomposerMetrics android_hwcomposer = 28;

  // Deprecated was AndroidJankMetrics;
  reserved 29;

  // G2D metrics.
  optional G2dMetrics g2d = 30;

  // Dmabuf heap metrics.
  optional AndroidDmaHeapMetric android_dma_heap = 32;

  // Metric to verify the quality of the trace.
  optional AndroidTraceQualityMetric android_trace_quality = 34;

  // Profiler smaps
  optional ProfilerSmaps profiler_smaps = 35;

  // Multiuser - metrics for switching users.
  optional AndroidMultiuserMetric android_multiuser = 36;

  // Metrics related to simpleperf tool
  optional AndroidSimpleperfMetric android_simpleperf = 37;

  // Metrics for the Camera team.
  optional AndroidCameraMetric android_camera = 38;

  // Metrics for dynamic voltage and frequency scaling.
  optional AndroidDvfsMetric android_dvfs = 39;

  // Metrics for network performance.
  optional AndroidNetworkMetric android_netperf = 40;

  // Metrics for the Camera team.
  // Note: this generates a lot of data so should not be requested unless it
  // is clear that this data is necessary.
  optional AndroidCameraUnaggregatedMetric android_camera_unagg = 41;

  // Metrics for RT runtime.
  optional AndroidRtRuntimeMetric android_rt_runtime = 42;

  // Metrics for IRQ runtime.
  optional AndroidIrqRuntimeMetric android_irq_runtime = 43;

  // Was metrics for the Trusty team.
  reserved 44;
  reserved 'android_trusty_workqueues';

  // Was summary of concurrent trace recording.
  reserved 45;
  reserved 'android_other_traces';

  // Per-process Binder transaction metrics.
  optional AndroidBinderMetric android_binder = 46;

  // Metrics for app deadline missed.
  optional AndroidFrameTimelineMetric android_frame_timeline_metric = 47;

  // Blocking calls (e.g. binder calls) for CUJs (important UI transitions).
  optional AndroidBlockingCallsCujMetric android_blocking_calls_cuj_metric = 49;

  optional AndroidMonitorContentionMetric android_monitor_contention = 50;

  optional AndroidSysUINotificationsBlockingCallsMetric
      android_sysui_notifications_blocking_calls_metric = 51;

  // Metrics to track codec framework.
  optional AndroidCodecMetrics codec_metrics = 52;

  // Metric to track Android IO.
  optional AndroidIo android_io = 53;

  // IO metrics on Android in unaggregated form.
  // Note: this generates a lot of data so should not be requested unless it
  // is clear that this data is necessary.
  optional AndroidIoUnaggregated android_io_unagg = 54;

  // Metrics for App Not Responding (ANR) errors.
  optional AndroidAnrMetric android_anr = 55;

  // Aggregated Android Monitor Contention metrics
  optional AndroidMonitorContentionAggMetric android_monitor_contention_agg =
      56;

  optional AndroidBootMetric android_boot = 57;

  // Metric for AdServices module.
  optional AdServicesMetric ad_services_metric = 58;

  optional SysuiNotifShadeListBuilderMetric
      sysui_notif_shade_list_builder_metric = 59;

  optional SysuiUpdateNotifOnUiModeChangedMetric
      sysui_update_notif_on_ui_mode_changed_metric = 60;

  // Metrics for Process starts.
  optional AndroidAppProcessStartsMetric android_app_process_starts = 61;

  // Android boot unaggregated metrics.
  optional AndroidBootUnagg android_boot_unagg = 62;

  // Android garbage collection metrics
  optional AndroidGarbageCollectionUnaggMetric
      android_garbage_collection_unagg = 63;

  // Multiuser - metrics for switching users.
  // Specific for Android Auto
  optional AndroidAutoMultiuserMetric android_auto_multiuser = 64;

  // All blocking calls (e.g. binder calls) for a trace.
  optional AndroidBlockingCallsUnagg android_blocking_calls_unagg = 65;

  // Android OOM unaggregated metrics.
  optional AndroidOomAdjusterMetric android_oom_adjuster = 66;

  // Android Broadcasts aggregated metrics
  optional AndroidBroadcastsMetric android_broadcasts = 68;

  // Android Wattson rail estimate for each app startup.
  optional AndroidWattsonTimePeriodMetric wattson_app_startup_rails = 69;

  // Android Wattson rail estimate for duration of entire trace.
  optional AndroidWattsonTimePeriodMetric wattson_trace_rails = 70;

  // Android Anomaly metric
  optional AndroidAnomalyMetric android_anomaly = 71;

  // Android Wattson app startup metrics.
  optional AndroidWattsonTasksAttributionMetric wattson_trace_threads = 72;

  // Android Wattson thread attribution during markers time window.
  optional AndroidWattsonTasksAttributionMetric wattson_markers_threads = 73;

  // Android Wattson estimate during markers time window.
  optional AndroidWattsonTimePeriodMetric wattson_markers_rails = 74;

  // Android Wattson estimate during time windows defined by atrace apps.
  optional AndroidWattsonTimePeriodMetric wattson_atrace_apps_rails = 75;

  // Android GC stats.
  optional AndroidGarbageCollectionStats android_garbage_collection_stats = 76;

  optional CloneDuration clone_duration = 77;

  // Per-frame blocking calls (e.g. binder calls) during CUJs (important UI
  // transitions).
  optional AndroidCujBlockingCallsPerFrameMetric
      android_blocking_calls_cuj_per_frame_metric = 78;

  // Android Wattson thread attribution during app startups.
  optional AndroidWattsonTasksAttributionMetric wattson_app_startup_threads =
      79;

  // Android Wattson thread attribution during atrace app windows.
  optional AndroidWattsonTasksAttributionMetric wattson_atrace_apps_threads =
      80;

  // Android
  // Demo extensions.
  extensions 450 to 499;

  // Vendor extensions.
  extensions 500 to 1000;

  // Chrome metrics.
  extensions 1001 to 2000;

  // WebView metrics.
  extensions 2001 to 2500;

  // AndroidXR metrics.
  extensions 2501 to 3000;

  // DO NOT ADD ANY OTHER FIELDS HERE. ADDITION OF NEW v1 METRICS IS NO LONGER
  // ALLOWED. PLEASE USE METRICS v2 INSTEAD.
}
