/*
 * Copyright (C) 2016 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 = "proto3";

package profiler.proto;
option java_package = "com.android.tools.profiler.proto";
option java_outer_classname = "Cpu";

import "profiler.proto";

// CPU data of a given app process.
message CpuProfilerData {
  ProfilerData basic_info = 1;
  oneof data {
    CpuUsageData cpu_usage = 2;
    ThreadActivities thread_activities = 3;
  }
}

// CPU usage data of an app process and the entire system at a given point.
//
// CPU usage data is most valuable when app data is combined with system data,
// e.g., showing the CPU usage percentage number. One data consumer (e.g., an
// Android Studio instance) would request an app's data, and another consumer
// (e.g., another Android Studio instance) would request another app's. Both of
// them need system data. Therefore, we put system data together with every
// piece of app specific data.
//
// The absolute values of fields in this message are not very interesting.
// The difference of two instances is more useful. It can show the system-
// wide CPU utilization percentage and an app's CPU utilization percentage.
// The values of the fields may overflow their type, but the usefulness stays
// the same.
message CpuUsageData {
  // Amount of time that this process has been using CPU, measured in
  // milliseconds.
  int64 app_cpu_time_in_millisec = 1;
  // Amount of time that the entire system (including applications) has been
  // using CPU, measured in milliseconds.
  int64 system_cpu_time_in_millisec = 2;
  // Amount of time since the system start, measured in milliseconds.
  int64 elapsed_time_in_millisec = 3;
}

// Thread activities, which is essentially changes in thread states.
message ThreadActivities {
  repeated TheadActivity activities = 1;
}

// A thread activity, which is essentially the change of a thread's state.
message TheadActivity {
  // TODO: Reduce the number of |State| values to exactly what we surface
  // to the user.
  enum State {
    UNSPECIFIED = 0;
    RUNNING = 1;
    SLEEPING = 2;
    WAITING = 3;
    ZOMBIE = 4;
    STOPPED = 5;
    TRACING = 6;
    PAGING = 7;
    DEAD = 8;
    WAKEKILL = 9;
    WAKING = 10;
    PARKED = 11;
  }
  int32 tid = 1;
  State new_state = 2;
  // Name of the thread.
  string name = 3;
  // Timestamp when the activity happens (or is detected).
  // Null means the timestamp of this activity is the same as the timestamp
  // as the |CpuProfilerData| message that includes this |TheadActivity|
  // message.
  int64 timestamp = 4;
}
