12
#define MAX_TOKEN 2048
15
* Read next token from file. Tokens are separated by the character
17
* Tokens are returned as NUL terminated character strings which
18
* almost certainly should always be freed with free() after use.
20
* There is an internally imposed maximum token size of MAX_TOKEN bytes.
22
* All errors are handled by returning a NULL pointer.
24
char *ReadToken(FILE *file, char delimiter)
26
char *buf = malloc((unsigned) MAX_TOKEN);
36
while ( (input = getc(file)) != EOF ) {
40
if (input == delimiter) {
45
*temp++ = (char) input;
46
if (used == MAX_TOKEN) {
52
/* duplicate string to minimize problems if string is not
53
freed in calling program */
68
int FindToken(char *token, FILE *file, char delimiter)
72
while (input = ReadToken(file, delimiter)) {
73
if (strcmp(input, token) == 0) {
86
* Return the starting time and duration of the events file.
88
void GetTimeSpan(FILE *file, DoublePrecision *start, DoublePrecision *duration)
95
if (FindToken("TIME", file, ':')) {
96
end = *start = atof(input = ReadToken(file, ':'));
100
while (FindToken("TIME", file, ':')) {
101
end = atof(input = ReadToken(file, ':'));
105
*duration = end - *start;
107
(void) fseek(file, 0L, 0);
111
int main(int argc, char **argv)
117
DoublePrecision time, start, duration=0.0, otim, span, margin, comms, useful;
118
int newstate, state, i, nproc, lo, hi;
124
else if (argc == 3) {
129
(void) fprintf(stderr, "usage: %s [lo hi]\n", argv[0]);
130
(void) fprintf(stderr, "... with no arguments parse all event files\n");
131
(void) fprintf(stderr, "... or with lo & hi only files in this range\n");
132
(void) fprintf(stderr, "... e.g. parse 16 31\n");
136
/* open the file that will have the plot stuff in it */
137
/* change of heart here ... just write to stdout */
140
if (!(plot = fopen("plot", "w"))) {
141
perror("failed to open plot file");
148
/* Determine how many processes there are and maximum time span */
151
for (i=lo; i<=hi; i++) {
153
(void) sprintf(filename, "events.%03d", nproc);
155
if ( !(file = fopen(filename, "r")) ) {
159
GetTimeSpan(file, &start, &span);
162
if (span > duration) {
169
margin = duration * 0.1;
171
(void) fprintf(plot, "s %d %d %d %d\n",0,0,
172
(int) ((margin*2.0+duration)*100.0), 5*nproc);
173
/* (void) fprintf(stderr, "nproc=%d, duration=%4.2f\n", nproc, duration); */
175
/* Now go thru the files and actually parse the contents */
177
for (i=lo; i<=hi; i++) {
178
(void) sprintf(filename, "events.%03d", i);
180
if ( !(file = fopen(filename, "r")) ) {
184
GetTimeSpan(file, &start, &span);
190
(void) fprintf(plot, "t %d %d %d\n", 0, state, i);
192
while ( token = ReadToken(file, ':') ) {
193
if (strcmp(token, "BEGIN") == 0) {
194
newstate = 5*(i-lo) + 1;
196
else if (strcmp(token, "END") == 0) {
203
/* Have a BEGIN or END ... only process Snd/Rcv at moment */
205
event = ReadToken(file, ':');
206
if ((strcmp(event, "Snd") == 0)
207
|| (strcmp(event,"Rcv") == 0)
208
|| (strcmp(event,"Waitcom") == 0)) {
210
if (FindToken("TIME", file, ':')) {
211
time = atof(ReadToken(file, ':')) - start + margin;
213
(void) fprintf(plot, "l %d %d %d %d\n",
214
(int) (otim*100.0), state,
215
(int) (time*100.0), state);
216
(void) fprintf(plot, "l %d %d %d %d\n",
217
(int) (time*100.0), state,
218
(int) (time*100.0), newstate);
220
/* Accumulate the time spent in communication */
222
if (newstate == (5*(i-lo))) {
223
comms = comms + time - otim;
230
else if (strcmp(event, "Process") == 0) {
231
if (FindToken("TIME", file, ':')) {
232
time = atof(ReadToken(file, ':')) - start + margin;
234
(void) fprintf(plot, "l %d %d %d %d\n", (int) (otim*100.0), state,
235
(int) (time*100.0), state);
241
/* Assume that non-communication time is useful */
243
useful = 100.0 * (span - comms) / duration;
245
(void) fprintf(plot, "t %d %d %4.1f%%\n",
246
(int) (100.0*duration+150.0*margin), 5*(i-lo), useful);