annotate.h 3.6 KB

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