annotate.h 3.4 KB

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