target.h 1.5 KB

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