darshan.h 6.77 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 9 10 11 12 13
#ifndef __DARSHAN_H
#define __DARSHAN_H

#include <unistd.h>
#include <sys/types.h>
#include <stdint.h>
#include <mpi.h>
14

15 16
#include "darshan-log-format.h"

17 18 19 20 21 22 23 24 25 26 27 28
/* Environment variable to override CP_JOBID */
#define CP_JOBID_OVERRIDE "DARSHAN_JOBID"

/* Environment variable to override __CP_LOG_PATH */
#define CP_LOG_PATH_OVERRIDE "DARSHAN_LOGPATH"

/* Environment variable to override __CP_LOG_PATH */
#define CP_LOG_HINTS_OVERRIDE "DARSHAN_LOGHINTS"

/* Environment variable to override __CP_MEM_ALIGNMENT */
#define CP_MEM_ALIGNMENT_OVERRIDE "DARSHAN_MEMALIGN"

29 30 31 32
/* macros for declaring wrapper functions and calling MPI routines
 * consistently regardless of whether static or dynamic linking is used
 */
#ifdef DARSHAN_PRELOAD
Shane Snyder's avatar
Shane Snyder committed
33

34 35 36
#include <dlfcn.h>
#include <stdlib.h>

37 38
#define DARSHAN_FORWARD_DECL(__func,__ret,__args) \
  __ret (*__real_ ## __func)__args = NULL
39

40
#define DARSHAN_DECL(__func) __func
41

42
#define DARSHAN_MPI_CALL(__func) __real_ ## __func
43

44 45
#define MAP_OR_FAIL(__func) \
    if (!(__real_ ## __func)) \
46
    { \
47 48 49
        __real_ ## __func = dlsym(RTLD_NEXT, #__func); \
        if(!(__real_ ## __func)) { \
           fprintf(stderr, "Darshan failed to map symbol: %s\n", #__func); \
50 51 52 53 54 55
           exit(1); \
       } \
    }

#else

56 57
#define DARSHAN_FORWARD_DECL(__name,__ret,__args) \
  extern __ret __real_ ## __name __args;
58 59 60

#define DARSHAN_DECL(__name) __wrap_ ## __name

61
#define DARSHAN_MPI_CALL(__func) __func
62

63
#define MAP_OR_FAIL(__func)
64 65 66

#endif

67 68 69 70 71 72 73
/* macros for manipulating a module's counter variables */
/* NOTE: These macros assume a module's record stores integer
 * and floating point counters in arrays, named counters and
 * fcounters, respectively. __rec_p is the a pointer to the
 * data record, __counter is the counter in question, and
 * __value is the corresponding data value.
 */
74 75 76 77 78 79 80 81 82
#define DARSHAN_COUNTER_SET(__rec_p, __counter, __value) do{ \
    (__rec_p)->counters[__counter] = __value; \
} while(0)

#define DARSHAN_COUNTER_F_SET(__rec_p, __counter, __value) do{ \
    (__rec_p)->fcounters[__counter] = __value; \
} while(0)

#define DARSHAN_COUNTER_INC(__rec_p, __counter, __value) do{ \
83
    (__rec_p)->counters[__counter] += __value; \
84 85 86
} while(0)

#define DARSHAN_COUNTER_F_INC(__rec_p, __counter, __value) do{ \
87
    (__rec_p)->fcounters[__counter] += __value; \
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
} while(0)

#define DARSHAN_COUNTER_F_INC_NO_OVERLAP(__rec_p, __tm1, __tm2, __last, __counter) do{ \
    if(__tm1 > __last) \
        DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __tm1)); \
    else \
        DARSHAN_COUNTER_F_INC(__rec_p, __counter, (__tm2 - __last)); \
    if(__tm2 > __last) \
        __last = __tm2; \
} while(0)

#define DARSHAN_COUNTER_VALUE(__rec_p, __counter) \
    ((__rec_p)->counters[__counter])

#define DARSHAN_COUNTER_F_VALUE(__rec_p, __counter) \
    ((__rec_p)->fcounters[__counter])

#define DARSHAN_COUNTER_MAX(__rec_p, __counter, __value) do{ \
    if((__rec_p)->counters[__counter] < __value) \
        (__rec_p)->counters[__counter] = __value; \
} while(0)
109

