annotate.h 3.1 KB

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