blob: 2d0c506908926f6fce822adc45a39e76911edd10 [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;
Adrian Hunter539e6bb2013-11-01 15:51:34 +020015 bool force_per_cpu;
Namhyung Kim12864b32012-04-26 14:15:22 +090016};
17
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030018enum target_errno {
19 TARGET_ERRNO__SUCCESS = 0,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090020
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 Melo602ad872013-11-12 16:46:16 -030028 __TARGET_ERRNO__START = -10000,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090029
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030030 /* 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 Kim60bbdda2012-05-07 14:09:00 +090036
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030037 /* for target__parse_uid() */
38 TARGET_ERRNO__INVALID_UID,
39 TARGET_ERRNO__USER_NOT_FOUND,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090040
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030041 __TARGET_ERRNO__END,
Namhyung Kim60bbdda2012-05-07 14:09:00 +090042};
43
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030044enum target_errno target__validate(struct target *target);
45enum target_errno target__parse_uid(struct target *target);
Namhyung Kim12864b32012-04-26 14:15:22 +090046
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030047int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
Namhyung Kim16ad2ff2012-05-07 14:09:02 +090048
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030049static inline bool target__has_task(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090050{
Namhyung Kimaa22dd42012-05-16 18:45:47 +090051 return target->tid || target->pid || target->uid_str;
Namhyung Kimd67356e2012-05-07 14:09:03 +090052}
53
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030054static inline bool target__has_cpu(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090055{
Namhyung Kimaa22dd42012-05-16 18:45:47 +090056 return target->system_wide || target->cpu_list;
Namhyung Kimd67356e2012-05-07 14:09:03 +090057}
58
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030059static inline bool target__none(struct target *target)
Namhyung Kimd67356e2012-05-07 14:09:03 +090060{
Arnaldo Carvalho de Melo602ad872013-11-12 16:46:16 -030061 return !target__has_task(target) && !target__has_cpu(target);
Namhyung Kimd67356e2012-05-07 14:09:03 +090062}
63
Namhyung Kim12864b32012-04-26 14:15:22 +090064#endif /* _PERF_TARGET_H */