darshan-apmpi-logutils.c 5.39 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 30 31
char *apmpi_counter_names[] = {
    APMPI_PERF_COUNTERS
};
Sudheer Chunduri's avatar
Sudheer Chunduri committed
32 33
#undef X
#define X F
Sudheer Chunduri's avatar
Sudheer Chunduri committed
34 35 36
char *apmpi_f_counter_names[] = {
    APMPI_PERF_F_COUNTERS
};
Sudheer Chunduri's avatar
Sudheer Chunduri committed
37 38
#undef Y
#undef Z
Sudheer Chunduri's avatar
Sudheer Chunduri committed
39
#undef X
Sudheer Chunduri's avatar
Sudheer Chunduri committed
40

Sudheer Chunduri's avatar
Sudheer Chunduri committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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
67
    if(fd->mod_map[APMPI_MOD].len == 0)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        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
84
    if (fd->mod_ver[APMPI_MOD] == 0)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
85 86
    {
        printf("Either unknown or debug version: %d\n",
Sudheer Chunduri's avatar
Sudheer Chunduri committed
87
               fd->mod_ver[APMPI_MOD]);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
88 89 90
        return(0);
    }

Sudheer Chunduri's avatar
Sudheer Chunduri committed
91 92
    if ((fd->mod_ver[APMPI_MOD] > 0) &&
        (fd->mod_ver[APMPI_MOD] < APMPI_VER))
Sudheer Chunduri's avatar
Sudheer Chunduri committed
93 94 95 96 97
    {
        /* perform conversion as needed */
    }

    /* v1, current version */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
98
    if (fd->mod_ver[APMPI_MOD] == APMPI_VER)
Sudheer Chunduri's avatar
Sudheer Chunduri committed
99 100 101
    {
            rec_len = sizeof(struct darshan_apmpi_perf_record);

Sudheer Chunduri's avatar
Sudheer Chunduri committed
102
        ret = darshan_log_get_mod(fd, APMPI_MOD, buffer, rec_len);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
103 104 105 106 107 108 109 110 111
    }

    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
112
                /*DARSHAN_BSWAP64(&(prf_rec->group));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
113 114 115
                DARSHAN_BSWAP64(&(prf_rec->chassis));
                DARSHAN_BSWAP64(&(prf_rec->blade));
                DARSHAN_BSWAP64(&(prf_rec->node));
Sudheer Chunduri's avatar
Sudheer Chunduri committed
116
                */
Sudheer Chunduri's avatar
Sudheer Chunduri committed
117 118 119 120
                for (i = 0; i < APMPI_NUM_INDICES; i++)
                {
                    DARSHAN_BSWAP64(&prf_rec->counters[i]);
                }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
121 122 123 124
                for (i = 0; i < APMPI_F_NUM_INDICES; i++)
                {
                    DARSHAN_BSWAP64(&prf_rec->fcounters[i]);
                }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
125 126 127 128 129 130
        }
        *buf_p = buffer;
        return(1);
    }
    else if (ret < 0)
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
131 132
 //       *buf_p = NULL;
 //     if (buffer) free(buffer);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
133 134 135 136
        return(-1);
    }
    else
    {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
137 138
  //      *buf_p = NULL;
  //      if (buffer) free(buffer);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
139 140 141 142 143 144 145 146 147 148
        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
149
    rec_len = sizeof(struct darshan_apmpi_perf_record);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
150
    
Sudheer Chunduri's avatar
Sudheer Chunduri committed
151 152
    ret = darshan_log_put_mod(fd, APMPI_MOD, buf,
                              rec_len, APMPI_VER);
Sudheer Chunduri's avatar
Sudheer Chunduri committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    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
169
            DARSHAN_U_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
Sudheer Chunduri's avatar
Sudheer Chunduri committed
170 171 172 173
                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
174 175
        for(i = 0; i < APMPI_F_NUM_INDICES; i++)
        {
Sudheer Chunduri's avatar
Sudheer Chunduri committed
176
            DARSHAN_F_COUNTER_PRINT(darshan_module_names[APMPI_MOD],
Sudheer Chunduri's avatar
Sudheer Chunduri committed
177 178 179 180
                prf_rec->base_rec.rank, prf_rec->base_rec.id,
                apmpi_f_counter_names[i], prf_rec->fcounters[i],
                "", "", "");
        }
Sudheer Chunduri's avatar
Sudheer Chunduri committed
181 182 183 184 185 186 187

    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
188 189 190
    //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
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

    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
 */