//
// Copyright (C) 2019 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.

// @generated by protoc-gen-es v2.2.2 with parameter "target=ts"
// @generated from file protos/perfetto/config/profiling/perf_event_config.proto (package perfetto.protos, syntax proto2)
/* eslint-disable */

import type { GenEnum, GenFile, GenMessage } from "@bufbuild/protobuf/codegenv1";
import { enumDesc, fileDesc, messageDesc } from "@bufbuild/protobuf/codegenv1";
import type { FollowerEvent, PerfEvents_Timebase } from "../../common/perf_events_pb";
import { file_protos_perfetto_common_perf_events } from "../../common/perf_events_pb";
import type { Message } from "@bufbuild/protobuf";

/**
 * Describes the file protos/perfetto/config/profiling/perf_event_config.proto.
 */
export const file_protos_perfetto_config_profiling_perf_event_config: GenFile = /*@__PURE__*/
  fileDesc("Cjhwcm90b3MvcGVyZmV0dG8vY29uZmlnL3Byb2ZpbGluZy9wZXJmX2V2ZW50X2NvbmZpZy5wcm90bxIPcGVyZmV0dG8ucHJvdG9zIqQICg9QZXJmRXZlbnRDb25maWcSNgoIdGltZWJhc2UYDyABKAsyJC5wZXJmZXR0by5wcm90b3MuUGVyZkV2ZW50cy5UaW1lYmFzZRIxCglmb2xsb3dlcnMYEyADKAsyHi5wZXJmZXR0by5wcm90b3MuRm9sbG93ZXJFdmVudBJOChJjYWxsc3RhY2tfc2FtcGxpbmcYECABKAsyMi5wZXJmZXR0by5wcm90b3MuUGVyZkV2ZW50Q29uZmlnLkNhbGxzdGFja1NhbXBsaW5nEiIKGnJpbmdfYnVmZmVyX3JlYWRfcGVyaW9kX21zGAggASgNEhkKEXJpbmdfYnVmZmVyX3BhZ2VzGAMgASgNEiEKGW1heF9lbnF1ZXVlZF9mb290cHJpbnRfa2IYESABKAQSHAoUbWF4X2RhZW1vbl9tZW1vcnlfa2IYDSABKA0SJAoccmVtb3RlX2Rlc2NyaXB0b3JfdGltZW91dF9tcxgJIAEoDRIkChx1bndpbmRfc3RhdGVfY2xlYXJfcGVyaW9kX21zGAogASgNEhsKE3RhcmdldF9pbnN0YWxsZWRfYnkYEiADKAkSEAoIYWxsX2NwdXMYASABKAgSGgoSc2FtcGxpbmdfZnJlcXVlbmN5GAIgASgNEhUKDWtlcm5lbF9mcmFtZXMYDCABKAgSEgoKdGFyZ2V0X3BpZBgEIAMoBRIWCg50YXJnZXRfY21kbGluZRgFIAMoCRITCgtleGNsdWRlX3BpZBgGIAMoBRIXCg9leGNsdWRlX2NtZGxpbmUYByADKAkSIAoYYWRkaXRpb25hbF9jbWRsaW5lX2NvdW50GAsgASgNGqMBChFDYWxsc3RhY2tTYW1wbGluZxI1CgVzY29wZRgBIAEoCzImLnBlcmZldHRvLnByb3Rvcy5QZXJmRXZlbnRDb25maWcuU2NvcGUSFQoNa2VybmVsX2ZyYW1lcxgCIAEoCBJACgt1c2VyX2ZyYW1lcxgDIAEoDjIrLnBlcmZldHRvLnByb3Rvcy5QZXJmRXZlbnRDb25maWcuVW53aW5kTW9kZRqgAQoFU2NvcGUSEgoKdGFyZ2V0X3BpZBgBIAMoBRIWCg50YXJnZXRfY21kbGluZRgCIAMoCRITCgtleGNsdWRlX3BpZBgDIAMoBRIXCg9leGNsdWRlX2NtZGxpbmUYBCADKAkSIAoYYWRkaXRpb25hbF9jbWRsaW5lX2NvdW50GAUgASgNEhsKE3Byb2Nlc3Nfc2hhcmRfY291bnQYBiABKA0iXQoKVW53aW5kTW9kZRISCg5VTldJTkRfVU5LTk9XThAAEg8KC1VOV0lORF9TS0lQEAESEAoMVU5XSU5EX0RXQVJGEAISGAoUVU5XSU5EX0ZSQU1FX1BPSU5URVIQA0oECA4QDw", [file_protos_perfetto_common_perf_events]);

