xref: /linux/tools/perf/util/target.h (revision c4de673b775e4db48cd2db6277e0c6714332ca0c)
1 #ifndef _PERF_TARGET_H
2 #define _PERF_TARGET_H
3 
4 #include <stdbool.h>
5 #include <sys/types.h>
6 
7 struct target {
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;
14 	bool	     uses_mmap;
15 	bool	     force_per_cpu;
16 };
17 
18 enum target_errno {
19 	TARGET_ERRNO__SUCCESS		= 0,
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 	 */
28 	__TARGET_ERRNO__START		= -10000,
29 
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,
36 
37 	/* for target__parse_uid() */
38 	TARGET_ERRNO__INVALID_UID,
39 	TARGET_ERRNO__USER_NOT_FOUND,
40 
41 	__TARGET_ERRNO__END,
42 };
43 
44 enum target_errno target__validate(struct target *target);
45 enum target_errno target__parse_uid(struct target *target);
46 
47 int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
48 
49 static inline bool target__has_task(struct target *target)
50 {
51 	return target->tid || target->pid || target->uid_str;
52 }
53 
54 static inline bool target__has_cpu(struct target *target)
55 {
56 	return target->system_wide || target->cpu_list;
57 }
58 
59 static inline bool target__none(struct target *target)
60 {
61 	return !target__has_task(target) && !target__has_cpu(target);
62 }
63 
64 #endif /* _PERF_TARGET_H */
65