~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to pvm3/src/tev.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
static char rcsid[] =
 
3
        "$Id: tev.c,v 1.6 1997/12/23 20:25:50 pvmsrc Exp $";
 
4
 
 
5
/*
 
6
 *         PVM version 3.4:  Parallel Virtual Machine System
 
7
 *               University of Tennessee, Knoxville TN.
 
8
 *           Oak Ridge National Laboratory, Oak Ridge TN.
 
9
 *                   Emory University, Atlanta GA.
 
10
 *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
 
11
 *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
 
12
 *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
 
13
 *                   (C) 1997 All Rights Reserved
 
14
 *
 
15
 *                              NOTICE
 
16
 *
 
17
 * Permission to use, copy, modify, and distribute this software and
 
18
 * its documentation for any purpose and without fee is hereby granted
 
19
 * provided that the above copyright notice appear in all copies and
 
20
 * that both the copyright notice and this permission notice appear in
 
21
 * supporting documentation.
 
22
 *
 
23
 * Neither the Institutions (Emory University, Oak Ridge National
 
24
 * Laboratory, and University of Tennessee) nor the Authors make any
 
25
 * representations about the suitability of this software for any
 
26
 * purpose.  This software is provided ``as is'' without express or
 
27
 * implied warranty.
 
28
 *
 
29
 * PVM version 3 was funded in part by the U.S. Department of Energy,
 
30
 * the National Science Foundation and the State of Tennessee.
 
31
 */
 
32
 
 
33
 
 
34
/*
 
35
 *      tev.c
 
36
 *
 
37
 *      Tracing routines.
 
38
 *
 
39
 */
 
40
 
 
41
 
 
42
#include <stdio.h>
 
43
#include <pvm3.h>
 
44
#ifdef WIN32
 
45
#include "..\xdr\types.h"
 
46
#include "..\xdr\xdr.h"
 
47
#else
 
48
#include <rpc/types.h>
 
49
#include <rpc/xdr.h>
 
50
#endif
 
51
#ifdef  SYSVSTR
 
52
#include <string.h>
 
53
#else
 
54
#include <strings.h>
 
55
#endif
 
56
#include "pmsg.h"
 
57
#include "tvdefs.h"
 
58
#include "lpvm.h"
 
59
#include <pvmtev.h>
 
60
#include "tevmac.h"
 
61
#include "global.h"
 
62
 
 
63
 
 
64
/***************
 
65
 **  Globals  **
 
66
 **           **
 
67
 ***************/
 
68
 
 
69
struct pmsg *midtobuf();
 
70
 
 
71
 
 
72
/***************
 
73
 **  Private  **
 
74
 **           **
 
75
 ***************/
 
76
 
 
77
 
 
78
/* "High Performance" Direct Packing Guts Macros :-) */
 
79
 
 
80
#define PACK_BYTE( _vp, _cnt, _std ) \
 
81
        (pvmtrcmp->m_codef->enc_byte) \
 
82
                ( pvmtrcmp, (void *) _vp, _cnt, _std, 1 )
 
83
 
 
84
#define PACK_CPLX( _vp, _cnt, _std ) \
 
85
        (pvmtrcmp->m_codef->enc_cplx) \
 
86
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(float) * 2 )
 
87
 
 
88
#define PACK_DCPLX( _vp, _cnt, _std ) \
 
89
        (pvmtrcmp->m_codef->enc_dcplx) \
 
90
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(double) * 2 )
 
91
 
 
92
#define PACK_DOUBLE( _vp, _cnt, _std ) \
 
93
        (pvmtrcmp->m_codef->enc_double) \
 
94
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(double) )
 
95
 
 
96
#define PACK_FLOAT( _vp, _cnt, _std ) \
 
97
        (pvmtrcmp->m_codef->enc_float) \
 
98
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(float) )
 
99
 
 
100
#define PACK_INT( _vp, _cnt, _std ) \
 
101
        (pvmtrcmp->m_codef->enc_int) \
 
102
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(int) )
 
103
 
 
104
#define PACK_UINT( _vp, _cnt, _std ) \
 
105
        (pvmtrcmp->m_codef->enc_int) \
 
106
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(int) )
 
107
 
 
108
#define PACK_LONG( _vp, _cnt, _std ) \
 
109
        (pvmtrcmp->m_codef->enc_long) \
 
110
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(long) )
 
111
 
 
112
#define PACK_ULONG( _vp, _cnt, _std ) \
 
113
        (pvmtrcmp->m_codef->enc_long) \
 
114
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(long) )
 
115
 
 
116
#define PACK_SHORT( _vp, _cnt, _std ) \
 
117
        (pvmtrcmp->m_codef->enc_short) \
 
118
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(short) )
 
119
 
 
120
#define PACK_USHORT( _vp, _cnt, _std ) \
 
121
        (pvmtrcmp->m_codef->enc_short) \
 
122
                ( pvmtrcmp, (void *) _vp, _cnt, _std, sizeof(short) )
 
123
 
 
124
#define PACK_STRING( _vp ) \
 
125
        ( pvmtrctmp = strlen( _vp ) + 1, \
 
126
                (pvmtrcmp->m_codef->enc_int) \
 
127
                        ( pvmtrcmp, (void *) &pvmtrctmp, 1, 1, sizeof(int) ), \
 
128
                (pvmtrcmp->m_codef->enc_byte) \
 
129
                        ( pvmtrcmp, (void *) _vp, pvmtrctmp, 1, 1 ) )
 
130
 
 
131
 
 
132
/* Trace Event Data Packing Routines - Descriptor */
 
133
 
 
134
static int
 