/**
 * Configuration for the traced_perf profiler.
 *
 * Example config for basic cpu profiling:
 *   perf_event_config {
 *     timebase {
 *       frequency: 80
 *     }
 *     callstack_sampling {
 *       scope {
 *         target_cmdline: "surfaceflinger"
 *         target_cmdline: "system_server"
 *       }
 *       kernel_frames: true
 *     }
 *   }
 *
 * Next id: 20
 *
 * @generated from message perfetto.protos.PerfEventConfig
 */
export type PerfEventConfig = Message<"perfetto.protos.PerfEventConfig"> & {
  /**
   * What event to sample on, and how often.
   * Defined in common/perf_events.proto.
   *
   * @generated from field: optional perfetto.protos.PerfEvents.Timebase timebase = 15;
   */
  timebase?: PerfEvents_Timebase;

  /**
   * Other events associated with the leader described in the timebase.
   *
   * @generated from field: repeated perfetto.protos.FollowerEvent followers = 19;
   */
  followers: FollowerEvent[];

  /**
   * If set, the profiler will sample userspace processes' callstacks at the
   * interval specified by the |timebase|.
   * If unset, the profiler will record only the event counts.
   *
   * @generated from field: optional perfetto.protos.PerfEventConfig.CallstackSampling callstack_sampling = 16;
   */
  callstackSampling?: PerfEventConfig_CallstackSampling;

  /**
   * How often the per-cpu ring buffers are read by the producer.
   * If unset, an implementation-defined default is used.
   *
   * @generated from field: optional uint32 ring_buffer_read_period_ms = 8;
   */
  ringBufferReadPeriodMs: number;

  /**
   * Size (in 4k pages) of each per-cpu ring buffer that is filled by the
   * kernel. If set, must be a power of two.
   * If unset, an implementation-defined default is used.
   *
   * @generated from field: optional uint32 ring_buffer_pages = 3;
   */
  ringBufferPages: number;

  /**
   * Drop samples if the heap memory held by the samples in the unwinder queue
   * is above the given limit. This counts the memory across all concurrent data
   * sources (not just this one's), and there is no fairness guarantee - the
   * whole quota might be used up by a concurrent source.
   *
   * @generated from field: optional uint64 max_enqueued_footprint_kb = 17;
   */
  maxEnqueuedFootprintKb: bigint;

  /**
   * Stop the data source if traced_perf's combined {RssAnon + Swap} memory
   * footprint exceeds this value.
   *
   * @generated from field: optional uint32 max_daemon_memory_kb = 13;
   */
  maxDaemonMemoryKb: number;

  /**
   * Timeout for the remote /proc/<pid>/{maps,mem} file descriptors for a
   * sampled process. This is primarily for Android, where this lookup is
   * asynchronous. As long as the producer is waiting, the associated samples
   * will be kept enqueued (putting pressure on the capacity of the shared
   * unwinding queue). Once a lookup for a process expires, all associated
   * samples are discarded. However, if the lookup still succeeds after the
   * timeout, future samples will be handled normally.
   * If unset, an implementation-defined default is used.
   *
   * @generated from field: optional uint32 remote_descriptor_timeout_ms = 9;
   */
  remoteDescriptorTimeoutMs: number;

  /**
   * Optional period for clearing state cached by the unwinder. This is a heavy
   * operation that is only necessary for traces that target a wide set of
   * processes, and require the memory footprint to be reset periodically.
   * If unset, the cached state will not be cleared.
   *
   * @generated from field: optional uint32 unwind_state_clear_period_ms = 10;
   */
  unwindStateClearPeriodMs: number;

  /**
   * If set, only profile target if it was installed by a package with one of
   * these names. Special values:
   * * "@system": installed on the system partition
   * * "@product": installed on the product partition
   * * "@null": sideloaded
   * Supported on Android 12+.
   *
   * @generated from field: repeated string target_installed_by = 18;
   */
  targetInstalledBy: string[];

  /**
   * Note: legacy configs had to set |all_cpus| to true to pass parsing.
   * We rely on this to detect such configs.
   *
   * @generated from field: optional bool all_cpus = 1;
   */
  allCpus: boolean;

  /**
   * @generated from field: optional uint32 sampling_frequency = 2;
   */
  samplingFrequency: number;

  /**
   * @generated from field: optional bool kernel_frames = 12;
   */
  kernelFrames: boolean;

  /**
   * @generated from field: repeated int32 target_pid = 4;
   */
  targetPid: number[];

  /**
   * @generated from field: repeated string target_cmdline = 5;
   */
  targetCmdline: string[];

  /**
   * @generated from field: repeated int32 exclude_pid = 6;
   */
  excludePid: number[];

  /**
   * @generated from field: repeated string exclude_cmdline = 7;
   */
  excludeCmdline: string[];

  /**
   * @generated from field: optional uint32 additional_cmdline_count = 11;
   */
  additionalCmdlineCount: number;
};

