One python demo to analysis the decoding time and update texture and swapbuffer time

来源:互联网 发布:太极拳威力知乎 编辑:程序博客网 时间:2024/06/11 14:41

avoid to forget to save this python demo here.

#!/usr/bin/python#coding:utf-8#by jamesimport threadingfrom time import ctime,sleepimport osimport stringimport numpy as npimport matplotlib.mlab as mlabimport matplotlib.pyplot as pltthreads = []decode_time_list=[]swap_time_list=[]updateTexture_time_list=[]#analysis log file namefile_name = "2.log"#show the frame count in figureshow_frame_count = -1def process(filename):        file = open(filename,"r")    decode_line = 0    render_line = 0    update_line = 0    for eachline in file.readlines():        index0 = eachline.find('avcodec_decode_video2')        index1 = eachline.find('SDL_RenderPresent')        index2 = eachline.find('SDL_UpdateTexture')        if index0 != -1:            str = eachline.split("[")[1].split("]")[0]            time = int(str)              decode_time_list.append(time)            decode_line += 1            print "decode: %s ms" %str        elif index1 != -1:            str = eachline.split("[")[1].split("]")[0]            time = int(str)            swap_time_list.append(time)            print "swap  : %s ms" %str        elif index2 != -1:            str = eachline.split("[")[1].split("]")[0]            time = int(str)              updateTexture_time_list.append(time)            print "draw  : %s ms" %str        print "decoding frame count: %d" %(len(decode_time_list))def drawBar(arr, des):    if show_frame_count != -1 :        count = show_frame_count    else :        count = len(arr)    print "frame count = %d" %count    X = np.arange(count)       Y = arr[0:count]#arr    fig = plt.figure()    bar_width = 1.0    text_hight = 1    plt.bar(X, Y, bar_width, color="red", edgecolor = 'white')    #plt.text(X, Y + text_hight, '%d' %Y, ha='center', va= 'bottom')        plt.xlabel("frame count")    y_str = "time consuming (ms)";    plt.ylabel(y_str)            title_str = des + ":" +y_str + ":Frame count:" + str(count);    plt.title(title_str)    plt.show()t1 = threading.Thread(target=drawBar,args=(decode_time_list,"Decoding",))threads.append(t1)t2 = threading.Thread(target=drawBar,args=(swap_time_list,"SwapBuffer",))threads.append(t2)t3 = threading.Thread(target=drawBar,args=(updateTexture_time_list, "UpdateTexture",))threads.append(t3)if __name__ == '__main__':    process(file_name);       drawBar(decode_time_list,"Decoding");        drawBar(swap_time_list,"SwapBuffer");    drawBar(updateTexture_time_list,"UpdateTexture");    #for t in threads:    #    t.setDaemon(False)    #    t.start()    #    print "thread ------started"    


0 0