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