135
tev_pack_byte_desc( did, array, datap, cnt, std )
 
136
int did;
 
137
int array;
 
138
void *datap;
 
139
int cnt;
 
140
int std;
 
141
{
 
142
        int type;
 
143
        int cc;
 
144
 
 
145
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
146
                return( cc );
 
147
 
 
148
        type = TEV_DATA_BYTE | array;
 
149
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
150
                return( cc );
 
151
 
 
152
        if ( array == TEV_DATA_ARRAY )
 
153
        {
 
154
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
155
                        return( cc );
 
156
        }
 
157
 
 
158
        return( PACK_BYTE( datap, cnt, std ) );
 
159
}
 
160
 
 
161
static int
 
162
tev_pack_cplx_desc( did, array, datap, cnt, std )
 
163
int did;
 
164
int array;
 
165
void *datap;
 
166
int cnt;
 
167
int std;
 
168
{
 
169
        int type;
 
170
        int cc;
 
171
 
 
172
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
173
                return( cc );
 
174
 
 
175
        type = TEV_DATA_CPLX | array;
 
176
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
177
                return( cc );
 
178
 
 
179
        if ( array == TEV_DATA_ARRAY )
 
180
        {
 
181
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
182
                        return( cc );
 
183
        }
 
184
 
 
185
        return( PACK_CPLX( datap, cnt, std ) );
 
186
}
 
187
 
 
188
static int
 
189
tev_pack_dcplx_desc( did, array, datap, cnt, std )
 
190
int did;
 
191
int array;
 
192
void *datap;
 
193
int cnt;
 
194
int std;
 
195
{
 
196
        int type;
 
197
        int cc;
 
198
 
 
199
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
200
                return( cc );
 
201
 
 
202
        type = TEV_DATA_DCPLX | array;
 
203
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
204
                return( cc );
 
205
 
 
206
        if ( array == TEV_DATA_ARRAY )
 
207
        {
 
208
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
209
                        return( cc );
 
210
        }
 
211
 
 
212
        return( PACK_DCPLX( datap, cnt, std ) );
 
213
}
 
214
 
 
215
static int
 
216
tev_pack_double_desc( did, array, datap, cnt, std )
 
217
int did;
 
218
int array;
 
219
void *datap;
 
220
int cnt;
 
221
int std;
 
222
{
 
223
        int type;
 
224
        int cc;
 
225
 
 
226
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
227
                return( cc );
 
228
 
 
229
        type = TEV_DATA_DOUBLE | array;
 
230
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
231
                return( cc );
 
232
 
 
233
        if ( array == TEV_DATA_ARRAY )
 
234
        {
 
235
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
236
                        return( cc );
 
237
        }
 
238
 
 
239
        return( PACK_DOUBLE( datap, cnt, std ) );
 
240
}
 
241
 
 
242
static int
 
243
tev_pack_float_desc( did, array, datap, cnt, std )
 
244
int did;
 
245
int array;
 
246
void *datap;
 
247
int cnt;
 
248
int std;
 
249
{
 
250
        int type;
 
251
        int cc;
 
252
 
 
253
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
254
                return( cc );
 
255
 
 
256
        type = TEV_DATA_FLOAT | array;
 
257
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
258
                return( cc );
 
259
 
 
260
        if ( array == TEV_DATA_ARRAY )
 
261
        {
 
262
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
263
                        return( cc );
 
264
        }
 
265
 
 
266
        return( PACK_FLOAT( datap, cnt, std ) );
 
267
}
 
268
 
 
269
static int
 
270
tev_pack_int_desc( did, array, datap, cnt, std )
 
271
int did;
 
272
int array;
 
273
void *datap;
 
274
int cnt;
 
275
int std;
 
276
{
 
277
        int type;
 
278
        int cc;
 
279
 
 
280
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
281
                return( cc );
 
282
 
 
283
        type = TEV_DATA_INT | array;
 
284
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
285
                return( cc );
 
286
 
 
287
        if ( array == TEV_DATA_ARRAY )
 
288
        {
 
289
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
290
                        return( cc );
 
291
        }
 
292
 
 
293
        return( PACK_INT( datap, cnt, std ) );
 
294
}
 
295
 
 
296
static int
 
297
tev_pack_uint_desc( did, array, datap, cnt, std )
 
298
int did;
 
299
int array;
 
300
void *datap;
 
301
int cnt;
 
302
int std;
 
303
{
 
304
        int type;
 
305
        int cc;
 
306
 
 
307
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
308
                return( cc );
 
309
 
 
310
        type = TEV_DATA_UINT | array;
 
311
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
312
                return( cc );
 
313
 
 
314
        if ( array == TEV_DATA_ARRAY )
 
315
        {
 
316
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
317
                        return( cc );
 
318
        }
 
319
 
 
320
        return( PACK_UINT( datap, cnt, std ) );
 
321
}
 
322
 
 
323
static int
 
324
tev_pack_long_desc( did, array, datap, cnt, std )
 
325
int did;
 
326
int array;
 
327
void *datap;
 
328
int cnt;
 
329
int std;
 
330
{
 
331
        int type;
 
332
        int cc;
 
333
 
 
334
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
335
                return( cc );
 
336
 
 
337
        type = TEV_DATA_LONG | array;
 
338
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
339
                return( cc );
 
340
 
 
341
        if ( array == TEV_DATA_ARRAY )
 
342
        {
 
343
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
344
                        return( cc );
 
345
        }
 
346
 
 
347
        return( PACK_LONG( datap, cnt, std ) );
 
348
}
 
349
 
 
350
static int
 
351
tev_pack_ulong_desc( did, array, datap, cnt, std )
 
352
int did;
 
