annotate.h 4.2 KB

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