/src/netcdf-c/libnczarr/zdebug.c
Line | Count | Source |
1 | | /********************************************************************* |
2 | | * Copyright 2018, UCAR/Unidata |
3 | | * See netcdf/COPYRIGHT file for copying and redistribution conditions. |
4 | | *********************************************************************/ |
5 | | #include "zincludes.h" |
6 | | |
7 | | /* Mnemonic */ |
8 | 0 | #define RAW 1 |
9 | | |
10 | | /**************************************************/ |
11 | | /* Data Structure */ |
12 | | |
13 | | struct ZUTEST* zutest = NULL; |
14 | | |
15 | | /**************************************************/ |
16 | | |
17 | | #ifdef ZCATCH |
18 | | /* Place breakpoint here to catch errors close to where they occur*/ |
19 | | int |
20 | | zbreakpoint(int err) |
21 | | { |
22 | | return ncbreakpoint(err); |
23 | | } |
24 | | |
25 | | int |
26 | | zthrow(int err, const char* file, const char* fcn, int line) |
27 | | { |
28 | | if(err == 0) return err; |
29 | | ncbacktrace(); |
30 | | return zbreakpoint(err); |
31 | | } |
32 | | |
33 | | int |
34 | | zreport(int err, const char* msg, const char* file, const char* fcn, int line) |
35 | | { |
36 | | if(err == 0) return err; |
37 | | ZLOG(NCLOGWARN,"!!! zreport: err=%d msg=%s @ %s#%s:%d",err,msg,file,fcn,line); |
38 | | ncbacktrace(); |
39 | | return zbreakpoint(err); |
40 | | } |
41 | | |
42 | | #endif /*ZCATCH*/ |
43 | | |
44 | | /**************************************************/ |
45 | | /* Data Structure printers */ |
46 | | |
47 | | #if 0 |
48 | | static NClist llocal = {NULL}; |
49 | | static void* ldata[1024]; |
50 | | #endif |
51 | 0 | #define BDATASIZE (1<<14) |
52 | | static NCbytes blocal = {NULL}; |
53 | | static char bdata[BDATASIZE]; |
54 | | |
55 | | static void |
56 | | nczprint_setup(void) |
57 | 0 | { |
58 | | #if 0 |
59 | | if(llocal.content == NULL) { |
60 | | NClist* l = nclistnew(); |
61 | | nclistsetcontents(l,ldata,1024,0); |
62 | | llocal = *l; |
63 | | nullfree(l); } |
64 | | #endif |
65 | 0 | if(blocal.content == NULL) { |
66 | 0 | NCbytes* b = ncbytesnew(); |
67 | 0 | ncbytessetcontents(b,bdata,BDATASIZE,0); |
68 | 0 | blocal = *b; |
69 | 0 | nullfree(b); |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | char* |
74 | | nczprint_slice(const NCZSlice slice) |
75 | 0 | { |
76 | 0 | return nczprint_slicex(slice,!RAW); |
77 | 0 | } |
78 | | |
79 | | char* |
80 | | nczprint_slicex(const NCZSlice slice, int raw) |
81 | 0 | { |
82 | 0 | char* result = NULL; |
83 | 0 | char value[64]; |
84 | |
|
85 | 0 | nczprint_setup(); |
86 | 0 | if(raw) |
87 | 0 | ncbytescat(&blocal,"["); |
88 | 0 | else |
89 | 0 | ncbytescat(&blocal,"Slice{"); |
90 | 0 | snprintf(value,sizeof(value),"%lu",(unsigned long)slice.start); |
91 | 0 | ncbytescat(&blocal,value); |
92 | 0 | ncbytescat(&blocal,":"); |
93 | 0 | snprintf(value,sizeof(value),"%lu",(unsigned long)slice.stop); |
94 | 0 | ncbytescat(&blocal,value); |
95 | 0 | if(slice.stride != 1) { |
96 | 0 | ncbytescat(&blocal,":"); |
97 | 0 | snprintf(value,sizeof(value),"%lu",(unsigned long)slice.stride); |
98 | 0 | ncbytescat(&blocal,value); |
99 | 0 | } |
100 | 0 | ncbytescat(&blocal,"|"); |
101 | 0 | snprintf(value,sizeof(value),"%lu",(unsigned long)slice.len); |
102 | 0 | ncbytescat(&blocal,value); |
103 | 0 | if(raw) |
104 | 0 | ncbytescat(&blocal,"]"); |
105 | 0 | else |
106 | 0 | ncbytescat(&blocal,"}"); |
107 | 0 | result = ncbytescontents(&blocal); |
108 | 0 | return (result); |
109 | 0 | } |
110 | | |
111 | | char* |
112 | | nczprint_slices(int rank, const NCZSlice* slices) |
113 | 0 | { |
114 | 0 | return nczprint_slicesx(rank, slices, !RAW); |
115 | 0 | } |
116 | | |
117 | | char* |
118 | | nczprint_slicesx(int rank, const NCZSlice* slices, int raw) |
119 | 0 | { |
120 | 0 | int i; |
121 | 0 | char* result = NULL; |
122 | |
|
123 | 0 | nczprint_setup(); |
124 | 0 | for(i=0;i<rank;i++) { |
125 | 0 | char* ssl; |
126 | 0 | if(!raw) |
127 | 0 | ncbytescat(&blocal,"["); |
128 | 0 | ssl = nczprint_slicex(slices[i],raw); |
129 | 0 | ncbytescat(&blocal,ssl); |
130 | 0 | if(!raw) |
131 | 0 | ncbytescat(&blocal,"]"); |
132 | 0 | } |
133 | 0 | result = ncbytescontents(&blocal); |
134 | 0 | return (result); |
135 | 0 | } |
136 | | |
137 | | char* |
138 | | nczprint_slab(int rank, const NCZSlice* slices) |
139 | 0 | { |
140 | 0 | return nczprint_slicesx(rank,slices,RAW); |
141 | 0 | } |
142 | | |
143 | | char* |
144 | | nczprint_odom(const NCZOdometer* odom) |
145 | 0 | { |
146 | 0 | char* result = NULL; |
147 | 0 | char value[128]; |
148 | 0 | char* txt = NULL; |
149 | |
|
150 | 0 | nczprint_setup(); |
151 | 0 | snprintf(value,sizeof(value),"Odometer{rank=%d ",odom->rank); |
152 | 0 | ncbytescat(&blocal,value); |
153 | |
|
154 | 0 | ncbytescat(&blocal," start="); |
155 | 0 | txt = nczprint_vector(odom->rank,odom->start); |
156 | 0 | ncbytescat(&blocal,txt); |
157 | 0 | ncbytescat(&blocal," stop="); |
158 | 0 | txt = nczprint_vector(odom->rank,odom->stop); |
159 | 0 | ncbytescat(&blocal,txt); |
160 | 0 | ncbytescat(&blocal," len="); |
161 | 0 | txt = nczprint_vector(odom->rank,odom->len); |
162 | 0 | ncbytescat(&blocal,txt); |
163 | 0 | ncbytescat(&blocal," stride="); |
164 | 0 | txt = nczprint_vector(odom->rank,odom->stride); |
165 | 0 | ncbytescat(&blocal,txt); |
166 | 0 | ncbytescat(&blocal," index="); |
167 | 0 | txt = nczprint_vector(odom->rank,odom->index); |
168 | 0 | ncbytescat(&blocal,txt); |
169 | 0 | ncbytescat(&blocal," offset="); |
170 | 0 | snprintf(value,sizeof(value),"%llu",nczodom_offset(odom)); |
171 | 0 | ncbytescat(&blocal,value); |
172 | 0 | ncbytescat(&blocal," avail="); |
173 | 0 | snprintf(value,sizeof(value),"%llu",nczodom_avail(odom)); |
174 | 0 | ncbytescat(&blocal,value); |
175 | 0 | ncbytescat(&blocal," more="); |
176 | 0 | snprintf(value,sizeof(value),"%d",nczodom_more(odom)); |
177 | 0 | ncbytescat(&blocal,value); |
178 | | |
179 | 0 | ncbytescat(&blocal,"}"); |
180 | 0 | result = ncbytescontents(&blocal); |
181 | 0 | return (result); |
182 | 0 | } |
183 | | |
184 | | char* |
185 | | nczprint_projection(const NCZProjection proj) |
186 | 0 | { |
187 | 0 | return nczprint_projectionx(proj,!RAW); |
188 | 0 | } |
189 | | |
190 | | char* |
191 | | nczprint_projectionx(const NCZProjection proj, int raw) |
192 | 0 | { |
193 | 0 | char* result = NULL; |
194 | 0 | char value[128]; |
195 | |
|
196 | 0 | nczprint_setup(); |
197 | 0 | ncbytescat(&blocal,"Projection{"); |
198 | 0 | snprintf(value,sizeof(value),"id=%d,",proj.id); |
199 | 0 | ncbytescat(&blocal,value); |
200 | 0 | if(proj.skip) ncbytescat(&blocal,"*"); |
201 | 0 | snprintf(value,sizeof(value),"chunkindex=%lu",(unsigned long)proj.chunkindex); |
202 | 0 | ncbytescat(&blocal,value); |
203 | 0 | snprintf(value,sizeof(value),",first=%lu",(unsigned long)proj.first); |
204 | 0 | ncbytescat(&blocal,value); |
205 | 0 | snprintf(value,sizeof(value),",last=%lu",(unsigned long)proj.last); |
206 | 0 | ncbytescat(&blocal,value); |
207 | 0 | snprintf(value,sizeof(value),",limit=%lu",(unsigned long)proj.limit); |
208 | 0 | ncbytescat(&blocal,value); |
209 | 0 | snprintf(value,sizeof(value),",iopos=%lu",(unsigned long)proj.iopos); |
210 | 0 | ncbytescat(&blocal,value); |
211 | 0 | snprintf(value,sizeof(value),",iocount=%lu",(unsigned long)proj.iocount); |
212 | 0 | ncbytescat(&blocal,value); |
213 | 0 | ncbytescat(&blocal,",chunkslice="); |
214 | 0 | result = nczprint_slicex(proj.chunkslice,raw); |
215 | 0 | ncbytescat(&blocal,result); |
216 | 0 | ncbytescat(&blocal,",memslice="); |
217 | 0 | result = nczprint_slicex(proj.memslice,raw); |
218 | 0 | ncbytescat(&blocal,result); |
219 | 0 | result = ncbytescontents(&blocal); |
220 | 0 | return (result); |
221 | 0 | } |
222 | | |
223 | | char* |
224 | | nczprint_allsliceprojections(int r, const NCZSliceProjections* slp) |
225 | 0 | { |
226 | 0 | int i; |
227 | 0 | char* s; |
228 | |
|
229 | 0 | nczprint_setup(); |
230 | 0 | for(i=0;i<r;i++) { |
231 | 0 | s = nczprint_sliceprojections(slp[i]); |
232 | 0 | ncbytescat(&blocal,s); |
233 | 0 | } |
234 | 0 | s = ncbytescontents(&blocal); |
235 | 0 | return (s); |
236 | 0 | } |
237 | | |
238 | | char* |
239 | | nczprint_sliceprojections(const NCZSliceProjections slp) |
240 | 0 | { |
241 | 0 | return nczprint_sliceprojectionsx(slp,!RAW); |
242 | 0 | } |
243 | | |
244 | | char* |
245 | | nczprint_sliceprojectionsx(const NCZSliceProjections slp, int raw) |
246 | 0 | { |
247 | 0 | char* result = NULL; |
248 | 0 | char tmp[4096]; |
249 | 0 | int i; |
250 | |
|
251 | 0 | nczprint_setup(); |
252 | 0 | snprintf(tmp,sizeof(tmp),"SliceProjection{r=%d range=%s count=%ld", |
253 | 0 | slp.r,nczprint_chunkrange(slp.range),(long)slp.count); |
254 | 0 | ncbytescat(&blocal,tmp); |
255 | 0 | ncbytescat(&blocal,",projections=[\n"); |
256 | 0 | for(i=0;i<slp.count;i++) { |
257 | 0 | NCZProjection* p = (NCZProjection*)&slp.projections[i]; |
258 | 0 | ncbytescat(&blocal,"\t"); |
259 | 0 | result = nczprint_projectionx(*p,raw); |
260 | 0 | ncbytescat(&blocal,result); |
261 | 0 | ncbytescat(&blocal,"\n"); |
262 | 0 | } |
263 | 0 | result = NULL; |
264 | 0 | ncbytescat(&blocal,"]"); |
265 | 0 | ncbytescat(&blocal,"}\n"); |
266 | 0 | result = ncbytescontents(&blocal); |
267 | 0 | return (result); |
268 | 0 | } |
269 | | |
270 | | char* |
271 | | nczprint_chunkrange(const NCZChunkRange range) |
272 | 0 | { |
273 | 0 | char* result = NULL; |
274 | 0 | char digits[64]; |
275 | |
|
276 | 0 | nczprint_setup(); |
277 | 0 | ncbytescat(&blocal,"ChunkRange{start="); |
278 | 0 | snprintf(digits,sizeof(digits),"%llu",range.start); |
279 | 0 | ncbytescat(&blocal,digits); |
280 | 0 | ncbytescat(&blocal," stop="); |
281 | 0 | snprintf(digits,sizeof(digits),"%llu",range.stop); |
282 | 0 | ncbytescat(&blocal,digits); |
283 | 0 | ncbytescat(&blocal,"}"); |
284 | 0 | result = ncbytescontents(&blocal); |
285 | 0 | return (result); |
286 | 0 | } |
287 | | |
288 | | char* |
289 | | nczprint_idvector(size_t len, const int* ids) |
290 | 0 | { |
291 | 0 | size64_t v[4096]; |
292 | 0 | size_t i; |
293 | 0 | for(i=0;i<len;i++) v[i] = ids[i]; |
294 | 0 | return nczprint_vector(len,v); |
295 | 0 | } |
296 | | |
297 | | char* |
298 | | nczprint_paramvector(size_t len, const unsigned* params) |
299 | 0 | { |
300 | 0 | size64_t v[4096]; |
301 | 0 | size_t i; |
302 | 0 | for(i=0;i<len;i++) v[i] = params[i]; |
303 | 0 | return nczprint_vector(len,v); |
304 | 0 | } |
305 | | |
306 | | char* |
307 | | nczprint_sizevector(size_t len, const size_t* sizes) |
308 | 0 | { |
309 | 0 | size64_t v[4096]; |
310 | 0 | size_t i; |
311 | 0 | for(i=0;i<len;i++) v[i] = sizes[i]; |
312 | 0 | return nczprint_vector(len,v); |
313 | 0 | } |
314 | | |
315 | | char* |
316 | | nczprint_vector(size_t len, const size64_t* vec) |
317 | 0 | { |
318 | 0 | char* result = NULL; |
319 | 0 | int i; |
320 | 0 | char value[128]; |
321 | |
|
322 | 0 | nczprint_setup(); |
323 | 0 | ncbytescat(&blocal,"("); |
324 | 0 | for(i=0;i<len;i++) { |
325 | 0 | if(i > 0) ncbytescat(&blocal,","); |
326 | 0 | snprintf(value,sizeof(value),"%lu",(unsigned long)vec[i]); |
327 | 0 | ncbytescat(&blocal,value); |
328 | 0 | } |
329 | 0 | ncbytescat(&blocal,")"); |
330 | 0 | result = ncbytescontents(&blocal); |
331 | 0 | return (result); |
332 | 0 | } |
333 | | |
334 | | char* |
335 | | nczprint_envv(NClist* envv) |
336 | 0 | { |
337 | 0 | char* result = NULL; |
338 | 0 | int i; |
339 | |
|
340 | 0 | nczprint_setup(); |
341 | 0 | ncbytescat(&blocal,"("); |
342 | 0 | if(envv) { |
343 | 0 | for(i=0;i<nclistlength(envv);i++) { |
344 | 0 | const char* p = (const char*)nclistget(envv,i); |
345 | 0 | if(i > 0) ncbytescat(&blocal,","); |
346 | 0 | ncbytescat(&blocal,"'"); |
347 | 0 | ncbytescat(&blocal,p); |
348 | 0 | ncbytescat(&blocal,"'"); |
349 | 0 | } |
350 | 0 | } |
351 | 0 | ncbytescat(&blocal,")"); |
352 | 0 | result = ncbytescontents(&blocal); |
353 | 0 | return (result); |
354 | 0 | } |
355 | | |
356 | | void |
357 | | zdumpcommon(const struct Common* c) |
358 | 0 | { |
359 | 0 | int r; |
360 | 0 | fprintf(stderr,"Common:\n"); |
361 | | #if 0 |
362 | | fprintf(stderr,"\tfile: %s\n",c->file->controller->path); |
363 | | fprintf(stderr,"\tvar: %s\n",c->var->hdr.name); |
364 | | fprintf(stderr,"\treading=%d\n",c->reading); |
365 | | #endif |
366 | 0 | fprintf(stderr,"\trank=%d",c->rank); |
367 | 0 | fprintf(stderr," dimlens=%s",nczprint_vector(c->rank,c->dimlens)); |
368 | 0 | fprintf(stderr," chunklens=%s",nczprint_vector(c->rank,c->chunklens)); |
369 | | #if 0 |
370 | | fprintf(stderr,"\tmemory=%p\n",c->memory); |
371 | | fprintf(stderr,"\ttypesize=%d\n",c->typesize); |
372 | | fprintf(stderr,"\tswap=%d\n",c->swap); |
373 | | #endif |
374 | 0 | fprintf(stderr," shape=%s\n",nczprint_vector(c->rank,c->shape)); |
375 | 0 | fprintf(stderr,"\tallprojections:\n"); |
376 | 0 | for(r=0;r<c->rank;r++) |
377 | 0 | fprintf(stderr,"\t\t[%d] %s\n",r,nczprint_sliceprojectionsx(c->allprojections[r],RAW)); |
378 | | fflush(stderr); |
379 | 0 | } |