trace.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2012 The Chromium OS Authors.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  17. * MA 02111-1307 USA
  18. */
  19. #ifndef __TRACE_H
  20. #define __TRACE_H
  21. enum {
  22. /*
  23. * This affects the granularity of our trace. We can bin function
  24. * entry points into groups on the basis that functions typically
  25. * have a minimum size, so entry points can't appear any closer
  26. * than this to each other.
  27. *
  28. * The value here assumes a minimum instruction size of 4 bytes,
  29. * or that instructions are 2 bytes but there are at least 2 of
  30. * them in every function.
  31. *
  32. * Increasing this value reduces the number of functions we can
  33. * resolve, but reduces the size of the uintptr_t array used for
  34. * our function list, which is the length of the code divided by
  35. * this value.
  36. */
  37. FUNC_SITE_SIZE = 4, /* distance between function sites */
  38. };
  39. enum trace_chunk_type {
  40. TRACE_CHUNK_FUNCS,
  41. TRACE_CHUNK_CALLS,
  42. };
  43. /* A trace record for a function, as written to the profile output file */
  44. struct trace_output_func {
  45. uint32_t offset; /* Function offset into code */
  46. uint32_t call_count; /* Number of times called */
  47. };
  48. /* A header at the start of the trace output buffer */
  49. struct trace_output_hdr {
  50. enum trace_chunk_type type; /* Record type */
  51. uint32_t rec_count; /* Number of records */
  52. };
  53. /* Print statistics about traced function calls */
  54. void trace_print_stats(void);
  55. /**
  56. * Dump a list of functions and call counts into a buffer
  57. *
  58. * Each record in the buffer is a struct trace_func_stats. The 'needed'
  59. * parameter returns the number of bytes needed to complete the operation,
  60. * which may be more than buff_size if your buffer is too small.
  61. *
  62. * @param buff Buffer in which to place data, or NULL to count size
  63. * @param buff_size Size of buffer
  64. * @param needed Returns number of bytes used / needed
  65. * @return 0 if ok, -1 on error (buffer exhausted)
  66. */
  67. int trace_list_functions(void *buff, int buff_size, unsigned *needed);
  68. /* Flags for ftrace_record */
  69. enum ftrace_flags {
  70. FUNCF_EXIT = 0UL << 30,
  71. FUNCF_ENTRY = 1UL << 30,
  72. FUNCF_TEXTBASE = 2UL << 30,
  73. FUNCF_TIMESTAMP_MASK = 0x3fffffff,
  74. };
  75. #define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL)
  76. /* Information about a single function entry/exit */
  77. struct trace_call {
  78. uint32_t func; /* Function offset */
  79. uint32_t caller; /* Caller function offset */
  80. uint32_t flags; /* Flags and timestamp */
  81. };
  82. int trace_list_calls(void *buff, int buff_size, unsigned int *needed);
  83. /**
  84. * Turn function tracing on and off
  85. *
  86. * Don't enable trace if it has not been initialised.
  87. *
  88. * @param enabled 1 to enable trace, 0 to disable
  89. */
  90. void trace_set_enabled(int enabled);
  91. #ifdef CONFIG_TRACE_EARLY
  92. int trace_early_init(void);
  93. #else
  94. static inline int trace_early_init(void)
  95. {
  96. return 0;
  97. }
  98. #endif
  99. /**
  100. * Init the trace system
  101. *
  102. * This should be called after relocation with a suitably large buffer
  103. * (typically as large as the U-Boot text area)
  104. *
  105. * @param buff Pointer to trace buffer
  106. * @param buff_size Size of trace buffer
  107. */
  108. int trace_init(void *buff, size_t buff_size);
  109. #endif