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