trace.h 2.9 KB

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