/*
 * 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;

// Metadata for chrome traces.
message ChromeMetadataPacket {
  optional BackgroundTracingMetadata background_tracing_metadata = 1;

  // Version code of Chrome used by Android's Play Store. This field is only set
  // on Android.
  optional int32 chrome_version_code = 2;

  // Comma separated list of enabled categories for tracing. The list of
  // possible category strings are listed in code
  // base/trace_event/builtin_categories.h.
  optional string enabled_categories = 3;

  // Finch name and group based on the ActiveGroupId.
  message FinchHash {
    optional uint32 name = 1;
    optional uint32 group = 2;
  }

  // List of Finch study/groups that apply to this trace.
  repeated FinchHash field_trial_hashes = 4;

  // The package name of the app which is being traced. This field is only set
  // on Android.
  optional string app_package_name = 5;
}

// Metadata related to background tracing scenarios, states and triggers.
message BackgroundTracingMetadata {
  // Information about a trigger rule defined in the experiment config.
  message TriggerRule {
    enum TriggerType {
      TRIGGER_UNSPECIFIED = 0;

      // Traces are triggered by specific range of values of an UMA histogram.
      MONITOR_AND_DUMP_WHEN_SPECIFIC_HISTOGRAM_AND_VALUE = 1;

      // Traces are triggered by specific named events in chromium codebase,
      // like "second-update-failure".
      MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED = 2;
    }
    optional TriggerType trigger_type = 1;

    // Configuration of histogram trigger.
    message HistogramRule {
      // UMA histogram name hash, same as HistogramEventProto.name_hash.
      optional fixed64 histogram_name_hash = 1;

      // Range of values of the histogram that activates trigger.
      optional int64 histogram_min_trigger = 2;
      optional int64 histogram_max_trigger = 3;
    }
    optional HistogramRule histogram_rule = 2;

    // Configuration of named trigger.
    message NamedRule {
      enum EventType {
        UNSPECIFIED = 0;
        SESSION_RESTORE = 1;
        NAVIGATION = 2;
        STARTUP = 3;
        REACHED_CODE = 4;
        CONTENT_TRIGGER = 5;

        TEST_RULE = 1000;
      }
      optional EventType event_type = 1;

      // If |event_type| is CONTENT_TRIGGER, then this stores the hash of the
      // content-trigger that actually fired.
      optional fixed64 content_trigger_name_hash = 2;
    }
    optional NamedRule named_rule = 3;

    // Hash of the rule name.
    optional fixed32 name_hash = 4;
  }

  // Specifies the rule that caused the trace to be uploaded.
  optional TriggerRule triggered_rule = 1;

  // List of all active triggers in current session, when trace was triggered.
  repeated TriggerRule active_rules = 2;

  // Hash of the scenario name.
  optional fixed32 scenario_name_hash = 3;
}
