thread-stack.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include <linux/rbtree.h>
  20. struct thread;
  21. struct comm;
  22. struct ip_callchain;
  23. struct symbol;
  24. struct dso;
  25. struct call_return_processor;
  26. struct comm;
  27. struct perf_sample;
  28. struct addr_location;
  29. /*
  30. * Call/Return flags.
  31. *
  32. * CALL_RETURN_NO_CALL: 'return' but no matching 'call'
  33. * CALL_RETURN_NO_RETURN: 'call' but no matching 'return'
  34. */
  35. enum {
  36. CALL_RETURN_NO_CALL = 1 << 0,
  37. CALL_RETURN_NO_RETURN = 1 << 1,
  38. };
  39. /**
  40. * struct call_return - paired call/return information.
  41. * @thread: thread in which call/return occurred
  42. * @comm: comm in which call/return occurred
  43. * @cp: call path
  44. * @call_time: timestamp of call (if known)
  45. * @return_time: timestamp of return (if known)
  46. * @branch_count: number of branches seen between call and return
  47. * @call_ref: external reference to 'call' sample (e.g. db_id)
  48. * @return_ref: external reference to 'return' sample (e.g. db_id)
  49. * @db_id: id used for db-export
  50. * @flags: Call/Return flags
  51. */
  52. struct call_return {
  53. struct thread *thread;
  54. struct comm *comm;
  55. struct call_path *cp;
  56. u64 call_time;
  57. u64 return_time;
  58. u64 branch_count;
  59. u64 call_ref;
  60. u64 return_ref;
  61. u64 db_id;
  62. u32 flags;
  63. };
  64. /**
  65. * struct call_path - node in list of calls leading to a function call.
  66. * @parent: call path to the parent function call
  67. * @sym: symbol of function called
  68. * @ip: only if sym is null, the ip of the function
  69. * @db_id: id used for db-export
  70. * @in_kernel: whether function is a in the kernel
  71. * @rb_node: node in parent's tree of called functions
  72. * @children: tree of call paths of functions called
  73. *
  74. * In combination with the call_return structure, the call_path structure
  75. * defines a context-sensitve call-graph.
  76. */
  77. struct call_path {
  78. struct call_path *parent;
  79. struct symbol *sym;
  80. u64 ip;
  81. u64 db_id;
  82. bool in_kernel;
  83. struct rb_node rb_node;
  84. struct rb_root children;
  85. };
  86. int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
  87. u64 to_ip, u16 insn_len, u64 trace_nr);
  88. void thread_stack__set_trace_nr(struct thread *thread, u64 trace_nr);
  89. void thread_stack__sample(struct thread *thread, struct ip_callchain *chain,
  90. size_t sz, u64 ip);
  91. int thread_stack__flush(struct thread *thread);
  92. void thread_stack__free(struct thread *thread);
  93. struct call_return_processor *
  94. call_return_processor__new(int (*process)(struct call_return *cr, void *data),
  95. void *data);
  96. void call_return_processor__free(struct call_return_processor *crp);
  97. int thread_stack__process(struct thread *thread, struct comm *comm,
  98. struct perf_sample *sample,
  99. struct addr_location *from_al,
  100. struct addr_location *to_al, u64 ref,
  101. struct call_return_processor *crp);
  102. #endif