353
int array;
 
354
void *datap;
 
355
int cnt;
 
356
int std;
 
357
{
 
358
        int type;
 
359
        int cc;
 
360
 
 
361
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
362
                return( cc );
 
363
 
 
364
        type = TEV_DATA_ULONG | array;
 
365
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
366
                return( cc );
 
367
 
 
368
        if ( array == TEV_DATA_ARRAY )
 
369
        {
 
370
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
371
                        return( cc );
 
372
        }
 
373
 
 
374
        return( PACK_ULONG( datap, cnt, std ) );
 
375
}
 
376
 
 
377
static int
 
378
tev_pack_short_desc( did, array, datap, cnt, std )
 
379
int did;
 
380
int array;
 
381
void *datap;
 
382
int cnt;
 
383
int std;
 
384
{
 
385
        int type;
 
386
        int cc;
 
387
 
 
388
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
389
                return( cc );
 
390
 
 
391
        type = TEV_DATA_SHORT | array;
 
392
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
393
                return( cc );
 
394
 
 
395
        if ( array == TEV_DATA_ARRAY )
 
396
        {
 
397
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
398
                        return( cc );
 
399
        }
 
400
 
 
401
        return( PACK_SHORT( datap, cnt, std ) );
 
402
}
 
403
 
 
404
static int
 
405
tev_pack_ushort_desc( did, array, datap, cnt, std )
 
406
int did;
 
407
int array;
 
408
void *datap;
 
409
int cnt;
 
410
int std;
 
411
{
 
412
        int type;
 
413
        int cc;
 
414
 
 
415
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
416
                return( cc );
 
417
 
 
418
        type = TEV_DATA_USHORT | array;
 
419
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
420
                return( cc );
 
421
 
 
422
        if ( array == TEV_DATA_ARRAY )
 
423
        {
 
424
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
425
                        return( cc );
 
426
        }
 
427
 
 
428
        return( PACK_USHORT( datap, cnt, std ) );
 
429
}
 
430
 
 
431
static int
 
432
tev_pack_string_desc( did, array, datap, cnt, std )
 
433
int did;
 
434
int array;
 
435
void *datap;
 
436
int cnt;
 
437
int std;
 
438
{
 
439
        int type;
 
440
        int num;
 
441
        int cc;
 
442
        int i;
 
443
 
 
444
        if ( (cc = PACK_INT( &did, 1, 1 )) )
 
445
                return( cc );
 
446
 
 
447
        type = TEV_DATA_STRING | array;
 
448
        if ( (cc = PACK_INT( &type, 1, 1 )) )
 
449
                return( cc );
 
450
 
 
451
        if ( array == TEV_DATA_ARRAY )
 
452
        {
 
453
                if ( std <= 0 )
 
454
                        return( PvmBadParam );
 
455
 
 
456
                num = ( cnt + ( std - 1 ) ) / std;
 
457
                if ( (cc = PACK_INT( &num, 1, 1 )) )
 
458
                        return( cc );
 
459
 
 
460
                for ( i=0 ; i < cnt ; i += std )
 
461
                        if ( (cc = PACK_STRING( ((char **) datap)[i] )) )
 
462
                                return( cc );
 
463
 
 
464
                return( 0 );
 
465
        }
 
466
 
 
467
        else
 
468
                return( PACK_STRING( (char *) datap ) );
 
469
}
 
470
 
 
471
 
 
472
/* Trace Event Data Packing Routines - Raw */
 
473
 
 
474
static int
 
475
tev_pack_byte_raw( did, array, datap, cnt, std )
 
476
int did;
 
477
int array;
 
478
void *datap;
 
479
int cnt;
 
480
int std;
 
481
{
 
482
        int cc;
 
483
 
 
484
        if ( array == TEV_DATA_ARRAY )
 
485
        {
 
486
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
487
                        return( cc );
 
488
        }
 
489
 
 
490
        return( PACK_BYTE( datap, cnt, std ) );
 
491
}
 
492
 
 
493
static int
 
494
tev_pack_cplx_raw( did, array, datap, cnt, std )
 
495
int did;
 
496
int array;
 
497
void *datap;
 
498
int cnt;
 
499
int std;
 
500
{
 
501
        int cc;
 
502
 
 
503
        if ( array == TEV_DATA_ARRAY )
 
504
        {
 
505
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
506
                        return( cc );
 
507
        }
 
508
 
 
509
        return( PACK_CPLX( datap, cnt, std ) );
 
510
}
 
511
 
 
512
static int
 
513
tev_pack_dcplx_raw( did, array, datap, cnt, std )
 
514
int did;
 
515
int array;
 
516
void *datap;
 
517
int cnt;
 
518
int std;
 
519
{
 
520
        int cc;
 
521
 
 
522
        if ( array == TEV_DATA_ARRAY )
 
523
        {
 
524
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
525
                        return( cc );
 
526
        }
 
527
 
 
528
        return( PACK_DCPLX( datap, cnt, std ) );
 
529
}
 
530
 
 
531
static int
 
532
tev_pack_double_raw( did, array, datap, cnt, std )
 
533
int did;
 
534
int array;
 
535
void *datap;
 
536
int cnt;
 
537
int std;
 
538
{
 
539
        int cc;
 
540
 
 
541
        if ( array == TEV_DATA_ARRAY )
 
542
        {
 
543
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
544
                        return( cc );
 
545
        }
 
546
 
 
547
        return( PACK_DOUBLE( datap, cnt, std ) );
 
548
}
 
549
 
 
550
static int
 
551
tev_pack_float_raw( did, array, datap, cnt, std )
 
552
int did;
 
553
int array;
 
