mem_measure_tool.h (5833B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * This file defines memory measurement tool constants and functions. 8 */ 9 10 #ifndef _MEMORY_MEASUREMENT_TOOL 11 #define _MEMORY_MEASUREMENT_TOOL 12 13 #include <sal/core/thread.h> 14 #include <sal/types.h> 15 #include <sal/core/libc.h> 16 #include <shared/bsl.h> 17 18 #define MEMORY_MEASUREMENT_DIAGNOSTICS_PRINT 1 19 20 #define MEMORY_MEASUREMENT_ELEMENTS_MAX_NUM 100 21 #define MEMORY_MEASUREMENT_ID_MAX_LENGTH 256 22 23 #define MEMORY_MEASUREMENT_INITIALIZE do { \ 24 if(!memory_measurement_tool_initialized) { \ 25 memory_measurement_tool_init(); \ 26 memory_measurement_tool_initialized = 1; \ 27 } \ 28 } while(0) 29 30 typedef struct memory_measurement_element_s { 31 char id[MEMORY_MEASUREMENT_ID_MAX_LENGTH]; 32 uint8 is_active; 33 uint32 sal_size; 34 uint32 sw_state_size; 35 sal_thread_t thread_id; 36 } memory_measurement_element_t; 37 38 typedef struct memory_measurement_tool_s { 39 int count; 40 memory_measurement_element_t elements[MEMORY_MEASUREMENT_ELEMENTS_MAX_NUM]; 41 } memory_measurement_tool_t; 42 43 typedef struct memory_measurement_element_dnx_s { 44 /** ID of the measurment element, used as handle */ 45 char id[MEMORY_MEASUREMENT_ID_MAX_LENGTH]; 46 /** Indicates weather the measurment element is currently active */ 47 uint8 is_active; 48 /** Holds the size of the memory allocated for the current measurment element */ 49 uint32 dnx_sw_state_size_alloc; 50 /** Holds the size of the memory freed for the current measurment element */ 51 uint32 dnx_sw_state_size_free; 52 /** Holds the thread ID. Memory measurement is done only on the calling thread*/ 53 sal_thread_t thread_id; 54 } memory_measurement_element_dnx_t; 55 56 typedef struct memory_measurement_tool_dnx_s { 57 /** Number of the measurment elements */ 58 int count; 59 memory_measurement_element_dnx_t elements[MEMORY_MEASUREMENT_ELEMENTS_MAX_NUM]; 60 } memory_measurement_tool_dnx_t; 61 62 extern int memory_measurement_tool_initialized; 63 extern memory_measurement_tool_t memory_measurement_tool; 64 extern int memory_consumption_start_measurement(char *str); 65 extern int memory_consumption_pause_measurement(char *str); 66 extern int memory_consumption_end_measurement(char *str); 67 extern uint32 memory_consumption_measurement_get_sal_size(char *str); 68 extern int memory_measurement_print(char *str); 69 extern void memory_measurement_tool_init(void); 70 71 /* 72 * Static structure that holds the information from the memory measurement tool 73 */ 74 extern memory_measurement_tool_dnx_t memory_measurement_tool_dnx; 75 76 /** 77 * \brief - Function to start a measurement in the memory measurement tool. The memory measurement tool works on a stop-watch basis, meaning that measurements can be started and ended. 78 * The actual memory value is the amount allocated/freed for SW state inbetween the start and end functions. 79 * 80 * \par DIRECT_INPUT: 81 * \param [in] str - Measurement element ID. 82 * 83 * \par INDIRECT INPUT: 84 * * None 85 * \par DIRECT OUTPUT: 86 * shr_error_e 87 * \par INDIRECT OUTPUT 88 * * None 89 * \remark 90 * * None 91 * \see 92 * * None 93 */ 94 extern int memory_consumption_start_measurement_dnx(char *str); 95 96 /** 97 * \brief - Function to end measurement in the memory measurement tool. The memory measurement tool works on a stop-watch basis, meaning that measurements can be started and ended. 98 * The actual memory value is the amount allocated/freed for SW state inbetween the start and end functions. 99 * 100 * \par DIRECT_INPUT: 101 * \param [in] str - Measurement element ID. 102 * 103 * \par INDIRECT INPUT: 104 * * None 105 * \par DIRECT OUTPUT: 106 * shr_error_e 107 * \par INDIRECT OUTPUT 108 * * None 109 * \remark 110 * * None 111 * \see 112 * * None 113 */ 114 extern int memory_consumption_end_measurement_dnx(char *str); 115 116 /** 117 * \brief - Function to cleat the measurement entry in the memory measurement tool. The memory measurement tool works on a stop-watch basis, meaning that measurements can be started and ended. 118 * The actual memory value is the amount allocated/freed for SW state inbetween the start and end functions. 119 * 120 * \par DIRECT_INPUT: 121 * \param [in] str - Measurement element ID. 122 * 123 * \par INDIRECT INPUT: 124 * * None 125 * \par DIRECT OUTPUT: 126 * shr_error_e 127 * \par INDIRECT OUTPUT 128 * * None 129 * \remark 130 * * None 131 * \see 132 * * None 133 */ 134 extern int memory_consumption_clear_measurement_dnx(char *str); 135 136 /** 137 * \brief - Function to get the value of a specific measurement from the memory measurement tool 138 * 139 * \par DIRECT_INPUT: 140 * \param [in] str - Measurement element ID. 141 * \param [out] dnx_sw_state_size - size of the memory allocated for SW state for the specified measurement element in bytes. 142 * \param [in] is_alloc - indicates if we want to get the memory allocated or memory freed. 143 * 144 * \par INDIRECT INPUT: 145 * * None 146 * \par DIRECT OUTPUT: 147 * shr_error_e 148 * \par INDIRECT OUTPUT 149 * * None 150 * \remark 151 * * None 152 * \see 153 * * None 154 */ 155 extern int memory_measurement_dnx_sw_state_get(char *str, uint32 *dnx_sw_state_size, int is_alloc); 156 157 /** 158 * \brief - Function to sample the allocated size in bytes from the SW state memory allocation macro 159 * 160 * \par DIRECT_INPUT: 161 * \param [in] size - size of the memory allocated for SW state in bytes. 162 * \param [in] is_alloc - indicates if we want to get the memory allocated or memory freed. 163 * 164 * \par INDIRECT INPUT: 165 * * None 166 * \par DIRECT OUTPUT: 167 * None 168 * \par INDIRECT OUTPUT 169 * * None 170 * \remark 171 * * None 172 * \see 173 * * None 174 */ 175 extern void memory_measurement_dnx_sw_state_sample(uint32 size, int is_alloc); 176 177 #endif /* _MEMORY_MEASUREMENT_TOOL */