thread-stack.h 3.5 KB

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