annotate.h 3.5 KB

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