1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5HFdbg.c
* Feb 24 2006
* Quincey Koziol <koziol@ncsa.uiuc.edu>
*
* Purpose: Dump debugging information about a fractal heap
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#define H5HF_PACKAGE /*suppress error about including H5HFpkg */
#define H5HF_DEBUGGING /* Need access to fractal heap debugging routines */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free Lists */
#include "H5HFpkg.h" /* Fractal heaps */
#include "H5MMprivate.h" /* Memory management */
#include "H5Vprivate.h" /* Vectors and arrays */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/* User data for direct block debugging iterator callback */
typedef struct {
FILE *stream; /* Stream for output */
int indent; /* Indention amount */
int fwidth; /* Field width mount */
haddr_t dblock_addr; /* Direct block's address */
hsize_t dblock_size; /* Direct block's size */
uint8_t *marker; /* 'Marker' array for free space */
size_t sect_count; /* Number of free space sections in block */
size_t amount_free; /* Amount of free space in block */
} H5HF_debug_iter_ud1_t;
/* User data for free space section iterator callback */
typedef struct {
H5FS_t *fspace; /* Free space manager */
FILE *stream; /* Stream for output */
int indent; /* Indention amount */
int fwidth; /* Field width mount */
} H5HF_debug_iter_ud2_t;
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
static herr_t H5HF_dtable_debug(H5HF_dtable_t *dtable, FILE *stream,
int indent, int fwidth);
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5HF_dtable_debug
*
* Purpose: Prints debugging info about a doubling table
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Feb 28 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF_dtable_debug(H5HF_dtable_t *dtable, FILE *stream, int indent, int fwidth)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_dtable_debug)
/*
* Check arguments.
*/
HDassert(dtable);
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
/*
* Print the values.
*/
/* Creation parameter values */
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Doubling table width:",
dtable->cparam.width);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Starting block size:",
dtable->cparam.start_block_size);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Max. direct block size:",
dtable->cparam.max_direct_size);
HDfprintf(stream, "%*s%-*s %u (bits)\n", indent, "", fwidth,
"Max. index size:",
dtable->cparam.max_index);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Starting # of rows in root indirect block:",
dtable->cparam.start_root_rows);
/* Run-time varying parameter values */
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
"Table's root address:",
dtable->table_addr);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Current # of rows in root indirect block:",
dtable->curr_root_rows);
/* Computed values */
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Max. # of rows in root indirect block:",
dtable->max_root_rows);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Max. # of direct rows in any indirect block:",
dtable->max_direct_rows);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"# of bits for IDs in first row:",
dtable->first_row_bits);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"# of IDs in first row:",
dtable->num_id_first_row);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_dtable_debug() */
/*-------------------------------------------------------------------------
* Function: H5HF_hdr_debug
*
* Purpose: Prints debugging info about a fractal heap header.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Feb 24 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth)
{
H5HF_hdr_t *hdr = NULL; /* Fractal heap header info */
H5HF_hdr_cache_ud_t cache_udata; /* User-data for callback */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_hdr_debug, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
/* Set up user data for protect call */
cache_udata.f = f;
cache_udata.dxpl_id = dxpl_id;
/*
* Load the fractal heap header.
*/
if(NULL == (hdr = H5AC2_protect(f, dxpl_id, H5AC2_FHEAP_HDR, addr, (size_t)H5HF_SPEC_READ_SIZE(f), &cache_udata, H5AC2_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
/* Print opening message */
HDfprintf(stream, "%*sFractal Heap Header...\n", indent, "");
/*
* Print the values.
*/
HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
"Heap is:",
hdr->man_dtable.curr_root_rows > 0 ? "Indirect" : "Direct");
HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth,
"Objects stored in 'debugging' format:",
hdr->debug_objs);
HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth,
"'Write once' flag:",
hdr->write_once);
HDfprintf(stream, "%*s%-*s %t\n", indent, "", fwidth,
"'Huge' object IDs have wrapped:",
hdr->huge_ids_wrapped);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Free space in managed blocks:",
hdr->total_man_free);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Managed space data block size:",
hdr->man_size);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Total managed space allocated:",
hdr->man_alloc_size);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Offset of managed space iterator:",
hdr->man_iter_off);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Number of managed objects in heap:",
hdr->man_nobjs);
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
"Address of free space manager for managed blocks:",
hdr->fs_addr);
HDfprintf(stream, "%*s%-*s %lu\n", indent, "", fwidth,
"Max. size of managed object:",
(unsigned long)hdr->max_man_size);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"'Huge' object space used:",
hdr->huge_size);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Number of 'huge' objects in heap:",
hdr->huge_nobjs);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"ID of next 'huge' object:",
hdr->huge_next_id);
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
"Address of v2 B-tree for 'huge' objects:",
hdr->huge_bt2_addr);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"'Tiny' object space used:",
hdr->tiny_size);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Number of 'tiny' objects in heap:",
hdr->tiny_nobjs);
HDfprintf(stream, "%*sManaged Objects Doubling-Table Info...\n", indent, "");
H5HF_dtable_debug(&hdr->man_dtable, stream, indent + 3, MAX(0, fwidth - 3));
/* Print information about I/O filters */
if(hdr->filter_len > 0) {
HDfprintf(stream, "%*sI/O filter Info...\n", indent, "");
if(hdr->man_dtable.curr_root_rows == 0) {
HDfprintf(stream, "%*s%-*s %Zu\n", indent + 3, "", MAX(0, fwidth - 3),
"Compressed size of root direct block:",
hdr->pline_root_direct_size);
HDfprintf(stream, "%*s%-*s %x\n", indent + 3, "", MAX(0, fwidth - 3),
"Filter mask for root direct block:",
hdr->pline_root_direct_filter_mask);
} /* end if */
H5O_debug_id(H5O_PLINE_ID, f, dxpl_id, &(hdr->pline), stream,
indent + 3, MAX(0, fwidth - 3));
} /* end if */
done:
if(hdr && H5AC2_unprotect(f, dxpl_id, H5AC2_FHEAP_HDR, addr, (size_t)0, hdr, H5AC2__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_hdr_debug() */
/*-------------------------------------------------------------------------
* Function: H5HF_dblock_debug_cb
*
* Purpose: Detect free space within a direct block
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 13 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF_dblock_debug_cb(const H5FS_section_info_t *_sect, void *_udata)
{
const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Section to dump info */
H5HF_debug_iter_ud1_t *udata = (H5HF_debug_iter_ud1_t *)_udata; /* User data for callbacks */
haddr_t sect_start, sect_end; /* Section's beginning and ending offsets */
haddr_t dblock_start, dblock_end; /* Direct block's beginning and ending offsets */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5HF_dblock_debug_cb)
/*
* Check arguments.
*/
HDassert(sect);
HDassert(udata);
/* Set up some local variables, for convenience */
sect_start = sect->sect_info.addr;
sect_end = (sect->sect_info.addr + sect->sect_info.size) - 1;
HDassert(sect_end >= sect_start);
dblock_start = udata->dblock_addr;
dblock_end = (udata->dblock_addr + udata->dblock_size) - 1;
HDassert(dblock_end >= dblock_start);
/* Check for overlap between free space section & direct block */
if((sect_start <= dblock_end && sect_end >=dblock_start) || /* section within or overlaps w/beginning of direct block*/
(sect_start <= dblock_end && sect_end >=dblock_end)) { /* section overlaps w/end of direct block */
char temp_str[32]; /* Temporary string for formatting */
size_t start, end; /* Start & end of the overlapping area */
size_t len; /* Length of the overlapping area */
size_t overlap; /* Track any overlaps */
unsigned u; /* Local index variable */
/* Calculate the starting & ending */
if(sect_start < dblock_start)
start = 0;
else
H5_ASSIGN_OVERFLOW(/* To: */ start, /* From: */ (sect_start - dblock_start), /* From: */ hsize_t, /* To: */ size_t)
if(sect_end > dblock_end)
H5_ASSIGN_OVERFLOW(/* To: */ end, /* From: */ udata->dblock_size, /* From: */ hsize_t, /* To: */ size_t)
else
H5_ASSIGN_OVERFLOW(/* To: */ end, /* From: */ ((sect_end - dblock_start) + 1), /* From: */ hsize_t, /* To: */ size_t)
/* Calculate the length */
len = end - start;
sprintf(temp_str, "Section #%u:", (unsigned)udata->sect_count);
HDfprintf(udata->stream, "%*s%-*s %8Zu, %8Zu\n", udata->indent + 3, "", MAX(0, udata->fwidth - 9),
temp_str,
start, len);
udata->sect_count++;
/* Mark this node's free space & check for overlaps w/other sections */
overlap = 0;
for(u = start; u < end; u++) {
if(udata->marker[u])
overlap++;
udata->marker[u] = 1;
} /* end for */
/* Flag overlaps */
if (overlap)
fprintf(udata->stream, "***THAT FREE BLOCK OVERLAPPED A PREVIOUS ONE!\n");
else
udata->amount_free += len;
} /* end if */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5HF_dblock_debug_cb() */
/*-------------------------------------------------------------------------
* Function: H5HF_dblock_debug
*
* Purpose: Prints debugging info about a fractal heap direct block.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Feb 28 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_dblock_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream,
int indent, int fwidth, haddr_t hdr_addr, size_t block_size)
{
H5HF_hdr_t *hdr = NULL; /* Fractal heap header info */
H5HF_direct_t *dblock = NULL; /* Fractal heap direct block info */
H5HF_hdr_cache_ud_t cache_udata; /* User-data for callback */
size_t blk_prefix_size; /* Size of prefix for block */
size_t amount_free; /* Amount of free space in block */
uint8_t *marker = NULL; /* Track free space for block */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_dblock_debug, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
HDassert(H5F_addr_defined(hdr_addr));
HDassert(block_size > 0);
/* Set up user data for protect call */
cache_udata.f = f;
cache_udata.dxpl_id = dxpl_id;
/*
* Load the fractal heap header.
*/
if(NULL == (hdr = H5AC2_protect(f, dxpl_id, H5AC2_FHEAP_HDR, hdr_addr, (size_t)H5HF_SPEC_READ_SIZE(f), &cache_udata, H5AC2_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
/*
* Load the heap direct block
*/
if(NULL == (dblock = H5HF_man_dblock_protect(hdr, dxpl_id, addr, block_size, NULL, 0, H5AC2_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap direct block")
/* Print opening message */
HDfprintf(stream, "%*sFractal Heap Direct Block...\n", indent, "");
/*
* Print the values.
*/
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
"Address of fractal heap that owns this block:",
hdr->heap_addr);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Offset of direct block in heap:",
dblock->block_off);
blk_prefix_size = H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Size of block header:",
blk_prefix_size);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Size of block offsets:",
dblock->blk_off_size);
/* Allocate space for the free space markers */
if(NULL == (marker = H5MM_calloc(dblock->size)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
/* Initialize the free space information for the heap */
if(H5HF_space_start(hdr, dxpl_id, FALSE) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize heap free space")
/* If there is a free space manager for the heap, check for sections that overlap this block */
if(hdr->fspace) {
H5HF_debug_iter_ud1_t udata; /* User data for callbacks */
/* Prepare user data for section iteration callback */
udata.stream = stream;
udata.indent = indent;
udata.fwidth = fwidth;
udata.dblock_addr = dblock->block_off;
udata.dblock_size = block_size;
udata.marker = marker;
udata.sect_count = 0;
udata.amount_free = 0;
/* Print header */
HDfprintf(stream, "%*sFree Blocks (offset, size):\n", indent, "");
/* Iterate over the free space sections, to detect overlaps with this block */
if(H5FS_sect_iterate(f, dxpl_id, hdr->fspace, H5HF_dblock_debug_cb, &udata) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_BADITER, FAIL, "can't iterate over heap's free space")
/* Close the free space information */
if(H5HF_space_close(hdr, dxpl_id) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't release free space info")
/* Keep the amount of space free */
amount_free = udata.amount_free;
/* Check for no free space */
if(amount_free == 0)
HDfprintf(stream, "%*s<none>\n", indent + 3, "");
} /* end if */
else
amount_free = 0;
HDfprintf(stream, "%*s%-*s %.2f%%\n", indent, "", fwidth,
"Percent of available space for data used:",
(100.0 * (double)((dblock->size - blk_prefix_size) - amount_free) / (double)(dblock->size - blk_prefix_size)));
/*
* Print the data in a VMS-style octal dump.
*/
H5_buffer_dump(stream, indent, dblock->blk, marker, (size_t)0, dblock->size);
done:
if(dblock && H5AC2_unprotect(f, dxpl_id, H5AC2_FHEAP_DBLOCK, addr, (size_t)0, dblock, H5AC2__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap direct block")
if(hdr && H5AC2_unprotect(f, dxpl_id, H5AC2_FHEAP_HDR, hdr_addr, (size_t)0, hdr, H5AC2__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap header")
H5MM_xfree(marker);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_dblock_debug() */
/*-------------------------------------------------------------------------
* Function: H5HF_iblock_debug
*
* Purpose: Prints debugging info about a fractal heap indirect block.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Mar 7 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_iblock_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream,
int indent, int fwidth, haddr_t hdr_addr, unsigned nrows)
{
H5HF_hdr_t *hdr = NULL; /* Fractal heap header info */
H5HF_indirect_t *iblock = NULL; /* Fractal heap direct block info */
H5HF_hdr_cache_ud_t cache_udata; /* User-data for callback */
hbool_t did_protect; /* Whether we protected the indirect block or not */
char temp_str[64]; /* Temporary string, for formatting */
size_t u, v; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_iblock_debug, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(addr));
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
HDassert(H5F_addr_defined(hdr_addr));
HDassert(nrows > 0);
/* Set up user data for protect call */
cache_udata.f = f;
cache_udata.dxpl_id = dxpl_id;
/*
* Load the fractal heap header.
*/
if(NULL == (hdr = H5AC2_protect(f, dxpl_id, H5AC2_FHEAP_HDR, hdr_addr, (size_t)H5HF_SPEC_READ_SIZE(f), &cache_udata, H5AC2_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
/*
* Load the heap indirect block
*/
if(NULL == (iblock = H5HF_man_iblock_protect(hdr, dxpl_id, addr, nrows, NULL, 0, FALSE, H5AC2_READ, &did_protect)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap indirect block")
/* Print opening message */
HDfprintf(stream, "%*sFractal Heap Indirect Block...\n", indent, "");
/*
* Print the values.
*/
HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
"Address of fractal heap that owns this block:",
hdr->heap_addr);
HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
"Offset of indirect block in heap:",
iblock->block_off);
HDfprintf(stream, "%*s%-*s %Zu\n", indent, "", fwidth,
"Size of indirect block:",
iblock->size);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Current # of rows:",
iblock->nrows);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Max. # of rows:",
iblock->max_rows);
HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
"Max direct block rows:",
hdr->man_dtable.max_direct_rows);
/* Print the entry tables */
if(hdr->filter_len > 0)
HDfprintf(stream, "%*sDirect Block Entries: (address/compressed size/filter mask)\n", indent, "");
else
HDfprintf(stream, "%*sDirect Block Entries: (address)\n", indent, "");
for(u = 0; u < hdr->man_dtable.max_direct_rows && u < iblock->nrows; u++) {
sprintf(temp_str, "Row #%u: (block size: %lu)", (unsigned)u, (unsigned long)hdr->man_dtable.row_block_size[u]);
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str);
for(v = 0; v < hdr->man_dtable.cparam.width; v++) {
size_t off = (u * hdr->man_dtable.cparam.width) + v;
sprintf(temp_str, "Col #%u:", (unsigned)v);
if(hdr->filter_len > 0)
HDfprintf(stream, "%*s%-*s %9a/%6Zu/%x\n", indent + 6, "", MAX(0, fwidth - 6),
temp_str,
iblock->ents[off].addr,
iblock->filt_ents[off].size,
iblock->filt_ents[off].filter_mask);
else
HDfprintf(stream, "%*s%-*s %9a\n", indent + 6, "", MAX(0, fwidth - 6),
temp_str,
iblock->ents[off].addr);
} /* end for */
} /* end for */
HDfprintf(stream, "%*sIndirect Block Entries:\n", indent, "");
if(iblock->nrows > hdr->man_dtable.max_direct_rows) {
unsigned first_row_bits; /* Number of bits used bit addresses in first row */
unsigned num_indirect_rows; /* Number of rows of blocks in each indirect block */
first_row_bits = H5V_log2_of2((uint32_t)hdr->man_dtable.cparam.start_block_size) +
H5V_log2_of2(hdr->man_dtable.cparam.width);
for(u = hdr->man_dtable.max_direct_rows; u < iblock->nrows; u++) {
num_indirect_rows = (H5V_log2_gen(hdr->man_dtable.row_block_size[u]) - first_row_bits) + 1;
sprintf(temp_str, "Row #%u: (# of rows: %u)", (unsigned)u, num_indirect_rows);
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
temp_str);
for(v = 0; v < hdr->man_dtable.cparam.width; v++) {
size_t off = (u * hdr->man_dtable.cparam.width) + v;
sprintf(temp_str, "Col #%u:", (unsigned)v);
HDfprintf(stream, "%*s%-*s %9a\n", indent + 6, "", MAX(0, fwidth - 6),
temp_str,
iblock->ents[off].addr);
} /* end for */
} /* end for */
} /* end if */
else
HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
"<none>");
done:
if(iblock && H5HF_man_iblock_unprotect(iblock, dxpl_id, H5AC2__NO_FLAGS_SET, did_protect) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap direct block")
if(hdr && H5AC2_unprotect(f, dxpl_id, H5AC2_FHEAP_HDR, hdr_addr, (size_t)0, hdr, H5AC2__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_iblock_debug() */
/*-------------------------------------------------------------------------
* Function: H5HF_sects_debug_cb
*
* Purpose: Prints debugging info about a free space section for a fractal heap.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 13 2006
*
*-------------------------------------------------------------------------
*/
static herr_t
H5HF_sects_debug_cb(const H5FS_section_info_t *_sect, void *_udata)
{
const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Section to dump info */
H5HF_debug_iter_ud2_t *udata = (H5HF_debug_iter_ud2_t *)_udata; /* User data for callbacks */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5HF_sects_debug_cb)
/*
* Check arguments.
*/
HDassert(sect);
HDassert(udata);
/* Print generic section information */
HDfprintf(udata->stream, "%*s%-*s %s\n", udata->indent, "", udata->fwidth,
"Section type:",
(sect->sect_info.type == H5HF_FSPACE_SECT_SINGLE ? "single" :
(sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW ? "first row" :
(sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW ? "normal row" : "unknown"))));
HDfprintf(udata->stream, "%*s%-*s %a\n", udata->indent, "", udata->fwidth,
"Section address:",
sect->sect_info.addr);
HDfprintf(udata->stream, "%*s%-*s %Hu\n", udata->indent, "", udata->fwidth,
"Section size:",
sect->sect_info.size);
#ifdef QAK
HDfprintf(udata->stream, "%*s%-*s %s\n", udata->indent, "", udata->fwidth,
"Section state:",
(sect->sect_info.state == H5FS_SECT_LIVE ? "live" : "serialized"));
#endif /* QAK */
/* Dump section-specific debugging information */
if(H5FS_sect_debug(udata->fspace, _sect, udata->stream, udata->indent + 3, MAX(0, udata->fwidth - 3)) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_BADITER, FAIL, "can't dump section's debugging info")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_sects_debug_cb() */
/*-------------------------------------------------------------------------
* Function: H5HF_sects_debug
*
* Purpose: Prints debugging info about free space sections for a fractal heap.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* May 9 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5HF_sects_debug(H5F_t *f, hid_t dxpl_id, haddr_t fh_addr,
FILE *stream, int indent, int fwidth)
{
H5HF_hdr_t *hdr = NULL; /* Fractal heap header info */
H5HF_hdr_cache_ud_t cache_udata; /* User-data for callback */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5HF_sects_debug, FAIL)
/*
* Check arguments.
*/
HDassert(f);
HDassert(H5F_addr_defined(fh_addr));
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
/* Set up user data for protect call */
cache_udata.f = f;
cache_udata.dxpl_id = dxpl_id;
/*
* Load the fractal heap header.
*/
if(NULL == (hdr = H5AC2_protect(f, dxpl_id, H5AC2_FHEAP_HDR, fh_addr, (size_t)H5HF_SPEC_READ_SIZE(f), &cache_udata, H5AC2_READ)))
HGOTO_ERROR(H5E_HEAP, H5E_CANTLOAD, FAIL, "unable to load fractal heap header")
/* Initialize the free space information for the heap */
if(H5HF_space_start(hdr, dxpl_id, FALSE) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize heap free space")
/* If there is a free space manager for the heap, iterate over them */
if(hdr->fspace) {
H5HF_debug_iter_ud2_t udata; /* User data for callbacks */
/* Prepare user data for section iteration callback */
udata.fspace = hdr->fspace;
udata.stream = stream;
udata.indent = indent;
udata.fwidth = fwidth;
/* Iterate over all the free space sections */
if(H5FS_sect_iterate(f, dxpl_id, hdr->fspace, H5HF_sects_debug_cb, &udata) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_BADITER, FAIL, "can't iterate over heap's free space")
/* Close the free space information */
if(H5HF_space_close(hdr, dxpl_id) < 0)
HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't release free space info")
} /* end if */
done:
if(hdr && H5AC2_unprotect(f, dxpl_id, H5AC2_FHEAP_HDR, fh_addr, (size_t)0, hdr, H5AC2__NO_FLAGS_SET) < 0)
HDONE_ERROR(H5E_HEAP, H5E_PROTECT, FAIL, "unable to release fractal heap header")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5HF_sects_debug() */
|