syntax = "proto2";

package uprobestats.protos;

message UprobestatsConfig {

  // A Task consists of one or more probes that target the same process and are
  // activated and deactivated together.
  message Task {

    // A ProbeConfig defines the spec of a single probe, including which BPF to
    // use and where to place the probe.
    message ProbeConfig {

      // Name of the BPF program and function. E.g.
      // prog_BitmapAllocation_uprobe_bitmap_constructor_heap. Note that this
      // does not include the full BPF program path.
      optional string bpf_name = 1;

      // Path to an executable or a library. E.g.
      // /system/framework/arm64/boot-framework.oat. This is made a repeated
      // paths to allow backup paths to be provided. Sometimes a library may be
      // re-compiled by ART and stored in a different location. uprobestats
      // would try to place the probe on each of the paths in the order
      // specified here until the probe is successfully placed.
      // Superseded by `fully_qualified_class_name`, `method_name`, and `fully_qualified_parameters`.
      repeated string file_paths = 2;

      // Full method signature. E.g.
      // void android.content.pm.PackageManagerInternal.finishPackageInstall(int, boolean)
      // Superseded by `fully_qualified_class_name`, `method_name`, and `fully_qualified_parameters`.
      optional string method_signature = 3;

      // Fully qualified class name of the method being targeted. E.g.
      // "android.content.pm.PackageManagerInternal"
      // Supersedes `file_paths` and `method_signature`
      optional string fully_qualified_class_name = 4;
      // Method name of the method being targeted. E.g. "finishPackageInstall"
      // Supersedes `file_paths` and `method_signature`
      optional string method_name = 5;
      // Fully qualified parameters list of the method being targeted. E.g. ["int", "boolean"]
      // Supersedes `file_paths` and `method_signature`
      repeated string fully_qualified_parameters = 6;

      repeated BinderTransactionFilter binder_transaction_filters = 7;
    }

    repeated ProbeConfig probe_configs = 1;

    // Name of the FDs that the BPF programs write to. E.g.
    // map_BitmapAllocation_output_buf. Note that this does not include the full file path.
    repeated string bpf_maps = 2;

    // Name of the process to be probed, e.g. system_server.
    optional string target_process_name = 3;

    // How long the probes should remain active.
    optional int32 duration_seconds = 4;

    message StatsdLoggingConfig {
      optional int64 atom_id = 1;
      // The positions of any arguments to the method call that should be sent to the atom.
      // These arguments MUST be primitive types (e.g. bool, int), NOT complex objects
      // (that will be nothing but pointers). The positions should be ordered in the same
      // order as the corresponding fields of the atom to be populated.
      //
      // For example, given the method:
      // `void startThing(int argA, int argB, int argC)`
      // and the atom:
      // ```
      // proto StartAppInvocations {
      //   optional int logged_arg_b = 1;
      //   optional int logged_arg_a = 2;
      // }
      // ```
      // The config value should be [1, 0], meaning the 2nd argument is actually the
      // first field in the atom, and vice versa.
      repeated int32 primitive_argument_positions = 2;
    }
    optional StatsdLoggingConfig statsd_logging_config = 5;

    enum TargetProcessSelection {
      UNKNOWN = 0;
      SPECIFIC_PROCESS_NAME = 1;
      ANY_APP_PROCESS_ON_START = 2;
      SPECIFIC_APP_PROCESS_ON_START = 3;
    };

    optional TargetProcessSelection target_process_selection = 6;

    message BinderTransactionFilter {
      optional string interface_name = 1;
      repeated int64 method_ids = 2;
    }

  }

  repeated Task tasks = 1;
}
