target.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _PERF_TARGET_H
  2. #define _PERF_TARGET_H
  3. #include <stdbool.h>
  4. #include <sys/types.h>
  5. struct target {
  6. const char *pid;
  7. const char *tid;
  8. const char *cpu_list;
  9. const char *uid_str;
  10. uid_t uid;
  11. bool system_wide;
  12. bool uses_mmap;
  13. };
  14. enum target_errno {
  15. TARGET_ERRNO__SUCCESS = 0,
  16. /*
  17. * Choose an arbitrary negative big number not to clash with standard
  18. * errno since SUS requires the errno has distinct positive values.
  19. * See 'Issue 6' in the link below.
  20. *
  21. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  22. */
  23. __TARGET_ERRNO__START = -10000,
  24. /* for target__validate() */
  25. TARGET_ERRNO__PID_OVERRIDE_CPU = __TARGET_ERRNO__START,
  26. TARGET_ERRNO__PID_OVERRIDE_UID,
  27. TARGET_ERRNO__UID_OVERRIDE_CPU,
  28. TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
  29. TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
  30. /* for target__parse_uid() */
  31. TARGET_ERRNO__INVALID_UID,
  32. TARGET_ERRNO__USER_NOT_FOUND,
  33. __TARGET_ERRNO__END,
  34. };
  35. enum target_errno target__validate(struct target *target);
  36. enum target_errno target__parse_uid(struct target *target);
  37. int target__strerror(struct target *target, int errnum, char *buf, size_t buflen);
  38. static inline bool target__has_task(struct target *target)
  39. {
  40. return target->tid || target->pid || target->uid_str;
  41. }
  42. static inline bool target__has_cpu(struct target *target)
  43. {
  44. return target->system_wide || target->cpu_list;
  45. }
  46. static inline bool target__none(struct target *target)
  47. {
  48. return !target__has_task(target) && !target__has_cpu(target);
  49. }
  50. #endif /* _PERF_TARGET_H */