// This is an abbreviated version of the full Perfetto schema.
// Most of them are for OS or Chrome traces and we'll never use them.
// Full doc: https://github.com/google/perfetto/tree/main/protos/perfetto
//
// Build it with
// protoc --ruby_out=lib/graphql/tracing/perfetto_trace --proto_path=lib/graphql/tracing/perfetto_trace trace.proto
syntax = "proto2";
package perfetto_trace.protos;
option ruby_package = "GraphQL::Tracing::PerfettoTrace";

message Trace {
  repeated TracePacket packet = 1;
}

message TracePacket {
  optional uint64 timestamp = 8;
  oneof data {
    TrackEvent track_event = 11;
    TrackDescriptor track_descriptor = 60;
  }
  oneof optional_trusted_packet_sequence_id {
    uint32 trusted_packet_sequence_id = 10;
  }
  optional InternedData interned_data = 12;
  optional bool first_packet_on_sequence = 87;
  optional bool previous_packet_dropped = 42;
  optional uint32 sequence_flags = 13;
}

message TrackEvent {
  repeated uint64 category_iids = 3;
  repeated string categories = 22;
  oneof name_field {
    uint64 name_iid = 10;
    string name = 23;
  }
  enum Type {
    TYPE_UNSPECIFIED = 0;
    TYPE_SLICE_BEGIN = 1;
    TYPE_SLICE_END = 2;
    TYPE_INSTANT = 3;
    TYPE_COUNTER = 4;
  }
  optional Type type = 9;
  optional uint64 track_uuid = 11;
  oneof counter_value_field {
    int64 counter_value = 30;
    double double_counter_value = 44;
  }
  repeated uint64 extra_counter_track_uuids = 31;
  repeated int64 extra_counter_values = 12;
  repeated uint64 extra_double_counter_track_uuids = 45;
  repeated double extra_double_counter_values = 46;
  repeated fixed64 flow_ids = 47;
  repeated fixed64 terminating_flow_ids = 48;
  repeated DebugAnnotation debug_annotations = 4;
}

message DebugAnnotation {
  oneof name_field {
    uint64 name_iid = 1;
    string name = 10;
  }
  oneof value {
    bool bool_value = 2;
    uint64 uint_value = 3;
    int64 int_value = 4;
    double double_value = 5;
    string string_value = 6;
    uint64 string_value_iid = 17;
  }
  repeated DebugAnnotation dict_entries = 11;
  repeated DebugAnnotation array_values = 12;
  uint64 string_value_iid = 17;
}

message TrackDescriptor {
  optional uint64 uuid = 1;
  optional uint64 parent_uuid = 5;

  oneof static_or_dynamic_name {
    string name = 2;
  }

  optional CounterDescriptor counter = 8;
  enum ChildTracksOrdering {
    UNKNOWN = 0;
    LEXICOGRAPHIC = 1;
    CHRONOLOGICAL = 2;
    EXPLICIT = 3;
  }
  optional ChildTracksOrdering child_ordering = 11;
  optional int32 sibling_order_rank = 12;
}

message CounterDescriptor {
  enum BuiltinCounterType {
    COUNTER_UNSPECIFIED = 0;
    COUNTER_THREAD_TIME_NS = 1;
    COUNTER_THREAD_INSTRUCTION_COUNT = 2;
  }
  enum Unit {
    UNIT_UNSPECIFIED = 0;
    UNIT_TIME_NS = 1;
    UNIT_COUNT = 2;
    UNIT_SIZE_BYTES = 3;
  }
  optional BuiltinCounterType type = 1;
  repeated string categories = 2;
  optional Unit unit = 3;
  optional string unit_name = 6;
  optional int64 unit_multiplier = 4;
  optional bool is_incremental = 5;
}

message InternedData {
  repeated EventCategory event_categories = 1;
  repeated EventName event_names = 2;
  repeated DebugAnnotationName debug_annotation_names = 3;
  repeated InternedString debug_annotation_string_values = 29;
}

message InternedString {
  optional uint64 iid = 1;
  optional bytes str = 2;
}

message EventCategory {
  optional uint64 iid = 1;
  optional string name = 2;
}

message EventName {
  optional uint64 iid = 1;
  optional string name = 2;
}

message DebugAnnotationName {
  optional uint64 iid = 1;
  optional string name = 2;
}