554
void *datap;
 
555
int cnt;
 
556
int std;
 
557
{
 
558
        int cc;
 
559
 
 
560
        if ( array == TEV_DATA_ARRAY )
 
561
        {
 
562
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
563
                        return( cc );
 
564
        }
 
565
 
 
566
        return( PACK_FLOAT( datap, cnt, std ) );
 
567
}
 
568
 
 
569
static int
 
570
tev_pack_int_raw( did, array, datap, cnt, std )
 
571
int did;
 
572
int array;
 
573
void *datap;
 
574
int cnt;
 
575
int std;
 
576
{
 
577
        int cc;
 
578
 
 
579
        if ( array == TEV_DATA_ARRAY )
 
580
        {
 
581
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
582
                        return( cc );
 
583
        }
 
584
 
 
585
        return( PACK_INT( datap, cnt, std ) );
 
586
}
 
587
 
 
588
static int
 
589
tev_pack_uint_raw( did, array, datap, cnt, std )
 
590
int did;
 
591
int array;
 
592
void *datap;
 
593
int cnt;
 
594
int std;
 
595
{
 
596
        int cc;
 
597
 
 
598
        if ( array == TEV_DATA_ARRAY )
 
599
        {
 
600
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
601
                        return( cc );
 
602
        }
 
603
 
 
604
        return( PACK_UINT( datap, cnt, std ) );
 
605
}
 
606
 
 
607
static int
 
608
tev_pack_long_raw( did, array, datap, cnt, std )
 
609
int did;
 
610
int array;
 
611
void *datap;
 
612
int cnt;
 
613
int std;
 
614
{
 
615
        int cc;
 
616
 
 
617
        if ( array == TEV_DATA_ARRAY )
 
618
        {
 
619
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
620
                        return( cc );
 
621
        }
 
622
 
 
623
        return( PACK_LONG( datap, cnt, std ) );
 
624
}
 
625
 
 
626
static int
 
627
tev_pack_ulong_raw( did, array, datap, cnt, std )
 
628
int did;
 
629
int array;
 
630
void *datap;
 
631
int cnt;
 
632
int std;
 
633
{
 
634
        int cc;
 
635
 
 
636
        if ( array == TEV_DATA_ARRAY )
 
637
        {
 
638
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
639
                        return( cc );
 
640
        }
 
641
 
 
642
        return( PACK_ULONG( datap, cnt, std ) );
 
643
}
 
644
 
 
645
static int
 
646
tev_pack_short_raw( did, array, datap, cnt, std )
 
647
int did;
 
648
int array;
 
649
void *datap;
 
650
int cnt;
 
651
int std;
 
652
{
 
653
        int cc;
 
654
 
 
655
        if ( array == TEV_DATA_ARRAY )
 
656
        {
 
657
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
658
                        return( cc );
 
659
        }
 
660
 
 
661
        return( PACK_SHORT( datap, cnt, std ) );
 
662
}
 
663
 
 
664
static int
 
665
tev_pack_ushort_raw( did, array, datap, cnt, std )
 
666
int did;
 
667
int array;
 
668
void *datap;
 
669
int cnt;
 
670
int std;
 
671
{
 
672
        int cc;
 
673
 
 
674
        if ( array == TEV_DATA_ARRAY )
 
675
        {
 
676
                if ( (cc = PACK_INT( &cnt, 1, 1 )) )
 
677
                        return( cc );
 
678
        }
 
679
 
 
680
        return( PACK_USHORT( datap, cnt, std ) );
 
681
}
 
682
 
 
683
static int
 
684
tev_pack_string_raw( did, array, datap, cnt, std )
 
685
int did;
 
686
int array;
 
687
void *datap;
 
688
int cnt;
 
689
int std;
 
690
{
 
691
        int num;
 
692
        int cc;
 
693
        int i;
 
694
 
 
695
        if ( array == TEV_DATA_ARRAY )
 
696
        {
 
697
                if ( std <= 0 )
 
698
                        return( PvmBadParam );
 
699
 
 
700
                num = ( cnt + ( std - 1 ) ) / std;
 
701
                if ( (cc = PACK_INT( &num, 1, 1 )) )
 
702
                        return( cc );
 
703
 
 
704
                for ( i=0 ; i < cnt ; i += std )
 
705
                        if ( (cc = PACK_STRING( ((char **) datap)[i] )) )
 
706
                                return( cc );
 
707
 
 
708
                return( 0 );
 
709
        }
 
710
 
 
711
        else
 
712
                return( PACK_STRING( (char *) datap ) );
 
713
}
 
714
 
 
715
 
 
716
/* ARGSUSED */
 
717
static int
 
718
tev_pack_nop( did, array, datap, cnt, std )
 
719
int did;
 
720
int array;
 
721
void *datap;
 
722
int cnt;
 
723
int std;
 
724
{
 
725
        return( 0 );
 
726
}
 
727
 
 
728
 
 
729
/* Trace Descriptor Packing Vector */
 
730
 
 
731
static struct pvmtrcencvec pvmtrccodef_desc = {
 
732
        tev_pack_byte_desc,
 
733
        tev_pack_cplx_desc,
 
734
        tev_pack_dcplx_desc,
 
735
        tev_pack_double_desc,
 
736
        tev_pack_float_desc,
 
737
        tev_pack_int_desc,
 
738
        tev_pack_uint_desc,
 
739
        tev_pack_long_desc,
 
740
        tev_pack_ulong_desc,
 
741
        tev_pack_short_desc,
 
742
        tev_pack_ushort_desc,
 
743
        tev_pack_string_desc };
 
744
 
 
745
 
 
746
/* Trace Raw Packing Vector */
 
