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://www.hdfgroup.org/licenses.               *
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
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 /* Headers */
35 /***********/
36 #include "H5private.h"   /* Generic Functions                            */
37 #include "H5Eprivate.h"  /* Error handling                               */
38 #include "H5FSpkg.h"     /* File free space                              */
39 #include "H5HFprivate.h" /* Fractal heaps                                */
40 #include "H5MFprivate.h" /* File memory management                       */
41 
42 /****************/
43 /* Local Macros */
44 /****************/
45 
46 /******************/
47 /* Local Typedefs */
48 /******************/
49 
50 /********************/
51 /* Package Typedefs */
52 /********************/
53 
54 /********************/
55 /* Local Prototypes */
56 /********************/
57 
58 /*********************/
59 /* Package Variables */
60 /*********************/
61 
62 /*****************************/
63 /* Library Private Variables */
64 /*****************************/
65 
66 /*******************/
67 /* Local Variables */
68 /*******************/
69 
70 /*-------------------------------------------------------------------------
71  * Function:    H5FS_debug
72  *
73  * Purpose:     Prints debugging info about a free space manager.
74  *
75  * Return:      SUCCEED/FAIL
76  *
77  * Programmer:  Quincey Koziol
78  *              May  9 2006
79  *
80  *-------------------------------------------------------------------------
81  */
82 herr_t
H5FS_debug(H5F_t * f,haddr_t addr,FILE * stream,int indent,int fwidth)83 H5FS_debug(H5F_t *f, haddr_t addr, FILE *stream, int indent, int fwidth)
84 {
85     H5FS_t *            fspace = NULL;       /* Free space header info */
86     H5FS_hdr_cache_ud_t cache_udata;         /* User-data for cache callback */
87     herr_t              ret_value = SUCCEED; /* Return value */
88 
89     FUNC_ENTER_NOAPI(FAIL)
90 
91     /*
92      * Check arguments.
93      */
94     HDassert(f);
95     HDassert(H5F_addr_defined(addr));
96     HDassert(stream);
97     HDassert(indent >= 0);
98     HDassert(fwidth >= 0);
99 
100     /* Initialize user data for protecting the free space manager */
101     cache_udata.f              = f;
102     cache_udata.nclasses       = 0;
103     cache_udata.classes        = NULL;
104     cache_udata.cls_init_udata = NULL;
105     cache_udata.addr           = addr;
106 
107     /*
108      * Load the free space header.
109      */
110     if (NULL ==
111         (fspace = (H5FS_t *)H5AC_protect(f, H5AC_FSPACE_HDR, addr, &cache_udata, H5AC__READ_ONLY_FLAG)))
112         HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, FAIL, "unable to load free space header")
113 
114     /* Print opening message */
115     HDfprintf(stream, "%*sFree Space Header...\n", indent, "");
116 
117     /*
118      * Print the values.
119      */
120     HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth, "Free space client:",
121               (fspace->client == H5FS_CLIENT_FHEAP_ID
122                    ? "Fractal heap"
123                    : (fspace->client == H5FS_CLIENT_FILE_ID ? "File" : "Unknown")));
124     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
125               "Total free space tracked:", fspace->tot_space);
126     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
127               "Total number of free space sections tracked:", fspace->tot_sect_count);
128     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
129               "Number of serializable free space sections tracked:", fspace->serial_sect_count);
130     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
131               "Number of ghost free space sections tracked:", fspace->ghost_sect_count);
132     HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
133               "Number of free space section classes:", (unsigned)fspace->nclasses);
134     HDfprintf(stream, "%*s%-*s %u%%\n", indent, "", fwidth, "Shrink percent:", fspace->shrink_percent);
135     HDfprintf(stream, "%*s%-*s %u%%\n", indent, "", fwidth, "Expand percent:", fspace->expand_percent);
136     HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
137               "# of bits for section address space:", fspace->max_sect_addr);
138     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
139               "Maximum section size:", fspace->max_sect_size);
140     HDfprintf(stream, "%*s%-*s %" PRIuHADDR "\n", indent, "", fwidth,
141               "Serialized sections address:", fspace->sect_addr);
142     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
143               "Serialized sections size used:", fspace->sect_size);
144     HDfprintf(stream, "%*s%-*s %" PRIuHSIZE "\n", indent, "", fwidth,
145               "Serialized sections size allocated:", fspace->alloc_sect_size);
146 
147 done:
148     if (fspace && H5AC_unprotect(f, H5AC_FSPACE_HDR, addr, fspace, H5AC__NO_FLAGS_SET) < 0)
149         HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
150 
151     FUNC_LEAVE_NOAPI(ret_value)
152 } /* end H5FS_debug() */
153 
154 /*-------------------------------------------------------------------------
155  * Function:    H5FS_sect_debug
156  *
157  * Purpose:     Prints debugging info about a free space section.
158  *
159  * Return:      SUCCEED/FAIL
160  *
161  * Programmer:  Quincey Koziol
162  *              May 30 2006
163  *
164  *-------------------------------------------------------------------------
165  */
166 herr_t
H5FS_sect_debug(const H5FS_t * fspace,const H5FS_section_info_t * sect,FILE * stream,int indent,int fwidth)167 H5FS_sect_debug(const H5FS_t *fspace, const H5FS_section_info_t *sect, FILE *stream, int indent, int fwidth)
168 {
169     herr_t ret_value = SUCCEED; /* Return value */
170 
171     FUNC_ENTER_NOAPI(FAIL)
172 
173     /*
174      * Check arguments.
175      */
176     HDassert(fspace);
177     HDassert(sect);
178     HDassert(stream);
179     HDassert(indent >= 0);
180     HDassert(fwidth >= 0);
181 
182     /* Call the section's debugging routine */
183     if (fspace->sect_cls[sect->type].debug)
184         if ((fspace->sect_cls[sect->type].debug)(sect, stream, indent, fwidth) < 0)
185             HGOTO_ERROR(H5E_FSPACE, H5E_BADITER, FAIL, "can't dump section's debugging info")
186 
187 done:
188     FUNC_LEAVE_NOAPI(ret_value)
189 } /* end H5FS_sect_debug() */
190 
191 /*-------------------------------------------------------------------------
192  * Function:    H5FS_sects_debug
193  *
194  * Purpose:     Prints debugging info about the free space sections.
195  *
196  * Return:      SUCCEED/FAIL
197  *
198  * Programmer:  Quincey Koziol
199  *              May  9 2006
200  *
201  *-------------------------------------------------------------------------
202  */
203 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)204 H5FS_sects_debug(H5F_t *f, haddr_t H5_ATTR_UNUSED addr, FILE *stream, int indent, int fwidth, haddr_t fs_addr,
205                  haddr_t client_addr)
206 {
207     H5FS_t *            fspace = NULL;       /* Free space header info */
208     H5FS_client_t       client;              /* The client of the free space */
209     H5FS_hdr_cache_ud_t cache_udata;         /* User-data for cache callback */
210     herr_t              ret_value = SUCCEED; /* Return value */
211 
212     FUNC_ENTER_NOAPI(FAIL)
213 
214     /*
215      * Check arguments.
216      */
217     HDassert(f);
218     HDassert(H5F_addr_defined(addr));
219     HDassert(stream);
220     HDassert(indent >= 0);
221     HDassert(fwidth >= 0);
222     HDassert(H5F_addr_defined(fs_addr));
223     HDassert(H5F_addr_defined(client_addr));
224 
225     /* Initialize user data for protecting the free space manager */
226     cache_udata.f              = f;
227     cache_udata.nclasses       = 0;
228     cache_udata.classes        = NULL;
229     cache_udata.cls_init_udata = NULL;
230     cache_udata.addr           = fs_addr;
231 
232     /*
233      * Load the free space header.
234      */
235     if (NULL ==
236         (fspace = (H5FS_t *)H5AC_protect(f, H5AC_FSPACE_HDR, fs_addr, &cache_udata, H5AC__READ_ONLY_FLAG)))
237         HGOTO_ERROR(H5E_FSPACE, H5E_CANTLOAD, FAIL, "unable to load free space header")
238 
239     /* Retrieve the client id */
240     client = fspace->client;
241 
242     /* Release the free space header */
243     /* (set the "deleted" flag for the unprotect, so the cache entry is removed
244      *  and reloaded later, with the correct client information -QAK)
245      */
246     if (H5AC_unprotect(f, H5AC_FSPACE_HDR, fs_addr, fspace, H5AC__DELETED_FLAG) < 0)
247         HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
248     fspace = NULL;
249 
250     /* Print opening message */
251     HDfprintf(stream, "%*sFree Space Sections...\n", indent, "");
252 
253     /*
254      * Print the values.
255      */
256     switch (client) {
257         case H5FS_CLIENT_FHEAP_ID:
258             if (H5HF_sects_debug(f, client_addr, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
259                 HGOTO_ERROR(H5E_FSPACE, H5E_SYSTEM, FAIL, "unable to dump fractal heap free space sections")
260             break;
261 
262         case H5FS_CLIENT_FILE_ID:
263             if (H5MF_sects_debug(f, fs_addr, stream, indent + 3, MAX(0, fwidth - 3)) < 0)
264                 HGOTO_ERROR(H5E_FSPACE, H5E_SYSTEM, FAIL, "unable to dump file free space sections")
265             break;
266 
267         case H5FS_NUM_CLIENT_ID:
268         default:
269             HDfprintf(stream, "Unknown client!\n");
270             break;
271     } /* end switch */
272 
273 done:
274     if (fspace && H5AC_unprotect(f, H5AC_FSPACE_HDR, fs_addr, fspace, H5AC__NO_FLAGS_SET) < 0)
275         HDONE_ERROR(H5E_FSPACE, H5E_PROTECT, FAIL, "unable to release free space header")
276 
277     FUNC_LEAVE_NOAPI(ret_value)
278 } /* end H5FS_sects_debug() */
279