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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
|
/* This file is part of the Pablo Performance Analysis Environment
//
// (R)
// The Pablo Performance Analysis Environment software is NOT in
// the public domain. However, it is freely available without fee for
// education, research, and non-profit purposes. By obtaining copies
// of this and other files that comprise the Pablo Performance Analysis
// Environment, you, the Licensee, agree to abide by the following
// conditions and understandings with respect to the copyrighted software:
//
// 1. The software is copyrighted in the name of the Board of Trustees
// of the University of Illinois (UI), and ownership of the software
// remains with the UI.
//
// 2. Permission to use, copy, and modify this software and its documentation
// for education, research, and non-profit purposes is hereby granted
// to Licensee, provided that the copyright notice, the original author's
// names and unit identification, and this permission notice appear on
// all such copies, and that no charge be made for such copies. Any
// entity desiring permission to incorporate this software into commercial
// products should contact:
//
// Professor Daniel A. Reed reed@cs.uiuc.edu
// University of Illinois
// Department of Computer Science
// 2413 Digital Computer Laboratory
// 1304 West Springfield Avenue
// Urbana, Illinois 61801
// USA
//
// 3. Licensee may not use the name, logo, or any other symbol of the UI
// nor the names of any of its employees nor any adaptation thereof in
// advertizing or publicity pertaining to the software without specific
// prior written approval of the UI.
//
// 4. THE UI MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE
// SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS
// OR IMPLIED WARRANTY.
//
// 5. The UI shall not be liable for any damages suffered by Licensee from
// the use of this software.
//
// 6. The software was developed under agreements between the UI and the
// Federal Government which entitle the Government to certain rights.
//
// *************************************************************************
//
// Developed by: The Pablo Research Group
// University of Illinois at Urbana-Champaign
// Department of Computer Science
// 1304 W. Springfield Avenue
// Urbana, IL 61801
//
// http://www-pablo.cs.uiuc.edu
//
// Send comments to: pablo-feedback@guitar.cs.uiuc.edu
//
// Copyright (c) 1987-1998
// The University of Illinois Board of Trustees.
// All Rights Reserved.
//
// PABLO is a registered trademark of
// The Board of Trustees of the University of Illinois
// registered in the U.S. Patent and Trademark Office.
//
// Project Manager and Principal Investigator:
// Daniel A. Reed (reed@cs.uiuc.edu)
//
// Funded in part by the Defense Advanced Research Projects Agency under
// DARPA contracts DABT63-94-C0049 (SIO Initiative), F30602-96-C-0161,
// and DABT63-96-C-0027 by the National Science Foundation under the PACI
// program and grants NSF CDA 94-01124 and ASC 97-20202, and by the
// Department of Energy under contracts DOE B-341494, W-7405-ENG-48, and
// 1-B-333164.
//========================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#ifndef fileno
int fileno ( FILE * );
#endif
/* on ipsc/860 don't include this or you'll get multiply defined SEEK_* */
#ifndef __NX
#include <unistd.h>
#endif
#define HDFtrace3OPEN__
int HDFtrace3OPEN( const char *, int, mode_t );
#include "SDDFparam.h"
#include "TraceParam.h"
#include "SystemDepend.h"
#include "Trace.h"
#include "IO_TraceParams.h"
#include "HDFIOTrace.h"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* mode_t is not defined on the ipsc/860 so we define it here */
#ifdef __NX
typedef unsigned int mode_t;
#endif
int OUTPUT_SWITCH;
extern void preInitIOTrace( void );
#include "ProcIDs.h"
#include "HDF5Trace.h"
#include "IOTrace.h"
#define NO_OUTPUT 0
#define SDDF_OUTPUT 1
#define RT_OUTPUT 2
void HDFinitTrace_RT ( const char *, unsigned int );
void HDFinitTrace_SDDF ( const char *, unsigned int );
void hinittracex_ ( int [], int *, unsigned *, int * );
void hdfendtrace_ ( void ) ;
void HDFendTrace (void);
void HDFendTrace_RT (void);
void HDFendTrace_SDDF(void);
void HDFfinalTimeStamp( void );
void startHDFtraceEvent (int );
int computeProcMask (int eventID);
int computePacketTag(int eventID);
void endHDFtraceEvent (int , int , char *, int );
void traceEvent ( int , char *, unsigned );
void HDFtraceEvent_RT ( int , HDFsetInfo *, unsigned );
void HDFtraceIOEvent( int , void *, unsigned );
uint procTrace;
extern int IOtracingEnabled;
char *hdfRecordPointer;
/*======================================================================*
// NAME *
// HDFinitTrace -- initialize HDF tracing *
// USAGE *
// VOID HDFinitTrace( traceFileName, procTraceMask, out_sw ) *
// char *traceFileName; IN: name of the generated trace output *
// file *
// uint32 procTraceMask; IN: families of procedures to trace *
// int out_sw IN: indicates whether to produce SDDF *
// file or Final Summary *
// RETURNS *
// None. *
//======================================================================*/
/*======================================================================*
// fortran to C interface. To insure portability, the character array *
// passed in Fortran is converted to an integer array using the ICHAR *
// function. This program converts it from integer to char, then *
// passes it to the C initialization routine. *
//======================================================================*/
void hinittracex_( int *file, int *len, unsigned *procMask, int *out_sw )
{
char *fileName;
int i;
fileName = (char *)malloc(*len+1);
for ( i = 0; i < *len; ++i ) {
fileName[i] = file[i];
}
fileName[*len+1] = 0;
HDFinitTrace ( fileName, *procMask, *out_sw );
}
void HDFinitTrace( const char *traceFileName, unsigned procTraceMask,
unsigned out_sw )
{
OUTPUT_SWITCH = out_sw;
if ( out_sw == SDDF_OUTPUT ) {
HDFinitTrace_SDDF( traceFileName, procTraceMask );
IOtracingEnabled = 1;
} else if ( out_sw == RT_OUTPUT ) {
HDFinitTrace_RT( traceFileName, procTraceMask );
IOtracingEnabled = 1;
} else if ( out_sw == NO_OUTPUT ) {
procTrace = 0;
IOtracingEnabled = 0;
} else {
fprintf(stderr,">> Error in HDFinitTrace: the third argument ");
fprintf(stderr,"must have the value 0, 1, <<<\n");
fprintf(stderr,">> or 2. The value received was %u.", out_sw);
fprintf(stderr," Exiting program. <<<\n");
exit (-1);
}
}
/*======================================================================*
// NAME *
// HDFendTrace -- end HDF tracing *
// USAGE *
// VOID HDFendTrace(VOID) *
// RETURNS *
// None. *
//======================================================================*/
void hdfendtrace_( void )
{
HDFendTrace ();
}
void HDFendTrace(void)
{
if ( OUTPUT_SWITCH == SDDF_OUTPUT ) {
HDFendTrace_SDDF( );
} else if ( OUTPUT_SWITCH == RT_OUTPUT ) {
HDFendTrace_RT( );
}
procTrace = 0;
}
void startHDFtraceEvent(int eventID)
{
if ( OUTPUT_SWITCH == SDDF_OUTPUT ) {
traceEvent( eventID, NULL, 0 ) ;
} else {
HDFtraceEvent_RT( eventID, NULL, 0 ) ;
}
}
void endHDFtraceEvent(int eventID, int setID, char *setName, int IDtype )
{
HDFsetInfo info;
info.setID = setID;
info.setName = setName;
if ( OUTPUT_SWITCH == SDDF_OUTPUT ) {
traceEvent( eventID, (char *)&info, 0 ) ;
} else if (OUTPUT_SWITCH == RT_OUTPUT ) {
HDFtraceEvent_RT( eventID, &info, 0 ) ;
} else if ( OUTPUT_SWITCH < 0 ) {
fprintf(stderr,"endHDFtraceEvent: ");
fprintf(stderr,"invalid OUTPUT_SWITCH %d, IDtype = %d\n",
OUTPUT_SWITCH, IDtype ) ;
}
}
/******************************************************************************/
/*+ Open routines +*/
/*+ ------------- +*/
/*+ +*/
/*+ Routine: FILE *HDFtraceFOPEN( const char *filename, const char *type ) +*/
/*+ substitute for fopen() +*/
/*+ generates fopenBeginID, fopenEndID +*/
/*+ record Open (fopenBegin) +*/
/*+ Mode = -1 +*/
/*+ +*/
FILE *HDFtraceFOPEN( const char *filename, const char *type )
{
FILE *fp;
int fd, id;
int flags = 0;
struct open_args openArgs;
size_t typeLen;
if ( IOtracingEnabled ) {
strcpy( openArgs.filename, filename );
/* check for 'b' - usually if 2 chars, second is '+' */
typeLen = strlen( type );
if ( ( typeLen == 2 ) && ( type [1] == 'b' ) ) {
typeLen = 1;
}
if ( typeLen == 1 ) {
switch( type[0] ) {
case 'r':
flags = flags | O_RDONLY;
break;
case 'w':
flags = O_TRUNC | O_CREAT | O_WRONLY;
break;
case 'a':
flags = flags | O_APPEND | O_CREAT | O_WRONLY;
break;
}
} else {
switch( type[0] ) {
case 'r':
flags = O_RDWR;
break;
case 'w':
flags = O_TRUNC | O_CREAT | O_RDWR;
break;
case 'a':
flags = O_APPEND | O_CREAT | O_RDWR;
break;
}
}
openArgs.flags = flags;
openArgs.mode= -1;
HDFtraceIOEvent( fopenBeginID, (void *)&openArgs, sizeof(openArgs) );
}
fp = fopen( filename, type );
if ( fp != NULL ) {
fd = fileno( fp );
id = set_c_mappedID( fd );
} else {
id = -1;
}
if ( IOtracingEnabled ) {
HDFtraceIOEvent( fopenEndID, (void *) &id, int_SIZE );
}
return( fp );
}
/*+ Routine: int HDFtraceCREAT( const char *path, mode_t mode ) +*/
/*+ substitute for creat() +*/
/*+ generates openBeginID, openEndID +*/
/*+ record Open (openBeginID) +*/
/*+ +*/
int HDFtraceCREAT( const char *path, mode_t mode )
{
struct open_args openArgs;
int fd;
int id;
if ( IOtracingEnabled ) {
strcpy( openArgs.filename, path );
openArgs.flags = O_WRONLY | O_CREAT | O_TRUNC;
openArgs.mode = (int) mode;
HDFtraceIOEvent( openBeginID, (void *)&openArgs, sizeof(openArgs) );
}
fd = creat( path, mode );
id = set_c_mappedID( fd );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( openEndID, (void *) &id, int_SIZE );
}
return( fd );
}
/******************************************************************************/
/*+ Flush routines +*/
/*+ -------------- +*/
/*+ +*/
/*+ Routine: int HDFtraceFFLUSH( FILE *stream ) +*/
/*+ substitute for fflush() +*/
/*+ generates fflushBeginID, fflushEndID +*/
/*+ record Flush (fflushBeginID) +*/
/*+ +*/
int HDFtraceFFLUSH( FILE *stream )
{
int ret;
int id;
int fd;
if ( IOtracingEnabled ) {
/*
* If stream is NULL, all files open for write are flushed.
* We show this with a -2 in the trace record as too much overhead
* to try and tell what files those are and generate individual
* trace records.
*/
if ( stream == NULL ) {
id = -2;
} else {
fd = fileno( stream );
id = c_mappedID( fd );
HDFtraceIOEvent( fflushBeginID, (void *) 0, int_SIZE );
}
}
ret = fflush( stream );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( fflushEndID, (void *) &id, 0 );
}
/*
* Note that if fflush called on stream open for reading, the file pointer
* is moved to EOF if it isn't there already. We don't account for that
* in our file positioning information.
*/
return( ret );
}
/******************************************************************************/
/*+ Close routines +*/
/*+ -------------- +*/
/*+ +*/
/*+ Routine: int HDFtraceFCLOSE( FILE *stream ) +*/
/*+ substitute for fclose() +*/
/*+ generates fcloseBeginID, fcloseEndID +*/
/*+ record Close (fcloseBeginID) +*/
/*+ +*/
int HDFtraceFCLOSE( FILE *stream )
{
int ret;
int id;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
id = c_mappedID( fd );
HDFtraceIOEvent( fcloseBeginID, (void *) &id, int_SIZE );
}
ret = fclose( stream );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( fcloseEndID, (void *) 0, 0 );
}
return( ret );
}
/*+ Routine: int HDFtrace3OPEN( char *path, int flags, mode_t mode ) +*/
/*+ substitute for open() when called with 3 arguments +*/
/*+ generates openBeginID, openEndID +*/
/*+ record Open (openBeginID) +*/
/*+ +*/
int HDFtrace3OPEN( const char *path, int flags, mode_t mode )
{
struct open_args openArgs;
int fd;
int id;
if ( IOtracingEnabled ) {
strcpy( openArgs.filename, path );
openArgs.flags = flags;
openArgs.mode = (int) mode;
HDFtraceIOEvent( openBeginID, (char *)&openArgs, sizeof(openArgs) );
}
fd = open( path, flags, mode );
id = set_c_mappedID( fd );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( openEndID, (char *) &id, int_SIZE );
}
return( fd );
}
/*+ Routine: int HDFtraceCLOSE( int fd ) +*/
/*+ substitute for close() +*/
/*+ generates closeBeginID, closeEndID +*/
/*+ record Close (closeBeginID) +*/
/*+ +*/
int HDFtraceCLOSE( int fd )
{
int ret;
int id;
if ( IOtracingEnabled ) {
id = c_mappedID( fd );
HDFtraceIOEvent( closeBeginID, (void *) &id, int_SIZE );
}
ret = close( fd );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( closeEndID, (void *) 0, 0 );
}
return( ret );
}
/******************************************************************************/
/*+ Read routines +*/
/*+ ------------- +*/
/*+ +*/
/*+ Routine: int HDFtraceREAD( int fd, char *buf, int nbyte ) +*/
/*+ substitute for read() +*/
/*+ generates readBeginID, readEndID +*/
/*+ record Read (readBeginID) +*/
/*+ Number Variables = 1 +*/
/*+ Cause = -1 +*/
/*+ +*/
size_t HDFtraceREAD( int fd, char *buf, int nbyte )
{
struct read_write_args readArgs;
size_t ret;
int bytes;
if ( IOtracingEnabled ) {
readArgs.fileID = c_mappedID( fd );
readArgs.numVariables = 1;
readArgs.cause = -1;
HDFtraceIOEvent( readBeginID, (void *) &readArgs, sizeof(readArgs) );
}
ret = read( fd, buf, nbyte );
if ( IOtracingEnabled ) {
if ( ret > 0 ) {
bytes = (int)ret;
} else {
bytes = 0;
}
HDFtraceIOEvent( readEndID, (void *) &bytes, int_SIZE );
}
return( ret );
}
/*+ Routine: int HDFtraceFREAD( char *ptr, int size, int nitems, +*/
/*+ FILE *stream) +*/
/*+ substitute for fread() +*/
/*+ generates freadBeginID, freadEndID +*/
/*+ record Read (freadBeginID) +*/
/*+ Number Variables = nitems +*/
/*+ Cause = -1 +*/
/*+ +*/
size_t HDFtraceFREAD( void *ptr, int size, int nitems, FILE *stream )
{
struct read_write_args readArgs;
size_t ret;
int nbytes;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
readArgs.fileID = c_mappedID( fd );
readArgs.numVariables = nitems;
readArgs.cause = -1;
HDFtraceIOEvent( freadBeginID, (void *) &readArgs, sizeof(readArgs) );
}
ret = fread( ptr, size, nitems, stream );
if ( IOtracingEnabled ) {
if ( ret > 0 ) {
nbytes = (int)ret * size ;
} else {
nbytes = 0;
}
HDFtraceIOEvent( freadEndID, (void *) &nbytes, int_SIZE );
}
return( ret );
}
/******************************************************************************/
/*+ Seek routines +*/
/*+ ------------- +*/
/*+ +*/
/*+ Routine: off_t HDFtraceLSEEK( int fd, off_t offset, int whence ) +*/
/*+ substitute for lseek() +*/
/*+ generates lseekBeginID, lseekEndID +*/
/*+ record Seek (lseekBeginID) +*/
/*+ +*/
off_t HDFtraceLSEEK( int fd, off_t offset, int whence )
{
struct seek_args seekArgs;
off_t ret;
long arg;
if ( IOtracingEnabled ) {
seekArgs.fileID = c_mappedID( fd );
seekArgs.offset = (int) offset;
seekArgs.whence = whence;
HDFtraceIOEvent( lseekBeginID, (void *) &seekArgs, sizeof(seekArgs) );
}
ret = lseek( fd, offset, whence );
if ( IOtracingEnabled ) {
arg = (long) ret;
HDFtraceIOEvent( lseekEndID, (void *)&arg, long_SIZE );
}
return( ret );
}
/*+ routine: int HDF traceFSEEK( FILE *stream, long offset, int whence ) +*/
/*+ substitute for fseek() +*/
/*+ generates fseekBeginID, fseekEndID +*/
/*+ record Seek (fseekBeginID) +*/
/*+ +*/
int HDFtraceFSEEK( FILE *stream, long offset, int whence )
{
struct seek_args seekArgs;
int ret;
long arg;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
seekArgs.fileID = c_mappedID( fd );;
seekArgs.offset = (int) offset;
seekArgs.whence = whence;
HDFtraceIOEvent( fseekBeginID, (void *) &seekArgs, sizeof(seekArgs) );
}
ret = fseek( stream, offset, whence );
if ( IOtracingEnabled ) {
arg = ftell( stream );
HDFtraceIOEvent( fseekEndID, (void *)&arg, long_SIZE );
}
return( ret );
}
#ifdef fpos_t
/*+ Routine: int HDFtraceFSETPOS( FILE *stream, const fpos_t *position ) +*/
/*+ substitute for fsetpos() +*/
/*+ generates fsetposBeginID, fsetposEndID +*/
/*+ record Seek (fsetposBeginID) +*/
/*+ +*/
int HDFtraceFSETPOS( FILE stream, const fpos_t *position )
{
struct seek_args seekArgs;
int ret;
long arg;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
seekArgs.fileID = c_mappedID( fd );;
seekArgs.offset = (int) *position;
seekArgs.whence = SEEK_SET;
HDFtraceIOEvent( fsetposBeginID, (void *) &seekArgs, sizeof(seekArgs) );
}
ret = fsetpos( stream, position );
if ( IOtracingEnabled ) {
arg = (long) *position;
HDFtraceIOEvent( fsetposEndID, (void *)&arg, long_SIZE );
}
return( ret );
}
#endif /* fpos_t */
/*+ Routine: void HDFtraceREWIND ( FILE *stream ) +*/
/*+ substitute for rewind() +*/
/*+ generates rewindBeginID, rewindEndID +*/
/*+ record Seek (rewindBeginID) +*/
/*+ Offset = 0 +*/
/*+ Whence = SEEK_SET +*/
/*+ +*/
void HDFtraceREWIND( FILE *stream )
{
struct seek_args seekArgs;
long arg;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
seekArgs.fileID = c_mappedID( fd );
seekArgs.offset = 0;
seekArgs.whence = SEEK_SET;
HDFtraceIOEvent( rewindBeginID, (void *) &seekArgs, sizeof(seekArgs) );
}
rewind( stream );
if ( IOtracingEnabled ) {
arg = 0;
HDFtraceIOEvent( rewindEndID, (void *)&arg, long_SIZE );
}
return;
}
/******************************************************************************/
/*+ Write routines +*/
/*+ -------------- +*/
/*+ +*/
/*+ Routine: int HDFtraceWRITE( int fd, char *buf, int nbyte ) +*/
/*+ substitute for write() +*/
/*+ generates writeBeginID, writeEndID +*/
/*+ record Write (writeBeginID) +*/
/*+ Number Variables = 1 +*/
/*+ Cause = -1 +*/
/*+ +*/
size_t HDFtraceWRITE( int fd, const char *buf, int nbyte )
{
struct read_write_args writeArgs;
size_t ret;
int bytes;
if ( IOtracingEnabled ) {
writeArgs.fileID = c_mappedID( fd );
writeArgs.numVariables = 1;
writeArgs.cause = -1;
HDFtraceIOEvent( writeBeginID, (void *) &writeArgs, sizeof(writeArgs) );
}
ret = write( fd, buf, nbyte );
if ( IOtracingEnabled ) {
if ( ret > 0 ) {
bytes = (int)ret;
} else {
bytes = 0;
}
HDFtraceIOEvent( writeEndID, (void *) &bytes, int_SIZE );
}
return( ret );
}
/*+ Routine: size_t HDFtraceFWRITE( const char *ptr, int size, int nitems, +*/
/*+ FILE *stream ) +*/
/*+ substitute for fwrite() +*/
/*+ generates fwriteBeginID, fwriteEndID +*/
/*+ record Write (fwriteBeginID) +*/
/*+ Number Variables = nitems +*/
/*+ Cause = -1 +*/
/*+ +*/
size_t HDFtraceFWRITE( const char *ptr, int size, int nitems, FILE *stream )
{
struct read_write_args writeArgs;
size_t ret;
int nbytes;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
writeArgs.fileID = c_mappedID( fd );
writeArgs.numVariables = nitems;
writeArgs.cause = -1;
HDFtraceIOEvent( fwriteBeginID, (void *) &writeArgs, sizeof(writeArgs) );
}
ret = fwrite( ptr, size, nitems, stream );
if ( IOtracingEnabled ) {
if ( ret > 0 ) {
nbytes = (int)ret * size ;
} else {
nbytes = 0;
}
HDFtraceIOEvent( fwriteEndID, (void *) &nbytes, int_SIZE );
}
return( ret );
}
/*+ Routine: int HDFtracePUTS( char *s ) +*/
/*+ substitute for puts() +*/
/*+ generates fwriteBeginID, fwriteEndID +*/
/*+ record Write (fwriteBeginID) +*/
/*+ Number Variables = 1 +*/
/*+ Cause = -1 +*/
/*+ +*/
int HDFtracePUTS( char *s )
{
struct read_write_args writeArgs;
int ret;
int fd = fileno( stdout );
if ( IOtracingEnabled ) {
writeArgs.fileID = c_mappedID( fd );
writeArgs.numVariables = 1;
writeArgs.cause = -1;
HDFtraceIOEvent( fwriteBeginID, (void *) &writeArgs, sizeof(writeArgs) );
}
ret = puts( s );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( fwriteEndID, (void *) &ret, int_SIZE );
}
return( ret );
}
/*+ Routine: int HDFtraceFPUTC( int c, FILE *stream ) +*/
/*+ substitute for fputc() +*/
/*+ generates fwriteBeginID, fwriteEndID +*/
/*+ record Write (fwriteBeginID) +*/
/*+ Number Variables = 1 +*/
/*+ Cause = -1 +*/
/*+ +*/
int HDFtraceFPUTC( int c, FILE *stream )
{
struct read_write_args writeArgs;
int ret;
int nbytes = char_SIZE;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
writeArgs.fileID = c_mappedID( fd );
writeArgs.numVariables = 1;
writeArgs.cause = -1;
HDFtraceIOEvent( fwriteBeginID, (void *) &writeArgs, sizeof(writeArgs) );
}
ret = fputc( c, stream );
if ( IOtracingEnabled ) {
if ( ret == EOF ) {
nbytes = 0;
HDFtraceIOEvent( fwriteEndID, (void *) &nbytes, int_SIZE );
}
}
return( ret );
}
/*+ Routine: int HDFtraceFPUTS( char *s, FILE *stream ) +*/
/*+ substitute for fputs() +*/
/*+ generates fwriteBeginID, fwriteEndID +*/
/*+ record Write (fwriteBeginID) +*/
/*+ Number Variables = 1 +*/
/*+ Cause = -1 +*/
/*+ +*/
int HDFtraceFPUTS( const char *s, FILE *stream )
{
struct read_write_args writeArgs;
int ret;
int fd = fileno( stream );
if ( IOtracingEnabled ) {
writeArgs.fileID = c_mappedID( fd );
writeArgs.numVariables = 1;
writeArgs.cause = -1;
HDFtraceIOEvent(fwriteBeginID, (void *)&writeArgs, sizeof(writeArgs));
}
ret = fputs( s, stream );
if ( IOtracingEnabled ) {
HDFtraceIOEvent( fwriteEndID, (void *) &ret, int_SIZE );
}
return( ret );
}
void *HDFtraceMALLOC(size_t bytes )
{
void *ptr;
int byte_req;
byte_req = (int)bytes;
if ( IOtracingEnabled ) {
HDFtraceIOEvent ( ID_malloc, NULL, 0 );
}
ptr = malloc( bytes );
if ( IOtracingEnabled ) {
HDFtraceIOEvent ( -ID_malloc, &byte_req, sizeof(int) );
}
return ptr ;
}
void HDFtraceIOEvent( int eventType, void *dataPtr, unsigned dataLen )
{
if ( OUTPUT_SWITCH == 1 ) {
traceEvent( eventType, dataPtr, dataLen );
} else {
HDFtraceEvent_RT( eventType, (HDFsetInfo *)dataPtr, dataLen );
}
}
/*======================================================================*
// record the final time stamp *
//======================================================================*/
void HDFfinalTimeStamp( void )
{
TR_LOCK criticalSection;
CLOCK currentTime;
double seconds;
struct {
int packetLength,
packetType,
packetTag,
timeDim;
double Seconds;
int eventID,
node,
dataLen;
} Packet;
criticalSection = TRlock();
currentTime = getClock();
seconds = clockToSeconds( currentTime );
Packet.packetLength = sizeof(Packet);
Packet.packetType = PKT_DATA;
Packet.packetTag = FAMILY_EXTERNAL | RECORD_TRACE;
Packet.timeDim = 0; /* use fp time stamp only */
Packet.Seconds = seconds; /* fp time stamp */
Packet.eventID = ID_timeStamp;
Packet.node = TRgetNode();
Packet.dataLen = 0;
putBytes( (void *)&Packet , sizeof(Packet) );
}
|