747
 
 
748
static struct pvmtrcencvec pvmtrccodef_raw = {
 
749
        tev_pack_byte_raw,
 
750
        tev_pack_cplx_raw,
 
751
        tev_pack_dcplx_raw,
 
752
        tev_pack_double_raw,
 
753
        tev_pack_float_raw,
 
754
        tev_pack_int_raw,
 
755
        tev_pack_uint_raw,
 
756
        tev_pack_long_raw,
 
757
        tev_pack_ulong_raw,
 
758
        tev_pack_short_raw,
 
759
        tev_pack_ushort_raw,
 
760
        tev_pack_string_raw };
 
761
 
 
762
 
 
763
/* Trace NOP Packing Vector */
 
764
 
 
765
static struct pvmtrcencvec pvmtrccodef_nop = {
 
766
        tev_pack_nop,
 
767
        tev_pack_nop,
 
768
        tev_pack_nop,
 
769
        tev_pack_nop,
 
770
        tev_pack_nop,
 
771
        tev_pack_nop,
 
772
        tev_pack_nop,
 
773
        tev_pack_nop,
 
774
        tev_pack_nop,
 
775
        tev_pack_nop,
 
776
        tev_pack_nop,
 
777
        tev_pack_nop };
 
778
 
 
779
 
 
780
/*
 
781
 *      tev_init()
 
782
 *
 
783
 *      Initialize Trace Status Vector.
 
784
 */
 
785
 
 
786
void
 
787
tev_init()
 
788
{
 
789
        int i;
 
790
 
 
791
        if ( pvmtrc.trctid > 0 && pvmmytid != pvmtrc.trctid )
 
792
        {
 
793
                /* Reset Trace Descriptor Counts */
 
794
 
 
795
                for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
 
796
                {
 
797
                        pvmtevinfo[i].desc_status = 0;
 
798
 
 
799
                        pvmtevinfo[i].mark.tv_sec =
 
800
                                pvmtevinfo[i].mark.tv_usec = 0;
 
801
 
 
802
                        pvmtevinfo[i].total.tv_sec =
 
803
                                pvmtevinfo[i].total.tv_usec = 0;
 
804
 
 
805
                        pvmtevinfo[i].count = 0;
 
806
                }
 
807
        }
 
808
}
 
809
 
 
810
 
 
811
/*
 
812
 *      tev_begin()
 
813
 *
 
814
 *      Trace Event Begin - create message, pack header
 
815
 */
 
816
 
 
817
int
 
818
tev_begin( kind, entry_exit )
 
819
int kind;
 
820
int entry_exit;
 
821
{
 
822
        struct timeval timestamp;
 
823
 
 
824
        int newbuffer;
 
825
        int tmp;
 
826
 
 
827
        /* Get Timestamp */
 
828
 
 
829
        if ( pvmtrc.trcopt != PvmTraceCount )
 
830
                gettimeofday( &timestamp, (struct timezone *) 0 );
 
831
 
 
832
        switch ( pvmtrc.trcopt )
 
833
        {
 
834
                case PvmTraceFull:
 
835
                {
 
836
                        /* Check for Descriptor Dump (one each, begin/end events) */
 
837
 
 
838
                        if ( !( (pvmtevinfo[ kind - TEV_FIRST ].desc_status)
 
839
                                & entry_exit ) )
 
840
                        {
 
841
                                pvmtevinfo[ kind - TEV_FIRST ].desc_status |=
 
842
                                        entry_exit;
 
843
 
 
844
                                /* Set Trace Event Packing Vector */
 
845
 
 
846
                                pvmtrccodef = &pvmtrccodef_desc;
 
847
 
 
848
                                /* Set Descriptor Mode */
 
849
 
 
850
                                pvmtrcdesc = 1;
 
851
                        }
 
852
 
 
853
                        /* Set Regular Trace Event Packing & Mode */
 
854
 
 
855
                        else
 
856
                        {
 
857
                                pvmtrccodef = &pvmtrccodef_raw;
 
858
                        
 
859
                                pvmtrcdesc = 0;
 
860
                        }
 
861
 
 
862
                        /* Initialize Trace Event Message Buffer? */
 
863
 
 
864
                        newbuffer = 0;
 
865
 
 
866
                        if ( !pvmtrcsbf )
 
867
                        {
 
868
                                pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
 
869
                                pvmtrcmp = midtobuf( pvmtrcsbf );
 
870
 
 
871
                                newbuffer++;
 
872
                        }
 
873
 
 
874
                        /* Select Trace Event Buffer (save current) */
 
875
 
 
876
                        pvmtrcsbfsave = pvm_setsbuf( pvmtrcsbf );
 
877
 
 
878
                        /* Pack Event Buffer Marker */
 
879
 
 
880
                        if ( newbuffer && pvmtrc.trcbuf )
 
881
                        {
 
882
                                tmp = TEV_MARK_EVENT_BUFFER;
 
883
                                pvm_pkint( &tmp, 1, 1 );
 
884
                        }
 
885
 
 
886
                        /* Descriptor Header */
 
887
 
 
888
                        if ( pvmtrcdesc )
 
889
                        {
 
890
                                /* Pack Event Marker */
 
891
 
 
892
                                tmp = TEV_MARK_EVENT_DESC;
 
893
                                pvm_pkint( &tmp, 1, 1 );
 
894
 
 
895
                                /* Pack Descriptor Event ID & Event Name */
 
896
 
 
897
                                tmp = kind | entry_exit;
 
898
                                pvm_pkint( &tmp, 1, 1 );
 
899
 
 
900
                                pvm_pkstr( pvmtevinfo[ kind - TEV_FIRST ].name );
 
901
                        }
 
902
 
 
903
                        /* Regular Header */
 
904
 
 
905
                        else
 
906
                        {
 
907
                                /* Pack Event Marker */
 
908
 
 
909
                                tmp = TEV_MARK_EVENT_RECORD;
 
910
                                pvm_pkint( &tmp, 1, 1 );
 
911
 
 
912
                                /* Pack Event ID */
 
913
 
 
914
                                tmp = kind | entry_exit;
 
915
                                pvm_pkint( &tmp, 1, 1 );
 
916
                        }
 
917
 
 
918
                        /* Pack Event Header */
 
919
 
 
920
                        TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
 
921
                                (int *) &(timestamp.tv_sec), 1, 1 );
 
922
                        TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
 
923
                                (int *) &(timestamp.tv_usec), 1, 1 );
 
924
                        TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
 
925
                                &pvmmytid, 1, 1 );
 
