darshan-diff.c 4.07 KB
Newer Older
1
2
3
4
5
/*
 *  (C) 2009 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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)
{
Philip Carns's avatar
Philip Carns committed
27
28
    printf("- %s %" PRId64 "\n", prefix, arg1);
    printf("+ %s %" PRId64 "\n", prefix, arg2);
29
30
31
32
33
34
35
36
37
}


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];
38
    int i, ret1,ret2;
39
40
41
42
43
44
45

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

46
    file1 = darshan_log_open(argv[1], "r");
47
    if(!file1) {
48
        perror("darshan_log_open");
49
50
        return(-1);
    }
51
    file2 = darshan_log_open(argv[2], "r");
52
    if(!file2) {
53
        perror("darshan_log_open");
54
55
56
        return(-1);
    }

57
    if (darshan_log_getjob(file1, &job1))
58
    {
59
        darshan_log_close(file1);
60
61
        return(-1);
    }
62
    if (darshan_log_getjob(file2, &job2))
63
    {
64
        darshan_log_close(file2);
65
66
67
        return(-1);
    }

68
    if (darshan_log_getexe(file1, exe1))
69
    {
70
        darshan_log_close(file1);
71
72
        return(-1);
    }
73
    if (darshan_log_getexe(file2, exe2))
74
    {
75
        darshan_log_close(file2);
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
        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 {
101
        ret1 = darshan_log_getfile(file1, &job1, &cp_file1);
102
103
	if (ret1 < 0) 
	{
104
105
		perror("darshan_log_getfile");
		darshan_log_close(file1);
106
107
		return(-1);
	}
108
        ret2 = darshan_log_getfile(file2, &job2, &cp_file2);
109
110
	if (ret2 < 0) 
	{
111
112
		perror("darshan_log_getfile");
		darshan_log_close(file2);
113
114
115
116
117
118
		return(-1);
	}

        for(i=0; i<CP_NUM_INDICES; i++) {
            if (cp_file1.counters[i] != cp_file2.counters[i]) {
		printf("- ");
Philip Carns's avatar
Philip Carns committed
119
		printf("%" PRId64 "\t%" PRIu64 "\t%s\t%" PRId64 "\t...%s\n",
120
121
			cp_file1.rank, cp_file1.hash, darshan_names[i], 
			cp_file1.counters[i], cp_file1.name_suffix);
122
		printf("+ ");
Philip Carns's avatar
Philip Carns committed
123
		printf("%" PRId64 "\t%" PRIu64 "\t%s\t%" PRId64 "\t...%s\n",
124
125
			cp_file2.rank, cp_file2.hash, darshan_names[i], 
			cp_file2.counters[i], cp_file2.name_suffix);
126
127
128
129
130
            }
        }
        for(i=0; i<CP_F_NUM_INDICES; i++) {
            if (cp_file1.fcounters[i] != cp_file2.fcounters[i]) {
		printf("- ");
Philip Carns's avatar
Philip Carns committed
131
		printf("%" PRId64 "\t%" PRIu64 "\t%s\t%f\t...%s\n",
132
			cp_file1.rank, cp_file1.hash, darshan_f_names[i], 
133
134
			cp_file1.fcounters[i], cp_file1.name_suffix);
		printf("+ ");
Philip Carns's avatar
Philip Carns committed
135
		printf("%" PRId64 "\t%" PRIu64 "\t%s\t%f\t...%s\n",
136
			cp_file2.rank, cp_file2.hash, darshan_f_names[i], 
137
138
139
140
141
			cp_file2.fcounters[i], cp_file2.name_suffix);
            }
        }


142
    } while (ret1 == 1 || ret2 == 1);
143
144


145
146
    darshan_log_close(file1);
    darshan_log_close(file2);
147
148
149
150
151
152
153
154
155
156
157
    return(0);
}

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