annotate.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef __PERF_ANNOTATE_H
  2. #define __PERF_ANNOTATE_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. #include "types.h"
  6. #include "symbol.h"
  7. #include "hist.h"
  8. #include "sort.h"
  9. #include <linux/list.h>
  10. #include <linux/rbtree.h>
  11. #include <pthread.h>
  12. struct ins;
  13. struct ins_operands {
  14. char *raw;
  15. struct {
  16. char *raw;
  17. char *name;
  18. u64 addr;
  19. u64 offset;
  20. } target;
  21. union {
  22. struct {
  23. char *raw;
  24. char *name;
  25. u64 addr;
  26. } source;
  27. struct {
  28. struct ins *ins;
  29. struct ins_operands *ops;
  30. } locked;
  31. };
  32. };
  33. struct ins_ops {
  34. void (*free)(struct ins_operands *ops);
  35. int (*parse)(struct ins_operands *ops);
  36. int (*scnprintf)(struct ins *ins, char *bf, size_t size,
  37. struct ins_operands *ops);
  38. };
  39. struct ins {
  40. const char *name;
  41. struct ins_ops *ops;
  42. };
  43. bool ins__is_jump(const struct ins *ins);
  44. bool ins__is_call(const struct ins *ins);
  45. int ins__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops);
  46. struct disasm_line {
  47. struct list_head node;
  48. s64 offset;
  49. char *line;
  50. char *name;
  51. struct ins *ins;
  52. struct ins_operands ops;
  53. };
  54. static inline bool disasm_line__has_offset(const struct disasm_line *dl)
  55. {
  56. return dl->ops.target.offset != UINT64_MAX;
  57. }
  58. void disasm_line__free(struct disasm_line *dl);
  59. struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
  60. int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
  61. size_t disasm__fprintf(struct list_head *head, FILE *fp);
  62. struct sym_hist {
  63. u64 sum;
  64. u64 addr[0];
  65. };
  66. struct source_line_percent {
  67. double percent;
  68. double percent_sum;
  69. };
  70. struct source_line {
  71. struct rb_node node;
  72. char *path;
  73. int nr_pcnt;
  74. struct source_line_percent p[1];
  75. };
  76. /** struct annotated_source - symbols with hits have this attached as in sannotation
  77. *
  78. * @histogram: Array of addr hit histograms per event being monitored
  79. * @lines: If 'print_lines' is specified, per source code line percentages
  80. * @source: source parsed from a disassembler like objdump -dS
  81. *
  82. * lines is allocated, percentages calculated and all sorted by percentage
  83. * when the annotation is about to be presented, so the percentages are for
  84. * one of the entries in the histogram array, i.e. for the event/counter being
  85. * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
  86. * returns.
  87. */
  88. struct annotated_source {
  89. struct list_head source;
  90. struct source_line *lines;
  91. int nr_histograms;
  92. int sizeof_sym_hist;
  93. struct sym_hist histograms[0];
  94. };
  95. struct annotation {
  96. pthread_mutex_t lock;
  97. struct annotated_source *src;
  98. };
  99. struct sannotation {
  100. struct annotation annotation;
  101. struct symbol symbol;
  102. };
  103. static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
  104. {
  105. return (((void *)&notes->src->histograms) +
  106. (notes->src->sizeof_sym_hist * idx));
  107. }
  108. static inline struct annotation *symbol__annotation(struct symbol *sym)
  109. {
  110. struct sannotation *a = container_of(sym, struct sannotation, symbol);
  111. return &a->annotation;
  112. }
  113. int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
  114. int evidx, u64 addr);
  115. int symbol__alloc_hist(struct symbol *sym);
  116. void symbol__annotate_zero_histograms(struct symbol *sym);
  117. int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
  118. int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym);
  119. int symbol__annotate_printf(struct symbol *sym, struct map *map,
  120. struct perf_evsel *evsel, bool full_paths,
  121. int min_pcnt, int max_lines, int context);
  122. void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
  123. void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
  124. void disasm__purge(struct list_head *head);
  125. int symbol__tty_annotate(struct symbol *sym, struct map *map,
  126. struct perf_evsel *evsel, bool print_lines,
  127. bool full_paths, int min_pcnt, int max_lines);
  128. #ifdef NEWT_SUPPORT
  129. int symbol__tui_annotate(struct symbol *sym, struct map *map,
  130. struct perf_evsel *evsel,
  131. struct hist_browser_timer *hbt);
  132. #else
  133. static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
  134. struct map *map __maybe_unused,
  135. struct perf_evsel *evsel __maybe_unused,
  136. struct hist_browser_timer *hbt
  137. __maybe_unused)
  138. {
  139. return 0;
  140. }
  141. #endif
  142. #ifdef GTK2_SUPPORT
  143. int symbol__gtk_annotate(struct symbol *sym, struct map *map,
  144. struct perf_evsel *evsel,
  145. struct hist_browser_timer *hbt);
  146. static inline int hist_entry__gtk_annotate(struct hist_entry *he,
  147. struct perf_evsel *evsel,
  148. struct hist_browser_timer *hbt)
  149. {
  150. return symbol__gtk_annotate(he->ms.sym, he->ms.map, evsel, hbt);
  151. }
  152. void perf_gtk__show_annotations(void);
  153. #else
  154. static inline int hist_entry__gtk_annotate(struct hist_entry *he __maybe_unused,
  155. struct perf_evsel *evsel __maybe_unused,
  156. struct hist_browser_timer *hbt __maybe_unused)
  157. {
  158. return 0;
  159. }
  160. static inline void perf_gtk__show_annotations(void) {}
  161. #endif
  162. extern const char *disassembler_style;
  163. #endif /* __PERF_ANNOTATE_H */