110 111 112 113 114
/* NOTE: This macro is for storing histogram counters with 10
 * distinct buckets. For an example of how it is used, consult
 * the POSIX module implementation, which stores histograms of
 * access sizes for POSIX I/O functions.
 */
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
#define DARSHAN_BUCKET_INC(__rec_p, __counter_base, __value) do {\
    if(__value < 101) \
        (__rec_p)->counters[__counter_base] += 1; \
    else if(__value < 1025) \
        (__rec_p)->counters[__counter_base+1] += 1; \
    else if(__value < 10241) \
        (__rec_p)->counters[__counter_base+2] += 1; \
    else if(__value < 102401) \
        (__rec_p)->counters[__counter_base+3] += 1; \
    else if(__value < 1048577) \
        (__rec_p)->counters[__counter_base+4] += 1; \
    else if(__value < 4194305) \
        (__rec_p)->counters[__counter_base+5] += 1; \
    else if(__value < 10485761) \
        (__rec_p)->counters[__counter_base+6] += 1; \
    else if(__value < 104857601) \
        (__rec_p)->counters[__counter_base+7] += 1; \
    else if(__value < 1073741825) \
        (__rec_p)->counters[__counter_base+8] += 1; \
    else \
        (__rec_p)->counters[__counter_base+9] += 1; \
} while(0)

Shane Snyder's avatar
Shane Snyder committed
138
/* module developers provide the following functions to darshan-core */
139
struct darshan_module_funcs
140
{
141 142
    /* perform any necessary pre-shutdown steps */
    void (*begin_shutdown)(void);
Shane Snyder's avatar
Shane Snyder committed
143 144 145 146 147 148 149 150 151 152 153
    /* retrieve module data to write to log file */
    void (*get_output_data)(
        void** buf, /* output parameter to save module buffer address */
        int* size /* output parameter to save module buffer size */
    );
    /* shutdown module data structures */
    void (*shutdown)(void);
    /* (OPTIONAL) perform any necessary steps prior to performing a reduction
     * of shared Darshan I/O records. To bypass shared file reduction mechanism,
     * set this pointer to NULL.
     */
154
    void (*setup_reduction)(
Shane Snyder's avatar
Shane Snyder committed
155
        darshan_record_id *shared_recs, /* input list of shared records */
156
        int *shared_rec_count, /* in/out shared record count */
Shane Snyder's avatar
Shane Snyder committed
157 158 159
        void **send_buf, /* send buffer for shared file reduction */
        void **recv_buf, /* recv buffer for shared file reduction (root only) */
        int *rec_size /* size of records being stored for this module */
160
    );
Shane Snyder's avatar
Shane Snyder committed
161 162 163 164 165 166
    /* (OPTIONAL) perform the actual shared file reduction operation. This 
     * operation follows the prototype of MPI_Op_create, which allows the
     * specification of user-defined combination functions which may be used
     * directly by MPI. To bypass shared file reduction mechanism, set this
     * pointer to NULL. 
     */
167
    void (*record_reduction_op)(
168 169 170 171 172
        void* infile_v,
        void* inoutfile_v,
        int *len,
        MPI_Datatype *datatype
    );
173 174
};

Shane Snyder's avatar
Shane Snyder committed
175 176 177 178 179 180
enum darshan_io_type
{
    DARSHAN_IO_READ = 1,
    DARSHAN_IO_WRITE = 2,
};

181 182 183
/* paths that darshan will not trace */
extern char* darshan_path_exclusions[]; /* defined in lib/darshan-core.c */

184 185 186
/*****************************************************
* darshan-core functions exported to darshan modules *
*****************************************************/
187

188
void darshan_core_register_module(
189
    darshan_module_id mod_id,
190
    struct darshan_module_funcs *funcs,
191 192
    int *mod_mem_limit,
    int *sys_mem_alignment);
193

194 195 196
void darshan_core_unregister_module(
    darshan_module_id mod_id);

Shane Snyder's avatar
Shane Snyder committed
197
void darshan_core_register_record(
198 199 200
    void *name,
    int len,
    int printable_flag,
201
    darshan_module_id mod_id,
202 203
    darshan_record_id *rec_id,
    int *file_alignment);
204

Shane Snyder's avatar
Shane Snyder committed
205 206 207 208
void darshan_core_unregister_record(
    darshan_record_id rec_id,
    darshan_module_id mod_id);

209
double darshan_core_wtime(void);
210

211 212 213 214 215 216
/***********************************************
* darshan-common functions for darshan modules *
***********************************************/

char* darshan_clean_file_path(const char* path);

217
#endif /* __DARSHAN_H */