/**
 * Describes the message perfetto.protos.PerfEventConfig.
 * Use `create(PerfEventConfigSchema)` to create a new message.
 */
export const PerfEventConfigSchema: GenMessage<PerfEventConfig> = /*@__PURE__*/
  messageDesc(file_protos_perfetto_config_profiling_perf_event_config, 0);

/**
 * @generated from message perfetto.protos.PerfEventConfig.CallstackSampling
 */
export type PerfEventConfig_CallstackSampling = Message<"perfetto.protos.PerfEventConfig.CallstackSampling"> & {
  /**
   * Defines a set of processes for which samples are retained/skipped. If
   * unset, all samples are kept, but beware that it will be very heavy on the
   * stack unwinder, which might start dropping samples due to overload.
   *
   * @generated from field: optional perfetto.protos.PerfEventConfig.Scope scope = 1;
   */
  scope?: PerfEventConfig_Scope;

  /**
   * If true, callstacks will include the kernel-space frames. Such frames can
   * be identified by a magical "kernel" string as their mapping name.
   * Requires traced_perf to be running as root, or kptr_restrict to have been
   * manually unrestricted. On Android, the platform should do the right thing
   * on debug builds.
   * This does *not* disclose KASLR, as only the function names are emitted.
   *
   * @generated from field: optional bool kernel_frames = 2;
   */
  kernelFrames: boolean;

  /**
   * Whether to record and unwind userspace callstacks. If unset, defaults to
   * including userspace (UNWIND_DWARF) both for backwards compatibility and
   * as the most common default (this defaulting is only applicable if the
   * outer CallstackSampling message is explicitly set).
   *
   * @generated from field: optional perfetto.protos.PerfEventConfig.UnwindMode user_frames = 3;
   */
  userFrames: PerfEventConfig_UnwindMode;
};

/**
 * Describes the message perfetto.protos.PerfEventConfig.CallstackSampling.
 * Use `create(PerfEventConfig_CallstackSamplingSchema)` to create a new message.
 */
export const PerfEventConfig_CallstackSamplingSchema: GenMessage<PerfEventConfig_CallstackSampling> = /*@__PURE__*/
  messageDesc(file_protos_perfetto_config_profiling_perf_event_config, 0, 0);

/**
 * @generated from message perfetto.protos.PerfEventConfig.Scope
 */
