annotate.h 3.1 KB

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