| 1 |
|
| 2 | #ifndef _PERF_TARGET_H
|
| 3 | #define _PERF_TARGET_H
|
| 4 |
|
| 5 | #include <stdbool.h>
|
| 6 | #include <sys/types.h>
|
| 7 |
|
| 8 | struct target {
|
| 9 | const char *pid;
|
| 10 | const char *tid;
|
| 11 | const char *cpu_list;
|
| 12 | const char *bpf_str;
|
| 13 | bool system_wide;
|
| 14 | bool uses_mmap;
|
| 15 | bool default_per_cpu;
|
| 16 | bool per_thread;
|
| 17 | bool use_bpf;
|
| 18 | bool inherit;
|
| 19 | int initial_delay;
|
| 20 | const char *attr_map;
|
| 21 | };
|
| 22 |
|
| 23 | enum target_errno {
|
| 24 | TARGET_ERRNO__SUCCESS = 0,
|
| 25 |
|
| 26 | |
| 27 | * Choose an arbitrary negative big number not to clash with standard
|
| 28 | * errno since SUS requires the errno has distinct positive values.
|
| 29 | * See 'Issue 6' in the link below.
|
| 30 | *
|
| 31 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
|
| 32 |
|
| 33 | __TARGET_ERRNO__START = -10000,
|
| 34 |
|
| 35 |
|
| 36 | TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
|
| 37 | TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
|
| 38 | TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
|
| 39 | TARGET_ERRNO__BPF_OVERRIDE_CPU,
|
| 40 | TARGET_ERRNO__BPF_OVERRIDE_PID,
|
| 41 | TARGET_ERRNO__BPF_OVERRIDE_THREAD,
|
| 42 |
|
| 43 | __TARGET_ERRNO__END,
|
| 44 | };
|
| 45 |
|
| 46 | enum target_errno target__validate(struct target *target);
|
| 47 |
|
| 48 | uid_t parse_uid(const char *str);
|
| 49 |
|
| 50 | int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
|
| 51 |
|
| 52 | static inline bool target__has_task(const struct target *target)
|
| 53 | {
|
| 54 | return target->tid || target->pid;
|
| 55 | }
|
| 56 |
|
| 57 | static inline bool target__has_cpu(const struct target *target)
|
| 58 | {
|
| 59 | return target->system_wide || target->cpu_list;
|
| 60 | }
|
| 61 |
|
| 62 | static inline bool target__none(const struct target *target)
|
| 63 | {
|
| 64 | return !target__has_task(target) && !target__has_cpu(target);
|
| 65 | }
|
| 66 |
|
| 67 | static inline bool target__enable_on_exec(const struct target *target)
|
| 68 | {
|
| 69 | |
| 70 | * Normally enable_on_exec should be set if:
|
| 71 | * 1) The tracee process is forked (not attaching to existed task or cpu).
|
| 72 | * 2) And initial_delay is not configured.
|
| 73 | * Otherwise, we enable tracee events manually.
|
| 74 |
|
| 75 | return target__none(target) && !target->initial_delay;
|
| 76 | }
|
| 77 |
|
| 78 | static inline bool target__has_per_thread(const struct target *target)
|
| 79 | {
|
| 80 | return target->system_wide && target->per_thread;
|
| 81 | }
|
| 82 |
|
| 83 | static inline bool target__uses_dummy_map(const struct target *target)
|
| 84 | {
|
| 85 | bool use_dummy = false;
|
| 86 |
|
| 87 | if (target->default_per_cpu)
|
| 88 | use_dummy = target->per_thread ? true : false;
|
| 89 | else if (target__has_task(target) ||
|
| 90 | (!target__has_cpu(target) && !target->uses_mmap))
|
| 91 | use_dummy = true;
|
| 92 | else if (target__has_per_thread(target))
|
| 93 | use_dummy = true;
|
| 94 |
|
| 95 | return use_dummy;
|
| 96 | }
|
| 97 |
|
| 98 | #endif
|