darshan-logutils.h 4.33 KB
Newer Older
1
/*
Shane Snyder's avatar
Shane Snyder committed
2 3 4
 * Copyright (C) 2015 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
5 6
 */

7 8
#ifndef __DARSHAN_LOG_UTILS_H
#define __DARSHAN_LOG_UTILS_H
9

10 11 12 13 14
#include <zlib.h>
#ifdef HAVE_LIBBZ2
#include <bzlib.h>
#endif

15
#include "uthash-1.9.2/src/uthash.h"
16

17 18
#include "darshan-log-format.h"

19 20
/* default to a buffer size of 4 MiB for compression/decompression */
#define DARSHAN_DEF_COMP_BUF_SZ (4*1024*1024)
21

22 23 24 25
/* TODO: can we refactor this def out of header? modules currently poke at swap_flag
 * directly, but other than that there's no reason for another module to know this
 * definition.
 */
26 27
struct darshan_fd_s
{
28
    int fildes;
29
    int64_t pos;
30
    enum darshan_comp_type comp_type;
31 32
    char version[8];
    int swap_flag;
33 34
    char *exe_mnt_data;
    struct darshan_log_map job_map;
35 36 37
    struct darshan_log_map rec_map;
    struct darshan_log_map mod_map[DARSHAN_MAX_MODS];
};
38
typedef struct darshan_fd_s* darshan_fd;
39

40 41 42 43 44 45
struct darshan_record_ref
{
    struct darshan_record rec;
    UT_hash_handle hlink;
};

46 47 48
struct darshan_mod_logutil_funcs
{
    int (*log_get_record)(
49 50 51
        void** mod_buf_p,
        int* mod_bytes_left,
        void** file_rec,
52 53
        darshan_record_id* rec_id,
        int byte_swap_flag
54 55 56 57 58 59 60 61 62 63 64 65 66
    );
    void (*log_print_record)(
        void *file_rec,
        char *file_name,
        char *mnt_pt,
        char *fs_type
    );
};

extern struct darshan_mod_logutil_funcs *mod_logutils[DARSHAN_MAX_MODS];

#include "darshan-posix-logutils.h"
#include "darshan-mpiio-logutils.h"
67
#include "darshan-hdf5-logutils.h"
68
#include "darshan-pnetcdf-logutils.h"
69
#include "darshan-bgq-logutils.h"
70

71 72
darshan_fd darshan_log_open(const char *name);
darshan_fd darshan_log_create(const char *name, enum darshan_comp_type comp_type);
73
int darshan_log_getheader(darshan_fd fd, struct darshan_header *header);
74
int darshan_log_putheader(darshan_fd fd);
75
int darshan_log_getjob(darshan_fd fd, struct darshan_job *job);
76
int darshan_log_putjob(darshan_fd fd, struct darshan_job *job);
77
int darshan_log_getexe(darshan_fd fd, char *buf);
78
int darshan_log_putexe(darshan_fd fd, char *buf);
79
int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
80
    char*** fs_types, int* count);
81 82
int darshan_log_putmounts(darshan_fd fd, char** mnt_pts,
    char** fs_types, int count);
83
int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash);
84 85
int darshan_log_puthash(darshan_fd fd, struct darshan_record_ref *hash);
int darshan_log_getmod(darshan_fd fd, darshan_module_id mod_id,
86
    void *mod_buf, int *mod_buf_sz);
87 88
int darshan_log_putmod(darshan_fd fd, darshan_module_id mod_id,
    void *mod_buf, int mod_buf_sz);
89
void darshan_log_close(darshan_fd file);
90

91 92 93 94 95 96 97 98 99 100 101
/* convenience macros for printing Darshan counters */
#define DARSHAN_PRINT_HEADER() \
    printf("\n#<module>\t<rank>\t<file>\t<counter>\t<value>" \
           "\t<file name>\t<mount pt>\t<fs type>\n")

#define DARSHAN_COUNTER_PRINT(__mod_name, __rank, __file_id, \
                              __counter, __counter_val, __file_name, \
                              __mnt_pt, __fs_type) do { \
    printf("%s\t%" PRId64 "\t%" PRIu64 "\t%s\t%" PRId64 "\t%s\t%s\t%s\n", \
        __mod_name, __rank, __file_id, __counter, __counter_val, \
        __file_name, __mnt_pt, __fs_type); \
102
} while(0)
103 104 105 106 107 108 109

#define DARSHAN_F_COUNTER_PRINT(__mod_name, __rank, __file_id, \
                                __counter, __counter_val, __file_name, \
                                __mnt_pt, __fs_type) do { \
    printf("%s\t%" PRId64 "\t%" PRIu64 "\t%s\t%f\t%s\t%s\t%s\n", \
        __mod_name, __rank, __file_id, __counter, __counter_val, \
        __file_name, __mnt_pt, __fs_type); \
110 111
} while(0)

112 113 114 115 116 117 118 119 120 121 122 123 124 125
/* naive byte swap implementation */
#define DARSHAN_BSWAP64(__ptr) do {\
    char __dst_char[8]; \
    char* __src_char = (char*)__ptr; \
    __dst_char[0] = __src_char[7]; \
    __dst_char[1] = __src_char[6]; \
    __dst_char[2] = __src_char[5]; \
    __dst_char[3] = __src_char[4]; \
    __dst_char[4] = __src_char[3]; \
    __dst_char[5] = __src_char[2]; \
    __dst_char[6] = __src_char[1]; \
    __dst_char[7] = __src_char[0]; \
    memcpy(__ptr, __dst_char, 8); \
} while(0)
126 127 128 129 130 131 132 133 134 135
#define DARSHAN_BSWAP32(__ptr) do {\
    char __dst_char[4]; \
    char* __src_char = (char*)__ptr; \
    __dst_char[0] = __src_char[3]; \
    __dst_char[1] = __src_char[2]; \
    __dst_char[2] = __src_char[1]; \
    __dst_char[3] = __src_char[0]; \
    memcpy(__ptr, __dst_char, 4); \
} while(0)

136
#endif