prueba.py 4.41 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
German Leon's avatar
German Leon committed
5
import signal
leon@uji.es's avatar
leon@uji.es committed
6
import common_functions as cf
German Leon's avatar
German Leon committed
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
"""
German Leon's avatar
German Leon committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def handler(signum, frame):
      global pid,pillo,t0
      print ("handler:+++++++++++========================++++++++++++")
      #print ("+++++++++++========================++++++++++++") 
      #gdb.execute("nexti")
      settimeslice()
      pillo=time.time()-t0
      os.kill(os.getpid(), signal.SIGINT)
      #print ("+++++++++++========================++++++++++++") 
def setalarm():
    signal.signal(signal.SIGALRM,handler)
    #print ("No disponible")
def settimeslice():  
     #signal.alarm(1)   
     signal.setitimer(signal.ITIMER_REAL,1.0,1.0)
     #print ("No disponible")
def pausealarm():
     signal.setitimer(signal.ITIMER_REAL,0) 
     #print ("No disponible") 
     
German Leon's avatar
German Leon committed
43

leon@uji.es's avatar
leon@uji.es committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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:
German Leon's avatar
German Leon committed
73
      if (regs[m.group(1)]!=m.group(2)):
leon@uji.es's avatar
leon@uji.es committed
74
75
76
77
78
79
        regdst.add(m.group(1))
  
  
  
  print (type(lista))
  print(lista)
German Leon's avatar
German Leon committed
80
def set_event(event):
German Leon's avatar
German Leon committed
81
82
83
      global trun,ocurrencias,t,pillo,t0,bp
      #pausealarm()
   
German Leon's avatar
German Leon committed
84
      if (isinstance(event, gdb.BreakpointEvent)):
German Leon's avatar
German Leon committed
85
86
87
        print ("Bp")
        t0=time.clock()
        bp.enabled=False
German Leon's avatar
German Leon committed
88
        ocurrencias=ocurrencias+1
German Leon's avatar
German Leon committed
89
        #signal.setitimer(signal.ITIMER_REAL,3)
German Leon's avatar
German Leon committed
90
      else:  
German Leon's avatar
German Leon committed
91
92
93
94
95
96
97
98
99
        print ("set_event")
        #signal.setitimer(signal.ITIMER_REAL,0)
        trun=(time.clock()-t0)
        #signal.setitimer(signal.ITIMER_REAL,2)
      #signal.setitimer(signal.ITIMER_REAL,0.1)
      t=time.time()-t0
      print ("\n Pongo: "+str(t)+"  Pillo;"+str(pillo)+"\n")
      #settimeslice()   
      #gdb.execute("c")
German Leon's avatar
German Leon committed
100
101

def main():      
German Leon's avatar
German Leon committed
102
103
    global ocurrencias,t,nosalir,trun,pid,t0,pillo,bp
    
German Leon's avatar
German Leon committed
104
    was_hit = False
German Leon's avatar
German Leon committed
105
    #pid=os.getpid()
German Leon's avatar
German Leon committed
106
107
    ocurrencias=0
    # Initialize GDB to run the appset pagination off
German Leon's avatar
German Leon committed
108
    gdb.execute('catch signal SIGALRM') 
German Leon's avatar
German Leon committed
109
110
111
112
    gdb.execute("set confirm off")
    gdb.execute("set pagination off")
    gdb.execute("set target-async off")
    gdb.execute("set non-stop off")
German Leon's avatar
German Leon committed
113
114
    setalarm()
    settimeslice()
German Leon's avatar
German Leon committed
115
116
117
118
119
    # Connecting to a exit handler event
    gdb.events.exited.connect(exit_handler)

    # Connecting to a stop signal event
    gdb.events.stop.connect(set_event)
German Leon's avatar
German Leon committed
120
    #gdb.events.cont.connect(set_event_cont)
leon@uji.es's avatar
leon@uji.es committed
121
122
123
    #gdb.execute("file ~/rodinia_3.1/cuda/lud/cuda/lud_cuda")
    #gdb.execute("set arg -s 10000")
    #gdb.execute("break lud_cuda")
German Leon's avatar
German Leon committed
124
125
126
127
128
129
  

    t0=time.time()
    print (t0)

    pillo=t0
leon@uji.es's avatar
leon@uji.es committed
130
131
    gdb.execute("file codes/mmElem/matrixMul")
    gdb.execute("set arg -wA=16384 -hA=16384 -hB=16384 -wB=16384")
German Leon's avatar
German Leon committed
132
133
134
135
136
137
    #gdb.execute("set cuda break_on_launch application")
   # bp=gdb.Breakpoint('matrixMulCUDA')
    #gdb.execute('handle SIGALRM stop')
    #gdb.execute('handle SIGALRM ignore')
    #gdb.execute('handle SIGALRM')
    gdb.execute('catch signal SIGALRM')  
German Leon's avatar
German Leon committed
138
    gdb.execute('r')
German Leon's avatar
German Leon committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    #selectrd()
    print ("1")
    gdb.execute("c")
    print ("1")
    gdb.execute("c")
    gdb.execute("c")
    gdb.execute("c")
    pausealarm()
    gdb.execute("c")
    gdb.execute("c")
  #nosalir=True
   # while nosalir:
    #  gdb.execute("finish")
     # gdb.execute("c")"
German Leon's avatar
German Leon committed
153
154
155
156
157
158
159
160
    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()