darshan-logutils.h 6.6 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
#include <limits.h>
11 12 13 14 15
#include <zlib.h>
#ifdef HAVE_LIBBZ2
#include <bzlib.h>
#endif

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

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

20 21 22
/* Maximum size of a record - Lustre OST lists can get huge, but 81920 is enough
 * for 10K OSTs 
 */
Shane Snyder's avatar
Shane Snyder committed
23
#define DEF_MOD_BUF_SIZE 81920
24

25 26 27
struct darshan_fd_int_state;

/* darshan file descriptor definition */
28 29
struct darshan_fd_s
{
30
    /* log file version */
31
    char version[8];
32
    /* flag indicating whether byte swapping needs to be
33 34
     * performed on log file data
     */
35
    int swap_flag;
36 37
    /* flag indicating whether a log file contains partial data */
    int partial_flag;
38 39
    /* compression type used on log file */
    enum darshan_comp_type comp_type;
40
    /* log file offset/length maps for each log file region */
41
    struct darshan_log_map job_map;
42
    struct darshan_log_map name_map;
43
    struct darshan_log_map mod_map[DARSHAN_MAX_MODS];
44 45
    /* module-specific log-format versions contained in log */
    uint32_t mod_ver[DARSHAN_MAX_MODS];
46

47 48
    /* KEEP OUT -- remaining state hidden in logutils source */
    struct darshan_fd_int_state *state;
49
};
50
typedef struct darshan_fd_s* darshan_fd;
51

52
struct darshan_name_record_ref
53
{
54
    struct darshan_name_record *name_record;
55
    UT_hash_handle hlink;
56
};
Cong Xu's avatar
Cong Xu committed
57

58 59 60 61 62
/* DXT */
struct lustre_record_ref
{
	struct darshan_lustre_record *rec;
	UT_hash_handle hlink;
63 64
};

65 66 67 68 69 70
struct darshan_mnt_info
{
    char mnt_type[DARSHAN_EXE_LEN];
    char mnt_path[DARSHAN_EXE_LEN];
};

71 72 73
/* functions to be implemented by each module for integration with
 * darshan log file utilities (e.g., parser & convert tools)
 */
74 75
struct darshan_mod_logutil_funcs
{
76 77 78
    /* retrieve a single module record from the log file. 
     * return 1 on successful read of record, 0 on no more
     * module data, -1 on error
79
     *      - 'fd' is the file descriptor to get record from
80 81
     *      - 'buf' is a pointer to a buffer address to store the record in
     *          * NOTE: if the buffer pointed to is NULL, the record memory is malloc'ed
82
     */
83
    int (*log_get_record)(
84
        darshan_fd fd,
85
        void** buf
86
    );
87 88
    /* put a single module record into the log file.
     * return 0 on success, -1 on error
89 90
     *      - 'fd' is the file descriptor to put record into
     *      - 'buf' is the buffer containing the record data
91
     */
92 93
    int (*log_put_record)(
        darshan_fd fd,
94
        void *buf
95
    );
96
    /* print the counters for a given log record
97 98 99
     *      - 'rec' is the record's data buffer
     *      - 'name' is the name string associated with this record (or NULL if there isn't one)
     *      - 'mnt_pt' is the file path mount point string
100 101
     *      - 'fs_type' is the file system type string
     */
102
    void (*log_print_record)(
103
        void *rec,
104 105
        char *file_name,
        char *mnt_pt,
106
        char *fs_type
107
    );
108 109 110 111 112
    /* print module-specific description of I/O characterization data
     *      - 'ver' is the version of the record
     */
    void (*log_print_description)(
        int ver);
113
    /* print a text diff of 2 module records */
114
    void (*log_print_diff)(
115 116 117 118
        void *rec1,
        char *name1,
        void *rec2,
        char *name2
119
    );
120 121 122 123 124 125
    /* combine two records into a single aggregate record */
    void (*log_agg_records)(
        void *rec,
        void *agg_rec,
        int init_flag
    );
126 127
};

Shane Snyder's avatar
Shane Snyder committed
128
extern struct darshan_mod_logutil_funcs *mod_logutils[];
129 130 131

#include "darshan-posix-logutils.h"
#include "darshan-mpiio-logutils.h"
132
#include "darshan-hdf5-logutils.h"
133
#include "darshan-pnetcdf-logutils.h"
134
#include "darshan-bgq-logutils.h"
135
#include "darshan-lustre-logutils.h"
136
#include "darshan-stdio-logutils.h"
137

138 139
/* DXT */
#include "darshan-dxt-logutils.h"
140
#include "darshan-mdhim-logutils.h"
141

142
darshan_fd darshan_log_open(const char *name);
143 144
darshan_fd darshan_log_create(const char *name, enum darshan_comp_type comp_type,
    int partial_flag);
145 146 147 148
int darshan_log_get_job(darshan_fd fd, struct darshan_job *job);
int darshan_log_put_job(darshan_fd fd, struct darshan_job *job);
int darshan_log_get_exe(darshan_fd fd, char *buf);
int darshan_log_put_exe(darshan_fd fd, char *buf);
149
int darshan_log_get_mounts(darshan_fd fd, struct darshan_mnt_info **mnt_data_array,
150
    int* count);
151
int darshan_log_put_mounts(darshan_fd fd, struct darshan_mnt_info *mnt_data_array,
152
    int count);
153 154 155
int darshan_log_get_namehash(darshan_fd fd, struct darshan_name_record_ref **hash);
int darshan_log_put_namehash(darshan_fd fd, struct darshan_name_record_ref *hash);
int darshan_log_get_mod(darshan_fd fd, darshan_module_id mod_id,
156
    void *mod_buf, int mod_buf_sz);
157
int darshan_log_put_mod(darshan_fd fd, darshan_module_id mod_id,
158
    void *mod_buf, int mod_buf_sz, int ver);
159
void darshan_log_close(darshan_fd file);
160
void darshan_log_print_version_warnings(const char *version_string);
161

162 163
/* convenience macros for printing Darshan counters */
#define DARSHAN_PRINT_HEADER() \
164
    printf("\n#<module>\t<rank>\t<record id>\t<counter>\t<value>" \
165 166 167 168 169 170 171 172
           "\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); \
173
} while(0)
174 175 176 177 178 179 180

#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); \
181 182
} while(0)

183 184 185 186 187 188 189 190 191 192 193 194 195 196
/* 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)
197 198 199 200 201 202 203 204 205 206
#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)

207
#endif