target.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef _PERF_TARGET_H
  2. #define _PERF_TARGET_H
  3. #include <stdbool.h>
  4. #include <sys/types.h>
  5. struct perf_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. };
  13. enum perf_target_errno {
  14. PERF_ERRNO_TARGET__SUCCESS = 0,
  15. /*
  16. * Choose an arbitrary negative big number not to clash with standard
  17. * errno since SUS requires the errno has distinct positive values.
  18. * See 'Issue 6' in the link below.
  19. *
  20. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  21. */
  22. __PERF_ERRNO_TARGET__START = -10000,
  23. /* for perf_target__validate() */
  24. PERF_ERRNO_TARGET__PID_OVERRIDE_CPU = __PERF_ERRNO_TARGET__START,
  25. PERF_ERRNO_TARGET__PID_OVERRIDE_UID,
  26. PERF_ERRNO_TARGET__UID_OVERRIDE_CPU,
  27. PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM,
  28. PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM,
  29. /* for perf_target__parse_uid() */
  30. PERF_ERRNO_TARGET__INVALID_UID,
  31. PERF_ERRNO_TARGET__USER_NOT_FOUND,
  32. __PERF_ERRNO_TARGET__END,
  33. };
  34. enum perf_target_errno perf_target__validate(struct perf_target *target);
  35. enum perf_target_errno perf_target__parse_uid(struct perf_target *target);
  36. int perf_target__strerror(struct perf_target *target, int errnum, char *buf,
  37. size_t buflen);
  38. static inline bool perf_target__no_task(struct perf_target *target)
  39. {
  40. return !target->pid && !target->tid && !target->uid_str;
  41. }
  42. static inline bool perf_target__no_cpu(struct perf_target *target)
  43. {
  44. return !target->system_wide && !target->cpu_list;
  45. }
  46. static inline bool perf_target__none(struct perf_target *target)
  47. {
  48. return perf_target__no_task(target) && perf_target__no_cpu(target);
  49. }
  50. #endif /* _PERF_TARGET_H */