thread-stack.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * thread-stack.h: Synthesize a thread's stack using call / return events
  3. * Copyright (c) 2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #ifndef __PERF_THREAD_STACK_H
  16. #define __PERF_THREAD_STACK_H
  17. #include <sys/types.h>
  18. #include <linux/types.h>
  19. struct thread;
  20. struct comm;
  21. struct ip_callchain;
  22. struct symbol;
  23. struct dso;
  24. struct comm;
  25. struct perf_sample;
  26. struct addr_location;
  27. struct call_path;
  28. /*
  29. * Call/Return flags.
  30. *
  31. * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
  32. * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
  33. */
  34. enum {
  35. CALL_RETURN_NO_CALL = 1 << 0,
  36. CALL_RETURN_NO_RETURN = 1 << 1,
  37. };
  38. /**
  39. * struct call_return - paired call/return information.
  40. * @thread: thread in which call/return occurred
  41. * @comm: comm in which call/return occurred
  42. * @cp: call path
  43. * @call_time: timestamp of call (if known)
  44. * @return_time: timestamp of return (if known)
  45. * @branch_count: number of branches seen between call and return
  46. * @call_ref: external reference to 'call' sample (e.g. db_id)
  47. * @return_ref: external reference to 'return' sample (e.g. db_id)
  48. * @db_id: id used for db-export
  49. * @flags: Call/Return flags
  50. */
  51. struct call_return {
  52. struct thread *thread;
  53. struct comm *comm;
  54. struct call_path *cp;
  55. u64 call_time;
  56. u64 return_time;
  57. u64 branch_count;
  58. u64 call_ref;
  59. u64 return_ref;
  60. u64 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, void *data);
  73. void *data;
  74. };
  75. int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
  76. u64 to_ip, u16 insn_len, u64 trace_nr);
  77. void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
  78. void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
  79. size_t sz, u64 ip);
  80. int thread_stack__flush(struct thread *thread);
  81. void thread_stack__free(struct thread *thread);
  82. size_t thread_stack__depth(struct thread *thread);
  83. struct call_return_processor *
  84. call_return_processor__new(int (*process)(struct call_return *cr, void *data),
  85. void *data);
  86. void call_return_processor__free(struct call_return_processor *crp);
  87. int thread_stack__process(struct thread *thread, struct comm *comm,
  88. struct perf_sample *sample,
  89. struct addr_location *from_al,
  90. struct addr_location *to_al, u64 ref,
  91. struct call_return_processor *crp);
  92. #endif