annotate.h 3.4 KB

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