我用了dmtracedump -o -g test.png test.trace命令,没有报错,但是test.png没有生成,不知道是什么问题,请各位大侠帮助

解决方案 »

  1.   

    http://blog.csdn.net/zjujoe/article/details/6080738这个人说这个工具不能用,上面有一个他自己写的脚本,我运行后出现ValueError: invalid literal for int() with base 10: '1\tmain'这个错误,完全不懂,等待高手指点阿
      

  2.   

    我试过了,dmtracedump的确不能使,有问题。 我修改test.trace在#end后,在SLOW之前加个回车,可以生成一个错误的png图像。 说明dmtracedump无法对正确的.trace文件进行绘制。 而且搜了下大家的反馈都说这个工具不能使。 Google没有完善好。
      

  3.   

    哦,那那个脚本呢?能不能行呢?那个脚本我试过,报了ValueError: invalid literal for int() with base 10: '1\tmain'这个错误
      

  4.   

    看看这个:
    http://www.cnblogs.com/GnagWang/archive/2011/05/18/2049604.html
    希望有帮助
      

  5.   

    很早就看了,同意7楼的观点,现在只有看那个脚本能不能实现了,想问7楼一个问题test.trace你是怎么修改的阿,我只能用traceview打开阿
      

  6.   


    用vim 编辑 那个脚本也有问题 我问了问同事  他帮我研究了一下,画出来了 这是个振奋的消息 
    我去学习下 完了告诉你 
      

  7.   

    http://blog.csdn.net/yiyaaixuexi/article/details/6716884555555555 写完了 1点了 睡觉了  
      

  8.   


    #!/usr/bin/env python
    """ 
    turn the traceview data into a jpg pic, showing methods call relationship 
    """  
    import sys  
    import os  
    import struct  
    import re  
    ################################################################################  
    ########################  Global Variable  #####################################  
    ################################################################################  
    target_thread=1 #the thread that we want to track, filt out other threads  
    #all_actions = ["enter","exit","exception","reserved"]  
    all_threads = {}  
    all_methods = {}  
    all_records = []  
    parent_methods = {}  
    child_methods = {}  
    method_calls = {}  
    ################################################################################  
    ##############################   Methods   #####################################  
    ################################################################################  
    def add_one_thread(line):  
    fields = line.split("\t")  
    all_threads[int(fields[0],10)]=fields  
    def add_one_method(line):  
        fields = line.split("\t")  
        all_methods[int(fields[0],16)]=fields  
    def add_one_record(one):  
        thread_id,=struct.unpack("B",one[:1])  
        if (thread_id == target_thread):
            tmp,=struct.unpack("L",one[1:5])  
            method_id= (tmp / 4) * 4;  
            method_action= tmp % 4;  
            time_offset,=struct.unpack("L",one[5:])  
            all_records.append([thread_id, method_id, method_action, time_offset])  
    def handle_one_call(parent_method_id,method_id):  
         if not (parent_methods.has_key(parent_method_id)):  
                parent_methods[parent_method_id]=1  
         if not (child_methods.has_key(method_id)):  
               child_methods[method_id]=1  
         if method_calls.has_key(parent_method_id):  
               if method_calls[parent_method_id].has_key(method_id):  
                   method_calls[parent_method_id][method_id]+=1  
               else:  
                  method_calls[parent_method_id][method_id]=1  
         else:  
              method_calls[parent_method_id]={}  
              method_calls[parent_method_id][method_id]=1  
    def gen_funcname(method_id):
        r1=re.compile(r'[/{1}1t;>]')
        str1=r1.sub("_",all_methods[method_id][1])
        str2=r1.sub("_",all_methods[method_id][2])
        return str1+"_"+str2  
    def gen_dot_script_file():  
        myoutfile = open("graph.dot", "w")  
        myoutfile.write("digraph vanzo {\n\n");  
        for one in all_methods.keys():
            if parent_methods.has_key(one):
                myoutfile.write(gen_funcname(one)+"  [shape=rectangle];\n")
            else:
                if child_methods.has_key(one):
                    myoutfile.write(gen_funcname(one)+"  [shape=ellipse];\n")  
        for one in method_calls.keys():  
            for two in method_calls[one]:  
                    myoutfile.write(gen_funcname(one) + ' -> ' + gen_funcname(two) +  ' [label="'  +str(method_calls[one][two]) + '"  fontsize="10"];\n')  
        myoutfile.write("\n}\n");  
        myoutfile.close  
            
    ################################################################################  
       ########################## Script starts from here #############################  
      ################################################################################  
    if len(sys.argv) < 2:    
        print 'No input file specified.'    
        sys.exit()  
    if not (os.path.exists(sys.argv[1])):
        print "input file not exists"
        sys.exit()  
    #Now handle the text part  
    current_section=0  
    for line in open(sys.argv[1]):
        line2 = line.strip()
        if (line2.startswith("*")):
            if (line2.startswith("*version")):
                current_section=1
            else:
                if (line2.startswith("*threads")):
                    current_section=2
                else:
                    if (line2.startswith("*methods")):
                        current_section=3
                    else:
                        if (line2.startswith("*end")):
                            current_section=4
                            break
            continue
        if current_section==2:
            add_one_thread(line2)
        if current_section==3:
            add_one_method(line2)  
            
    #Now handle the binary part  
    mybinfile = open(sys.argv[1], "rb")   
    alldata = mybinfile.read()  
    mybinfile.close()  
    pos=alldata.find("SLOW")  
    offset,=struct.unpack("H",alldata[pos+6:pos+8])  
    pos2=pos+offset #pos2 is where the record begin  
    numofrecords = len(alldata) - pos2  
    numofrecords = numofrecords / 9  
    for i in xrange(numofrecords):
        add_one_record(alldata[pos2 + i * 9:pos2 + i * 9 + 9])
    my_stack=[0]  
    for onerecord in all_records:  
        thread_id=onerecord[0];      
        method_id=onerecord[1];  
        action=onerecord[2];  
        time=onerecord[3];  
        if(action==0):
            if(len(my_stack) > 1):
                parent_method_id=my_stack[-1]  
                handle_one_call(parent_method_id,method_id)  
            my_stack.append(method_id)
        else:
            if(action==1):
                if(len(my_stack) > 1):
                    my_stack.pop()  
    gen_dot_script_file()  
      
    os.system("dot -Tjpg:gd graph.dot -o output.jpg;rm -f graph.dot");  
    这是我的那个脚本,感觉和你的一样阿
      

  9.   

     File "./draw", line 112
        add_one_record(alldata[pos2 + i * 9:pos2 + i * 9 + 9])my_stack=[0]  
                                                                     ^
    SyntaxError: invalid syntax
    有问题把,,你把你的脚本和trace文件发给我试一下麻,再试一下我的trace文件
      

  10.   

    File "./draw", line 112
      add_one_record(alldata[pos2 + i * 9:pos2 + i * 9 + 9])my_stack=[0]  
      ^
    SyntaxError: invalid syntax
      

  11.   

    说错了 应该有换行#!/usr/bin/env python  
    """ 
    turn the traceview data into a jpg pic, showing methods call relationship 
    """  
    import sys  
    import os  
    import struct  
    import re  
    ################################################################################  
    ########################  Global Variable  #####################################  
    ################################################################################  
    target_thread=1 #the thread that we want to track, filt out other threads  
    #all_actions = ["enter","exit","exception","reserved"]  
    all_threads = {}  
    all_methods = {}  
    all_records = []  
    parent_methods = {}  
    child_methods = {}  
    method_calls = {}  
    ################################################################################  
    ##############################   Methods   #####################################  
    ################################################################################  
    def add_one_thread(line):  
    fields = line.split("\t")  
    all_threads[int(fields[0],10)]=fields  
    def add_one_method(line):  
    fields = line.split("\t")  
    all_methods[int(fields[0],16)]=fields  
    def add_one_record(one):  
    thread_id,=struct.unpack("B",one[:1])  
    if (thread_id == target_thread):  
    tmp,=struct.unpack("L",one[1:5])  
    method_id= (tmp / 4) * 4;  
    method_action= tmp % 4;  
    time_offset,=struct.unpack("L",one[5:])  
    all_records.append([thread_id, method_id, method_action, time_offset])
    def handle_one_call(parent_method_id,method_id):  
    if not (parent_methods.has_key(parent_method_id)):  
    parent_methods[parent_method_id]=1  
    if not (child_methods.has_key(method_id)):  
    child_methods[method_id]=1  
    if method_calls.has_key(parent_method_id):  
    if method_calls[parent_method_id].has_key(method_id):  
    method_calls[parent_method_id][method_id]+=1  
    else:  
    method_calls[parent_method_id][method_id]=1  
    else:  
    method_calls[parent_method_id]={}  
    method_calls[parent_method_id][method_id]=1  
    def gen_funcname(method_id):  
    r1=re.compile(r'[/$<>]')  
    str1=r1.sub("_",all_methods[method_id][1])  
    str2=r1.sub("_",all_methods[method_id][2])  
    return str1+"_"+str2  
    def gen_dot_script_file():  
    myoutfile = open("graph.dot", "w")  
    myoutfile.write("digraph vanzo {\n\n");  
    for one in all_methods.keys():  
    if parent_methods.has_key(one):  
    myoutfile.write(gen_funcname(one)+"  [shape=rectangle];\n")  
    else:  
    if child_methods.has_key(one):  
    myoutfile.write(gen_funcname(one)+"  [shape=ellipse];\n")  
    for one in method_calls.keys():  
    for two in method_calls[one]:  
    myoutfile.write(gen_funcname(one) + ' -> ' + gen_funcname(two) +  ' [label="' + str(method_calls[one][two]) + '"  fontsize="10"];\n') 
    myoutfile.write("\n}\n");  
    myoutfile.close  ################################################################################  
    ########################## Script starts from here #############################  
    ################################################################################  
    if len(sys.argv) < 2:    
    print 'No input file specified.'    
    sys.exit()  
    if not (os.path.exists(sys.argv[1])):  
    print "input file not exists"  
    sys.exit()  
    #Now handle the text part  
    current_section=0  
    for line in open(sys.argv[1]):  
    line2 = line.strip()  
    if (line2.startswith("*")):  
    if (line2.startswith("*version")):  
    current_section=1  
    else:  
    if (line2.startswith("*threads")):  
    current_section=2  
    else:  
    if (line2.startswith("*methods")):  
    current_section=3  
    else:   
    if (line2.startswith("*end")):  
    current_section=4  
    break  
    continue  
    if current_section==2:  
    add_one_thread(line2)  
    if current_section==3:  
    add_one_method(line2)  #Now handle the binary part  
    mybinfile = open(sys.argv[1], "rb")   
    alldata = mybinfile.read()  
    mybinfile.close()  
    pos=alldata.find("SLOW")  
    offset,=struct.unpack("H",alldata[pos+6:pos+8])  
    pos2=pos+offset #pos2 is where the record begin  
    numofrecords = len(alldata) - pos2  
    numofrecords = numofrecords / 9  
    for i in xrange(numofrecords):  
    add_one_record(alldata[pos2 + i * 9:pos2 + i * 9 + 9])  my_stack=[0]  
    for onerecord in all_records:  
    thread_id=onerecord[0];      
    method_id=onerecord[1];  
    action=onerecord[2];  
    time=onerecord[3];  
    if(action==0):  
    if(len(my_stack) > 1):  
    parent_method_id=my_stack[-1]  
    handle_one_call(parent_method_id,method_id)  
    my_stack.append(method_id)  
    else:  
    if(action==1):  
    if(len(my_stack) > 1):  
    my_stack.pop()  
    gen_dot_script_file()  
    #os.system("dot -Tjpg graph.dot -o output.jpg;rm -f graph.dot");
    os.system("dot -Tpng:gd graph.dot -o output1.png");
      

  12.   

    就你发给我的邮件,我运行了还是那个错误
    hadoop@hadoop20:~/drawtrace$ ./drawtrace calc.trace 
      File "./drawtrace", line 112
        add_one_record(alldata[pos2 + i * 9:pos2 + i * 9 + 9])  my_stack=[0]  
                                                                       ^
    SyntaxError: invalid syntax
      

  13.   

      看你用什么编辑器打开的脚本呢  重新对齐一下  my_stack=[0]  是在下一行 
      

  14.   

    我终于知道是什么原因了,是我的机子是64位,得改代码:
    def add_one_record(one):
     30     thread_id,=struct.unpack("B",one[:1])
     31     if (thread_id == target_thread):
     32         tmp,=struct.unpack("I",one[1:5])
     33         method_id= (tmp / 4) * 4;
     34         method_action= tmp % 4;
     35         time_offset,=struct.unpack("I",one[5:])
     36         all_records.append([thread_id, method_id, method_action, time_offset    ])