0001
0002 #ifndef _PERF_TARGET_H
0003 #define _PERF_TARGET_H
0004
0005 #include <stdbool.h>
0006 #include <sys/types.h>
0007
0008 struct target {
0009 const char *pid;
0010 const char *tid;
0011 const char *cpu_list;
0012 const char *uid_str;
0013 const char *bpf_str;
0014 uid_t uid;
0015 bool system_wide;
0016 bool uses_mmap;
0017 bool default_per_cpu;
0018 bool per_thread;
0019 bool use_bpf;
0020 bool hybrid;
0021 const char *attr_map;
0022 };
0023
0024 enum target_errno {
0025 TARGET_ERRNO__SUCCESS = 0,
0026
0027
0028
0029
0030
0031
0032
0033
0034 __TARGET_ERRNO__START = -10000,
0035
0036
0037 TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
0038 TARGET_ERRNO__PID_OVERRIDE_UID,
0039 TARGET_ERRNO__UID_OVERRIDE_CPU,
0040 TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
0041 TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
0042 TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
0043 TARGET_ERRNO__BPF_OVERRIDE_CPU,
0044 TARGET_ERRNO__BPF_OVERRIDE_PID,
0045 TARGET_ERRNO__BPF_OVERRIDE_UID,
0046 TARGET_ERRNO__BPF_OVERRIDE_THREAD,
0047
0048
0049 TARGET_ERRNO__INVALID_UID,
0050 TARGET_ERRNO__USER_NOT_FOUND,
0051
0052 __TARGET_ERRNO__END,
0053 };
0054
0055 enum target_errno target__validate(struct target *target);
0056 enum target_errno target__parse_uid(struct target *target);
0057
0058 int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
0059
0060 static inline bool target__has_task(struct target *target)
0061 {
0062 return target->tid || target->pid || target->uid_str;
0063 }
0064
0065 static inline bool target__has_cpu(struct target *target)
0066 {
0067 return target->system_wide || target->cpu_list;
0068 }
0069
0070 static inline bool target__none(struct target *target)
0071 {
0072 return !target__has_task(target) && !target__has_cpu(target);
0073 }
0074
0075 static inline bool target__has_per_thread(struct target *target)
0076 {
0077 return target->system_wide && target->per_thread;
0078 }
0079
0080 static inline bool target__uses_dummy_map(struct target *target)
0081 {
0082 bool use_dummy = false;
0083
0084 if (target->default_per_cpu)
0085 use_dummy = target->per_thread ? true : false;
0086 else if (target__has_task(target) ||
0087 (!target__has_cpu(target) && !target->uses_mmap))
0088 use_dummy = true;
0089 else if (target__has_per_thread(target))
0090 use_dummy = true;
0091
0092 return use_dummy;
0093 }
0094
0095 #endif