darshan-lustre-logutils.c 8.08 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
/*
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#define _GNU_SOURCE
#include "darshan-util-config.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "darshan-logutils.h"

/* counter name strings for the LUSTRE module */
#define X(a) #a,
char *lustre_counter_names[] = {
    LUSTRE_COUNTERS
};
#undef X

27
static int darshan_log_get_lustre_record(darshan_fd fd, void** lustre_buf_p);
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
static int darshan_log_put_lustre_record(darshan_fd fd, void* lustre_buf, int ver);
static void darshan_log_print_lustre_record(void *file_rec,
    char *file_name, char *mnt_pt, char *fs_type, int ver);
static void darshan_log_print_lustre_description(void);
static void darshan_log_print_lustre_record_diff(void *rec1, char *file_name1,
    void *rec2, char *file_name2);

struct darshan_mod_logutil_funcs lustre_logutils =
{
    .log_get_record = &darshan_log_get_lustre_record,
    .log_put_record = &darshan_log_put_lustre_record,
    .log_print_record = &darshan_log_print_lustre_record,
    .log_print_description = &darshan_log_print_lustre_description,
    .log_print_diff = &darshan_log_print_lustre_record_diff
};

44
static int darshan_log_get_lustre_record(darshan_fd fd, void** lustre_buf_p)
45
{
46 47
    struct darshan_lustre_record *rec = *((struct darshan_lustre_record **)lustre_buf_p);
    struct darshan_lustre_record tmp_rec;
48 49 50
    int i;
    int ret;

51 52 53
    if(fd->mod_map[DARSHAN_LUSTRE_MOD].len == 0)
        return(0);

54
    /* retrieve the fixed-size portion of the record */
55
    ret = darshan_log_get_mod(fd, DARSHAN_LUSTRE_MOD, &tmp_rec,
56 57 58 59 60
        sizeof(struct darshan_lustre_record));
    if(ret < 0)
        return(-1);
    else if(ret < sizeof(struct darshan_lustre_record))
        return(0);
61

62 63 64 65 66 67 68
    if(*lustre_buf_p == NULL)
    {
        rec = malloc(LUSTRE_RECORD_SIZE(tmp_rec.counters[LUSTRE_STRIPE_WIDTH]));
        if(!rec)
            return(-1);
    }
    memcpy(rec, &tmp_rec, sizeof(struct darshan_lustre_record));
69 70 71

    /* swap bytes if necessary */
    if(fd->swap_flag)
72
    {
73 74
        DARSHAN_BSWAP64(&rec->base_rec.id);
        DARSHAN_BSWAP64(&rec->base_rec.rank);
75 76
        for(i=0; i<LUSTRE_NUM_INDICES; i++)
            DARSHAN_BSWAP64(&rec->counters[i]);
77
        DARSHAN_BSWAP64(&(rec->ost_ids[0]));
78
    }
79

80 81
    /* now read the rest of the record */
    if ( rec->counters[LUSTRE_STRIPE_WIDTH] > 1 ) {
82
        ret = darshan_log_get_mod(
83 84 85 86 87 88
            fd,
            DARSHAN_LUSTRE_MOD,
            (void*)(&(rec->ost_ids[1])),
            (rec->counters[LUSTRE_STRIPE_WIDTH] - 1)*sizeof(OST_ID)
        );
        if(ret < 0)
89
            ret = -1;
90
        else if(ret < (rec->counters[LUSTRE_STRIPE_WIDTH] - 1)*sizeof(OST_ID))
91 92 93
            ret = 0;
        else
            ret = 1;
94 95 96 97
        /* swap bytes if necessary */
        if ( fd->swap_flag )
            for (i = 1; i < rec->counters[LUSTRE_STRIPE_WIDTH]; i++ )
                DARSHAN_BSWAP64(&(rec->ost_ids[i]));
98
    }
99 100 101 102 103 104 105 106 107 108 109 110
    else
    {
        ret = 1;
    }

    if(*lustre_buf_p == NULL)
    {
        if(ret == 1)
            *lustre_buf_p = rec;
        else
            free(rec);
    }
111

112
    return(ret);
113 114 115 116 117 118 119
}

static int darshan_log_put_lustre_record(darshan_fd fd, void* lustre_buf, int ver)
{
    struct darshan_lustre_record *rec = (struct darshan_lustre_record *)lustre_buf;
    int ret;

120
    ret = darshan_log_put_mod(fd, DARSHAN_LUSTRE_MOD, rec,
121
        LUSTRE_RECORD_SIZE(rec->counters[LUSTRE_STRIPE_WIDTH]), DARSHAN_LUSTRE_VER);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    if(ret < 0)
        return(-1);

    return(0);
}

