darshan-logutils.h 4.84 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

Shane Snyder's avatar
Shane Snyder committed
10
#include <linux/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
struct darshan_fd_int_state;

/* darshan file descriptor definition */
23
24
struct darshan_fd_s
{
25
    /* log file version */
26
    char version[8];
27
28
    /* flag indicating whether byte swapping needs to be
     * performed on log file data */
29
    int swap_flag;
30
31
    /* flag indicating whether a log file contains partial data */
    int partial_flag;
32
33
    /* compression type used on log file */
    enum darshan_comp_type comp_type;
34
    /* log file offset/length maps for each log file region */
35
    struct darshan_log_map job_map;
36
37
    struct darshan_log_map rec_map;
    struct darshan_log_map mod_map[DARSHAN_MAX_MODS];
38

39
40
    /* KEEP OUT -- remaining state hidden in logutils source */
    struct darshan_fd_int_state *state;
41
};
42
typedef struct darshan_fd_s* darshan_fd;
43

44
45
struct darshan_record_ref
{
46
47
    char *name;
    darshan_record_id id;
48
49
50
    UT_hash_handle hlink;
};

51
52
53
/* functions to be implemented by each module for integration with
 * darshan log file utilities (e.g., parser & convert tools)
 */
54
55
struct darshan_mod_logutil_funcs
{
56
57
58
59
    /* 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
     */
60
    int (*log_get_record)(
61
62
63
64
        darshan_fd fd,
        void* buf,
        darshan_record_id* rec_id
    );
65
66
67
    /* put a single module record into the log file.
     * return 0 on success, -1 on error
     */
68
69
70
    int (*log_put_record)(
        darshan_fd fd,
        void *buf
71
    );
72
    /* print the counters for a given log file record */
73
74
75
76
77
78
79
80
    void (*log_print_record)(
        void *file_rec,
        char *file_name,
        char *mnt_pt,
        char *fs_type
    );
};

Shane Snyder's avatar
Shane Snyder committed
81
extern struct darshan_mod_logutil_funcs *mod_logutils[];
82
83
84

#include "darshan-posix-logutils.h"
#include "darshan-mpiio-logutils.h"
85
#include "darshan-hdf5-logutils.h"
86
#include "darshan-pnetcdf-logutils.h"
87
#include "darshan-bgq-logutils.h"
88

89
darshan_fd darshan_log_open(const char *name);
90
91
darshan_fd darshan_log_create(const char *name, enum darshan_comp_type comp_type,
    int partial_flag);
92
int darshan_log_getjob(darshan_fd fd, struct darshan_job *job);
93
int darshan_log_putjob(darshan_fd fd, struct darshan_job *job);
94
int darshan_log_getexe(darshan_fd fd, char *buf);
95
int darshan_log_putexe(darshan_fd fd, char *buf);
96
int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
97
    char*** fs_types, int* count);
98
99
int darshan_log_putmounts(darshan_fd fd, char** mnt_pts,
    char** fs_types, int count);
100
int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash);
101
102
int darshan_log_puthash(darshan_fd fd, struct darshan_record_ref *hash);
int darshan_log_getmod(darshan_fd fd, darshan_module_id mod_id,
103
    void *mod_buf, int mod_buf_sz);
104
105
int darshan_log_putmod(darshan_fd fd, darshan_module_id mod_id,
    void *mod_buf, int mod_buf_sz);
106
void darshan_log_close(darshan_fd file);
107

108
109
/* convenience macros for printing Darshan counters */
#define DARSHAN_PRINT_HEADER() \
110
    printf("\n#<module>\t<rank>\t<record id>\t<counter>\t<value>" \
111
112
113
114
115
116
117
118
           "\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); \
119
} while(0)
120
121
122
123
124
125
126

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

129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* 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)
143
144
145
146
147
148
149
150
151
152
#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)

153
#endif