/*
 * Copyright (C) 2025 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;

// AppWakelockInfo describes the time-independent properties of a wakelock, such
// as the owning package or wakelock tag. This is interned to reduce trace size.
// Event bundles refer to interned wakelock info by the iid.
message AppWakelockInfo {
  // The interned id of this wakelock.
  optional int32 iid = 1;

  // The app-provided tag of the wakelock.
  optional string tag = 2;

  // The wakelock flags (such as partial vs full).
  optional int32 flags = 3;

  // The pid that created the wakelock.
  optional int32 owner_pid = 4;

  // The uid that created the wakelock.
  optional int32 owner_uid = 5;

  // The uid of the work source root (if present).
  optional int32 work_uid = 6;
}

// AppWakelockBundle describes one or more wakelock events. Events are written
// in two paired array, such that the details for event i are in intern_id[i]
// and encoded_ts[i].
message AppWakelockBundle {
  // The interned id for the WakelockInfo of the event.
  repeated uint32 intern_id = 1 [packed = true];

  // The timestamp and event type, encoded as:
  //   (event_time - packet_time) << 1 | (acquired ? 1 : 0)
  repeated uint64 encoded_ts = 2 [packed = true];

  // For writing single packets (mainly by tokenization).
  optional AppWakelockInfo info = 3;
  optional bool acquired = 4;
}
