def draw_graph()

in contrib/profiler/profiler.py [0:0]


def draw_graph(sample_datas, output_dir, period, gpu_id):
    if not os.path.exists(output_dir + '/img'):
        os.mkdir(output_dir + '/img')
    sample_datas = np.array(sample_datas)
    gpu_nums = len(gpu_id)

    # draw the GPU memory usage
    gpu_mem, legends, times = list(), list(), list()
    for i in range(int(gpu_nums)):
        gpu_mem.append(100 * sample_datas[:, GPU_INFO_OFFSET + GPU_MEM_OFFSET + i * INFO_NUM_PER_GPU] /
                       sample_datas[:, GPU_INFO_OFFSET + GPU_MEM_OFFSET + i * INFO_NUM_PER_GPU + 1]
                       )
        legends.append('gpu_mem_used_' + str(gpu_id[i]))
    for i in range(sample_datas.shape[0]):
        times.append(i * period)
    plt.figure()
    plt.title('GPU Memory Utilization')
    plt.xlabel('Time(s)')
    plt.ylabel('GPU memory utilization(%)')
    plt.plot(times, np.array(gpu_mem).T)
    plt.legend(legends)
    plt.grid(True)
    plt.savefig(output_dir + '/img/GPU_MEM_Utilization.png')

    # draw the GPU usage
    gpu_usage, legends, times = list(), list(), list()
    for i in range(int(gpu_nums)):
        gpu_usage.append(sample_datas[:, GPU_INFO_OFFSET + i * INFO_NUM_PER_GPU])
        legends.append('gpu_used_' + str(gpu_id[i]))
    for i in range(sample_datas.shape[0]):
        times.append(i * period)
    plt.figure()
    plt.title('GPU Utilization')
    plt.xlabel('Time(s)')
    plt.ylabel('GPU utilization(%)')
    plt.plot(times, np.array(gpu_usage).T)
    plt.legend(legends)
    plt.grid(True)
    plt.savefig(output_dir + '/img/GPU_UTI_Utilization.png')

    # draw the CPU and GPU usage
    times = list()
    length = sample_datas.shape[0]
    gpu_usage = sample_datas[int(0.6 * length):int(0.6 * length) + 1000, GPU_INFO_OFFSET]
    cpu_usage = sample_datas[int(0.6 * length):int(0.6 * length) + 1000, SAMPLE_INFO.cpu_usage.value]
    for i in range(gpu_usage.shape[0]):
        times.append(i * period)
    fig = plt.figure()
    a1 = fig.add_subplot(111)
    a1.set_title('CPU & GPU Utilization')
    a1.plot(times, cpu_usage, label='cpu')
    plt.legend(loc='best')
    a1.set_ylim([0, np.max(cpu_usage) if np.max(cpu_usage) > 100 else 100])
    a1.set_ylabel('CPU utilization(%)')
    a1.set_xlabel('Time(s)')
    a2 = a1.twinx()
    a2.plot(times, gpu_usage, 'orange', label='gpu')
    plt.legend(loc='best')
    a2.set_ylim([0, 100])
    a2.set_ylabel('GPU utilization(%)')
    plt.grid(True)
    plt.savefig(output_dir + '/img/CPU_GPU_Utilization.png')

    # draw the IO usage
    times = list()
    # index 3 and 4 are the column of the I/O rate
    io_rate = [sample_datas[:, SAMPLE_INFO.io_read.value], sample_datas[:, SAMPLE_INFO.io_write.value]]
    legends = ['Disk read', 'Disk write']
    for i in range(sample_datas.shape[0]):
        times.append(i * period)
    plt.figure()
    plt.title('Disk Utilization')
    plt.xlabel('Time(s)')
    plt.ylabel('Disk Utilization(KBps)')
    plt.plot(times, np.array(io_rate).T)
    plt.legend(legends)
    plt.grid(True)
    plt.savefig(output_dir + '/img/Disk_Utilization.png')

    # draw the network usage
    times = list()
    # index 5 and 6 are the column of the network rate
    network_rate = [sample_datas[:, SAMPLE_INFO.network_inbound.value],
                    sample_datas[:, SAMPLE_INFO.network_outbound.value]]
    legends = ['Network Inbound', 'Network Outbound']
    for i in range(sample_datas.shape[0]):
        times.append(i * period)
    plt.figure()
    plt.title('Network Usage')
    plt.xlabel('Time(s)')
    plt.ylabel('Network Utilization(KBps)')
    plt.plot(times, np.array(network_rate).T)
    plt.legend(legends)
    plt.grid(True)
    plt.savefig(output_dir + '/img/Network_Utilization.png')