926
                        
 
927
                        break;
 
928
                }
 
929
 
 
930
                case PvmTraceTime:
 
931
                        pvmtrccodef = &pvmtrccodef_nop;
 
932
                        pvmtevinfo[ kind - TEV_FIRST ].mark = timestamp;
 
933
                        pvmtrcsavekind = kind;
 
934
                        break;
 
935
 
 
936
                case PvmTraceCount:
 
937
                        pvmtrccodef = &pvmtrccodef_nop;
 
938
                        pvmtrcsavekind = kind;
 
939
                        break;
 
940
 
 
941
                default:
 
942
                        pvmlogprintf(
 
943
                                "Uh-Oh! Bogus Tracing Option (%d) in tev_begin()...\n",
 
944
                                pvmtrc.trcopt );
 
945
                        pvmtrccodef = &pvmtrccodef_nop;
 
946
                        break;
 
947
        }
 
948
 
 
949
        return( 1 );
 
950
}
 
951
 
 
952
 
 
953
/*
 
954
 *      tev_fin()
 
955
 *
 
956
 *      Trace Event End - send message (check trace buffering)
 
957
 */
 
958
 
 
959
int
 
960
tev_fin()
 
961
{
 
962
        struct timeval timestamp;
 
963
 
 
964
        int flush;
 
965
        int size;
 
966
        int tmp;
 
967
 
 
968
        switch ( pvmtrc.trcopt )
 
969
        {
 
970
                case PvmTraceFull:
 
971
                {
 
972
                        /* Pack End of Event Descriptor Marker */
 
973
 
 
974
                        if ( pvmtrcdesc )
 
975
                        {
 
976
                                tmp = TEV_MARK_EVENT_DESC_END;
 
977
                                pvm_pkint( &tmp, 1, 1 );
 
978
                        }
 
979
 
 
980
                        /* Pack End of Event Marker */
 
981
 
 
982
                        else
 
983
                        {
 
984
                                tmp = TEV_MARK_EVENT_RECORD_END;
 
985
                                pvm_pkint( &tmp, 1, 1 );
 
986
                        }
 
987
 
 
988
                        /* Reset Send Buffer (Done Packing Stuff) */
 
989
 
 
990
                        pvm_setsbuf( pvmtrcsbfsave );
 
991
                        pvmtrcsbfsave = 0;
 
992
 
 
993
                        /* Check for Trace Message Send */
 
994
                        /* (pvmtrc.trcbuf == 0 means no buffering) */
 
995
 
 
996
                        flush = 0;
 
997
 
 
998
                        if ( !pvmtrc.trcbuf )
 
999
                                flush++;
 
1000
 
 
1001
                        else
 
1002
                        {
 
1003
                                if ( pvm_bufinfo( pvmtrcsbf, &size,
 
1004
                                                (int *) NULL, (int *) NULL ) ) {
 
1005
                                        pvmlogerror(
 
1006
                                                "tev_fin() error - get trace buffer size\n" );
 
1007
                                        size = -1;
 
1008
                                }
 
1009
 
 
1010
                                if ( size >= pvmtrc.trcbuf )
 
1011
                                        flush++;
 
1012
                        }
 
1013
 
 
1014
                        if ( flush )
 
1015
                                tev_flush( 0 );
 
1016
        
 
1017
                        break;
 
1018
                }
 
1019
 
 
1020
                case PvmTraceTime:
 
1021
                        gettimeofday( &timestamp, (struct timezone *) 0 );
 
1022
                        TVXSUBY( &(pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].total),
 
1023
                                &timestamp,
 
1024
                                &(pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].mark) );
 
1025
                        (pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].count)++;
 
1026
                        break;
 
1027
 
 
1028
                case PvmTraceCount:
 
1029
                        (pvmtevinfo[ pvmtrcsavekind - TEV_FIRST ].count)++;
 
1030
                        break;
 
1031
 
 
1032
                default:
 
1033
                        pvmlogprintf(
 
1034
                                "Uh-Oh! Bogus Tracing Option (%d) in tev_fin()...\n",
 
1035
                                pvmtrc.trcopt );
 
1036
                        break;
 
1037
        }
 
1038
 
 
1039
        return( 1 );
 
1040
}
 
1041
 
 
1042
 
 
1043
/*
 
1044
 *      tev_flush( setflag )
 
1045
 *
 
1046
 *              setflag - indicates whether current send buffer is
 
1047
 *                      already the trace buffer (0), or whether it needs
 
1048
 *                      to be set (1).
 
1049
 *
 
1050
 *      Trace Event Flush - send message, flush any trace buffer
 
1051
 */
 
1052
 
 
1053
void
 
1054
tev_flush( setflag )
 
1055
int setflag;
 
