darshan-apmpi-logutils.c 6.25 KB
Newer Older
Sudheer Chunduri's avatar
Sudheer Chunduri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2018 University of Chicago.
 * See COPYRIGHT notice in top-level directory.
 *
 */

#define _GNU_SOURCE
#include "darshan-util-config.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#include "darshan-logutils.h"
#include "darshan-apmpi-log-format.h"

Sudheer Chunduri's avatar
Sudheer Chunduri committed
23 24 25
/* counter name strings for the MPI module */
//#define X(a) #a,

Sudheer Chunduri's avatar
Sudheer Chunduri committed
26 27 28
#define Y(a) #a, 
#define Z(a) #a
#define X I
Sudheer Chunduri's avatar
Sudheer Chunduri committed
29
char *apmpi_counter_names[] = {
30
    APMPI_MPIOP_COUNTERS
Sudheer Chunduri's avatar
Sudheer Chunduri committed
31
};
Sudheer Chunduri's avatar
Sudheer Chunduri committed
32
#undef X
33 34 35 36 37 38 39 40 41 42 43 44
#define X F_P2P
char *apmpi_f_mpiop_totaltime_counter_names[] = {
    APMPI_F_MPIOP_TOTALTIME_COUNTERS
};
#undef X
#define X F_SYNC
char *apmpi_f_mpiop_totalsync_counter_names[] = {
    APMPI_F_MPIOP_SYNCTIME_COUNTERS
};
#undef X
char *apmpi_f_mpi_global_counter_names[] = {
    APMPI_F_MPI_GLOBAL_COUNTERS
Sudheer Chunduri's avatar
Sudheer Chunduri committed
45
};
Sudheer Chunduri's avatar
Sudheer Chunduri committed
46 47 48
#undef Y
#undef Z

Sudheer Chunduri's avatar
Sudheer Chunduri committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
static int darshan_log_get_apmpi_rec(darshan_fd fd, void** buf_p);
static int darshan_log_put_apmpi_rec(darshan_fd fd, void* buf);
static void darshan_log_print_apmpi_rec(void *file_rec,
    char *file_name, char *mnt_pt, char *fs_type);
static void darshan_log_print_apmpi_description(int ver);
static void darshan_log_print_apmpi_rec_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2);

struct darshan_mod_logutil_funcs apmpi_logutils =
{
    .log_get_record = &darshan_log_get_apmpi_rec,
    .log_put_record = &darshan_log_put_apmpi_rec,
    .log_print_record = &darshan_log_print_apmpi_rec,
    .log_print_description = &darshan_log_print_apmpi_description,
    .log_print_diff = &darshan_log_print_apmpi_rec_diff,
    .log_agg_records = NULL
};

static int darshan_log_get_apmpi_rec(darshan_fd fd, void** buf_p)
{
    struct darshan_apmpi_perf_record *prf_rec;
    int rec_len;
    char *buffer;
    int i;
    int ret = -1;

Sudheer Chunduri's avatar
Sudheer Chunduri committed
75
    if(fd->mod_map[APMPI_MOD].len == 0)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        return(0);

    if (!*buf_p)
    {
        /* assume this is the largest possible record size */
        buffer = malloc(sizeof(struct darshan_apmpi_perf_record));
        if (!buffer)
        {
            return(-1);
        }
    }
    else
    {
        buffer = *buf_p;
    }

Sudheer Chunduri's avatar
Sudheer Chunduri committed
92
    if (fd->mod_ver[APMPI_MOD] == 0)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
93 94
    {
        printf("Either unknown or debug version: %d\n",
Sudheer Chunduri's avatar
Sudheer Chunduri committed
95
               fd->mod_ver[APMPI_MOD]);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
96 97 98
        return(0);
    }

Sudheer Chunduri's avatar
Sudheer Chunduri committed
99 100
    if ((fd->mod_ver[APMPI_MOD] > 0) &&
        (fd->mod_ver[APMPI_MOD] < APMPI_VER))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
101 102 103 104 105
    {
        /* perform conversion as needed */
    }

    /* v1, current version */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
106
    if (fd->mod_ver[APMPI_MOD] == APMPI_VER)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
107 108 109
    {
            rec_len = sizeof(struct darshan_apmpi_perf_record);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
110
        ret = darshan_log_get_mod(fd, APMPI_MOD, buffer, rec_len);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
111 112 113 114 115 116 117 118 119
    }

    if (ret == rec_len)
    {
        if(fd->swap_flag)
        {
                prf_rec = (struct darshan_apmpi_perf_record*)buffer;
                DARSHAN_BSWAP64(&(prf_rec->base_rec.id));
                DARSHAN_BSWAP64(&(prf_rec->base_rec.rank));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
120
                /*DARSHAN_BSWAP64(&(prf_rec->group));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
121 122 123
                DARSHAN_BSWAP64(&(prf_rec->chassis));
                DARSHAN_BSWAP64(&(prf_rec->blade));
                DARSHAN_BSWAP64(&(prf_rec->node));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
124
                */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
125 126 127 128
                for (i = 0; i < APMPI_NUM_INDICES; i++)
                {
                    DARSHAN_BSWAP64(&prf_rec->counters[i]);
                }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
129 130 131 132
                for (i = 0; i < APMPI_F_NUM_INDICES; i++)
                {
                    DARSHAN_BSWAP64(&prf_rec->fcounters[i]);
                }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
133 134 135 136 137 138
        }
        *buf_p = buffer;
        return(1);
    }
    else if (ret < 0)
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
139 140
 //       *buf_p = NULL;
 //     if (buffer) free(buffer);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
141 142 143 144
        return(-1);
    }
    else
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
145 146
  //      *buf_p = NULL;
  //      if (buffer) free(buffer);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
