blob: 89bab7129de4a3c92b74ca037787431c155f251f [file] [log] [blame]
Namhyung Kim12864b32012-04-26 14:15:22 +09001#ifndef _PERF_TARGET_H
2#define _PERF_TARGET_H
3
4#include <stdbool.h>
5#include <sys/types.h>
6
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -03007struct target {
Namhyung Kim12864b32012-04-26 14:15:22 +09008 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 Kimd1cb9fc2012-05-16 18:45:49 +090014 bool uses_mmap;
Namhyung Kim12864b32012-04-26 14:15:22 +090015};
16
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030017enum target_errno {
18 TARGET_ERRNO__SUCCESS = 0,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090019
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 Melo602ad872013-11-12 16:46:16 -030027 __TARGET_ERRNO__START = -10000,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090028
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030029 /* 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 Kim60bbdda2012-05-07 14:09:00 +090035
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030036 /* for target__parse_uid() */
37 TARGET_ERRNO__INVALID_UID,
38 TARGET_ERRNO__USER_NOT_FOUND,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090039
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030040 __TARGET_ERRNO__END,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090041};
42
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030043enum target_errno target__validate(struct target *target);
44enum target_errno target__parse_uid(struct target *target);
Namhyung Kim12864b32012-04-26 14:15:22 +090045
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030046int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
Namhyung Kim16ad2ff2012-05-07 14:09:02 +090047
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030048static inline bool target__has_task(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090049{
Namhyung Kimaa22dd42012-05-16 18:45:47 +090050 return target->tid || target->pid || target->uid_str;
Namhyung Kimd67356e2012-05-07 14:09:03 +090051}
52
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030053static inline bool target__has_cpu(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090054{
Namhyung Kimaa22dd42012-05-16 18:45:47 +090055 return target->system_wide || target->cpu_list;
Namhyung Kimd67356e2012-05-07 14:09:03 +090056}
57
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030058static inline bool target__none(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090059{
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030060 return !target__has_task(target) && !target__has_cpu(target);
Namhyung Kimd67356e2012-05-07 14:09:03 +090061}
62
Namhyung Kim12864b32012-04-26 14:15:22 +090063#endif /* _PERF_TARGET_H */