target.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. bool uses_mmap;
  13. };
  14. enum perf_target_errno {
  15. PERF_ERRNO_TARGET__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. __PERF_ERRNO_TARGET__START = -10000,
  24. /* for perf_target__validate() */
  25. PERF_ERRNO_TARGET__PID_OVERRIDE_CPU = __PERF_ERRNO_TARGET__START,
  26. PERF_ERRNO_TARGET__PID_OVERRIDE_UID,
  27. PERF_ERRNO_TARGET__UID_OVERRIDE_CPU,
  28. PERF_ERRNO_TARGET__PID_OVERRIDE_SYSTEM,
  29. PERF_ERRNO_TARGET__UID_OVERRIDE_SYSTEM,
  30. /* for perf_target__parse_uid() */
  31. PERF_ERRNO_TARGET__INVALID_UID,
  32. PERF_ERRNO_TARGET__USER_NOT_FOUND,
  33. __PERF_ERRNO_TARGET__END,
  34. };
  35. enum perf_target_errno perf_target__validate(struct perf_target *target);
  36. enum perf_target_errno perf_target__parse_uid(struct perf_target *target);
  37. int perf_target__strerror(struct perf_target *target, int errnum, char *buf,
  38. size_t buflen);
  39. static inline bool perf_target__has_task(struct perf_target *target)
  40. {
  41. return target->tid || target->pid || target->uid_str;
  42. }
  43. static inline bool perf_target__has_cpu(struct perf_target *target)
  44. {
  45. return target->system_wide || target->cpu_list;
  46. }
  47. static inline bool perf_target__none(struct perf_target *target)
  48. {
  49. return !perf_target__has_task(target) && !perf_target__has_cpu(target);
  50. }
  51. #endif /* _PERF_TARGET_H */