thread-stack.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * thread-stack.h: Synthesize a thread's stack using call / return events
  4. * Copyright (c) 2014, Intel Corporation.
  5. */
  6. #ifndef __PERF_THREAD_STACK_H
  7. #define __PERF_THREAD_STACK_H
  8. #include <sys/types.h>
  9. #include <linux/types.h>
  10. struct thread;
  11. struct comm;
  12. struct ip_callchain;
  13. struct symbol;
  14. struct dso;
  15. struct comm;
  16. struct perf_sample;
  17. struct addr_location;
  18. struct call_path;
  19. /*
  20. * Call/Return flags.
  21. *
  22. * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
  23. * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
  24. * CALL_RETURN_NON_CALL: a branch but not a 'call' to the start of a different
  25. * symbol
  26. */
  27. enum {
  28. CALL_RETURN_NO_CALL = 1 << 0,
  29. CALL_RETURN_NO_RETURN = 1 << 1,
  30. CALL_RETURN_NON_CALL = 1 << 2,
  31. };
  32. /**
  33. * struct call_return - paired call/return information.
  34. * @thread: thread in which call/return occurred
  35. * @comm: comm in which call/return occurred
  36. * @cp: call path
  37. * @call_time: timestamp of call (if known)
  38. * @return_time: timestamp of return (if known)
  39. * @branch_count: number of branches seen between call and return
  40. * @insn_count: approx. number of instructions between call and return
  41. * @cyc_count: approx. number of cycles between call and return
  42. * @call_ref: external reference to 'call' sample (e.g. db_id)
  43. * @return_ref: external reference to 'return' sample (e.g. db_id)
  44. * @db_id: id used for db-export
  45. * @parent_db_id: id of parent call used for db-export
  46. * @flags: Call/Return flags
  47. */
  48. struct call_return {
  49. struct thread *thread;
  50. struct comm *comm;
  51. struct call_path *cp;
  52. u64 call_time;
  53. u64 return_time;
  54. u64 branch_count;
  55. u64 insn_count;
  56. u64 cyc_count;
  57. u64 call_ref;
  58. u64 return_ref;
  59. u64 db_id;
  60. u64 parent_db_id;
  61. u32 flags;
  62. };
  63. /**
  64. * struct call_return_processor - provides a call-back to consume call-return
  65. * information.
  66. * @cpr: call path root
  67. * @process: call-back that accepts call/return information
  68. * @data: anonymous data for call-back
  69. */
  70. struct call_return_processor {
  71. struct call_path_root *cpr;
  72. int (*process)(struct call_return *cr, u64 *parent_db_id, void *data);
  73. void *data;
  74. };
  75. int thread_stack__event(struct thread *thread, int cpu, u32 flags, u64 from_ip,
  76. u64 to_ip, u16 insn_len, u64 trace_nr, bool callstack,
  77. unsigned int br_stack_sz, bool mispred_all);
  78. void thread_stack__set_trace_nr(struct thread *thread, int cpu, u64 trace_nr);
  79. void thread_stack__sample(struct thread *thread, int cpu, struct ip_callchain *chain,
  80. size_t sz, u64 ip, u64 kernel_start);
  81. void thread_stack__sample_late(struct thread *thread, int cpu,
  82. struct ip_callchain *chain, size_t sz, u64 ip,
  83. u64 kernel_start);
  84. void thread_stack__br_sample(struct thread *thread, int cpu,
  85. struct branch_stack *dst, unsigned int sz);
  86. void thread_stack__br_sample_late(struct thread *thread, int cpu,
  87. struct branch_stack *dst, unsigned int sz,
  88. u64 sample_ip, u64 kernel_start);
  89. int thread_stack__flush(struct thread *thread);
  90. void thread_stack__free(struct thread *thread);
  91. size_t thread_stack__depth(struct thread *thread, int cpu);
  92. struct call_return_processor *
  93. call_return_processor__new(int (*process)(struct call_return *cr, u64 *parent_db_id, void *data),
  94. void *data);
  95. void call_return_processor__free(struct call_return_processor *crp);
  96. int thread_stack__process(struct thread *thread, struct comm *comm,
  97. struct perf_sample *sample,
  98. struct addr_location *from_al,
  99. struct addr_location *to_al, u64 ref,
  100. struct call_return_processor *crp);
  101. #endif