trace.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2012 The Chromium OS Authors.
  4. */
  5. #ifndef __TRACE_H
  6. #define __TRACE_H
  7. /* this file is included from a tool so uses uint32_t instead of u32, etc. */
  8. enum {
  9. /*
  10. * This affects the granularity of our trace. We can bin function
  11. * entry points into groups on the basis that functions typically
  12. * have a minimum size, so entry points can't appear any closer
  13. * than this to each other.
  14. *
  15. * The value here assumes a minimum instruction size of 4 bytes,
  16. * or that instructions are 2 bytes but there are at least 2 of
  17. * them in every function. Given that each function needs a call to
  18. * __cyg_profile_func_enter() and __cyg_profile_func_exit() as well,
  19. * we cannot have functions smaller that 16 bytes.
  20. *
  21. * Increasing this value reduces the number of functions we can
  22. * resolve, but reduces the size of the uintptr_t array used for
  23. * our function list, which is the length of the code divided by
  24. * this value.
  25. */
  26. FUNC_SITE_SIZE = 16, /* distance between function sites */
  27. TRACE_VERSION = 1,
  28. };
  29. enum trace_chunk_type {
  30. TRACE_CHUNK_FUNCS,
  31. TRACE_CHUNK_CALLS,
  32. };
  33. /* A trace record for a function, as written to the profile output file */
  34. struct trace_output_func {
  35. uint32_t offset; /* Function offset into code */
  36. uint32_t call_count; /* Number of times called */
  37. };
  38. /* A header at the start of the trace output buffer */
  39. struct trace_output_hdr {
  40. enum trace_chunk_type type; /* Record type */
  41. uint32_t version; /* Version (TRACE_VERSION) */
  42. uint32_t rec_count; /* Number of records */
  43. uint32_t spare; /* 0 */
  44. uint64_t text_base; /* Value of CONFIG_TEXT_BASE */
  45. uint64_t spare2; /* 0 */
  46. };
  47. /* Print statistics about traced function calls */
  48. void trace_print_stats(void);
  49. /**
  50. * Dump a list of functions and call counts into a buffer
  51. *
  52. * Each record in the buffer is a struct trace_func_stats. The 'needed'
  53. * parameter returns the number of bytes needed to complete the operation,
  54. * which may be more than buff_size if your buffer is too small.
  55. *
  56. * @param buff Buffer in which to place data, or NULL to count size
  57. * @param buff_size Size of buffer
  58. * @param needed Returns number of bytes used / needed
  59. * Return: 0 if ok, -1 on error (buffer exhausted)
  60. */
  61. int trace_list_functions(void *buff, size_t buff_size, size_t *needed);
  62. /* Flags for ftrace_record */
  63. enum ftrace_flags {
  64. FUNCF_EXIT = 0UL << 30,
  65. FUNCF_ENTRY = 1UL << 30,
  66. /* two more values are available */
  67. FUNCF_TIMESTAMP_MASK = 0x3fffffff,
  68. };
  69. #define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL)
  70. /* Information about a single function entry/exit */
  71. struct trace_call {
  72. uint32_t func; /* Function offset */
  73. uint32_t caller; /* Caller function offset */
  74. uint32_t flags; /* Flags and timestamp */
  75. };
  76. int trace_list_calls(void *buff, size_t buff_size, size_t *needed);
  77. /**
  78. * Turn function tracing on and off
  79. *
  80. * Don't enable trace if it has not been initialised.
  81. *
  82. * @param enabled 1 to enable trace, 0 to disable
  83. */
  84. void trace_set_enabled(int enabled);
  85. int trace_early_init(void);
  86. /**
  87. * Init the trace system
  88. *
  89. * This should be called after relocation with a suitably large buffer
  90. * (typically as large as the U-Boot text area)
  91. *
  92. * @param buff Pointer to trace buffer
  93. * @param buff_size Size of trace buffer
  94. */
  95. int trace_init(void *buff, size_t buff_size);
  96. #endif