prueba.py 2.74 KB
Newer Older
German Leon's avatar
German Leon committed
1
import os
leon@uji.es's avatar
leon@uji.es committed
2
import re
German Leon's avatar
German Leon committed
3
4
import gdb
import time
leon@uji.es's avatar
leon@uji.es committed
5
import common_functions as cf
German Leon's avatar
German Leon committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def exit_handler(event):
   global nosalir
   nosalir=False
  
   print(str("event type: exit"))
   try:
        print("exit code: {}".format(str(event.exit_code)))
   except Exception as err:
        err_str = "ERROR: {}".format(str(err))
        print(err_str)


"""
Handler that will put a breakpoint on the kernel after
signal
"""

leon@uji.es's avatar
leon@uji.es committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def selectrd():
  linea= cf.execute_command(gdb=gdb, to_execute="x/1i $pc")
  print (linea)#+"-"+str(len(linea))+"-"+linea[0])
  print ("============")
  lista=re.findall(r"R(\d+)", linea[0])
  #Si no hay nexti 
  listareg=[" R{} ".format(x) for x in lista]
  strlistareg="info registers "
  for x in listareg:
    strlistareg+=x;
  print (strlistareg)  
  valores= cf.execute_command(gdb=gdb, to_execute=strlistareg)  
  print("===========VALORES==========")
  regs={}
  for x in valores:
    print(x)
    m = re.match(r".*R(\d+).*0x([0-9a-fA-F]+).*", x)
    if m:
      regs[m.group(1)]=m.group(2)
      print (str(m.group(0))+"  "+str(m.group(1)))
  #Loop----
  gdb.execute("nexti")
  linea= cf.execute_command(gdb=gdb, to_execute="x/1i $pc")
  valores= cf.execute_command(gdb=gdb, to_execute=strlistareg)
  regdst={}
  for x in valores:
    print(x)
    m = re.match(r".*R(\d+).*0x([0-9a-fA-F]+).*", x)
    if m:
      if (regs[m.group(1)]!=m.group(2))
        regdst.add(m.group(1))
  
  
  
  print (type(lista))
  print(lista)
German Leon's avatar
German Leon committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def set_event(event):
      global trun,ocurrencias,t
      if (isinstance(event, gdb.BreakpointEvent)):
        t=time.clock()
        ocurrencias=ocurrencias+1
      else:  
        trun=(time.clock()-t)

    
    
def main():      
    global ocurrencias,t,nosalir,trun
    was_hit = False

    ocurrencias=0
    # Initialize GDB to run the appset pagination off
    gdb.execute("set confirm off")
    gdb.execute("set pagination off")
    gdb.execute("set target-async off")
    gdb.execute("set non-stop off")

    # Connecting to a exit handler event
    gdb.events.exited.connect(exit_handler)

    # Connecting to a stop signal event
    gdb.events.stop.connect(set_event)
    
leon@uji.es's avatar
leon@uji.es committed
86
87
88
89
90
91
92
93
    #gdb.execute("file ~/rodinia_3.1/cuda/lud/cuda/lud_cuda")
    #gdb.execute("set arg -s 10000")
    #gdb.execute("break lud_cuda")
    
    gdb.execute("file codes/mmElem/matrixMul")
    gdb.execute("set arg -wA=16384 -hA=16384 -hB=16384 -wB=16384")
    gdb.execute("set cuda break_on_launch application")
    
German Leon's avatar
German Leon committed
94
    gdb.execute('r')
leon@uji.es's avatar
leon@uji.es committed
95
    selectrd()
German Leon's avatar
German Leon committed
96
97
98
99
100
101
102
103
104
105
106
107
    nosalir=True
    while nosalir:
      gdb.execute("finish")
      gdb.execute("c")
    print (" Ocurrencias "+str(ocurrencias)+" Tiempo acumulado de ejecucciones "+ str(trun))
    f=open("tmpxxx_return_profiler.conf","w")
    f.write("Ocurrencias ="+str(ocurrencias)+"\n Tiempo "+str(trun)+"\n")
    f.close()

main()