darshan-null-logutils.c 4.09 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
/*
 * 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 <fcntl.h>
#include <errno.h>

#include "darshan-null-logutils.h"

/* integer counter name strings for the NULL module */
#define X(a) #a,
char *null_counter_names[] = {
    NULL_COUNTERS
};

/* floating point counter name strings for the NULL module */
char *null_f_counter_names[] = {
    NULL_F_COUNTERS
};
#undef X

/* prototypes for each of the NULL module's logutil functions */
35
static int darshan_log_get_null_record(darshan_fd fd, void* null_buf);
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
static int darshan_log_put_null_record(darshan_fd fd, void* null_buf);
static void darshan_log_print_null_record(void *file_rec,
    char *file_name, char *mnt_pt, char *fs_type);

/* structure storing each function needed for implementing the darshan
 * logutil interface. these functions are used for reading, writing, and
 * printing module data in a consistent manner.
 */
struct darshan_mod_logutil_funcs null_logutils =
{
    .log_get_record = &darshan_log_get_null_record,
    .log_put_record = &darshan_log_put_null_record,
    .log_print_record = &darshan_log_print_null_record,
};

/* retrieve a NULL record from log file descriptor 'fd', storing the
 * buffer in 'null_buf' and the corresponding Darshan record id in
 * 'rec_id'. Return 1 on successful record read, .
 */
55
static int darshan_log_get_null_record(darshan_fd fd, void* null_buf)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
{
    struct darshan_null_record *rec;
    int i;
    int ret;

    /* read a NULL module record from the darshan log file */
    ret = darshan_log_getmod(fd, DARSHAN_NULL_MOD, null_buf,
        sizeof(struct darshan_null_record));
    if(ret < 0)
        return(-1);
    else if(ret < sizeof(struct darshan_null_record))
        return(0);
    else
    {
        /* if the read was successful, do any necessary byte-swapping */
        rec = (struct darshan_null_record *)null_buf;
        if(fd->swap_flag)
        {
            /* swap bytes if necessary */
75 76
            DARSHAN_BSWAP64(&(rec->base_rec.id));
            DARSHAN_BSWAP64(&(rec->base_rec.rank));
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
            for(i=0; i<NULL_NUM_INDICES; i++)
                DARSHAN_BSWAP64(&rec->counters[i]);
            for(i=0; i<NULL_F_NUM_INDICES; i++)
                DARSHAN_BSWAP64(&rec->fcounters[i]);
        }

        return(1);
    }
}

/* write the NULL record stored in 'null_buf' to log file descriptor 'fd'.
 * Return 0 on success, -1 on failure
 */
static int darshan_log_put_null_record(darshan_fd fd, void* null_buf)
{
    struct darshan_null_record *rec = (struct darshan_null_record *)null_buf;
    int ret;

    /* append NULL record to darshan log file */
    ret = darshan_log_putmod(fd, DARSHAN_NULL_MOD, rec,
        sizeof(struct darshan_null_record));
    if(ret < 0)
        return(-1);

    return(0);
}

/* print all I/O data record statistics for the given NULL record */
static void darshan_log_print_null_record(void *file_rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
    int i;
    struct darshan_null_record *null_rec =
        (struct darshan_null_record *)file_rec;

    /* print each of the integer and floating point counters for the NULL module */
    for(i=0; i<NULL_NUM_INDICES; i++)
    {
        /* macro defined in darshan-logutils.h */
        DARSHAN_COUNTER_PRINT(darshan_module_names[DARSHAN_NULL_MOD],
117 118 119
            null_rec->base_rec.rank, null_rec->base_rec.id,
            null_counter_names[i], null_rec->counters[i],
            file_name, mnt_pt, fs_type);
120 121 122 123 124 125
    }

    for(i=0; i<NULL_F_NUM_INDICES; i++)
    {
        /* macro defined in darshan-logutils.h */
        DARSHAN_F_COUNTER_PRINT(darshan_module_names[DARSHAN_NULL_MOD],
126 127 128
            null_rec->base_rec.rank, null_rec->base_rec.id,
            null_f_counter_names[i], null_rec->fcounters[i],
            file_name, mnt_pt, fs_type);
129 130 131 132 133 134 135 136 137 138 139 140 141
    }

    return;
}

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