target.h 1.9 KB

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