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
|
#include "clogimpl.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
/* The header information for an alog file needs to be collected as the file
* is read. Therefore we collect it here in memory as we create the main part
* of the alogfile, and write it out later.
*/
CLOG_STATE statedefs[150]; /* state definitions */
CLOG_EVENT eventdefs[300]; /* event definitions */
int currsdef = 0; /* next empty state definition */
int curredef = 0; /* next empty event definition */
int numevents = 0; /* alog event count */
int procsfound[256]; /* process ids found in logfile */
int numprocs = 0; /* number of processes found so far */
int typesfound[256]; /* event types found in logfile */
int numtypes = 0; /* number of types found so far */
int numtasks = 0; /* alog task field unused? */
unsigned long firsttime = 0; /* place to remember the first timestamp */
unsigned long lasttime; /* place to remember the last timestamp */
int clogfd; /* intput clogfile */
FILE *alogfile; /* output alogfile */
FILE *atmpfile; /* temp file for first pass */
void alog_dumpblock ANSI_ARGS(( double *));
void alog_dumphdr ANSI_ARGS(( void ));
void checkproc ANSI_ARGS(( int ));
void checktype ANSI_ARGS(( int ));
int main( argc, argv )
int argc;
char *argv[];
{
int n;
double buf[ CLOG_BLOCK_SIZE / sizeof( double ) ];
char alogfilename[256];
char line[80]; /* line of alog file */
if (argc < 2) {
fprintf(stderr,"usage: ctoalog <clogfile>\n");
exit(-1);
}
if ((clogfd = open(argv[1], O_RDONLY, 0)) == -1) {
fprintf(stderr, "could not open clogfile %s for reading\n",argv[1]);
exit(-2);
}
if ((atmpfile = fopen("ctoatmp","w")) == NULL) {
fprintf(stderr, "could not open ctoatmp for writing\n");
exit(-3);
}
n = read(clogfd, buf, CLOG_BLOCK_SIZE);
while (n) {
if (n != CLOG_BLOCK_SIZE) {
fprintf(stderr,"could not read %d bytes\n", CLOG_BLOCK_SIZE);
exit(-3);
}
alog_dumpblock(buf);
n = read(clogfd, buf, CLOG_BLOCK_SIZE);
}
close(clogfd);
fclose(atmpfile);
strcpy(alogfilename, argv[1]);
strcat(alogfilename, ".alog");
if ((alogfile = fopen(alogfilename,"w")) == NULL) {
fprintf(stderr, "could not open alogfile %s for writing\n",
alogfilename);
exit(-3);
}
alog_dumphdr(); /* write negative events */
/* now copy tmp file onto end of alogfile */
if ((atmpfile = fopen("ctoatmp","r")) == NULL) {
fprintf(stderr, "could not reopen ctoatmp for reading\n");
exit(-3);
}
while (fgets(line, 80, atmpfile) != NULL)
fputs(line, alogfile);
fclose(alogfile);
return(0);
}
void alog_dumphdr()
{
int i;
fprintf(alogfile,"-1 0 0 0 0 0 Me\n");
fprintf(alogfile,"-2 0 0 %d 0 0\n", numevents);
fprintf(alogfile,"-3 0 0 %d 0 0\n", numprocs);
fprintf(alogfile,"-4 0 0 1 0 0\n"); /* tasks, unused */
fprintf(alogfile,"-5 0 0 %d 0 0\n", numtypes);
/* fprintf(alogfile,"-6 0 0 0 0 %lu\n", firsttime); */
fprintf(alogfile,"-6 0 0 0 0 %lu\n", (unsigned long) 0); /*times shifted to start at 0 */
fprintf(alogfile,"-7 0 0 0 0 %lu\n", lasttime);
fprintf(alogfile,"-8 0 0 1 0 0\n"); /* timer cycles, unused */
fprintf(alogfile,"-11 0 0 0 0 0\n");/* rollover */
for (i = 0; i < curredef; i++) /* event definitions */
{
fprintf(alogfile,"-9 0 0 %d 0 0 %s\n",
eventdefs[i].etype,
eventdefs[i].description);
}
for (i = 0; i < currsdef; i++) /* state definitions */
{
fprintf(alogfile,"-13 0 %d %d 0 0 %s %s\n",
statedefs[i].startetype,
statedefs[i].endetype,
statedefs[i].color,
statedefs[i].description);
}
}
void alog_dumpblock( p )
double *p;
{
int rtype;
CLOG_HEADER *h;
unsigned long alogtime;
int procid;
rtype = CLOG_UNDEF;
while (rtype != CLOG_ENDBLOCK && rtype != CLOG_ENDLOG) {
h = (CLOG_HEADER *) p;
rtype = h->rectype;
procid = h->procid;
alogtime = (unsigned long) (1000000 * h->timestamp);
alogtime = alogtime - firsttime; /* shift timestamps to start at 0 */
p = (double *) (h->rest); /* skip to end of header */
switch (rtype) {
case CLOG_MSGEVENT:
checkproc(procid); /* check whether we have seen this proc */
checktype(((CLOG_MSG *) p)->etype); /*check whether we have seen this type*/
if (!numevents++) {
firsttime = alogtime;
alogtime = 0;
}
lasttime = alogtime; /* save last timestamp */
fprintf(atmpfile, "%d %d %d %d %d %lu\n",
((CLOG_MSG *) p)->etype, procid, 0, 0, 0, alogtime);
p = (double *) (((CLOG_MSG *) p)->end);
break;
case CLOG_COLLEVENT:
checkproc(procid); /* check if we have seen this proc */
checktype(((CLOG_COLL *) p)->etype);/* check if we have seen this type*/
if (!numevents++) { /* first event */
firsttime = alogtime;
alogtime = 0;
}
lasttime = alogtime; /* save last timestamp */
fprintf(atmpfile, "%d %d %d %d %d %lu\n",
((CLOG_COLL *) p)->etype, procid, 0, 0, 0, alogtime);
p = (double *) (((CLOG_COLL *) p)->end);
break;
case CLOG_RAWEVENT:
checkproc(procid); /* check if we have seen this proc */
checktype(((CLOG_RAW *) p)->etype); /* check if we have seen this type*/
if (!numevents++) { /* first event */
firsttime = alogtime;
alogtime = 0;
}
lasttime = alogtime; /* save last timestamp */
fprintf(atmpfile, "%d %d %d %d %d %lu %s\n",
((CLOG_RAW *) p)->etype, procid, 0,
((CLOG_RAW *) p)->data, 0, alogtime,
((CLOG_RAW *) p)->string );
p = (double *) (((CLOG_RAW *) p)->end);
break;
case CLOG_SRCLOC:
p = (double *) (((CLOG_SRC *) p)->end);
break;
case CLOG_COMMEVENT:
p = (double *) (((CLOG_COMM *) p)->end);
break;
case CLOG_STATEDEF:
statedefs[currsdef] = *((CLOG_STATE *) p);
currsdef++;
p = (double *) (((CLOG_STATE *) p)->end);
break;
case CLOG_EVENTDEF:
eventdefs[curredef] = *((CLOG_EVENT *) p);
curredef++;
p = (double *) (((CLOG_EVENT *) p)->end);
break;
case CLOG_ENDBLOCK:
break;
case CLOG_ENDLOG:
break;
default:
printf("unrecognized record type\n");
}
}
}
void checkproc( procid )
int procid;
{
int i, found = 0;
for (i = 0; i < numprocs; i++) {
if (procid == procsfound[i]) {
found = 1;
break;
}
}
if (!found)
procsfound[numprocs++] = procid;
}
void checktype( typeid )
int typeid;
{
int i, found = 0;
for (i = 0; i < numtypes; i++) {
if (typeid == typesfound[i]) {
found = 1;
break;
}
}
if (!found)
typesfound[numtypes++] = typeid;
}
|