/*
 * 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 = "CpuProfiler";

import "cpu_profiler_data.proto";

service CpuProfilerService {
  rpc GetData(CpuDataRequest) returns (CpuDataResponse) {
  }

  // Starts collecting execution metrics of a running app, such as usage info
  // and thread states. Does nothing if the app is already being monitored.
  // TODO(b/29258733): Support configuring sampling details.
  rpc StartMonitoringApp(CpuStartRequest) returns (CpuStartResponse) {
  }

  // Stops monitoring a running app. Does nothing if the app is not being
  // monitored, or is not running.
  rpc StopMonitoringApp(CpuStopRequest) returns (CpuStopResponse) {
  }
}

// Requests profiler data from the app with ID being |app_id|, in the time range
// from |start_timestamp| (exclusive) to |end_timestamp| (inclusive), or
// mathematically written as in interval (start_timestamp, end_timestamp].
message CpuDataRequest {
  enum SpecialValues {
    // Protobuf requires the first enum value to be zero.
    UNSPECIFIED = 0;
    // A speical value used in |app_id| field to indicate the data of all apps
    // are requested.
    ANY_APP = -1;
  }
  int32 app_id = 1;  // Use |ANY_APP| if requesting the data of any apps.
  int64 start_timestamp = 2;  // Use -2^63 if no data is too old to return.
  int64 end_timestamp = 3;  // Use 2^63 - 1 if no data is too recent to return.
}

message CpuDataResponse {
  repeated CpuProfilerData data = 1;
}

message CpuStartRequest {
  int32 app_id = 1;
}

message CpuStartResponse {
  enum Status {
    UNSPECIFICED = 0;
    SUCCESS = 1;
    FAILURE_APP_NOT_RUNNING = 2;
    FAILURE_UNKNOWN = 3;
  }
  Status status = 1;
}

message CpuStopRequest {
  int32 app_id = 1;
}

message CpuStopResponse {
  enum Status {
    UNSPECIFICED = 0;
    SUCCESS = 1;
    FAILURE_UNKNOWN = 2;
  }
  Status status = 1;
}
