annotate.h 3.6 KB

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