Simon Glass | b2e16a8 | 2013-06-11 11:14:39 -0700 | [diff] [blame] | 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 | |
| 20 | #ifndef __TRACE_H |
| 21 | #define __TRACE_H |
| 22 | |
| 23 | enum { |
| 24 | /* |
| 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. |
| 29 | * |
| 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. |
| 33 | * |
| 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 |
| 37 | * this value. |
| 38 | */ |
| 39 | FUNC_SITE_SIZE = 4, /* distance between function sites */ |
| 40 | }; |
| 41 | |
| 42 | enum trace_chunk_type { |
| 43 | TRACE_CHUNK_FUNCS, |
| 44 | TRACE_CHUNK_CALLS, |
| 45 | }; |
| 46 | |
| 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 */ |
| 51 | }; |
| 52 | |
| 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 */ |
| 57 | }; |
| 58 | |
| 59 | /* Print statistics about traced function calls */ |
| 60 | void trace_print_stats(void); |
| 61 | |
| 62 | /** |
| 63 | * Dump a list of functions and call counts into a buffer |
| 64 | * |
| 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. |
| 68 | * |
| 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) |
| 73 | */ |
| 74 | int trace_list_functions(void *buff, int buff_size, unsigned *needed); |
| 75 | |
| 76 | /* Flags for ftrace_record */ |
| 77 | enum ftrace_flags { |
| 78 | FUNCF_EXIT = 0UL << 30, |
| 79 | FUNCF_ENTRY = 1UL << 30, |
| 80 | FUNCF_TEXTBASE = 2UL << 30, |
| 81 | |
| 82 | FUNCF_TIMESTAMP_MASK = 0x3fffffff, |
| 83 | }; |
| 84 | |
| 85 | #define TRACE_CALL_TYPE(call) ((call)->flags & 0xc0000000UL) |
| 86 | |
| 87 | /* Information about a single function entry/exit */ |
| 88 | struct trace_call { |
| 89 | uint32_t func; /* Function offset */ |
| 90 | uint32_t caller; /* Caller function offset */ |
| 91 | uint32_t flags; /* Flags and timestamp */ |
| 92 | }; |
| 93 | |
| 94 | int trace_list_calls(void *buff, int buff_size, unsigned int *needed); |
| 95 | |
| 96 | /** |
| 97 | * Turn function tracing on and off |
| 98 | * |
| 99 | * Don't enable trace if it has not been initialised. |
| 100 | * |
| 101 | * @param enabled 1 to enable trace, 0 to disable |
| 102 | */ |
| 103 | void trace_set_enabled(int enabled); |
| 104 | |
| 105 | #ifdef CONFIG_TRACE_EARLY |
| 106 | int trace_early_init(void); |
| 107 | #else |
| 108 | static inline int trace_early_init(void) |
| 109 | { |
| 110 | return 0; |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | /** |
| 115 | * Init the trace system |
| 116 | * |
| 117 | * This should be called after relocation with a suitably large buffer |
| 118 | * (typically as large as the U-Boot text area) |
| 119 | * |
| 120 | * @param buff Pointer to trace buffer |
| 121 | * @param buff_size Size of trace buffer |
| 122 | */ |
| 123 | int trace_init(void *buff, size_t buff_size); |
| 124 | |
| 125 | #endif |