File: clog.c

package info (click to toggle)
mpich 1.1.0-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 22,116 kB
  • ctags: 27,349
  • sloc: ansic: 193,435; sh: 11,172; fortran: 6,545; makefile: 5,801; cpp: 5,020; tcl: 3,548; asm: 3,536; csh: 1,079; java: 614; perl: 183; awk: 168; sed: 70; f90: 62
file content (315 lines) | stat: -rw-r--r-- 9,409 bytes parent folder | download | duplicates (2)
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
/* clog.c */
#include <stdlib.h>
#include <string.h>
#include "clogimpl.h"

char   CLOG_outdir[CLOG_DIR_LEN];
int    CLOG_status = 2;	/* initialized to CLOG not init, but logging on */
int    CLOG_Comm;		/* Default communicator */
void   *CLOG_ptr;		/* pointer into buffer, where next rec goes */
void   *CLOG_block_end;		/* pointer to end of buffer */
CLOG_BLOCK *CLOG_first, *CLOG_currbuff; /* blocks of buffer */
int    intsperdouble, charsperdouble;
int    CLOG_srcid = 900;	/* next id for source code location */
int    CLOG_nextevent = CLOG_MAXEVENT;
int    CLOG_nextstate = CLOG_MAXSTATE;
char   CLOG_execname[256];	/* name used for naming logfile (executable) */

/*@
    CLOG_Init - Initialize for CLOG logging
@*/
void CLOG_Init( )
{
    CLOG_Comm      = 0;		/* until we pass communicator in to CLOG_Init*/
    CLOG_timeinit();		/* initialize timer */
    CLOG_newbuff(&CLOG_first);	/* get first buffer */
    CLOG_status	  &= 0x01;	/* set initialized  */
    intsperdouble  = sizeof(double) / sizeof(int);
    charsperdouble = sizeof(double) / sizeof(char);
}

/*@
    CLOG_Finalize - Finalize  CLOG logging
@*/
void CLOG_Finalize( )
{
    CLOG_LOGENDLOG();
}

/*@
    CLOG_newbuff - get and initialize new block of buffer

Input Parameters:

. bufptr - pointer to be filled in with address of new block

@*/
void CLOG_newbuff( bufptr )
CLOG_BLOCK **bufptr;
{
    *bufptr = (CLOG_BLOCK *) MALLOC ( sizeof (CLOG_BLOCK) );
    (*bufptr)->next = NULL;
    CLOG_currbuff = *bufptr;
    CLOG_ptr = (*bufptr)->data;
    CLOG_block_end = (void *) ((char *) CLOG_ptr + CLOG_BLOCK_SIZE);
}

/************* to become macros once debugged ***********************/

void CLOG_put_hdr( type )
int type;
{
    if (((char *) CLOG_ptr + CLOG_MAX_REC_LEN) >= (char *) CLOG_block_end) {
	CLOG_LOGENDBLOCK();
	CLOG_newbuff(&CLOG_currbuff->next);
    }
    ((CLOG_HEADER *) CLOG_ptr)->timestamp = CLOG_timestamp(); 
    ((CLOG_HEADER *) CLOG_ptr)->rectype   = type;
				/* int length will be filled in later */
				/* int procid will be filled in later */
    CLOG_ptr = ((CLOG_HEADER *) CLOG_ptr)->rest; /* point past header */
}

void CLOG_LOGMSG( etype, tag, partner, comm, size )
int etype, tag, partner, comm, size;
{
    if (CLOG_OK) {                                                    
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_MSGEVENT);
	    ((CLOG_MSG *) CLOG_ptr)-> etype   = etype;
	    ((CLOG_MSG *) CLOG_ptr)-> tag     = tag;
	    ((CLOG_MSG *) CLOG_ptr)-> partner = partner;
	    ((CLOG_MSG *) CLOG_ptr)-> comm    = comm;
	    ((CLOG_MSG *) CLOG_ptr)-> size    = size;
	    ((CLOG_MSG *) CLOG_ptr)-> srcloc  = srcloc;
	    CLOG_ptr			      = ((CLOG_MSG *) CLOG_ptr)->end;
	}
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;
}

void CLOG_LOGRAW( etype, data, string )
int etype, data;
char *string;
{
    if (CLOG_OK) {                                                    
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_RAWEVENT);
	    ((CLOG_RAW *) CLOG_ptr)-> etype   = etype;
	    ((CLOG_RAW *) CLOG_ptr)-> data    = data;
	    ((CLOG_RAW *) CLOG_ptr)-> srcloc  = srcloc;
	    if (string)
		strncpy(((CLOG_RAW *)CLOG_ptr)->string, string,
			sizeof(CLOG_DESC));
	    else
		* ((char *) ((CLOG_RAW *)CLOG_ptr)->string) = '\0';

	    CLOG_ptr			      = ((CLOG_RAW *) CLOG_ptr)->end;
	    * ((char *) CLOG_ptr - 1)	= '\0'; /* ensure null terminated */
	}
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;                                                  
}

void CLOG_LOGCOLL( etype, root, size, comm )
int etype, root, size, comm;
{
    if (CLOG_OK) {                                                    
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_COLLEVENT);
	    ((CLOG_COLL *) CLOG_ptr)-> etype   = etype;
	    ((CLOG_COLL *) CLOG_ptr)-> root    = root;
	    ((CLOG_COLL *) CLOG_ptr)-> comm    = comm;
	    ((CLOG_COLL *) CLOG_ptr)-> size    = size;
	    ((CLOG_COLL *) CLOG_ptr)-> srcloc  = srcloc;
	    CLOG_ptr			      = ((CLOG_COLL *) CLOG_ptr)->end;
	}
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;                                                  
}