1056
{
 
1057
        char *event_names[ TEV_MAX - TEV_FIRST + 1 ];
 
1058
 
 
1059
        int timings_usec[ TEV_MAX - TEV_FIRST + 1 ];
 
1060
        int timings_sec[ TEV_MAX - TEV_FIRST + 1 ];
 
1061
        int counts[ TEV_MAX - TEV_FIRST + 1 ];
 
1062
 
 
1063
        struct timeval timestamp;
 
1064
 
 
1065
        int routetmp;
 
1066
        int savebuf;
 
1067
        int tmpbuf;
 
1068
        int num;
 
1069
        int tmp;
 
1070
        int i;
 
1071
 
 
1072
        if ( pvmtrc.trctid <= 0 || pvmmytid == pvmtrc.trctid )
 
1073
                return;
 
1074
 
 
1075
        switch ( pvmtrc.trcopt )
 
1076
        {
 
1077
                case PvmTraceFull:
 
1078
                {
 
1079
                        if ( setflag )
 
1080
                        {
 
1081
                                /* Verify Trace Record Message Buffer */
 
1082
 
 
1083
                                if ( !pvmtrcsbf )
 
1084
                                        return;
 
1085
 
 
1086
                                /* Set Send Buffer */
 
1087
 
 
1088
                                savebuf = pvm_setsbuf( pvmtrcsbf );
 
1089
                        }
 
1090
 
 
1091
                        /* Pack End of Event Buffer Marker */
 
1092
                        /* (pvmtrcbuf == 0 means no buffering) */
 
1093
 
 
1094
                        if ( pvmtrc.trcbuf )
 
1095
                        {
 
1096
                                tmp = TEV_MARK_EVENT_BUFFER_END;
 
1097
                                pvm_pkint( &tmp, 1, 1 );
 
1098
                        }
 
1099
 
 
1100
                        break;
 
1101
                }
 
1102
 
 
1103
                case PvmTraceTime:
 
1104
                {
 
1105
                        /* Set Up Send Buffer */
 
1106
 
 
1107
                        pvmtrccodef = &pvmtrccodef_desc;
 
1108
 
 
1109
                        pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
 
1110
                        pvmtrcmp = midtobuf( pvmtrcsbf );
 
1111
 
 
1112
                        savebuf = pvm_setsbuf( pvmtrcsbf );
 
1113
 
 
1114
                        /* Pack Event Marker */
 
1115
 
 
1116
                        tmp = TEV_MARK_EVENT_DESC;
 
1117
                        pvm_pkint( &tmp, 1, 1 );
 
1118
 
 
1119
                        /* Pack Descriptor Event ID & Event Name */
 
1120
 
 
1121
                        tmp = TEV_TIMING;
 
1122
                        pvm_pkint( &tmp, 1, 1 );
 
1123
 
 
1124
                        pvm_pkstr( pvmtevinfo[ TEV_TIMING - TEV_FIRST ].name );
 
1125
 
 
1126
                        /* Pack Event Header */
 
1127
 
 
1128
                        gettimeofday( &timestamp, (struct timezone *) 0 );
 
1129
 
 
1130
                        TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
 
1131
                                (int *) &(timestamp.tv_sec), 1, 1 );
 
1132
                        TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
 
1133
                                (int *) &(timestamp.tv_usec), 1, 1 );
 
1134
                        TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
 
1135
                                &pvmmytid, 1, 1 );
 
1136
 
 
1137
                        /* Collect Timing Array */
 
1138
 
 
1139
                        num = 0;
 
1140
 
 
1141
                        for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
 
1142
                        {
 
1143
                                if ( pvmtevinfo[i].count > 0 )
 
1144
                                {
 
1145
                                        event_names[num] = pvmtevinfo[i].name;
 
1146
 
 
1147
                                        timings_sec[num] = pvmtevinfo[i].total.tv_sec;
 
1148
                                        timings_usec[num] = pvmtevinfo[i].total.tv_usec;
 
1149
 
 
1150
                                        counts[num] = pvmtevinfo[i].count;
 
1151
 
 
1152
                                        pvmtevinfo[i].total.tv_sec =
 
1153
                                                pvmtevinfo[i].total.tv_usec = 0;
 
1154
 
 
1155
                                        pvmtevinfo[i].count = 0;
 
1156
 
 
1157
                                        num++;
 
1158
                                }
 
1159
                        }
 
1160
 
 
1161
                        /* Pack Number of Events & Arrays */
 
1162
 
 
1163
                        TEV_PACK_INT( TEV_DID_VCT, TEV_DATA_SCALAR,
 
1164
                                &num, 1, 1 );
 
1165
 
 
1166
                        TEV_PACK_STRING( TEV_DID_VID, TEV_DATA_ARRAY,
 
1167
                                event_names, num, 1 );
 
1168
 
 
1169
                        TEV_PACK_INT( TEV_DID_TGS, TEV_DATA_ARRAY,
 
1170
                                timings_sec, num, 1 );
 
1171
 
 
1172
                        TEV_PACK_INT( TEV_DID_TGU, TEV_DATA_ARRAY,
 
1173
                                timings_usec, num, 1 );
 
1174
 
 
1175
                        TEV_PACK_INT( TEV_DID_PRF, TEV_DATA_ARRAY,
 
1176
                                counts, num, 1 );
 
1177
 
 
1178
                        /* Pack End of Descriptor Marker */
 
1179
 
 
1180
                        tmp = TEV_MARK_EVENT_DESC_END;
 
1181
                        pvm_pkint( &tmp, 1, 1 );
 
1182
 
 
1183
                        setflag = 1;
 
1184
 
 
1185
                        break;
 
