2 * Copyright (c) 2012 The Chromium OS Authors.
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.
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.
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,
25 * This affects the granularity of our trace. We can bin function
26 * entry points into groups on the basis that functions typically
27 * have a minimum size, so entry points can't appear any closer
28 * than this to each other.
30 * The value here assumes a minimum instruction size of 4 bytes,
31 * or that instructions are 2 bytes but there are at least 2 of
32 * them in every function.
34 * Increasing this value reduces the number of functions we can
35 * resolve, but reduces the size of the uintptr_t array used for
36 * our function list, which is the length of the code divided by
39 FUNC_SITE_SIZE = 4, /* distance between function sites */
42 enum trace_chunk_type {
47 /* A trace record for a function, as written to the profile output file */
48 struct trace_output_func {
49 uint32_t offset; /* Function offset into code */
50 uint32_t call_count; /* Number of times called */
53 /* A header at the start of the trace output buffer */
54 struct trace_output_hdr {
55 enum trace_chunk_type type; /* Record type */
56 uint32_t rec_count; /* Number of records */
59 /* Print statistics about traced function calls */
60 void trace_print_stats(void);
63 * Dump a list of functions and call counts into a buffer
65 * Each record in the buffer is a struct trace_func_stats. The 'needed'
66 * parameter returns the number of bytes needed to complete the operation,
67 * which may be more than buff_size if your buffer is too small.
69 * @param buff Buffer in which to place data, or NULL to count size
70 * @param buff_size Size of buffer
71 * @param needed Returns number of bytes used / needed
72 * @return 0 if ok, -1 on error (buffer exhausted)
74 int trace_list_functions(void *buff, int buff_size, unsigned *needed);
76 /* Flags for ftrace_record */
78 FUNCF_EXIT = 0UL << 30,
79 FUNCF_ENTRY = 1UL << 30,
80 FUNCF_TEXTBASE = 2UL << 30,
82 FUNCF_TIMESTAMP_MASK = 0x3fffffff,
85 #define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL)
87 /* Information about a single function entry/exit */
89 uint32_t func; /* Function offset */
90 uint32_t caller; /* Caller function offset */
91 uint32_t flags; /* Flags and timestamp */
94 int trace_list_calls(void *buff, int buff_size, unsigned int *needed);
97 * Turn function tracing on and off
99 * Don't enable trace if it has not been initialised.
101 * @param enabled 1 to enable trace, 0 to disable
103 void trace_set_enabled(int enabled);
105 #ifdef CONFIG_TRACE_EARLY
106 int trace_early_init(void);
108 static inline int trace_early_init(void)
115 * Init the trace system
117 * This should be called after relocation with a suitably large buffer
118 * (typically as large as the U-Boot text area)
120 * @param buff Pointer to trace buffer
121 * @param buff_size Size of trace buffer
123 int trace_init(void *buff, size_t buff_size);