annotate.h 4.1 KB

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