darshan-logutils.h 2.96 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 "darshan-log-format.h"
16
#include "uthash-1.9.2/src/uthash.h"
17

18 19 20
/* default to a compression buffer size of 4 MiB */
#define DARSHAN_DEF_DECOMP_BUF_SZ (4*1024*1024)

21 22
/* TODO: we need to refactor s.t. utilities don't know implementation
   of this, but module-specific functions do */
23 24 25 26 27 28 29 30 31
struct darshan_fd_s
{
    gzFile gzf;
    int64_t pos;
    char version[8];
    int swap_flag;
    struct darshan_log_map rec_map;
    struct darshan_log_map mod_map[DARSHAN_MAX_MODS];
};
32
typedef struct darshan_fd_s* darshan_fd;
33

34 35 36 37 38 39
struct darshan_record_ref
{
    struct darshan_record rec;
    UT_hash_handle hlink;
};

40
darshan_fd darshan_log_open(const char *name, const char* mode);
41 42
int darshan_log_getheader(darshan_fd fd, struct darshan_header *header);
int darshan_log_getjob(darshan_fd fd, struct darshan_job *job);
43
int darshan_log_getexe(darshan_fd fd, char *buf);
44
int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
45
    char*** fs_types, int* count);
46
int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash);
47 48
int darshan_log_get_moddat(darshan_fd fd, darshan_module_id mod_id,
    void *moddat_buf, int moddat_buf_sz);
49
void darshan_log_close(darshan_fd file);
50

51
/* convenience macros for printing out counters */
52 53
#define CP_PRINT_HEADER() printf("#<rank>\t<file>\t<counter>\t<value>\t<name suffix>\t<mount pt>\t<fs type>\n")
#define CP_PRINT(__job, __file, __counter, __mnt_pt, __fs_type) do {\
Philip Carns's avatar
Philip Carns committed
54
        printf("%" PRId64 "\t%" PRIu64 "\t%s\t%" PRId64 "\t...%s\t%s\t%s\n", \
55 56
            (__file)->rank, (__file)->hash, darshan_names[__counter], \
            (__file)->counters[__counter], (__file)->name_suffix, \
57
            __mnt_pt, __fs_type); \
58
} while(0)
59
#define CP_F_PRINT(__job, __file, __counter, __mnt_pt, __fs_type) do {\
Philip Carns's avatar
Philip Carns committed
60
        printf("%" PRId64 "\t%" PRIu64 "\t%s\t%f\t...%s\t%s\t%s\n", \
61
            (__file)->rank, (__file)->hash, darshan_f_names[__counter], \
62 63
            (__file)->fcounters[__counter], (__file)->name_suffix, \
            __mnt_pt, __fs_type); \
64 65
} while(0)

66 67 68 69 70 71 72 73 74 75 76 77 78 79
/* 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)
80 81 82 83 84 85 86 87 88 89
#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)

90
#endif