1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*-------------------------------------------------------------------------
15 *
16 * Created: H5FSdbg.c
17 * May 9 2006
18 * Quincey Koziol <koziol@hdfgroup.org>
19 *
20 * Purpose: Dump debugging information about a free space manager
21 *
22 *-------------------------------------------------------------------------
23 */
24
25 /****************/
26 /* Module Setup */
27 /****************/
28
29 #include "H5FSmodule.h" /* This source code file is part of the H5FS module */
30 #define H5HF_DEBUGGING /* Need access to fractal heap debugging routines */
31 #define H5MF_DEBUGGING /* Need access to file space debugging routines */
32
33
34 /***********/
35 /* Headers */
36 /***********/
37 #include "H5private.h" /* Generic Functions */
38 #include "H5Eprivate.h" /* Error handling */
39 #include "H5FSpkg.h" /* File free space */
40 #include "H5HFprivate.h" /* Fractal heaps */
41 #include "H5MFprivate.h" /* File memory management */
42
43
44 /****************/
45 /* Local Macros */
46 /****************/
47
48
49 /******************/
50 /* Local Typedefs */
51 /******************/
52
53
54 /********************/
55 /* Package Typedefs */
56 /********************/
57
58
59 /********************/
60 /* Local Prototypes */
61 /********************/
62
63
64 /*********************/
65 /* Package Variables */
66 /*********************/
67
68
69 /*****************************/
70 /* Library Private Variables */
71 /*****************************/
72
73
74 /*******************/
75 /* Local Variables */
76 /*******************/
77
78
79 /*-------------------------------------------------------------------------
80 * Function: H5FS_debug
81 *
82 * Purpose: Prints debugging info about a free space manager.
83 *
84 * Return: SUCCEED/FAIL
85 *
86 * Programmer: Quincey Koziol
87 * May 9 2006
88 *
89 *-------------------------------------------------------------------------
90 */
91 herr_t
H5FS_debug(H5F_t * f,haddr_t addr,FILE * stream,int indent,int fwidth)92 H5FS_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth)
93 {
94 H5FS_t *fspace = NULL; /* Free space header info */
95 H5FS_hdr_cache_ud_t cache_udata; /* User-data for cache callback */
96 herr_t ret_value = SUCCEED; /* Return value */
97
98 FUNC_ENTER_NOAPI(FAIL)
99
100 /*
101 * Check arguments.
102 */
103 HDassert(f);
104 HDassert(H5F_addr_defined(addr));
105 HDassert(stream);
106 HDassert(indent >= 0);
107 HDassert(fwidth >= 0);
108
109 /* Initialize user data for protecting the free space manager */
110 cache_udata.f = f;
111 cache_udata.nclasses = 0;
112 cache_udata.classes = NULL;
113 cache_udata.cls_init_udata = NULL;
114 cache_udata.addr = addr;
115
116 /*
117 * Load the free space header.
118 */
119 if(NULL == (fspace = (H5FS_t *)H5AC_protect(f, H5AC_FSPACE_HDR, addr, &cache_udata, H5AC__READ_ONLY_FLAG)))
120 HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, FAIL, "unable to load free space header")
121
122 /* Print opening message */
123 HDfprintf(stream, "%*sFree Space Header...\n", indent, "");
124
125 /*
126 * Print the values.
127 */
128 HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
129 "Free space client:",
130 (fspace->client == H5FS_CLIENT_FHEAP_ID ? "Fractal heap" :
131 (fspace->client == H5FS_CLIENT_FILE_ID ? "File" : "Unknown")));
132 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
133 "Total free space tracked:",
134 fspace->tot_space);
135 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
136 "Total number of free space sections tracked:",
137 fspace->tot_sect_count);
138 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
139 "Number of serializable free space sections tracked:",
140 fspace->serial_sect_count);
141 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
142 "Number of ghost free space sections tracked:",
143 fspace->ghost_sect_count);
144 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
145 "Number of free space section classes:",
146 (unsigned)fspace->nclasses);
147 HDfprintf(stream, "%*s%-*s %u%%\n", indent, "", fwidth,
148 "Shrink percent:",
149 fspace->shrink_percent);
150 HDfprintf(stream, "%*s%-*s %u%%\n", indent, "", fwidth,
151 "Expand percent:",
152 fspace->expand_percent);
153 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
154 "# of bits for section address space:",
155 fspace->max_sect_addr);
156 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
157 "Maximum section size:",
158 fspace->max_sect_size);
159 HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
160 "Serialized sections address:",
161 fspace->sect_addr);
162 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
163 "Serialized sections size used:",
164 fspace->sect_size);
165 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
166 "Serialized sections size allocated:",
167 fspace->alloc_sect_size);
168
169 done:
170 if(fspace && H5AC_unprotect(f, H5AC_FSPACE_HDR, addr, fspace, H5AC__NO_FLAGS_SET) < 0)
171 HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
172
173 FUNC_LEAVE_NOAPI(ret_value)
174 } /* end H5FS_debug() */
175
176
177 /*-------------------------------------------------------------------------
178 * Function: H5FS_sect_debug
179 *
180 * Purpose: Prints debugging info about a free space section.
181 *
182 * Return: SUCCEED/FAIL
183 *
184 * Programmer: Quincey Koziol
185 * May 30 2006
186 *
187 *-------------------------------------------------------------------------
188 */
189 herr_t
H5FS_sect_debug(const H5FS_t * fspace,const H5FS_section_info_t * sect,FILE * stream,int indent,int fwidth)190 H5FS_sect_debug(const H5FS_t *fspace, const H5FS_section_info_t *sect, FILE *stream, int indent, int fwidth)
191 {
192 herr_t ret_value = SUCCEED; /* Return value */
193
194 FUNC_ENTER_NOAPI(FAIL)
195
196 /*
197 * Check arguments.
198 */
199 HDassert(fspace);
200 HDassert(sect);
201 HDassert(stream);
202 HDassert(indent >= 0);
203 HDassert(fwidth >= 0);
204
205 /* Call the section's debugging routine */
206 if(fspace->sect_cls[sect->type].debug)
207 if((fspace->sect_cls[sect->type].debug)(sect, stream, indent, fwidth) < 0)
208 HGOTO_ERROR(H5E_FSPACE, H5E_BADITER, FAIL, "can't dump section's debugging info")
209
210 done:
211 FUNC_LEAVE_NOAPI(ret_value)
212 } /* end H5FS_sect_debug() */
213
214
215 /*-------------------------------------------------------------------------
216 * Function: H5FS_sects_debug
217 *
218 * Purpose: Prints debugging info about the free space sections.
219 *
220 * Return: SUCCEED/FAIL
221 *
222 * Programmer: Quincey Koziol
223 * May 9 2006
224 *
225 *-------------------------------------------------------------------------
226 */
227 herr_t
H5FS_sects_debug(H5F_t * f,haddr_t H5_ATTR_UNUSED addr,FILE * stream,int indent,int fwidth,haddr_t fs_addr,haddr_t client_addr)228 H5FS_sects_debug(H5F_t *f, haddr_t H5_ATTR_UNUSED addr, FILE *stream, int indent, int fwidth,
229 haddr_t fs_addr, haddr_t client_addr)
230 {
231 H5FS_t *fspace = NULL; /* Free space header info */
232 H5FS_client_t client; /* The client of the free space */
233 H5FS_hdr_cache_ud_t cache_udata; /* User-data for cache callback */
234 herr_t ret_value = SUCCEED; /* Return value */
235
236 FUNC_ENTER_NOAPI(FAIL)
237
238 /*
239 * Check arguments.
240 */
241 HDassert(f);
242 HDassert(H5F_addr_defined(addr));
243 HDassert(stream);
244 HDassert(indent >= 0);
245 HDassert(fwidth >= 0);
246 HDassert(H5F_addr_defined(fs_addr));
247 HDassert(H5F_addr_defined(client_addr));
248
249 /* Initialize user data for protecting the free space manager */
250 cache_udata.f = f;
251 cache_udata.nclasses = 0;
252 cache_udata.classes = NULL;
253 cache_udata.cls_init_udata = NULL;
254 cache_udata.addr = fs_addr;
255
256 /*
257 * Load the free space header.
258 */
259 if(NULL == (fspace = (H5FS_t *)H5AC_protect(f, H5AC_FSPACE_HDR, fs_addr, &cache_udata, H5AC__READ_ONLY_FLAG)))
260 HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, FAIL, "unable to load free space header")
261
262 /* Retrieve the client id */
263 client = fspace->client;
264
265 /* Release the free space header */
266 /* (set the "deleted" flag for the unprotect, so the cache entry is removed
267 * and reloaded later, with the correct client information -QAK)
268 */
269 if(H5AC_unprotect(f, H5AC_FSPACE_HDR, fs_addr, fspace, H5AC__DELETED_FLAG) < 0)
270 HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
271 fspace = NULL;
272
273 /* Print opening message */
274 HDfprintf(stream, "%*sFree Space Sections...\n", indent, "");
275
276 /*
277 * Print the values.
278 */
279 switch(client) {
280 case H5FS_CLIENT_FHEAP_ID:
281 if(H5HF_sects_debug(f, client_addr, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
282 HGOTO_ERROR(H5E_FSPACE, H5E_SYSTEM, FAIL, "unable to dump fractal heap free space sections")
283 break;
284
285 case H5FS_CLIENT_FILE_ID:
286 if(H5MF_sects_debug(f, fs_addr, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
287 HGOTO_ERROR(H5E_FSPACE, H5E_SYSTEM, FAIL, "unable to dump file free space sections")
288 break;
289
290 case H5FS_NUM_CLIENT_ID:
291 default:
292 HDfprintf(stream, "Unknown client!\n");
293 break;
294 } /* end switch */
295
296 done:
297 if(fspace && H5AC_unprotect(f, H5AC_FSPACE_HDR, fs_addr, fspace, H5AC__NO_FLAGS_SET) < 0)
298 HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
299
300 FUNC_LEAVE_NOAPI(ret_value)
301 } /* end H5FS_sects_debug() */
302
303