darshan-diff.c 4.3 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 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
#include <stdio.h>
#include <zlib.h>
#include <string.h>
#include "darshan-log-format.h"
#include "darshan-logutils.h"


/* utility functions just for darshan-diff */

static void cd_print_str(char * prefix, char * arg1, char *arg2)
{
    printf("- %s %s\n", prefix, arg1);
    printf("+ %s %s\n", prefix, arg2);
}
static void cd_print_int(char * prefix, int arg1, int arg2)
{
    printf("- %s %d\n", prefix, arg1);
    printf("+ %s %d\n", prefix, arg2);
}
static void cd_print_int64(char * prefix, int64_t arg1, int64_t arg2)
{
    printf("- %s %lld\n", prefix, arg1);
    printf("+ %s %lld\n", prefix, arg2);
}


int main(int argc, char ** argv)
{
    darshan_fd file1, file2;
    struct darshan_job job1, job2;
    struct darshan_file cp_file1, cp_file2;
    char exe1[1024], exe2[1024];
    int no_files_flag1=0, no_files_flag2=0, i, ret1,ret2;

    if (argc != 3)
    {
        fprintf(stderr, "Usage: %s <file1> <file2>\n", argv[0]);
        return(-1);
    }

    file1 = darshan_open(argv[1]);
    if(!file1) {
        perror("darshan_open");
        return(-1);
    }
    file2 = darshan_open(argv[2]);
    if(!file2) {
        perror("darshan_open");
        return(-1);
    }

    if (darshan_job_init(file1, &job1))
    {
        darshan_finalize(file1);
        return(-1);
    }
    if (darshan_job_init(file2, &job2))
    {
        darshan_finalize(file2);
        return(-1);
    }

    if (darshan_getexe(file1, exe1, &no_files_flag1))
    {
        darshan_finalize(file1);
        return(-1);
    }
    if (darshan_getexe(file2, exe2, &no_files_flag2))
    {
        darshan_finalize(file2);
        return(-1);
    }

    if (strcmp(exe1, exe2)) 
        cd_print_str("# exe: ", exe1, exe2);

    if (job1.uid != job2.uid)
        cd_print_int("# uid:", job1.uid, job2.uid);
    if (job1.start_time != job2.start_time)
        cd_print_int64("# start_time:", 
                (int64_t)job1.start_time, (int64_t)job2.start_time);
    if (job1.end_time!= job2.end_time)
        cd_print_int64("# end_time:", 
                (int64_t)job1.end_time,(int64_t)job2.end_time);
    if (job1.nprocs!= job2.nprocs)
        cd_print_int("# nprocs:", job1.nprocs, job2.nprocs);
    if ((job1.end_time-job1.start_time) != (job2.end_time - job2.start_time))
        cd_print_int64("# run time:", 
                (int64_t)(job1.end_time - job1.start_time +1),
                (int64_t)(job2.end_time - job2.start_time + 1));

    /* if for some reason no files were accessed, then we'll have to fix-up the
     * buffers in the while loop */

    do {
        ret1 = darshan_getfile(file1, &cp_file1);
	if (ret1 < 0) 
	{
		perror("darshan_getfile");
		darshan_finalize(file1);
		return(-1);
	}
        ret2 = darshan_getfile(file2, &cp_file2);
	if (ret2 < 0) 
	{
		perror("darshan_getfile");
		darshan_finalize(file2);
		return(-1);
	}


        if (ret1 > 0 && ret1 <sizeof(cp_file1))
        {
            fprintf(stderr, "Error: %s has invalid size.\n", argv[1]);
            darshan_finalize(file1);
            return(-1);
        }
        if (ret2 > 0 && ret2< sizeof(cp_file2))
        {
            fprintf(stderr, "Error: %s has invalid size.\n", argv[2]);
            darshan_finalize(file2);
            return(-1);
        }
        for(i=0; i<CP_NUM_INDICES; i++) {
            if (cp_file1.counters[i] != cp_file2.counters[i]) {
		printf("- ");
		printf("%d\t%llu\t%s\t%lld\t...%s\n",
			cp_file1.rank, cp_file1.hash, darshan_names[i], 
			cp_file1.counters[i], cp_file1.name_suffix);
		printf("+ ");
		printf("%d\t%llu\t%s\t%lld\t...%s\n",
			cp_file2.rank, cp_file2.hash, darshan_names[i], 
			cp_file2.counters[i], cp_file2.name_suffix);
            }
        }
        for(i=0; i<CP_F_NUM_INDICES; i++) {
            if (cp_file1.fcounters[i] != cp_file2.fcounters[i]) {
		printf("- ");
		printf("%d\t%llu\t%s\t%f\t...%s\n",
			cp_file1.rank, cp_file1.hash, darshan_f_names[i], 
			cp_file1.fcounters[i], cp_file1.name_suffix);
		printf("+ ");
		printf("%d\t%llu\t%s\t%f\t...%s\n",
			cp_file2.rank, cp_file2.hash, darshan_f_names[i], 
			cp_file2.fcounters[i], cp_file2.name_suffix);
            }
        }


    } while (ret1 == sizeof(cp_file1) || ret2 == sizeof(cp_file2));


    darshan_finalize(file1);
    darshan_finalize(file2);
    return(0);
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */