annotate.h 3.6 KB

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