export type PerfEventConfig_Scope = Message<"perfetto.protos.PerfEventConfig.Scope"> & {
  /**
   * Process ID (TGID) allowlist. If this list is not empty, only matching
   * samples will be retained. If multiple allow/deny-lists are
   * specified by the config, then all of them are evaluated for each sampled
   * process.
   *
   * @generated from field: repeated int32 target_pid = 1;
   */
  targetPid: number[];

  /**
   * Command line allowlist, matched against the /proc/<pid>/cmdline (not the
   * comm string). The semantics of this field were changed since its original
   * introduction.
   *
   * On Android T+ (13+), this field can specify a single wildcard (*), and
   * the profiler will attempt to match it in two possible ways:
   * * if the pattern starts with a '/', then it is matched against the first
   *   segment of the cmdline (i.e. argv0). For example "/bin/e*" would match
   *   "/bin/echo".
   * * otherwise the pattern is matched against the part of argv0
   *   corresponding to the binary name (this is unrelated to /proc/pid/exe).
   *   For example "echo" would match "/bin/echo".
   *
   * On Android S (12) and below, both this pattern and /proc/pid/cmdline get
   * normalized prior to an exact string comparison. Normalization is as
   * follows: (1) trim everything beyond the first null or "@" byte; (2) if
   * the string contains forward slashes, trim everything up to and including
   * the last one.
   *
   * Implementation note: in either case, at most 511 characters of cmdline
   * are considered.
   *
   * @generated from field: repeated string target_cmdline = 2;
   */
  targetCmdline: string[];

  /**
   * List of excluded pids.
   *
   * @generated from field: repeated int32 exclude_pid = 3;
   */
  excludePid: number[];

  /**
   * List of excluded cmdlines. See description of |target_cmdline| for how
   * this is handled.
   *
   * @generated from field: repeated string exclude_cmdline = 4;
   */
  excludeCmdline: string[];

  /**
   * Number of additional command lines to sample. Only those which are
   * neither explicitly included nor excluded will be considered. Processes
   * are accepted on a first come, first served basis.
   *
   * @generated from field: optional uint32 additional_cmdline_count = 5;
   */
  additionalCmdlineCount: number;

  /**
   * If set to N, all encountered processes will be put into one of the N
   * possible bins, and only one randomly-chosen bin will be selected for
   * unwinding. The binning is simply "pid % N", under the assumption that
   * low-order bits of pids are roughly uniformly distributed. Other explicit
   * inclusions/exclusions in this |Scope| message are still respected.
   *
   * The profiler will report the chosen shard in PerfSampleDefaults, and the
   * values will be queryable in trace processor under the "stats" table as
   * "perf_process_shard_count" and "perf_chosen_process_shard".
   *
   * NB: all data sources in a config that set |process_shard_count| must set
   * it to the same value. The profiler will choose one bin for all those data
   * sources.
   *
   * @generated from field: optional uint32 process_shard_count = 6;
   */
  processShardCount: number;
};

/**
 * Describes the message perfetto.protos.PerfEventConfig.Scope.
 * Use `create(PerfEventConfig_ScopeSchema)` to create a new message.
 */
export const PerfEventConfig_ScopeSchema: GenMessage<PerfEventConfig_Scope> = /*@__PURE__*/
  messageDesc(file_protos_perfetto_config_profiling_perf_event_config, 0, 1);

/**
 * Userspace unwinding mode. A possible future addition is kernel-unwound
 * callchains for frame pointer based systems.
 *
 * @generated from enum perfetto.protos.PerfEventConfig.UnwindMode
 */
export enum PerfEventConfig_UnwindMode {
  /**
   * @generated from enum value: UNWIND_UNKNOWN = 0;
   */
  UNWIND_UNKNOWN = 0,

  /**
   * Do not unwind userspace:
   *
   * @generated from enum value: UNWIND_SKIP = 1;
   */
  UNWIND_SKIP = 1,

  /**
   * Use libunwindstack (default):
   *
   * @generated from enum value: UNWIND_DWARF = 2;
   */
  UNWIND_DWARF = 2,

  /**
   * Use userspace frame pointer unwinder:
   *
   * @generated from enum value: UNWIND_FRAME_POINTER = 3;
   */
  UNWIND_FRAME_POINTER = 3,
}

/**
 * Describes the enum perfetto.protos.PerfEventConfig.UnwindMode.
 */
export const PerfEventConfig_UnwindModeSchema: GenEnum<PerfEventConfig_UnwindMode> = /*@__PURE__*/
  enumDesc(file_protos_perfetto_config_profiling_perf_event_config, 0, 0);

