annotate.h 3.9 KB

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