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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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 COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Tdbg.c
* Jul 19 2007
* Quincey Koziol
*
* Purpose: Dump debugging information about a datatype
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5Tmodule.h" /* This source code file is part of the H5T module */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Tpkg.h" /* Datatypes */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5T__print_stats
*
* Purpose: Print statistics about a conversion path. Statistics are
* printed only if all the following conditions are true:
*
* 1. The library was compiled with H5T_DEBUG defined.
* 2. Data type debugging is turned on at run time.
* 3. The path was called at least one time.
*
* The optional NPRINT argument keeps track of the number of
* conversions paths for which statistics have been shown. If
* its value is zero then table headers are printed before the
* first line of output.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5T__print_stats(H5T_path_t H5_ATTR_UNUSED *path, int H5_ATTR_UNUSED *nprint /*in,out*/)
{
FUNC_ENTER_PACKAGE_NOERR
#ifdef H5T_DEBUG
if (H5DEBUG(T) && path->stats.ncalls > 0) {
hsize_t nbytes;
char bandwidth[32];
struct {
char *user;
char *system;
char *elapsed;
} timestrs = {H5_timer_get_time_string(path->stats.times.user),
H5_timer_get_time_string(path->stats.times.system),
H5_timer_get_time_string(path->stats.times.elapsed)};
if (nprint && 0 == (*nprint)++) {
fprintf(H5DEBUG(T), "H5T: type conversion statistics:\n");
fprintf(H5DEBUG(T), " %-16s %10s %10s %8s %8s %8s %10s\n", "Conversion", "Elmts", "Calls",
"User", "System", "Elapsed", "Bandwidth");
fprintf(H5DEBUG(T), " %-16s %10s %10s %8s %8s %8s %10s\n", "----------", "-----", "-----",
"----", "------", "-------", "---------");
} /* end if */
if (path->src && path->dst)
nbytes = MAX(H5T_get_size(path->src), H5T_get_size(path->dst));
else if (path->src)
nbytes = H5T_get_size(path->src);
else if (path->dst)
nbytes = H5T_get_size(path->dst);
else
nbytes = 0;
nbytes *= path->stats.nelmts;
H5_bandwidth(bandwidth, sizeof(bandwidth), (double)nbytes, path->stats.times.elapsed);
fprintf(H5DEBUG(T), " %-16s %10" PRIdHSIZE " %10u %8s %8s %8s %10s\n", path->name,
path->stats.nelmts, path->stats.ncalls, timestrs.user, timestrs.system, timestrs.elapsed,
bandwidth);
free(timestrs.user);
free(timestrs.system);
free(timestrs.elapsed);
}
#endif
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5T__print_stats() */
/*-------------------------------------------------------------------------
* Function: H5T_debug
*
* Purpose: Prints information about a data type.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5T_debug(const H5T_t *dt, FILE *stream)
{
const char *s1 = "";
const char *s2 = "";
unsigned i;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Check args */
assert(dt);
assert(stream);
switch (dt->shared->type) {
case H5T_NO_CLASS:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "no class");
break;
case H5T_INTEGER:
s1 = "int";
break;
case H5T_FLOAT:
s1 = "float";
break;
case H5T_TIME:
s1 = "time";
break;
case H5T_STRING:
s1 = "str";
break;
case H5T_BITFIELD:
s1 = "bits";
break;
case H5T_OPAQUE:
s1 = "opaque";
break;
case H5T_COMPOUND:
s1 = "struct";
break;
case H5T_ENUM:
s1 = "enum";
break;
case H5T_VLEN:
if (H5T_IS_VL_STRING(dt->shared))
s1 = "str";
else
s1 = "vlen";
break;
case H5T_REFERENCE:
case H5T_ARRAY:
case H5T_NCLASSES:
default:
s1 = "";
break;
} /* end switch */
switch (dt->shared->state) {
case H5T_STATE_TRANSIENT:
s2 = "[transient]";
break;
case H5T_STATE_RDONLY:
s2 = "[constant]";
break;
case H5T_STATE_IMMUTABLE:
s2 = "[predefined]";
break;
case H5T_STATE_NAMED:
s2 = "[named,closed]";
break;
case H5T_STATE_OPEN:
s2 = "[named,open]";
break;
default:
assert(0 && "This Should never be executed!");
} /* end switch */
fprintf(stream, "%s%s {nbytes=%lu", s1, s2, (unsigned long)(dt->shared->size));
if (H5T_IS_ATOMIC(dt->shared)) {
uint64_t tmp;
switch (dt->shared->u.atomic.order) {
case H5T_ORDER_ERROR:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "order error");
break;
case H5T_ORDER_BE:
s1 = "BE";
break;
case H5T_ORDER_LE:
s1 = "LE";
break;
case H5T_ORDER_VAX:
s1 = "VAX";
break;
case H5T_ORDER_NONE:
s1 = "NONE";
break;
case H5T_ORDER_MIXED:
default:
s1 = "order?";
break;
} /* end switch */
fprintf(stream, ", %s", s1);
if (dt->shared->u.atomic.offset)
fprintf(stream, ", offset=%lu", (unsigned long)(dt->shared->u.atomic.offset));
if (dt->shared->u.atomic.prec != 8 * dt->shared->size)
fprintf(stream, ", prec=%lu", (unsigned long)(dt->shared->u.atomic.prec));
switch (dt->shared->type) {
case H5T_NO_CLASS:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "no class");
break;
case H5T_INTEGER:
switch (dt->shared->u.atomic.u.i.sign) {
case H5T_SGN_ERROR:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "sign error");
break;
case H5T_SGN_NONE:
s1 = "unsigned";
break;
case H5T_SGN_2:
s1 = NULL;
break;
case H5T_NSGN:
default:
s1 = "sign?";
break;
} /* end switch */
if (s1)
fprintf(stream, ", %s", s1);
break;
case H5T_FLOAT:
switch (dt->shared->u.atomic.u.f.norm) {
case H5T_NORM_ERROR:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "norm error");
break;
case H5T_NORM_IMPLIED:
s1 = "implied";
break;
case H5T_NORM_MSBSET:
s1 = "msbset";
break;
case H5T_NORM_NONE:
s1 = "no-norm";
break;
default:
s1 = "norm?";
break;
} /* end switch */
fprintf(stream, ", sign=%lu+1", (unsigned long)(dt->shared->u.atomic.u.f.sign));
fprintf(stream, ", mant=%lu+%lu (%s)", (unsigned long)(dt->shared->u.atomic.u.f.mpos),
(unsigned long)(dt->shared->u.atomic.u.f.msize), s1);
fprintf(stream, ", exp=%lu+%lu", (unsigned long)(dt->shared->u.atomic.u.f.epos),
(unsigned long)(dt->shared->u.atomic.u.f.esize));
tmp = dt->shared->u.atomic.u.f.ebias >> 32;
if (tmp) {
size_t hi = (size_t)tmp;
size_t lo = (size_t)(dt->shared->u.atomic.u.f.ebias & 0xffffffff);
fprintf(stream, " bias=0x%08lx%08lx", (unsigned long)hi, (unsigned long)lo);
}
else {
size_t lo = (size_t)(dt->shared->u.atomic.u.f.ebias & 0xffffffff);
fprintf(stream, " bias=0x%08lx", (unsigned long)lo);
}
break;
case H5T_TIME:
case H5T_STRING:
case H5T_BITFIELD:
case H5T_OPAQUE:
case H5T_COMPOUND:
case H5T_REFERENCE:
case H5T_ENUM:
case H5T_VLEN:
case H5T_ARRAY:
case H5T_NCLASSES:
default:
/* No additional info */
break;
} /* end switch */
}
else if (H5T_COMPOUND == dt->shared->type) {
/* Compound data type */
for (i = 0; i < dt->shared->u.compnd.nmembs; i++) {
fprintf(stream, "\n\"%s\" @%lu", dt->shared->u.compnd.memb[i].name,
(unsigned long)(dt->shared->u.compnd.memb[i].offset));
fprintf(stream, " ");
H5T_debug(dt->shared->u.compnd.memb[i].type, stream);
} /* end for */
fprintf(stream, "\n");
}
else if (H5T_VLEN == dt->shared->type) {
switch (dt->shared->u.vlen.loc) {
case H5T_LOC_BADLOC:
HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "invalid datatype location");
break;
case H5T_LOC_MEMORY:
fprintf(stream, ", loc=memory");
break;
case H5T_LOC_DISK:
fprintf(stream, ", loc=disk");
break;
case H5T_LOC_MAXLOC:
default:
fprintf(stream, ", loc=UNKNOWN");
break;
} /* end switch */
if (H5T_IS_VL_STRING(dt->shared))
/* Variable length string datatype */
fprintf(stream, ", variable-length");
else {
/* Variable length sequence datatype */
fprintf(stream, " VLEN ");
H5T_debug(dt->shared->parent, stream);
fprintf(stream, "\n");
} /* end else */
}
else if (H5T_ENUM == dt->shared->type) {
size_t base_size;
/* Enumeration data type */
fprintf(stream, " ");
H5T_debug(dt->shared->parent, stream);
base_size = dt->shared->parent->shared->size;
for (i = 0; i < dt->shared->u.enumer.nmembs; i++) {
size_t k;
fprintf(stream, "\n\"%s\" = 0x", dt->shared->u.enumer.name[i]);
for (k = 0; k < base_size; k++)
fprintf(stream, "%02" PRIx8, *((uint8_t *)dt->shared->u.enumer.value + (i * base_size) + k));
} /* end for */
fprintf(stream, "\n");
}
else if (H5T_OPAQUE == dt->shared->type) {
fprintf(stream, ", tag=\"%s\"", dt->shared->u.opaque.tag);
}
else {
/* Unknown */
fprintf(stream, "unknown class %d\n", (int)(dt->shared->type));
}
fprintf(stream, "}");
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T_debug() */
|