static void darshan_log_print_lustre_record(void *rec, char *file_name,
    char *mnt_pt, char *fs_type, int ver)
{
    int i;
    struct darshan_lustre_record *lustre_rec =
        (struct darshan_lustre_record *)rec;

    for(i=0; i<LUSTRE_NUM_INDICES; i++)
    {
        DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
138
            lustre_rec->base_rec.rank, lustre_rec->base_rec.id, lustre_counter_names[i],
139 140 141
            lustre_rec->counters[i], file_name, mnt_pt, fs_type);
    }

142 143 144 145 146
    for (i = 0; i < lustre_rec->counters[LUSTRE_STRIPE_WIDTH]; i++ )
    {
        char strbuf[25];
        snprintf( strbuf, 25, "LUSTRE_OST_ID_%d", i );
        DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
147 148
            lustre_rec->base_rec.rank,
            lustre_rec->base_rec.id,
149 150 151 152 153 154 155
            strbuf,
            lustre_rec->ost_ids[i],
            file_name,
            mnt_pt,
            fs_type);
    }

156 157 158 159 160 161 162
    return;
}

static void darshan_log_print_lustre_description()
{
    /* TODO: add actual counter descriptions here */
    printf("\n# description of LUSTRE counters:\n");
163 164 165 166
    printf("#   LUSTRE_OSTS: number of OSTs across the entire file system.\n");
    printf("#   LUSTRE_MDTS: number of MDTs across the entire file system.\n");
    printf("#   LUSTRE_STRIPE_SIZE: stripe size for file in bytes.\n");
    printf("#   LUSTRE_STRIPE_WIDTH: number of OSTs over which file is striped.\n");
167 168
    printf("#   LUSTRE_STRIPE_OFFSET: OST ID offset specified when the file was created.\n");
    printf("#   LUSTRE_OST_ID_*: indices of OSTs over which the file is striped.\n");
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

    DARSHAN_PRINT_HEADER();

    return;
}

static void darshan_log_print_lustre_record_diff(void *rec1, char *file_name1,
    void *rec2, char *file_name2)
{
    struct darshan_lustre_record *lustre_rec1 = (struct darshan_lustre_record *)rec1;
    struct darshan_lustre_record *lustre_rec2 = (struct darshan_lustre_record *)rec2;
    int i;

    /* NOTE: we assume that both input records are the same module format version */

    for(i=0; i<LUSTRE_NUM_INDICES; i++)
    {
        if(!lustre_rec2)
        {
            printf("- ");
            DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
190 191
                lustre_rec1->base_rec.rank, lustre_rec1->base_rec.id,
                lustre_counter_names[i], lustre_rec1->counters[i], file_name1, "", "");
192 193 194 195 196 197

        }
        else if(!lustre_rec1)
        {
            printf("+ ");
            DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
198 199
                lustre_rec2->base_rec.rank, lustre_rec2->base_rec.id,
                lustre_counter_names[i], lustre_rec2->counters[i], file_name2, "", "");
200 201 202 203 204
        }
        else if(lustre_rec1->counters[i] != lustre_rec2->counters[i])
        {
            printf("- ");
            DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
205 206
                lustre_rec1->base_rec.rank, lustre_rec1->base_rec.id,
                lustre_counter_names[i], lustre_rec1->counters[i], file_name1, "", "");
207 208
            printf("+ ");
            DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
209 210
                lustre_rec2->base_rec.rank, lustre_rec2->base_rec.id,
                lustre_counter_names[i], lustre_rec2->counters[i], file_name2, "", "");
211 212 213
        }
    }

214 215 216 217 218 219 220 221 222 223
    /* would it be more or less useful to sort the OST IDs before comparing? */
    if ( lustre_rec1->counters[LUSTRE_STRIPE_WIDTH] == lustre_rec2->counters[LUSTRE_STRIPE_WIDTH] ) {
        for (i = 0; i < lustre_rec1->counters[LUSTRE_STRIPE_WIDTH]; i++ )
        {
            if (lustre_rec1->ost_ids[i] != lustre_rec2->ost_ids[i])
            {
                char strbuf[25];
                snprintf( strbuf, 25, "LUSTRE_OST_ID_%d", i );
                printf("- ");
                DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
224 225
                    lustre_rec1->base_rec.rank,
                    lustre_rec1->base_rec.id,
226 227 228 229 230 231 232
                    strbuf,
                    lustre_rec1->ost_ids[i],
                    file_name1,
                    "",
                    "");
                printf("+ ");
                DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_LUSTRE_MOD],
233 234
                    lustre_rec2->base_rec.rank,
                    lustre_rec2->base_rec.id,
235 236 237 238 239 240 241 242 243
                    strbuf,
                    lustre_rec2->ost_ids[i],
                    file_name2,
                    "",
                    "");
            }
        }
    }

244 245 246 247 248 249 250 251 252 253 254
    return;
}

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