Example #1
0
int test_util_get_io_perfs(
    PVFS_fs_id cur_fs,
    PVFS_credentials creds,
    int count)
{
    int ret, i, j;
    ret = PVFS_mgmt_perf_mon_list(
              cur_fs, &creds, perf_matrix,
              end_time_ms_array, addr_array, next_id_array,
              count, HISTORY, NULL, NULL);
    if(ret < 0)
    {
        PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
        return -1;
    }

    for(i = 0; i < count; i++)
    {
        for(j = 0; j < HISTORY; ++j)
        {
            if(!perf_matrix[i][j].valid_flag)
            {
                break;
            }

            printf("%d\t%llu\t%lld\t%lld\n",
                   count,
                   llu(perf_matrix[i][j].start_time_ms),
                   lld(perf_matrix[i][j].write),
                   lld(perf_matrix[i][j].read));
        }
    }

    return 0;
}
Example #2
0
int main(int argc, char **argv)
{
    int ret = -1;
    char *retc = NULL;
    PVFS_fs_id cur_fs;
    struct options* user_opts = NULL;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    int i;
    PVFS_credentials creds;
    int io_server_count;
    int64_t **perf_matrix;
    uint64_t* end_time_ms_array;
    uint32_t* next_id_array;
    PVFS_BMI_addr_t *addr_array, server_addr;
    char *cmd_buffer = (char *)malloc(CMD_BUF_SIZE);
    int max_keys, key_count;

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
        fprintf(stderr, "Error: failed to parse command line arguments.\n");
        usage(argc, argv);
        return(-1);
    }

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
        PVFS_perror("PVFS_util_init_defaults", ret);
        return(-1);
    }

    PVFS_util_gen_credentials(&creds);
    if (user_opts->server_addr_set)
    {
        if (PVFS_util_get_default_fsid(&cur_fs) < 0)
        {
            /* Can't find a file system */
            fprintf(stderr, "Error: failed to find a file system.\n");
            usage(argc, argv);
            return(-1);
        }
        if (user_opts->server_addr &&
                (BMI_addr_lookup (&server_addr, user_opts->server_addr) == 0))
        {
            /* set up single server */
            addr_array = (PVFS_BMI_addr_t *)malloc(sizeof(PVFS_BMI_addr_t));
            addr_array[0] = server_addr;
            io_server_count = 1;
        }
        else
        {
            /* bad argument - address not found */
            fprintf(stderr, "Error: failed to parse server address.\n");
            usage(argc, argv);
            return(-1);
        }
    }
    else
    {
        /* will sample all servers */
        /* translate local path into pvfs2 relative path */
        ret = PVFS_util_resolve(user_opts->mnt_point,
                                &cur_fs, pvfs_path, PVFS_NAME_MAX);
        if (ret < 0)
        {
            PVFS_perror("PVFS_util_resolve", ret);
            return(-1);
        }

        /* count how many I/O servers we have */
        ret = PVFS_mgmt_count_servers(cur_fs, &creds, PVFS_MGMT_IO_SERVER,
                                    &io_server_count);
        if (ret < 0)
        {
            PVFS_perror("PVFS_mgmt_count_servers", ret);
	        return(-1);
        }
    
        /* build a list of servers to talk to */
        addr_array = (PVFS_BMI_addr_t *)
	    malloc(io_server_count * sizeof(PVFS_BMI_addr_t));
        if (addr_array == NULL)
        {
	        perror("malloc");
	        return -1;
        }
        ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds,
				     PVFS_MGMT_IO_SERVER,
				     addr_array,
				     &io_server_count);
        if (ret < 0)
        {
	        PVFS_perror("PVFS_mgmt_get_server_array", ret);
	        return -1;
        }
    }

    /* count keys */
    for (max_keys = 0; key_table[max_keys].key_number >= 0; max_keys++);

    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (int64_t **)malloc(io_server_count * sizeof(int64_t *));
    if (!perf_matrix)
    {
        perror("malloc");
        return(-1);
    }
    for(i=0; i<io_server_count; i++)
    {
	    perf_matrix[i] = (int64_t *)malloc(HISTORY * (max_keys + 2)
                                        * sizeof(int64_t));
	    if (perf_matrix[i] == NULL)
	    {
	        perror("malloc");
	        return -1;
	    }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server 
     */
    next_id_array = (uint32_t *) malloc(io_server_count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
	     perror("malloc");
	     return -1;
    }
    memset(next_id_array, 0, io_server_count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)malloc(io_server_count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
	    perror("malloc");
	    return -1;
    }


    /* loop for ever, grabbing stats when requested */
    while (1)
    {
        int srv = 0;
        time_t snaptime = 0;
        const char *returnType = NULL; 
        int64_t returnValue = 0;
        /* wait for a request from SNMP driver */
        retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
        if (!retc)
        {
            /* error on read */
            return -1;
        }

        /* if PING output PONG */
        if (!strncasecmp(cmd_buffer, "PING", 4))
        {
            fprintf(stdout,"PONG\n");
	        fflush(stdout);
            continue;
        }

        /* try to parse GET command */
        if (!strncasecmp(cmd_buffer, "GET", 3))
        {
            char *c;
            /* found GET read OID */
            retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
            if (!retc)
            {
                /* error on read */
                return -1;
            }
            /* replace newlines with null char */
            for(c = cmd_buffer; *c != '\0'; c++)
                if (*c == '\n')
                    *c = '\0';
        }
        else
        {
            /* bad command */
            fprintf(stdout, "NONE\n");
            fflush(stdout);
            continue;
        }

        /* good command - read counters */
        if (time(NULL) - snaptime > 60)
        {
            snaptime = time(NULL);
            key_count = max_keys;
	        ret = PVFS_mgmt_perf_mon_list(cur_fs,
				          &creds,
				          perf_matrix, 
				          end_time_ms_array,
				          addr_array,
				          next_id_array,
				          io_server_count, 
                          &key_count,
				          HISTORY,
				          NULL, NULL);
	        if (ret < 0)
	        {
	            PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
	            return -1;
	        }
        }

        /* format requested OID */
        if (perf_matrix[srv][key_count] != 0)
        {
            int k;
            /* this is a valid measurement */
            for(k = 0; k < max_keys &&
                    strcmp(cmd_buffer, key_table[k].key_oid); k++);
            /* out of for loop k equals selected key */
            if (k < max_keys)
            {
                returnType = key_table[k].key_type;
                returnValue = perf_matrix[srv][key_table[k].key_number];
            }
            else
            {
                /* invalid command */
                fprintf(stdout,"NONE\n");
                fflush(stdout);
                continue;
            }
        }
        else
        {
            /* invalid measurement */
            fprintf(stdout,"NONE\n");
            fflush(stdout);
            continue;
        }
        fprintf(stdout, "%s\n%llu\n", returnType, llu(returnValue));
        fflush(stdout);
        /* return to top for next command */
    }

    PVFS_sys_finalize();

    return(ret);
}