annotate.h 3.7 KB

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