annotate.h 4.0 KB

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