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

message ObservableEvents {
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // State changes of data source instances associated with the consumer's
    // session. Note that not all data sources may support these notifications.
    // See |will_notify_on_start/stop| in DataSourceDescriptor.
    TYPE_DATA_SOURCES_INSTANCES = 1;

    // State change triggered when all data sources are in the STARTED state.
    // For data sources that registered with |will_notify_on_start| this happens
    // only after the data source has acked the start. This allows the consumer
    // to synchronize with the data sources and to perform actions (e.g. start a
    // test binary) only after trace recording is actually started.
    // Introduced in Android 11 (R).
    TYPE_ALL_DATA_SOURCES_STARTED = 2;

    // When a tracing session has one or more triggers of type CLONE_SNAPSHOT
    // and a matching trigger is hit, the service will send this notification to
    // the consumer after |stop_delay_ms|.
    TYPE_CLONE_TRIGGER_HIT = 4;

    // Note: internally these are used as OR flags. Next values: 4, 8, 16, ...

    // TODO(eseckler): Extend this for producer & data source registrations.
  }

  enum DataSourceInstanceState {
    // A data source is created in stopped state.
    DATA_SOURCE_INSTANCE_STATE_STOPPED = 1;
    DATA_SOURCE_INSTANCE_STATE_STARTED = 2;
  }

  message DataSourceInstanceStateChange {
    optional string producer_name = 1;
    optional string data_source_name = 2;
    optional DataSourceInstanceState state = 3;
  }

  message CloneTriggerHit {
    // The TracingSessionID of the original tracing session which had a
    // CLONE_SNAPSHOT trigger defined. This is necessary just because the
    // consumer has no idea of what is the TSID of its own tracing session and
    // there is no other good way to plumb it.
    optional int64 tracing_session_id = 1;

    // The name of the CLONE_SNAPSHOT trigger which was hit.
    optional string trigger_name = 2;
    // The name of the producer that sent the CLONE_SNAPSHOT trigger.
    optional string producer_name = 3;
    // The uid of the producer that sent the CLONE_SNAPSHOT trigger.
    optional uint32 producer_uid = 4;
    // The timestamp of the CLONE_SNAPSHOT trigger which was hit.
    optional uint64 boot_time_ns = 5;
    // The configured delay of the CLONE_SNAPSHOT trigger which was hit. For
    // informational purposes only.
    optional uint64 trigger_delay_ms = 6;
  }

  repeated DataSourceInstanceStateChange instance_state_changes = 1;
  optional bool all_data_sources_started = 2;
  optional CloneTriggerHit clone_trigger_hit = 3;
}
