sort.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef __PERF_SORT_H
  2. #define __PERF_SORT_H
  3. #include "../builtin.h"
  4. #include "util.h"
  5. #include "color.h"
  6. #include <linux/list.h>
  7. #include "cache.h"
  8. #include <linux/rbtree.h>
  9. #include "symbol.h"
  10. #include "string.h"
  11. #include "callchain.h"
  12. #include "strlist.h"
  13. #include "values.h"
  14. #include "../perf.h"
  15. #include "debug.h"
  16. #include "header.h"
  17. #include "parse-options.h"
  18. #include "parse-events.h"
  19. #include "thread.h"
  20. #include "sort.h"
  21. extern regex_t parent_regex;
  22. extern const char *sort_order;
  23. extern const char default_parent_pattern[];
  24. extern const char *parent_pattern;
  25. extern const char default_sort_order[];
  26. extern int sort__need_collapse;
  27. extern int sort__has_parent;
  28. extern int sort__has_sym;
  29. extern int sort__branch_mode;
  30. extern struct sort_entry sort_comm;
  31. extern struct sort_entry sort_dso;
  32. extern struct sort_entry sort_sym;
  33. extern struct sort_entry sort_parent;
  34. extern struct sort_entry sort_dso_from;
  35. extern struct sort_entry sort_dso_to;
  36. extern struct sort_entry sort_sym_from;
  37. extern struct sort_entry sort_sym_to;
  38. extern enum sort_type sort__first_dimension;
  39. struct he_stat {
  40. u64 period;
  41. u64 period_sys;
  42. u64 period_us;
  43. u64 period_guest_sys;
  44. u64 period_guest_us;
  45. u32 nr_events;
  46. };
  47. struct hist_entry_diff {
  48. bool computed;
  49. /* PERF_HPP__DELTA */
  50. double period_ratio_delta;
  51. /* PERF_HPP__RATIO */
  52. double period_ratio;
  53. /* HISTC_WEIGHTED_DIFF */
  54. s64 wdiff;
  55. };
  56. /**
  57. * struct hist_entry - histogram entry
  58. *
  59. * @row_offset - offset from the first callchain expanded to appear on screen
  60. * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
  61. */
  62. struct hist_entry {
  63. struct rb_node rb_node_in;
  64. struct rb_node rb_node;
  65. union {
  66. struct list_head node;
  67. struct list_head head;
  68. } pairs;
  69. struct he_stat stat;
  70. struct map_symbol ms;
  71. struct thread *thread;
  72. u64 ip;
  73. s32 cpu;
  74. struct hist_entry_diff diff;
  75. /* XXX These two should move to some tree widget lib */
  76. u16 row_offset;
  77. u16 nr_rows;
  78. bool init_have_children;
  79. char level;
  80. bool used;
  81. u8 filtered;
  82. char *srcline;
  83. struct symbol *parent;
  84. unsigned long position;
  85. struct rb_root sorted_chain;
  86. struct branch_info *branch_info;
  87. struct hists *hists;
  88. struct callchain_root callchain[0];
  89. };
  90. static inline bool hist_entry__has_pairs(struct hist_entry *he)
  91. {
  92. return !list_empty(&he->pairs.node);
  93. }
  94. static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
  95. {
  96. if (hist_entry__has_pairs(he))
  97. return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
  98. return NULL;
  99. }
  100. static inline void hist_entry__add_pair(struct hist_entry *he,
  101. struct hist_entry *pair)
  102. {
  103. list_add_tail(&he->pairs.head, &pair->pairs.node);
  104. }
  105. enum sort_type {
  106. /* common sort keys */
  107. SORT_PID,
  108. SORT_COMM,
  109. SORT_DSO,
  110. SORT_SYM,
  111. SORT_PARENT,
  112. SORT_CPU,
  113. SORT_SRCLINE,
  114. /* branch stack specific sort keys */
  115. __SORT_BRANCH_STACK,
  116. SORT_DSO_FROM = __SORT_BRANCH_STACK,
  117. SORT_DSO_TO,
  118. SORT_SYM_FROM,
  119. SORT_SYM_TO,
  120. SORT_MISPREDICT,
  121. };
  122. /*
  123. * configurable sorting bits
  124. */
  125. struct sort_entry {
  126. struct list_head list;
  127. const char *se_header;
  128. int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
  129. int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
  130. int (*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
  131. unsigned int width);
  132. u8 se_width_idx;
  133. bool elide;
  134. };
  135. extern struct sort_entry sort_thread;
  136. extern struct list_head hist_entry__sort_list;
  137. int setup_sorting(void);
  138. extern int sort_dimension__add(const char *);
  139. void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
  140. const char *list_name, FILE *fp);
  141. #endif /* __PERF_SORT_H */