Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 1 | #ifndef _PERF_TARGET_H |
| 2 | #define _PERF_TARGET_H |
| 3 | |
| 4 | #include <stdbool.h> |
| 5 | #include <sys/types.h> |
| 6 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 7 | struct target { |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 8 | const char *pid; |
| 9 | const char *tid; |
| 10 | const char *cpu_list; |
| 11 | const char *uid_str; |
| 12 | uid_t uid; |
| 13 | bool system_wide; |
Namhyung Kim | d1cb9fc | 2012-05-16 18:45:49 +0900 | [diff] [blame] | 14 | bool uses_mmap; |
Adrian Hunter | 539e6bb | 2013-11-01 15:51:34 +0200 | [diff] [blame] | 15 | bool force_per_cpu; |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 16 | }; |
| 17 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 18 | enum target_errno { |
| 19 | TARGET_ERRNO__SUCCESS = 0, |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Choose an arbitrary negative big number not to clash with standard |
| 23 | * errno since SUS requires the errno has distinct positive values. |
| 24 | * See 'Issue 6' in the link below. |
| 25 | * |
| 26 | * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html |
| 27 | */ |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 28 | __TARGET_ERRNO__START = -10000, |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame] | 29 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 30 | /* for target__validate() */ |
| 31 | TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START, |
| 32 | TARGET_ERRNO__PID_OVERRIDE_UID, |
| 33 | TARGET_ERRNO__UID_OVERRIDE_CPU, |
| 34 | TARGET_ERRNO__PID_OVERRIDE_SYSTEM, |
| 35 | TARGET_ERRNO__UID_OVERRIDE_SYSTEM, |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 37 | /* for target__parse_uid() */ |
| 38 | TARGET_ERRNO__INVALID_UID, |
| 39 | TARGET_ERRNO__USER_NOT_FOUND, |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame] | 40 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 41 | __TARGET_ERRNO__END, |
Namhyung Kim | 60bbdda | 2012-05-07 14:09:00 +0900 | [diff] [blame] | 42 | }; |
| 43 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 44 | enum target_errno target__validate(struct target *target); |
| 45 | enum target_errno target__parse_uid(struct target *target); |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 46 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 47 | int target__strerror(struct target *target, int errnum, char *buf, size_t buflen); |
Namhyung Kim | 16ad2ff | 2012-05-07 14:09:02 +0900 | [diff] [blame] | 48 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 49 | static inline bool target__has_task(struct target *target) |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 50 | { |
Namhyung Kim | aa22dd4 | 2012-05-16 18:45:47 +0900 | [diff] [blame] | 51 | return target->tid || target->pid || target->uid_str; |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 52 | } |
| 53 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 54 | static inline bool target__has_cpu(struct target *target) |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 55 | { |
Namhyung Kim | aa22dd4 | 2012-05-16 18:45:47 +0900 | [diff] [blame] | 56 | return target->system_wide || target->cpu_list; |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 57 | } |
| 58 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 59 | static inline bool target__none(struct target *target) |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 60 | { |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 61 | return !target__has_task(target) && !target__has_cpu(target); |
Namhyung Kim | d67356e | 2012-05-07 14:09:03 +0900 | [diff] [blame] | 62 | } |
| 63 | |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 64 | #endif /* _PERF_TARGET_H */ |