darshan-parser-trace.c 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <darshan-logutils.h>

/*
struct darshan_trace_record {
    int rank;
    int epoch; 
    int op;
    double tm1;
    double tm2;
    int send_count;
    int recv_count;
    long long int offset;
};
*/


25
void read_log(char *filename, char* csvfile, int epoch, char* counter) {
26 27 28 29 30
    
    int fd;
    ssize_t bytes_read;
    FILE *fout;
    struct darshan_trace_record d; 
31
    int flag = 1;
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

    if ((fd=open(filename,O_RDONLY))<0){
        perror("Open Failed");
        return;
    }
    
    if (csvfile){	
    	if ((fout=fopen(csvfile,"w"))==NULL){
        	perror("Open Failed");
        	return;	
    	}
    }
    else
	fout = stdout;

    fprintf(fout, "rank,epoch,counter,start_time,end_time,write_count,read_count,offset\n");
    while ((bytes_read = read(fd,&d,sizeof(struct darshan_trace_record)))>0) {
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
	if (epoch < 0) { 
		if (counter) { 
			if (strcmp(counter, darshan_names[d.op])) {
				flag = 0;
			}
		}
	}
	else {
		if (epoch != d.epoch) 
			flag = 0;
		else {
			if (counter) {
				if (strcmp(counter, darshan_names[d.op])) {
                                	flag = 0;
                        	}
			}
		}	
	}
	if (flag)
        	fprintf(fout, "%d,%d,%s,%.6f,%.6f,%d,%d,%lld\n",
69 70
               d.rank, d.epoch, darshan_names[d.op],d.tm1,d.tm2,d.send_count, d.recv_count,d.offset);

71
	flag = 1;
72 73 74 75 76 77 78 79 80 81 82
    }
    
    close(fd);
    if (csvfile)	
    	fclose(fout);

}


int main(int argc, char **argv)
{
83 84 85 86 87
    int epoch = -1;
    char *counter = NULL;	

    if (argc < 2) {
	printf("Call %s darshan_trace_file_name [epoch] [counter] \n", argv[0]);
88 89
	exit(1);
    }
90 91 92 93 94 95 96 97
    else {
	if (argc > 2) {	
    		epoch = atoi(argv[2]);
		if (argc > 3)
			counter = argv[3];
	} 	
    }
    read_log(argv[1], NULL, epoch, counter);
98 99 100

    return 0;
}