annotate.h 4.1 KB

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