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

6
#define _GNU_SOURCE
7
#include "darshan-util-config.h"
8 9
#include <stdio.h>
#include <string.h>
10
#include <assert.h>
11
#include <stdlib.h>
12
#include <unistd.h>
13
#include <inttypes.h>
14 15 16 17
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

18 19 20 21 22
#include <zlib.h>
#ifdef HAVE_LIBBZ2
#include <bzlib.h>
#endif

23 24
#include "darshan-logutils.h"

25 26 27 28 29 30 31 32 33 34 35 36
struct darshan_fd_s
{
    gzFile gzf;
#ifdef HAVE_LIBBZ2
    BZFILE* bzf;
#endif
    int64_t pos;
    char mode[2];
    int swap_flag;
    char version[10];
    int job_struct_size;
    char* name;
Philip Carns's avatar
Philip Carns committed
37
    int COMPAT_CP_EXE_LEN;
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
/* isn't there a clever c way to avoid this? */
char *darshan_names[] = {
    "CP_INDEP_OPENS",
    "CP_COLL_OPENS",               /* count of MPI collective opens */
    "CP_INDEP_READS",              /* count of independent MPI reads */
    "CP_INDEP_WRITES",             /* count of independent MPI writes */
    "CP_COLL_READS",               /* count of collective MPI reads */
    "CP_COLL_WRITES",              /* count of collective MPI writes */
    "CP_SPLIT_READS",              /* count of split collective MPI reads */
    "CP_SPLIT_WRITES",             /* count of split collective MPI writes */
    "CP_NB_READS",                 /* count of nonblocking MPI reads */
    "CP_NB_WRITES",                /* count of nonblocking MPI writes */
    "CP_SYNCS",                    /* count of MPI_File_sync */
    "CP_POSIX_READS",              /* count of posix reads */
    "CP_POSIX_WRITES",             /* count of posix writes */
    "CP_POSIX_OPENS",              /* count of posix opens */
    "CP_POSIX_SEEKS",              /* count of posix seeks */
    "CP_POSIX_STATS",              /* count of posix stat/lstat/fstats */
    "CP_POSIX_MMAPS",              /* count of posix mmaps */
    "CP_POSIX_FREADS",
    "CP_POSIX_FWRITES",
    "CP_POSIX_FOPENS",
    "CP_POSIX_FSEEKS",
    "CP_POSIX_FSYNCS",
    "CP_POSIX_FDSYNCS",
65 66 67
    "CP_INDEP_NC_OPENS",
    "CP_COLL_NC_OPENS",
    "CP_HDF5_OPENS",
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
    "CP_COMBINER_NAMED",           /* count of each MPI datatype category */
    "CP_COMBINER_DUP",
    "CP_COMBINER_CONTIGUOUS",
    "CP_COMBINER_VECTOR",
    "CP_COMBINER_HVECTOR_INTEGER",
    "CP_COMBINER_HVECTOR",
    "CP_COMBINER_INDEXED",
    "CP_COMBINER_HINDEXED_INTEGER",
    "CP_COMBINER_HINDEXED",
    "CP_COMBINER_INDEXED_BLOCK",
    "CP_COMBINER_STRUCT_INTEGER",
    "CP_COMBINER_STRUCT",
    "CP_COMBINER_SUBARRAY",
    "CP_COMBINER_DARRAY",
    "CP_COMBINER_F90_REAL",
    "CP_COMBINER_F90_COMPLEX",
    "CP_COMBINER_F90_INTEGER",
    "CP_COMBINER_RESIZED",
    "CP_HINTS",                     /* count of MPI hints used */
    "CP_VIEWS",                     /* count of MPI set view calls */
    "CP_MODE",                      /* mode of file */
    "CP_BYTES_READ",                /* total bytes read */
    "CP_BYTES_WRITTEN",             /* total bytes written */
    "CP_MAX_BYTE_READ",             /* highest offset byte read */
    "CP_MAX_BYTE_WRITTEN",          /* highest offset byte written */
    "CP_CONSEC_READS",              /* count of consecutive reads */
    "CP_CONSEC_WRITES",             /* count of consecutive writes */
    "CP_SEQ_READS",                 /* count of sequential reads */
    "CP_SEQ_WRITES",                /* count of sequential writes */
    "CP_RW_SWITCHES",
    "CP_MEM_NOT_ALIGNED",           /* count of accesses not mem aligned */
    "CP_MEM_ALIGNMENT",             /* mem alignment in bytes */
    "CP_FILE_NOT_ALIGNED",          /* count of accesses not file aligned */
    "CP_FILE_ALIGNMENT",            /* file alignment in bytes */
102 103
    "CP_MAX_READ_TIME_SIZE",
    "CP_MAX_WRITE_TIME_SIZE",
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
    "CP_SIZE_READ_0_100",           /* count of posix read size ranges */
    "CP_SIZE_READ_100_1K",
    "CP_SIZE_READ_1K_10K",
    "CP_SIZE_READ_10K_100K",
    "CP_SIZE_READ_100K_1M",
    "CP_SIZE_READ_1M_4M",
    "CP_SIZE_READ_4M_10M",
    "CP_SIZE_READ_10M_100M",
    "CP_SIZE_READ_100M_1G",
    "CP_SIZE_READ_1G_PLUS",
    "CP_SIZE_WRITE_0_100",          /* count of posix write size ranges */
    "CP_SIZE_WRITE_100_1K",
    "CP_SIZE_WRITE_1K_10K",
    "CP_SIZE_WRITE_10K_100K",
    "CP_SIZE_WRITE_100K_1M",
    "CP_SIZE_WRITE_1M_4M",
    "CP_SIZE_WRITE_4M_10M",
    "CP_SIZE_WRITE_10M_100M",
    "CP_SIZE_WRITE_100M_1G",
    "CP_SIZE_WRITE_1G_PLUS",
    "CP_SIZE_READ_AGG_0_100",       /* count of MPI read size ranges */
    "CP_SIZE_READ_AGG_100_1K",
    "CP_SIZE_READ_AGG_1K_10K",
    "CP_SIZE_READ_AGG_10K_100K",
    "CP_SIZE_READ_AGG_100K_1M",
    "CP_SIZE_READ_AGG_1M_4M",
    "CP_SIZE_READ_AGG_4M_10M",
    "CP_SIZE_READ_AGG_10M_100M",
    "CP_SIZE_READ_AGG_100M_1G",
    "CP_SIZE_READ_AGG_1G_PLUS",
    "CP_SIZE_WRITE_AGG_0_100",      /* count of MPI write size ranges */
    "CP_SIZE_WRITE_AGG_100_1K",
    "CP_SIZE_WRITE_AGG_1K_10K",
    "CP_SIZE_WRITE_AGG_10K_100K",
    "CP_SIZE_WRITE_AGG_100K_1M",
    "CP_SIZE_WRITE_AGG_1M_4M",
    "CP_SIZE_WRITE_AGG_4M_10M",
    "CP_SIZE_WRITE_AGG_10M_100M",
    "CP_SIZE_WRITE_AGG_100M_1G",
    "CP_SIZE_WRITE_AGG_1G_PLUS",
    "CP_EXTENT_READ_0_100",          /* count of MPI read extent ranges */
    "CP_EXTENT_READ_100_1K",
    "CP_EXTENT_READ_1K_10K",
    "CP_EXTENT_READ_10K_100K",
    "CP_EXTENT_READ_100K_1M",
    "CP_EXTENT_READ_1M_4M",
    "CP_EXTENT_READ_4M_10M",
    "CP_EXTENT_READ_10M_100M",
    "CP_EXTENT_READ_100M_1G",
    "CP_EXTENT_READ_1G_PLUS",
    "CP_EXTENT_WRITE_0_100",         /* count of MPI write extent ranges */
    "CP_EXTENT_WRITE_100_1K",
    "CP_EXTENT_WRITE_1K_10K",
    "CP_EXTENT_WRITE_10K_100K",
    "CP_EXTENT_WRITE_100K_1M",
    "CP_EXTENT_WRITE_1M_4M",
    "CP_EXTENT_WRITE_4M_10M",
    "CP_EXTENT_WRITE_10M_100M",
    "CP_EXTENT_WRITE_100M_1G",
    "CP_EXTENT_WRITE_1G_PLUS",
    "CP_STRIDE1_STRIDE",             /* the four most frequently appearing strides */
    "CP_STRIDE2_STRIDE",
    "CP_STRIDE3_STRIDE",
    "CP_STRIDE4_STRIDE",
    "CP_STRIDE1_COUNT",              /* count of each of the most frequent strides */
    "CP_STRIDE2_COUNT",
    "CP_STRIDE3_COUNT",
    "CP_STRIDE4_COUNT",
    "CP_ACCESS1_ACCESS",
    "CP_ACCESS2_ACCESS",
    "CP_ACCESS3_ACCESS",
    "CP_ACCESS4_ACCESS",
    "CP_ACCESS1_COUNT",
    "CP_ACCESS2_COUNT",
    "CP_ACCESS3_COUNT",
    "CP_ACCESS4_COUNT",
180
    "CP_DEVICE",
181
    "CP_SIZE_AT_OPEN",
182 183 184 185
    "CP_FASTEST_RANK",
    "CP_FASTEST_RANK_BYTES",
    "CP_SLOWEST_RANK",
    "CP_SLOWEST_RANK_BYTES",
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203

    "CP_NUM_INDICES"
};

/* isn't there a clever c way to avoid this? */
char *darshan_f_names[] = {
    "CP_F_OPEN_TIMESTAMP",        /* timestamp of first open */
    "CP_F_READ_START_TIMESTAMP",  /* timestamp of first read */
    "CP_F_WRITE_START_TIMESTAMP", /* timestamp of first write */
    "CP_F_CLOSE_TIMESTAMP",       /* timestamp of last close */
    "CP_F_READ_END_TIMESTAMP",    /* timestamp of last read */
    "CP_F_WRITE_END_TIMESTAMP",   /* timestamp of last write */
    "CP_F_POSIX_READ_TIME",       /* cumulative posix read time */
    "CP_F_POSIX_WRITE_TIME",      /* cumulative posix write time */
    "CP_F_POSIX_META_TIME",       /* cumulative posix meta time */
    "CP_F_MPI_META_TIME",         /* cumulative mpi-io metadata time */
    "CP_F_MPI_READ_TIME",         /* cumulative mpi-io read time */
    "CP_F_MPI_WRITE_TIME",        /* cumulative mpi-io write time */
204 205
    "CP_F_MAX_READ_TIME",
    "CP_F_MAX_WRITE_TIME",
206 207 208 209 210 211
    "CP_F_FASTEST_RANK_TIME",
    "CP_F_SLOWEST_RANK_TIME",
    "CP_F_VARIANCE_RANK_TIME",
    "CP_F_VARIANCE_RANK_BYTES",

    "CP_F_NUM_INDICES"
212 213
};

214 215 216 217 218 219 220
/* function pointers so that we can switch functions depending on what file
 * version is detected
 */
int (*getjob_internal)(darshan_fd file, struct darshan_job *job);
int (*getfile_internal)(darshan_fd fd, 
    struct darshan_job *job, 
    struct darshan_file *file);
221
#define JOB_SIZE_124 28
222
#define JOB_SIZE_200 56
Philip Carns's avatar
Philip Carns committed
223 224
#define CP_JOB_RECORD_SIZE_200 1024
#define CP_JOB_RECORD_SIZE_1x 1024
225

226
/* internal routines for parsing different file versions */
227
static int getjob_internal_201(darshan_fd file, struct darshan_job *job);
228
static int getjob_internal_200(darshan_fd file, struct darshan_job *job);
Philip Carns's avatar
Philip Carns committed
229 230
static int getfile_internal_204(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file);
231 232 233 234 235 236 237 238 239
static int getfile_internal_200(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file);
static int getjob_internal_124(darshan_fd file, struct darshan_job *job);
static int getfile_internal_124(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file);
static int getfile_internal_122(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file);
static int getfile_internal_121(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file);
240 241
static int getfile_internal_1x(darshan_fd fd, struct darshan_job *job, 
    struct darshan_file *file, int n_counters, int n_fcounters);
242
static void shift_missing_1_24(struct darshan_file* file);
243 244
static void shift_missing_1_22(struct darshan_file* file);
static void shift_missing_1_21(struct darshan_file* file);
245

246 247
static int darshan_log_seek(darshan_fd fd, int64_t offset);
static int darshan_log_read(darshan_fd fd, void* buf, int len);
248
static int darshan_log_write(darshan_fd fd, void* buf, int len);
249 250
static const char* darshan_log_error(darshan_fd fd, int* errnum);

251
/* a rather crude API for accessing raw binary darshan files */
252
darshan_fd darshan_log_open(const char *name, const char* mode)
253
{
254 255 256 257 258 259
    int test_fd;
    uint8_t magic[2];
    int ret;
    int try_bz2 = 1;
    int len = strlen(name);

260 261 262 263
    /* we only allows "w" or "r" modes, nothing fancy */
    assert(strlen(mode) == 1);
    assert(mode[0] == 'r' || mode[0] == 'w');

264 265 266 267 268
    darshan_fd tmp_fd = malloc(sizeof(*tmp_fd));
    if(!tmp_fd)
        return(NULL);
    memset(tmp_fd, 0, sizeof(*tmp_fd));

269 270 271 272 273 274 275 276 277
    tmp_fd->mode[0] = mode[0];
    tmp_fd->mode[1] = mode[1];
    tmp_fd->name  = strdup(name);
    if(!tmp_fd->name)
    {
        free(tmp_fd);
        return(NULL);
    }

278 279 280 281 282 283 284 285
    if(strcmp(mode, "r") == 0)
    {
        /* Try to detect if existing file is a bzip2 file or not.  Both 
         * libbz2 and libz will fall back to normal I/O (without compression) 
         * automatically, so we need to do some detection manually up front 
         * in order to get a chance to try both compression formats.
         */
        test_fd = open(name, O_RDONLY);
286
        if(test_fd < 0)
287 288
        {
            perror("open");
289
            free(tmp_fd->name);
290 291 292 293 294 295 296 297
            free(tmp_fd);
            return(NULL);
        }
        ret = read(test_fd, &magic, 2);
        if(ret != 2)
        {
            fprintf(stderr, "Error: failed to read any data from %s.\n", 
                name);
298
            free(tmp_fd->name);
299 300 301 302 303 304 305 306 307 308 309
            free(tmp_fd);
            close(test_fd);
            return(NULL);
        }
        /* header magic for bz2 */
        if(magic[0] != 0x42 && magic[1] != 0x5A)
        {
            try_bz2 = 0;
        }
        close(test_fd);
    }
310

311 312 313 314 315 316
    if(strcmp(mode, "w") == 0)
    {
        /* TODO: is this the behavior that we want? */
        /* if we are writing a new file, go by the file extension to tell
         * whether to use bz2 or not?
         */
317
        if(len >= 3 && name[len-3] == 'b' && name[len-2] == 'z' && name[len-1] == '2')
318 319 320 321 322
            try_bz2 = 1;
        else
            try_bz2 = 0;
    }

323
#ifdef HAVE_LIBBZ2
324 325 326
    if(try_bz2)
    {
        tmp_fd->bzf = BZ2_bzopen(name, mode);
327
        if(!tmp_fd->bzf)
328
        {
329 330 331
            free(tmp_fd->name);
            free(tmp_fd);
            return(NULL);
332
        }
333
        return(tmp_fd);
334
    }
335 336 337 338 339 340 341
#else
    if(try_bz2)
    {
        fprintf(stderr, "Error: this Darshan build does not support bz2 files.\n");
        fprintf(stderr, "Error: please install libbz2-dev and reconfigure.\n");
        return(NULL);
    }
342 343
#endif

344
    tmp_fd->gzf = gzopen(name, mode);
345 346
    if(!tmp_fd->gzf)
    {
347
        free(tmp_fd->name);
348 349 350 351
        free(tmp_fd);
        tmp_fd = NULL;
    }
    return tmp_fd;
352 353
}

354
/* darshan_log_getjob()
355 356 357
 *
 * returns 0 on success, -1 on failure
 */
358
int darshan_log_getjob(darshan_fd file, struct darshan_job *job)
359 360
{
    int ret;
361
    char buffer[DARSHAN_JOB_METADATA_LEN];
362

363 364 365
    ret = darshan_log_seek(file, 0);
    if(ret < 0)
        return(ret);
366

367 368 369
    /* read version number first so we know how to digest the rest of the
     * file
     */
370
    ret = darshan_log_read(file, file->version, 10);
371
    if(ret < 10)
372
    {
373
        fprintf(stderr, "Error: invalid log file (failed to read version).\n");
374 375 376
        return(-1);
    }

Philip Carns's avatar
Philip Carns committed
377 378 379 380 381 382 383 384
    if(strcmp(file->version, "2.05") == 0)
    {
        getjob_internal = getjob_internal_201;
        getfile_internal = getfile_internal_204;
        file->job_struct_size = sizeof(*job);
        file->COMPAT_CP_EXE_LEN = CP_EXE_LEN;
    }
    else if(strcmp(file->version, "2.04") == 0)
Philip Carns's avatar
Philip Carns committed
385 386 387 388 389 390 391
    {
        getjob_internal = getjob_internal_201;
        getfile_internal = getfile_internal_204;
        file->job_struct_size = sizeof(*job);
        file->COMPAT_CP_EXE_LEN = CP_EXE_LEN;
    }
    else if(strcmp(file->version, "2.03") == 0)
392 393 394 395
    {
        getjob_internal = getjob_internal_201;
        getfile_internal = getfile_internal_200;
        file->job_struct_size = sizeof(*job);
Philip Carns's avatar
Philip Carns committed
396
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_200-file->job_struct_size-1;
397 398
    }
    else if(strcmp(file->version, "2.02") == 0)
Philip Carns's avatar
Philip Carns committed
399 400 401 402
    {
        getjob_internal = getjob_internal_201;
        getfile_internal = getfile_internal_200;
        file->job_struct_size = sizeof(*job);
Philip Carns's avatar
Philip Carns committed
403
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_200-file->job_struct_size-1;
Philip Carns's avatar
Philip Carns committed
404 405
    }
    else if(strcmp(file->version, "2.01") == 0)
406
    {
407
        getjob_internal = getjob_internal_201;
408
        getfile_internal = getfile_internal_200;
409
        file->job_struct_size = sizeof(*job);
Philip Carns's avatar
Philip Carns committed
410
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_200-file->job_struct_size-1;
411
    }
412 413 414 415 416
    else if(strcmp(file->version, "2.00") == 0)
    {
        getjob_internal = getjob_internal_200;
        getfile_internal = getfile_internal_200;
        file->job_struct_size = JOB_SIZE_200;
Philip Carns's avatar
Philip Carns committed
417
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_200-file->job_struct_size-1;
418
    }
419
    else if(strcmp(file->version, "1.24") == 0)
420
    {
421 422
        getjob_internal = getjob_internal_124;
        getfile_internal = getfile_internal_124;
423
        file->job_struct_size = JOB_SIZE_124;
Philip Carns's avatar
Philip Carns committed
424
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_1x-file->job_struct_size-1;
425
    }
426
    else if(strcmp(file->version, "1.23") == 0)
427
    {
428 429 430
        /* same as 1.24, except that mnt points may be incorrect */
        getjob_internal = getjob_internal_124;
        getfile_internal = getfile_internal_124;
431
        file->job_struct_size = JOB_SIZE_124;
Philip Carns's avatar
Philip Carns committed
432
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_1x-file->job_struct_size-1;
433
    }
434
    else if(strcmp(file->version, "1.22") == 0)
435
    {
436 437
        getjob_internal = getjob_internal_124;
        getfile_internal = getfile_internal_122;
438
        file->job_struct_size = JOB_SIZE_124;
Philip Carns's avatar
Philip Carns committed
439
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_1x-file->job_struct_size-1;
440
    }
441
    else if(strcmp(file->version, "1.21") == 0)
442
    {
443
        getjob_internal = getjob_internal_124;
Philip Carns's avatar
Philip Carns committed
444
        getfile_internal = getfile_internal_121;
445
        file->job_struct_size = JOB_SIZE_124;
Philip Carns's avatar
Philip Carns committed
446
        file->COMPAT_CP_EXE_LEN = CP_JOB_RECORD_SIZE_1x-file->job_struct_size-1;
447 448
    }
    else
449
    {
450 451 452
        fprintf(stderr, "Error: incompatible darshan file.\n");
        fprintf(stderr, "Error: expected version %s, but got %s\n", 
                CP_VERSION, file->version);
453
        return(-1);
454 455
    }

456
    ret = getjob_internal(file, job);
457 458 459

    if (ret == 0)
    {
460
#ifdef HAVE_STRNDUP
461
        char *metadata = strndup(job->metadata, sizeof(job->metadata));
462
#else
Philip Carns's avatar
bug fix  
Philip Carns committed
463
        char *metadata = strdup(job->metadata);
464
#endif
465 466
        char *kv;
        char *key;
467
        char *value;
468 469
        char *save;

470 471 472
        for(kv=strtok_r(metadata, "\n", &save);
            kv != NULL;
            kv=strtok_r(NULL, "\n", &save))
473
        {
474 475 476 477 478 479 480 481 482 483 484 485
            /* NOTE: we intentionally only split on the first = character.
             * There may be additional = characters in the value portion
             * (for example, when storing mpi-io hints).
             */
            strcpy(buffer, kv);
            key = buffer;
            value = index(buffer, '=');
            if(!value)
                continue;
            /* convert = to a null terminator to split key and value */
            value[0] = '\0';
            value++;
486
            if (strcmp(key, "prev_ver") == 0)
487
            {
488
                strncpy(job->version_string, value, sizeof(job->version_string));
489
            }
490 491
        }
        free(metadata);
492 493
    }

494 495
    return(ret);
}
496

497 498 499 500 501 502 503 504
/* darshan_putjob()
 * write job header in gzfile
 *
 * return 0 on success, -1 on failure.
 */
int darshan_log_putjob(darshan_fd file, struct darshan_job *job)
{
    struct darshan_job job_copy;
505
    char    pv_str[64];
506
    int     ret;
507
    int len;
508

509 510
    ret = darshan_log_seek(file, 0);
    if(ret < 0)
511 512
        return(ret);

513 514
    memset(&job_copy, 0, sizeof(job_copy));
    memcpy(&job_copy, job, sizeof(job_copy));
515 516 517 518 519 520 521 522 523 524 525
    /* check for newline in existing metadata, add if needed */
    len = strlen(job_copy.metadata);
    if(len > 0 && len < DARSHAN_JOB_METADATA_LEN)
    {
        if(job_copy.metadata[len-1] != '\n')
        {
            job_copy.metadata[len] = '\n';
            job_copy.metadata[len+1] = '\0';
        }
    }

526
    sprintf(pv_str, "prev_ver=%s\n", job->version_string);
527
    sprintf(job_copy.version_string, "%s", CP_VERSION);
Philip Carns's avatar
Philip Carns committed
528 529 530 531
    if(strlen(job_copy.metadata) + strlen(pv_str) < DARSHAN_JOB_METADATA_LEN)
        strncat(job_copy.metadata, pv_str, strlen(pv_str));
    else
        sprintf(job_copy.metadata, "%s", pv_str);
532 533
    job_copy.magic_nr = CP_MAGIC_NR;

534
    ret = darshan_log_write(file, &job_copy, sizeof(job_copy));
535 536 537 538 539 540 541 542 543
    if (ret != sizeof(job_copy))
    {
        fprintf(stderr, "Error: failed to write job header: %d\n", ret);
        return(-1);
    }

    return(0);
}

544 545 546 547 548 549 550
/* darshan_log_getfile()
 *
 * return 1 if file record found, 0 on eof, and -1 on error
 */
int darshan_log_getfile(darshan_fd fd, struct darshan_job *job, struct darshan_file *file)
{
    int ret;
551

552 553 554
    ret = getfile_internal(fd, job, file);

    return(ret);
555 556
}

557 558 559 560 561 562 563 564
/* darshan_log_putfile()
 *
 * return 0 if file record written, -1 on error.
 */
int darshan_log_putfile(darshan_fd fd, struct darshan_job *job, struct darshan_file *file)
{
    int     ret;

565 566 567 568 569 570
    if(fd->pos < CP_JOB_RECORD_SIZE)
    {
        ret = darshan_log_seek(fd, CP_JOB_RECORD_SIZE);
        if(ret < 0)
            return(ret);
    }
571

572
    ret = darshan_log_write(fd, file, sizeof(*file));
573 574 575 576 577 578 579 580 581
    if (ret != sizeof(*file))
    {
        fprintf(stderr, "Error: writing file record failed: %d\n", ret);
        return(-1);
    }

    return(0);
}

582 583 584 585 586 587
/* darshan_log_getmounts()
 * 
 * retrieves mount table information from the log.  Note that devs, mnt_pts,
 * and fs_types are arrays that will be allocated by the function and must
 * be freed by the caller.  count will indicate the size of the arrays
 */
588
int darshan_log_getmounts(darshan_fd fd, int64_t** devs, char*** mnt_pts, char***
589
    fs_types, int* count)
590 591 592 593
{
    int ret;
    char* pos;
    int array_index = 0;
Philip Carns's avatar
Philip Carns committed
594
    char buf[fd->COMPAT_CP_EXE_LEN+1];
595

596 597 598
    ret = darshan_log_seek(fd, fd->job_struct_size);
    if(ret < 0)
        return(ret);
599

Philip Carns's avatar
Philip Carns committed
600 601
    ret = darshan_log_read(fd, buf, (fd->COMPAT_CP_EXE_LEN + 1));
    if (ret < (fd->COMPAT_CP_EXE_LEN + 1))
602
    {
603
        perror("darshan_log_read");
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
        return(-1);
    }

    /* count entries */
    *count = 0;
    pos = buf;
    while((pos = strchr(pos, '\n')) != NULL)
    {
        pos++;
        (*count)++;
    }

    if(*count == 0)
    {
        /* no mount entries present */
        return(0);
    }

    /* allocate output arrays */
623
    *devs = malloc((*count)*sizeof(int64_t));
624 625 626 627 628 629 630 631 632 633 634 635
    assert(*devs);
    *mnt_pts = malloc((*count)*sizeof(char*));
    assert(*mnt_pts);
    *fs_types = malloc((*count)*sizeof(char*));
    assert(*fs_types);
    
    /* work backwards through the table and parse each line (except for
     * first, which holds command line information)
     */
    while((pos = strrchr(buf, '\n')) != NULL)
    {
        /* overestimate string lengths */
Philip Carns's avatar
Philip Carns committed
636
        (*mnt_pts)[array_index] = malloc(fd->COMPAT_CP_EXE_LEN);
637
        assert((*mnt_pts)[array_index]);
Philip Carns's avatar
Philip Carns committed
638
        (*fs_types)[array_index] = malloc(fd->COMPAT_CP_EXE_LEN);
639 640
        assert((*fs_types)[array_index]);
        
Philip Carns's avatar
Philip Carns committed
641
        ret = sscanf(++pos, "%" PRId64 "\t%s\t%s", &(*devs)[array_index],
642 643
            (*fs_types)[array_index], (*mnt_pts)[array_index]);

644 645 646 647 648 649 650 651 652
        if(ret != 3)
        {
            fprintf(stderr, "Error: poorly formatted mount table in log file.\n");
            return(-1);
        }
        pos--;
        *pos = '\0';
        array_index++;
    }
653

654 655 656
    return (0);
}

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
/* darshan_log_putmounts
 *
 * encode mount information back into mtab format.
 *
 * returns 0 on success, -1 on failure.
 */
int darshan_log_putmounts(darshan_fd fd, int64_t* devs, char** mnt_pts, char** fs_types, int count)
{
    int     ret;
    char    line[1024];
    int     i;

    for(i=count-1; i>=0; i--)
    {
        sprintf(line, "\n%" PRId64 "\t%s\t%s",
                devs[i], fs_types[i], mnt_pts[i]);
673
        ret = darshan_log_write(fd, line, strlen(line));
674 675 676 677 678 679
        if (ret != strlen(line))
        {
            fprintf(stderr, "Error: failed to write mount entry: %d\n", ret);
            return(-1);
        }
    }
680 681 682 683 684 685 686 687

    /* seek ahead to end of exe region, will be zero filled */
    ret = darshan_log_seek(fd, CP_JOB_RECORD_SIZE);
    if (ret)
    {
        fprintf(stderr, "Error: forward seek failed: %d\n", CP_JOB_RECORD_SIZE);
    }

688 689
    return(0);
}
690

691
int darshan_log_getexe(darshan_fd fd, char *buf)
692 693
{
    int ret;
694
    char* newline;
695

696 697 698
    ret = darshan_log_seek(fd, fd->job_struct_size);
    if(ret < 0)
        return(ret);
699

Philip Carns's avatar
Philip Carns committed
700 701
    ret = darshan_log_read(fd, buf, (fd->COMPAT_CP_EXE_LEN + 1));
    if (ret < (fd->COMPAT_CP_EXE_LEN + 1))
702
    {
703
        perror("darshan_log_read");
704 705
        return(-1);
    }
706

707 708 709 710 711 712 713 714
    /* this call is only supposed to return the exe string, but starting in
     * log format 1.23 there could be a table of mount entry information
     * after the exe.  Look for newline character and truncate there.
     */
    newline = strchr(buf, '\n');
    if(newline)
        *newline = '\0';

715 716 717
    return (0);
}

718 719 720 721 722 723 724 725 726 727 728
/* darshan_log_putexe()
 *
 * Write the exe string to the log.
 *
 * return 0 on success, -1 on failure.
 */
int darshan_log_putexe(darshan_fd fd, char *buf)
{
    int     ret;
    int     len;

729 730
    ret = darshan_log_seek(fd, sizeof(struct darshan_job));
    if(ret < 0)
731 732 733 734
        return(ret);

    len = strlen(buf);

735
    ret = darshan_log_write(fd, buf, len);
736 737 738 739 740 741 742 743 744
    if (ret != len)
    {
        fprintf(stderr, "Error: failed to write exe info: %d\n", ret);
        ret = -1;
    }

    return(ret);
}

745
void darshan_log_close(darshan_fd file)
746
{
747 748 749 750 751 752 753 754
#ifdef HAVE_LIBBZ2
    if(file->bzf)
        BZ2_bzclose(file->bzf);
#endif

    if(file->gzf)
        gzclose(file->gzf);

755
    free(file->name);
756
    free(file);
757 758
}

759 760 761 762 763 764
/* darshan_log_print_version_warnings()
 *
 * Print summary of any problems with the detected log format
 */
void darshan_log_print_version_warnings(struct darshan_job *job)
{
Philip Carns's avatar
Philip Carns committed
765
    if(strcmp(job->version_string, "2.05") == 0)
766
    {
767
        /* current version */
768 769 770
        return;
    }

Philip Carns's avatar
Philip Carns committed
771 772 773 774 775 776 777
    if(strcmp(job->version_string, "2.04") == 0)
    {
        printf("# WARNING: version 2.04 log format has the following limitations:\n");
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
        return;
    }

Philip Carns's avatar
Philip Carns committed
778 779
    if(strcmp(job->version_string, "2.03") == 0)
    {
Philip Carns's avatar
Philip Carns committed
780
        /* no meaningful change to interpretation of log file, 2.03 just
Philip Carns's avatar
Philip Carns committed
781 782
         * increased the header space available for annotations.
         */
Philip Carns's avatar
Philip Carns committed
783 784
        printf("# WARNING: version 2.03 log format has the following limitations:\n");
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
Philip Carns's avatar
Philip Carns committed
785 786 787
        return;
    }

788 789 790 791
    if(strcmp(job->version_string, "2.02") == 0)
    {
        printf("# WARNING: version 2.01 log format has the following limitations:\n");
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
792
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
793 794 795
        return;
    }

Philip Carns's avatar
Philip Carns committed
796 797 798
    if(strcmp(job->version_string, "2.01") == 0)
    {
        printf("# WARNING: version 2.01 log format has the following limitations:\n");
799
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
800
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
801
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
Philip Carns's avatar
Philip Carns committed
802 803 804
        return;
    }

805 806
    if(strcmp(job->version_string, "2.00") == 0)
    {
Philip Carns's avatar
Philip Carns committed
807
        printf("# WARNING: version 2.00 log format has the following limitations:\n");
808
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
809
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
810
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
811 812
        return;
    }
813
 
814
    if(strcmp(job->version_string, "1.24") == 0)
815
    {
816 817 818 819 820 821 822 823 824
        printf("# WARNING: version 1.24 log format does not support the following parameters:\n");
        printf("#   CP_FASTEST_RANK\n");
        printf("#   CP_FASTEST_RANK_BYTES\n");
        printf("#   CP_SLOWEST_RANK\n");
        printf("#   CP_SLOWEST_RANK_BYTES\n");
        printf("#   CP_F_FASTEST_RANK_TIME\n");
        printf("#   CP_F_SLOWEST_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_BYTES\n");
Philip Carns's avatar
Philip Carns committed
825
        printf("# WARNING: version 1.24 log format has the following limitations:\n");
826
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
827 828
        printf("# - does not store the job id in the file.\n");
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
829
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
830 831
        return;
    }
832
    
833 834
    if(strcmp(job->version_string, "1.23") == 0)
    {
835 836 837 838 839 840 841 842 843
        printf("# WARNING: version 1.23 log format does not support the following parameters:\n");
        printf("#   CP_FASTEST_RANK\n");
        printf("#   CP_FASTEST_RANK_BYTES\n");
        printf("#   CP_SLOWEST_RANK\n");
        printf("#   CP_SLOWEST_RANK_BYTES\n");
        printf("#   CP_F_FASTEST_RANK_TIME\n");
        printf("#   CP_F_SLOWEST_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_BYTES\n");
Philip Carns's avatar
Philip Carns committed
844
        printf("# WARNING: version 1.23 log format has the following limitations:\n");
845
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
846 847 848
        printf("# - may have incorrect mount point mappings for files with rank > 0.\n");
        printf("# - does not store the job id in the file.\n");
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
849
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
850
        return;
851 852
    }

853 854 855 856
    if(strcmp(job->version_string, "1.22") == 0)
    {
        printf("# WARNING: version 1.22 log format does not support the following parameters:\n");
        printf("#   CP_DEVICE\n");
857
        printf("#   CP_SIZE_AT_OPEN\n");
858 859 860 861 862 863 864 865
        printf("#   CP_FASTEST_RANK\n");
        printf("#   CP_FASTEST_RANK_BYTES\n");
        printf("#   CP_SLOWEST_RANK\n");
        printf("#   CP_SLOWEST_RANK_BYTES\n");
        printf("#   CP_F_FASTEST_RANK_TIME\n");
        printf("#   CP_F_SLOWEST_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_BYTES\n");
Philip Carns's avatar
Philip Carns committed
866
        printf("# WARNING: version 1.22 log format has the following limitations:\n");
867
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
868 869 870 871
        printf("# - does not record mounted file systems, mount points, or fs types.\n");
        printf("# - attributes syncs to cumulative metadata time, rather than cumulative write time.\n");
        printf("# - does not store the job id in the file.\n");
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
872
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
873 874
        return;
    }
875 876 877 878 879 880 881 882 883

    if(strcmp(job->version_string, "1.21") == 0)
    {
        printf("# WARNING: version 1.21 log format does not support the following parameters:\n");
        printf("#   CP_INDEP_NC_OPENS\n");
        printf("#   CP_COLL_NC_OPENS\n");
        printf("#   CP_HDF5_OPENS\n");
        printf("#   CP_MAX_READ_TIME_SIZE\n");
        printf("#   CP_MAX_WRITE_TIME_SIZE\n");
884
        printf("#   CP_DEVICE\n");
885
        printf("#   CP_SIZE_AT_OPEN\n");
886 887
        printf("#   CP_F_MAX_READ_TIME\n");
        printf("#   CP_F_MAX_WRITE_TIME\n");
888 889 890 891 892 893 894 895
        printf("#   CP_FASTEST_RANK\n");
        printf("#   CP_FASTEST_RANK_BYTES\n");
        printf("#   CP_SLOWEST_RANK\n");
        printf("#   CP_SLOWEST_RANK_BYTES\n");
        printf("#   CP_F_FASTEST_RANK_TIME\n");
        printf("#   CP_F_SLOWEST_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_TIME\n");
        printf("#   CP_F_VARIANCE_RANK_BYTES\n");
Philip Carns's avatar
Philip Carns committed
896
        printf("# WARNING: version 1.21 log format has the following limitations:\n");
897
        printf("# - *_TIMESTAMP fields are not normalized relative to MPI_Init() time.\n");
Philip Carns's avatar
Philip Carns committed
898 899 900 901
        printf("# - does not record mounted file systems, mount points, or fs types.\n");
        printf("# - attributes syncs to cumulative metadata time, rather than cumulative write time.\n");
        printf("# - does not store the job id in the file.\n");
        printf("# - inaccurate statistics in some multi-threaded cases.\n");
Philip Carns's avatar
Philip Carns committed
902
        printf("# - CP_F_SLOWEST_RANK_TIME and CP_F_FASTEST_RANK_TIME only report elapsed time at the POSIX level.\n");
903 904 905 906 907 908 909 910
        return;
    }

    fprintf(stderr, "Error: version %s not supported by parser.\n",
        job->version_string);
    return;
}

911 912 913 914
/* shift_missing_1_21()
 *
 * translates indices to account for counters that weren't present in log
 * format 1.21
915
 */
916
/*******************************
Philip Carns's avatar
Philip Carns committed
917
 * version 1.21 to 2.00 differences 
918 919 920 921 922 923 924 925
 * - added:
 *   - CP_INDEP_NC_OPENS
 *   - CP_COLL_NC_OPENS
 *   - CP_HDF5_OPENS
 *   - CP_MAX_READ_TIME_SIZE
 *   - CP_MAX_WRITE_TIME_SIZE
 *   - CP_DEVICE
 *   - CP_SIZE_AT_OPEN
926 927 928 929
 *   - CP_FASTEST_RANK
 *   - CP_FASTEST_RANK_BYTES
 *   - CP_SLOWEST_RANK
 *   - CP_SLOWEST_RANK_BYTES
930 931
 *   - CP_F_MAX_READ_TIME
 *   - CP_F_MAX_WRITE_TIME
932 933 934 935
 *   - CP_F_FASTEST_RANK_TIME
 *   - CP_F_SLOWEST_RANK_TIME
 *   - CP_F_VARIANCE_RANK_TIME
 *   - CP_F_VARIANCE_RANK_BYTES
936
 * - changed params:
937 938 939
 *   - CP_FILE_RECORD_SIZE: 1184 to 1328
 *   - CP_NUM_INDICES: 133 to 144
 *   - CP_F_NUM_INDICES: 12 to 18
940
 */
941 942 943 944 945 946 947 948 949
static void shift_missing_1_21(struct darshan_file* file)
{
    int c_index = 0;
    int missing_counters[] = {
        CP_INDEP_NC_OPENS,
        CP_COLL_NC_OPENS,
        CP_HDF5_OPENS,
        CP_MAX_READ_TIME_SIZE,
        CP_MAX_WRITE_TIME_SIZE,
950
        CP_DEVICE,
951
        CP_SIZE_AT_OPEN,
952 953 954 955
        CP_FASTEST_RANK,
        CP_FASTEST_RANK_BYTES,
        CP_SLOWEST_RANK,
        CP_SLOWEST_RANK_BYTES,
956 957 958 959
        -1};
    int missing_f_counters[] = {
        CP_F_MAX_READ_TIME,
        CP_F_MAX_WRITE_TIME,
960 961 962 963
        CP_F_FASTEST_RANK_TIME,
        CP_F_SLOWEST_RANK_TIME,
        CP_F_VARIANCE_RANK_TIME,
        CP_F_VARIANCE_RANK_BYTES,
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
        -1};

    c_index = 0;
    while(missing_counters[c_index] != -1)
    {
        int missing_counter = missing_counters[c_index];
        c_index++;
        if(missing_counter < (CP_NUM_INDICES - 1))
        {
            /* shift down */
            memmove(&file->counters[missing_counter+1],
                &file->counters[missing_counter],
                (CP_NUM_INDICES-missing_counter-1)*sizeof(int64_t));
        }
        /* zero out missing counter */
        file->counters[missing_counter] = 0;
    }

    c_index = 0;
    while(missing_f_counters[c_index] != -1)
    {
        int missing_counter = missing_f_counters[c_index];
        c_index++;
        if(missing_counter < (CP_F_NUM_INDICES - 1))
        {
            /* shift down */
            memmove(&file->fcounters[missing_counter+1],
                &file->fcounters[missing_counter],
                (CP_F_NUM_INDICES-missing_counter-1)*sizeof(double));
        }
        /* zero out missing counter */
        file->fcounters[missing_counter] = 0;
    }

    return;
}
1000 1001 1002 1003 1004 1005

/* shift_missing_1_22()
 *
 * translates indices to account for counters that weren't present in log
 * format 1.22
 */
1006
/*******************************
Philip Carns's avatar
Philip Carns committed
1007
 * version 1.22 to 2.00 differences
1008 1009 1010 1011
 *
 * - added:
 *   - CP_DEVICE
 *   - CP_SIZE_AT_OPEN
1012 1013 1014 1015 1016 1017 1018 1019
 *   - CP_FASTEST_RANK
 *   - CP_FASTEST_RANK_BYTES
 *   - CP_SLOWEST_RANK
 *   - CP_SLOWEST_RANK_BYTES
 *   - CP_F_FASTEST_RANK_TIME
 *   - CP_F_SLOWEST_RANK_TIME
 *   - CP_F_VARIANCE_RANK_TIME
 *   - CP_F_VARIANCE_RANK_BYTES
1020
 * - changed params:
1021 1022 1023
 *   - CP_FILE_RECORD_SIZE: 1240 to 1328
 *   - CP_NUM_INDICES: 138 to 144
 *   - CP_F_NUM_INDICES: 14 to 18
1024
 */
1025 1026 1027 1028 1029
static void shift_missing_1_22(struct darshan_file* file)
{
    int c_index = 0;
    int missing_counters[] = {
        CP_DEVICE,
1030
        CP_SIZE_AT_OPEN,
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
        CP_FASTEST_RANK,
        CP_FASTEST_RANK_BYTES,
        CP_SLOWEST_RANK,
        CP_SLOWEST_RANK_BYTES,
        -1};
    int missing_f_counters[] = {
        CP_F_FASTEST_RANK_TIME,
        CP_F_SLOWEST_RANK_TIME,
        CP_F_VARIANCE_RANK_TIME,
        CP_F_VARIANCE_RANK_BYTES,
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
        -1};

    c_index = 0;
    while(missing_counters[c_index] != -1)
    {
        int missing_counter = missing_counters[c_index];
        c_index++;
        if(missing_counter < (CP_NUM_INDICES - 1))
        {
            /* shift down */
            memmove(&file->counters[missing_counter+1],
                &file->counters[missing_counter],
                (CP_NUM_INDICES-missing_counter-1)*sizeof(int64_t));
        }
        /* zero out missing counter */
        file->counters[missing_counter] = 0;
    }

1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    c_index = 0;
    while(missing_f_counters[c_index] != -1)
    {
        int missing_counter = missing_f_counters[c_index];
        c_index++;
        if(missing_counter < (CP_F_NUM_INDICES - 1))
        {
            /* shift down */
            memmove(&file->fcounters[missing_counter+1],
                &file->fcounters[missing_counter],
                (CP_F_NUM_INDICES-missing_counter-1)*sizeof(double));
        }
        /* zero out missing counter */
        file->fcounters[missing_counter] = 0;
    }

1075 1076
    return;
}
1077

1078 1079 1080 1081 1082 1083 1084 1085 1086
/* shift_missing_1_24()
 *
 * translates indices to account for counters that weren't present in log
 * format 1.24
 */
/*******************************
 * version 1.24 to 2.00 differences
 *
 * - added:
1087 1088 1089 1090
 *   - CP_FASTEST_RANK
 *   - CP_FASTEST_RANK_BYTES
 *   - CP_SLOWEST_RANK
 *   - CP_SLOWEST_RANK_BYTES
1091 1092 1093 1094 1095 1096 1097 1098 1099