annotate.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef __PERF_ANNOTATE_H
  2. #define __PERF_ANNOTATE_H
  3. #include <stdbool.h>
  4. #include "types.h"
  5. #include "symbol.h"
  6. #include <linux/list.h>
  7. #include <linux/rbtree.h>
  8. struct objdump_line {
  9. struct list_head node;
  10. s64 offset;
  11. char *line;
  12. };
  13. void objdump_line__free(struct objdump_line *self);
  14. struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
  15. struct objdump_line *pos);
  16. struct sym_hist {
  17. u64 sum;
  18. u64 addr[0];
  19. };
  20. struct source_line {
  21. struct rb_node node;
  22. double percent;
  23. char *path;
  24. };
  25. /** struct annotated_source - symbols with hits have this attached as in sannotation
  26. *
  27. * @histogram: Array of addr hit histograms per event being monitored
  28. * @lines: If 'print_lines' is specified, per source code line percentages
  29. * @source: source parsed from objdump -dS
  30. *
  31. * lines is allocated, percentages calculated and all sorted by percentage
  32. * when the annotation is about to be presented, so the percentages are for
  33. * one of the entries in the histogram array, i.e. for the event/counter being
  34. * presented. It is deallocated right after symbol__{tui,tty,etc}_annotate
  35. * returns.
  36. */
  37. struct annotated_source {
  38. struct list_head source;
  39. struct source_line *lines;
  40. int nr_histograms;
  41. int sizeof_sym_hist;
  42. struct sym_hist histograms[0];
  43. };
  44. struct annotation {
  45. pthread_mutex_t lock;
  46. struct annotated_source *src;
  47. };
  48. struct sannotation {
  49. struct annotation annotation;
  50. struct symbol symbol;
  51. };
  52. static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
  53. {
  54. return (((void *)&notes->src->histograms) +
  55. (notes->src->sizeof_sym_hist * idx));
  56. }
  57. static inline struct annotation *symbol__annotation(struct symbol *sym)
  58. {
  59. struct sannotation *a = container_of(sym, struct sannotation, symbol);
  60. return &a->annotation;
  61. }
  62. int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
  63. int evidx, u64 addr);
  64. int symbol__alloc_hist(struct symbol *sym, int nevents);
  65. void symbol__annotate_zero_histograms(struct symbol *sym);
  66. int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize);
  67. int symbol__annotate_init(struct map *map __used, struct symbol *sym);
  68. int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
  69. bool full_paths, int min_pcnt, int max_lines,
  70. int context);
  71. void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
  72. void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
  73. void objdump_line_list__purge(struct list_head *head);
  74. int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
  75. bool print_lines, bool full_paths, int min_pcnt,
  76. int max_lines);
  77. #ifdef NO_NEWT_SUPPORT
  78. static inline int symbol__tui_annotate(struct symbol *sym __used,
  79. struct map *map __used,
  80. int evidx __used, int refresh __used)
  81. {
  82. return 0;
  83. }
  84. #else
  85. int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
  86. int refresh);
  87. #endif
  88. #endif /* __PERF_ANNOTATE_H */