void CLOG_LOGCOMM( etype, parent, newcomm )
int etype, parent, newcomm;
{
    if (CLOG_OK) {
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_COMMEVENT);
	    ((CLOG_COMM *) CLOG_ptr)-> etype   = etype;
	    ((CLOG_COMM *) CLOG_ptr)-> parent  = parent;
	    ((CLOG_COMM *) CLOG_ptr)-> newcomm = newcomm;
	    ((CLOG_COMM *) CLOG_ptr)-> srcloc  = srcloc;
	    CLOG_ptr			       = ((CLOG_COMM *) CLOG_ptr)->end;
	}	
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;                                                  
}

void CLOG_LOGSTATE( stateid, startetype, endetype, color, description )
int stateid, startetype, endetype;
char *color, *description;
{
    if (CLOG_OK) {
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_STATEDEF);
	    ((CLOG_STATE *) CLOG_ptr)-> stateid	   = stateid;
	    ((CLOG_STATE *) CLOG_ptr)-> startetype = startetype;
	    ((CLOG_STATE *) CLOG_ptr)-> endetype   = endetype;
	    if (color)
		strncpy(((CLOG_STATE *)CLOG_ptr)->color, color,
			sizeof(CLOG_CNAME));
	    else
		* ((char *) ((CLOG_STATE *)CLOG_ptr)->color) = '\0';

	    if (description)
		strncpy(((CLOG_STATE *)CLOG_ptr)->description, description,
			sizeof(CLOG_CNAME));
	    else
		* ((char *) ((CLOG_STATE *)CLOG_ptr)->description) = '\0';

	    CLOG_ptr	              = ((CLOG_STATE *) CLOG_ptr)->end;
	    * ((char *) CLOG_ptr - 1) = '\0'; /* ensure null terminated */
	}	
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;                                                  
}

void CLOG_LOGEVENT( etype, description )
int etype;
char *description;
{
    if (CLOG_OK) {
	{   
	    static int first = 1;
	    static int srcloc;
	    if (first) {
		first = 0;
		srcloc = CLOG_srcid++;
		CLOG_LOGSRCLOC(srcloc, __LINE__, __FILE__);
	    }
	    CLOG_put_hdr(CLOG_EVENTDEF);
	    ((CLOG_EVENT *) CLOG_ptr)-> etype	  = etype;

	    if (description)
		strncpy(((CLOG_EVENT *)CLOG_ptr)->description, description,
			sizeof(CLOG_CNAME));
	    else
		* ((char *) ((CLOG_EVENT *)CLOG_ptr)->description) = '\0';

	    CLOG_ptr	       = ((CLOG_EVENT *) CLOG_ptr)->end;
	    * ((char *) CLOG_ptr - 1)	= '\0'; /* ensure null terminated */
	}	
    }                                                                 
    else if (CLOG_ERROR)                                              
	CLOG_not_init;                                                  
}

void CLOG_LOGSRCLOC( srcloc, lineno, filename )
int srcloc, lineno;
char *filename;
{
    if (CLOG_OK) {
	CLOG_put_hdr(CLOG_SRCLOC);
	((CLOG_SRC *) CLOG_ptr)->srcloc	= srcloc; 
	((CLOG_SRC *) CLOG_ptr)->lineno	= lineno; 
        strncpy(((CLOG_SRC *)CLOG_ptr)->filename, filename, sizeof(CLOG_FILE));
	CLOG_ptr			= ((CLOG_SRC *) CLOG_ptr)->end;
	* ((char *) CLOG_ptr - 1)	= '\0'; /* ensure null terminated */
    }
    else if (CLOG_ERROR)
	CLOG_not_init;
}

void CLOG_LOGTIMESHIFT( shift )
double shift;
{
    if (CLOG_OK) {
	CLOG_put_hdr(CLOG_SHIFT);
	((CLOG_TSHIFT *) CLOG_ptr)->timeshift = shift; 
	CLOG_ptr		= ((CLOG_TSHIFT *) CLOG_ptr)->end;
    }
    else if (CLOG_ERROR)
	CLOG_not_init;
}

void CLOG_LOGENDBLOCK()
{
    /* assumes there is room for this record */
    if (CLOG_OK) {
	((CLOG_HEADER *) CLOG_ptr)->timestamp = CLOG_timestamp(); 
	((CLOG_HEADER *) CLOG_ptr)->rectype   = CLOG_ENDBLOCK;
	CLOG_ptr = ((CLOG_HEADER *) CLOG_ptr)->rest; 
    }
    else
	if (CLOG_ERROR)                                              
	    CLOG_not_init;                                                  
}
    
void CLOG_LOGENDLOG()
{
    /* assumes there is room for this record */
    if (CLOG_OK) {
	((CLOG_HEADER *) CLOG_ptr)->timestamp = CLOG_timestamp(); 
	((CLOG_HEADER *) CLOG_ptr)->rectype   = CLOG_ENDLOG;
	CLOG_ptr = ((CLOG_HEADER *) CLOG_ptr)->rest; 
    }
    else
	if (CLOG_ERROR)                                              
	    CLOG_not_init;                                                  
}
       
/*@
    CLOG_get_new_event - obtain unused event id
@*/
int CLOG_get_new_event()
{
    return CLOG_nextevent++;
}

/*@
    CLOG_get_new_state - obtain unused state id
@*/
int CLOG_get_new_state()
{
    return CLOG_nextstate++;
}