Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
platform/mbed_mem_trace.h@167:1657b442184c, 2017-06-29 (annotated)
- Committer:
- thedo
- Date:
- Thu Jun 29 11:01:39 2017 +0000
- Revision:
- 167:1657b442184c
Opencv 3.1 project on GR-PEACH board, 4 apps
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 167:1657b442184c | 1 | |
thedo | 167:1657b442184c | 2 | /** \addtogroup platform */ |
thedo | 167:1657b442184c | 3 | /** @{*/ |
thedo | 167:1657b442184c | 4 | /* mbed Microcontroller Library |
thedo | 167:1657b442184c | 5 | * Copyright (c) 2006-2016 ARM Limited |
thedo | 167:1657b442184c | 6 | * |
thedo | 167:1657b442184c | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 167:1657b442184c | 8 | * you may not use this file except in compliance with the License. |
thedo | 167:1657b442184c | 9 | * You may obtain a copy of the License at |
thedo | 167:1657b442184c | 10 | * |
thedo | 167:1657b442184c | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 167:1657b442184c | 12 | * |
thedo | 167:1657b442184c | 13 | * Unless required by applicable law or agreed to in writing, software |
thedo | 167:1657b442184c | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 167:1657b442184c | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 167:1657b442184c | 16 | * See the License for the specific language governing permissions and |
thedo | 167:1657b442184c | 17 | * limitations under the License. |
thedo | 167:1657b442184c | 18 | */ |
thedo | 167:1657b442184c | 19 | |
thedo | 167:1657b442184c | 20 | #ifndef __MBED_MEM_TRACE_H__ |
thedo | 167:1657b442184c | 21 | #define __MBED_MEM_TRACE_H__ |
thedo | 167:1657b442184c | 22 | |
thedo | 167:1657b442184c | 23 | #ifdef __cplusplus |
thedo | 167:1657b442184c | 24 | extern "C" { |
thedo | 167:1657b442184c | 25 | #endif |
thedo | 167:1657b442184c | 26 | |
thedo | 167:1657b442184c | 27 | #include <stdint.h> |
thedo | 167:1657b442184c | 28 | #include <stddef.h> |
thedo | 167:1657b442184c | 29 | |
thedo | 167:1657b442184c | 30 | /* Operation types for tracer */ |
thedo | 167:1657b442184c | 31 | enum { |
thedo | 167:1657b442184c | 32 | MBED_MEM_TRACE_MALLOC, |
thedo | 167:1657b442184c | 33 | MBED_MEM_TRACE_REALLOC, |
thedo | 167:1657b442184c | 34 | MBED_MEM_TRACE_CALLOC, |
thedo | 167:1657b442184c | 35 | MBED_MEM_TRACE_FREE |
thedo | 167:1657b442184c | 36 | }; |
thedo | 167:1657b442184c | 37 | |
thedo | 167:1657b442184c | 38 | /* Prefix for the output of the default tracer */ |
thedo | 167:1657b442184c | 39 | #define MBED_MEM_DEFAULT_TRACER_PREFIX "#" |
thedo | 167:1657b442184c | 40 | |
thedo | 167:1657b442184c | 41 | /** |
thedo | 167:1657b442184c | 42 | * Type of the callback used by the memory tracer. This callback is called when a memory |
thedo | 167:1657b442184c | 43 | * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled |
thedo | 167:1657b442184c | 44 | * for that memory allocation function. |
thedo | 167:1657b442184c | 45 | * |
thedo | 167:1657b442184c | 46 | * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC, |
thedo | 167:1657b442184c | 47 | * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE). |
thedo | 167:1657b442184c | 48 | * @param res the result that the memory operation returned (NULL for 'free'). |
thedo | 167:1657b442184c | 49 | * @param caller the caller of the memory operation. Note that the value of 'caller' might be |
thedo | 167:1657b442184c | 50 | * unreliable. |
thedo | 167:1657b442184c | 51 | * |
thedo | 167:1657b442184c | 52 | * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations |
thedo | 167:1657b442184c | 53 | * that triggered its call (see 'man malloc' for details): |
thedo | 167:1657b442184c | 54 | * |
thedo | 167:1657b442184c | 55 | * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size). |
thedo | 167:1657b442184c | 56 | * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size). |
thedo | 167:1657b442184c | 57 | * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size). |
thedo | 167:1657b442184c | 58 | * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr). |
thedo | 167:1657b442184c | 59 | */ |
thedo | 167:1657b442184c | 60 | typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...); |
thedo | 167:1657b442184c | 61 | |
thedo | 167:1657b442184c | 62 | /** |
thedo | 167:1657b442184c | 63 | * Set the callback used by the memory tracer (use NULL for disable tracing). |
thedo | 167:1657b442184c | 64 | * |
thedo | 167:1657b442184c | 65 | * @param cb the callback to call on each memory operation. |
thedo | 167:1657b442184c | 66 | */ |
thedo | 167:1657b442184c | 67 | void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb); |
thedo | 167:1657b442184c | 68 | |
thedo | 167:1657b442184c | 69 | /** |
thedo | 167:1657b442184c | 70 | * Trace a call to 'malloc'. |
thedo | 167:1657b442184c | 71 | * @param res the result of running 'malloc'. |
thedo | 167:1657b442184c | 72 | * @param size the 'size' argument given to 'malloc'. |
thedo | 167:1657b442184c | 73 | * @param caller the caller of the memory operation. |
thedo | 167:1657b442184c | 74 | * @return 'res' (the first argument). |
thedo | 167:1657b442184c | 75 | */ |
thedo | 167:1657b442184c | 76 | void *mbed_mem_trace_malloc(void *res, size_t size, void *caller); |
thedo | 167:1657b442184c | 77 | |
thedo | 167:1657b442184c | 78 | /** |
thedo | 167:1657b442184c | 79 | * Trace a call to 'realloc'. |
thedo | 167:1657b442184c | 80 | * @param res the result of running 'realloc'. |
thedo | 167:1657b442184c | 81 | * @param ptr the 'ptr' argument given to 'realloc'. |
thedo | 167:1657b442184c | 82 | * @param size the 'size' argument given to 'realloc'. |
thedo | 167:1657b442184c | 83 | * @param caller the caller of the memory operation. |
thedo | 167:1657b442184c | 84 | * @return 'res' (the first argument). |
thedo | 167:1657b442184c | 85 | */ |
thedo | 167:1657b442184c | 86 | void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller); |
thedo | 167:1657b442184c | 87 | |
thedo | 167:1657b442184c | 88 | /** |
thedo | 167:1657b442184c | 89 | * Trace a call to 'calloc'. |
thedo | 167:1657b442184c | 90 | * @param res the result of running 'calloc'. |
thedo | 167:1657b442184c | 91 | * @param num the 'nmemb' argument given to 'calloc'. |
thedo | 167:1657b442184c | 92 | * @param size the 'size' argument given to 'calloc'. |
thedo | 167:1657b442184c | 93 | * @param caller the caller of the memory operation. |
thedo | 167:1657b442184c | 94 | * @return 'res' (the first argument). |
thedo | 167:1657b442184c | 95 | */ |
thedo | 167:1657b442184c | 96 | void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller); |
thedo | 167:1657b442184c | 97 | |
thedo | 167:1657b442184c | 98 | /** |
thedo | 167:1657b442184c | 99 | * Trace a call to 'free'. |
thedo | 167:1657b442184c | 100 | * @param ptr the 'ptr' argument given to 'free'. |
thedo | 167:1657b442184c | 101 | * @param caller the caller of the memory operation. |
thedo | 167:1657b442184c | 102 | */ |
thedo | 167:1657b442184c | 103 | void mbed_mem_trace_free(void *ptr, void *caller); |
thedo | 167:1657b442184c | 104 | |
thedo | 167:1657b442184c | 105 | /** |
thedo | 167:1657b442184c | 106 | * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used |
thedo | 167:1657b442184c | 107 | * as the second argument of 'mbed_mem_trace_setup'. |
thedo | 167:1657b442184c | 108 | * |
thedo | 167:1657b442184c | 109 | * The default callback outputs trace data using 'printf', in a format that's |
thedo | 167:1657b442184c | 110 | * easily parsable by an external tool. For each memory operation, the callback |
thedo | 167:1657b442184c | 111 | * outputs a line that begins with "#<op>:<0xresult>;<0xcaller>-": |
thedo | 167:1657b442184c | 112 | * |
thedo | 167:1657b442184c | 113 | * - 'op' identifies the memory operation ('m' for 'malloc', 'r' for 'realloc', |
thedo | 167:1657b442184c | 114 | * 'c' for 'calloc' and 'f' for 'free'). |
thedo | 167:1657b442184c | 115 | * - 'result' (base 16) is the result of the memor operation. This is always NULL |
thedo | 167:1657b442184c | 116 | * for 'free', since 'free' doesn't return anything. |
thedo | 167:1657b442184c | 117 | * - 'caller' (base 16) is the caller of the memory operation. Note that the value |
thedo | 167:1657b442184c | 118 | * of 'caller' might be unreliable. |
thedo | 167:1657b442184c | 119 | * |
thedo | 167:1657b442184c | 120 | * The rest of the output depends on the operation being traced: |
thedo | 167:1657b442184c | 121 | * |
thedo | 167:1657b442184c | 122 | * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'. |
thedo | 167:1657b442184c | 123 | * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'. |
thedo | 167:1657b442184c | 124 | * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'. |
thedo | 167:1657b442184c | 125 | * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'. |
thedo | 167:1657b442184c | 126 | * |
thedo | 167:1657b442184c | 127 | * Examples: |
thedo | 167:1657b442184c | 128 | * |
thedo | 167:1657b442184c | 129 | * - "#m:0x20003240;0x600d-50" encodes a 'malloc' that returned 0x20003240, was called |
thedo | 167:1657b442184c | 130 | * by the instruction at 0x600D with a the 'size' argument equal to 50. |
thedo | 167:1657b442184c | 131 | * - "#f:0x0;0x602f-0x20003240" encodes a 'free' that was called by the instruction at |
thedo | 167:1657b442184c | 132 | * 0x602f with the 'ptr' argument equal to 0x20003240. |
thedo | 167:1657b442184c | 133 | */ |
thedo | 167:1657b442184c | 134 | void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...); |
thedo | 167:1657b442184c | 135 | |
thedo | 167:1657b442184c | 136 | #ifdef __cplusplus |
thedo | 167:1657b442184c | 137 | } |
thedo | 167:1657b442184c | 138 | #endif |
thedo | 167:1657b442184c | 139 | |
thedo | 167:1657b442184c | 140 | #endif// #ifndef __MBED_MEM_TRACE_H__ |
thedo | 167:1657b442184c | 141 | |
thedo | 167:1657b442184c | 142 | |
thedo | 167:1657b442184c | 143 | /** @}*/ |
thedo | 167:1657b442184c | 144 |