147 148 149 150 151 152 153 154 155 156
        return(0);
    }
}

static int darshan_log_put_apmpi_rec(darshan_fd fd, void* buf)
{
    int ret;
    int rec_len;
    static int first_rec = 1;

Sudheer Chunduri's avatar
Sudheer Chunduri committed
157
    rec_len = sizeof(struct darshan_apmpi_perf_record);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
158
    
Sudheer Chunduri's avatar
Sudheer Chunduri committed
159 160
    ret = darshan_log_put_mod(fd, APMPI_MOD, buf,
                              rec_len, APMPI_VER);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    if(ret < 0)
        return(-1);

    return(0);
}

static void darshan_log_print_apmpi_rec(void *rec, char *file_name,
    char *mnt_pt, char *fs_type)
{
    int i;
    struct darshan_apmpi_perf_record *prf_rec;

        prf_rec = rec;
        
        for(i = 0; i < APMPI_NUM_INDICES; i++)
        {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
177
            DARSHAN_U_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
Sudheer Chunduri's avatar
Sudheer Chunduri committed
178 179 180 181
                prf_rec->base_rec.rank, prf_rec->base_rec.id,
                apmpi_counter_names[i], prf_rec->counters[i],
                "", "", "");
        }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
182 183
        for(i = 0; i < APMPI_F_NUM_INDICES; i++)
        {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
184
            DARSHAN_F_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
Sudheer Chunduri's avatar
Sudheer Chunduri committed
185
                prf_rec->base_rec.rank, prf_rec->base_rec.id,
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                apmpi_f_mpiop_totaltime_counter_names[i], prf_rec->fcounters[i],
                "", "", "");
        }
        for(i = 0; i < APMPI_F_SYNC_NUM_INDICES; i++)
        {
            DARSHAN_F_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
                prf_rec->base_rec.rank, prf_rec->base_rec.id,
                apmpi_f_mpiop_totalsync_counter_names[i], prf_rec->fsynccounters[i],
                "", "", "");
        }
        for(i = 0; i < APMPI_F_GLOBAL_NUM_INDICES; i++)
        {
            DARSHAN_F_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
                prf_rec->base_rec.rank, prf_rec->base_rec.id,
                apmpi_f_mpi_global_counter_names[i], prf_rec->fglobalcounters[i],
Sudheer Chunduri's avatar
Sudheer Chunduri committed
201 202
                "", "", "");
        }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
203 204 205 206 207 208 209

    return;
}

static void darshan_log_print_apmpi_description(int ver)
{
    printf("\n# description of APMPI counters: %d\n", ver);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
210 211 212
    //printf("#     node:    node connected to this router\n");
    //printf("#     AR_RTR_x_y_INQ_PRF_INCOMING_FLIT_VC[0-7]: flits on VCz of x y tile\n");
    //printf("#     AR_RTR_x_y_INQ_PRF_ROWBUS_STALL_CNT: stalls on x y tile\n");
Sudheer Chunduri's avatar
Sudheer Chunduri committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

    return;
}

static void darshan_log_print_apmpi_rec_diff(void *file_rec1, char *file_name1,
    void *file_rec2, char *file_name2)
{
    struct darshan_apmpi_perf_record   *prf_rec1;
    struct darshan_apmpi_perf_record   *prf_rec2;

    prf_rec2 = (struct darshan_apmpi_perf_record*) file_rec2;


    return;
}
/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 * End:
 *
 * vim: ts=8 sts=4 sw=4 expandtab
 */