1186
                }
 
1187
 
 
1188
                case PvmTraceCount:
 
1189
                {
 
1190
                        /* Set Up Send Buffer */
 
1191
 
 
1192
                        pvmtrccodef = &pvmtrccodef_desc;
 
1193
 
 
1194
                        pvmtrcsbf = pvm_mkbuf( PvmDataDefault );
 
1195
                        pvmtrcmp = midtobuf( pvmtrcsbf );
 
1196
 
 
1197
                        savebuf = pvm_setsbuf( pvmtrcsbf );
 
1198
 
 
1199
                        /* Pack Event Marker */
 
1200
 
 
1201
                        tmp = TEV_MARK_EVENT_DESC;
 
1202
                        pvm_pkint( &tmp, 1, 1 );
 
1203
 
 
1204
                        /* Pack Descriptor Event ID & Event Name */
 
1205
 
 
1206
                        tmp = TEV_PROFILING;
 
1207
                        pvm_pkint( &tmp, 1, 1 );
 
1208
 
 
1209
                        pvm_pkstr( pvmtevinfo[ TEV_PROFILING - TEV_FIRST ].name );
 
1210
 
 
1211
                        /* Pack Event Header */
 
1212
 
 
1213
                        gettimeofday( &timestamp, (struct timezone *) 0 );
 
1214
 
 
1215
                        TEV_PACK_INT( TEV_DID_TS, TEV_DATA_SCALAR,
 
1216
                                (int *) &(timestamp.tv_sec), 1, 1 );
 
1217
                        TEV_PACK_INT( TEV_DID_TU, TEV_DATA_SCALAR,
 
1218
                                (int *) &(timestamp.tv_usec), 1, 1 );
 
1219
                        TEV_PACK_INT( TEV_DID_TID, TEV_DATA_SCALAR,
 
1220
                                &pvmmytid, 1, 1 );
 
1221
 
 
1222
                        /* Collect Profiling Array */
 
1223
 
 
1224
                        num = 0;
 
1225
 
 
1226
                        for ( i=TEV_FIRST ; i <= TEV_MAX ; i++ )
 
1227
                        {
 
1228
                                if ( pvmtevinfo[i].count > 0 )
 
1229
                                {
 
1230
                                        event_names[num] = pvmtevinfo[i].name;
 
1231
 
 
1232
                                        counts[num] = pvmtevinfo[i].count;
 
1233
 
 
1234
                                        pvmtevinfo[i].count = 0;
 
1235
 
 
1236
                                        num++;
 
1237
                                }
 
1238
                        }
 
1239
 
 
1240
                        /* Pack Number of Events & Arrays */
 
1241
 
 
1242
                        TEV_PACK_INT( TEV_DID_VCT, TEV_DATA_SCALAR,
 
1243
                                &num, 1, 1 );
 
1244
 
 
1245
                        TEV_PACK_STRING( TEV_DID_VID, TEV_DATA_ARRAY,
 
1246
                                event_names, num, 1 );
 
1247
 
 
1248
                        TEV_PACK_INT( TEV_DID_PRF, TEV_DATA_ARRAY,
 
1249
                                counts, num, 1 );
 
1250
 
 
1251
                        /* Pack End of Descriptor Marker */
 
1252
 
 
1253
                        tmp = TEV_MARK_EVENT_DESC_END;
 
1254
                        pvm_pkint( &tmp, 1, 1 );
 
1255
 
 
1256
                        setflag = 1;
 
1257
 
 
1258
                        break;
 
1259
                }
 
1260
 
 
1261
                default:
 
1262
                        pvmlogprintf(
 
1263
                                "Uh-Oh! Bogus Tracing Option (%d) in tev_flush()...\n",
 
1264
                                pvmtrc.trcopt );
 
1265
                        return;
 
1266
        }
 
1267
 
 
1268
        /* Reset Send Buffer (Done Packing Stuff) */
 
1269
 
 
1270
        if ( setflag )
 
1271
                pvm_setsbuf( savebuf );
 
1272
 
 
1273
        /* Clear Out Trace Buffer Global Before Entering mroute()... */
 
1274
        /* (save in tmpbuf for sending, needed for mhf_invoke event) */
 
1275
 
 
1276
        tmpbuf = pvmtrcsbf;
 
1277
 
 
1278
        pvmtrcsbf = 0;
 
1279
 
 
1280
        /* Send Message */
 
1281
 
 
1282
        if ( (routetmp = pvmrouteopt) == PvmRouteDirect )
 
1283
                pvmrouteopt = PvmAllowDirect;
 
1284
 
 
1285
        pvmtrcmp->m_ctx = pvmtrc.trcctx;
 
1286
 
 
1287
        mroute( tmpbuf, pvmtrc.trctid, pvmtrc.trctag, &pvmtrcztv );
 
1288
 
 
1289
        pvmrouteopt = routetmp;
 
1290
 
 
1291
        /* Clean-up */
 
1292
 
 
1293
        pvm_freebuf( tmpbuf );
 
1294
}
 
1295
 
 
1296
 
 
1297
/*
 
1298
 *      tev_do_trace()
 
1299
 *
 
1300
 *      Export TEV_DO_TRACE() so user code doesn't have to import
 
1301
 *      masks and trace tid, etc.
 
1302
 */
 
1303
 
 
1304
int
 
1305
tev_do_trace( kind, entry_exit )
 
1306
        int kind;
 
1307
        int entry_exit;
 
1308
{
 
1309
        TEV_DECLS
 
1310
 
 
1311
        return( TEV_DO_TRACE( kind, entry_exit ) );
 
1312
}
 
1313
 
 
1314