trace.h 2.9 KB

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