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

// Config for polling process-related information from /proc/pid/status and
// related files on Linux.
//
// Data source name: "linux.process_stats".
message ProcessStatsConfig {
  enum Quirks {
    QUIRKS_UNSPECIFIED = 0;

    // This has been deprecated and ignored as per 2018-05-01. Full scan at
    // startup is now disabled by default and can be re-enabled using the
    // |scan_all_processes_on_start| arg.
    DISABLE_INITIAL_DUMP = 1 [deprecated = true];

    // If set, disables the special interaction with "linux.ftrace" data source,
    // where the process stats rescrapes any thread id seen in the ftrace
    // stream.
    DISABLE_ON_DEMAND = 2;
  }
  repeated Quirks quirks = 1;

  // If enabled all processes will be scanned and dumped when the trace starts.
  optional bool scan_all_processes_on_start = 2;

  // If enabled thread names are also recoded (this is redundant if sched_switch
  // is enabled).
  optional bool record_thread_names = 3;

  // If > 0 samples counters (see process_stats.proto) from
  // /proc/pid/status and oom_score_adj every X ms.
  // This is required to be > 100ms to avoid excessive CPU usage.
  optional uint32 proc_stats_poll_ms = 4;

  // id 5 never used

  // Explicit caching period during which the polling won't re-emit identical
  // counter values. This is required to be either = 0 or a multiple of
  // |proc_stats_poll_ms| (default: |proc_stats_poll_ms|). Non-multiples will be
  // rounded down to the nearest multiple.
  optional uint32 proc_stats_cache_ttl_ms = 6;

  // If true and |proc_stats_poll_ms| is set, sample memory stats from
  // /proc/pid/smaps_rollup.
  //
  // Android: does NOT work with the system daemons by default, as it requires
  // running the recording process (traced_probes or tracebox) as root. It is
  // possible to avoid the root requirement, but the exact steps depend on the
  // Linux distibution. The proc file requires passing a PTRACE_MODE_READ
  // check, and might be further covered by the procfs "hidepid" mount option.
  optional bool scan_smaps_rollup = 10;

  // If true: process descriptions will include process age (starttime in
  // /proc/pid/stat).
  // Introduced in: perfetto v44.
  optional bool record_process_age = 11;

  // If true and |proc_stats_poll_ms| is set, process stats will include time
  // spent running in user/kernel mode (utime/stime in /proc/pid/stat).
  // Introduced in: perfetto v44.
  optional bool record_process_runtime = 12;

  // If true obtain per-process dmabuf resident set size from
  // /proc/pid/dmabuf_rss.
  // This feature is not in upstream linux, and is available only on some
  // Android kernels.
  optional bool record_process_dmabuf_rss = 13;

  // WARNING: unmaintained and deprecated. If true this will resolve file
  // descriptors for each process so these can be mapped to their actual device
  // or file. Requires raw_syscalls/sys_{enter,exit} ftrace events to be enabled
  // or new fds opened after initially scanning a process will not be
  // recognized.
  optional bool resolve_process_fds = 9;

  // record_thread_time_in_state
  reserved 7;
  // thread_time_in_state_cache_size
  reserved 8;
}
