profiler_new.py 3.25 KB
Newer Older
German Leon's avatar
German Leon committed
1
2
import gdb

German Leon's avatar
German Leon committed
3
4
5
6
import time
import re
import sys
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

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
22
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
def numreg (kernel):
  try:
    disassemble_array = cf.execute_command(gdb=gdb, to_execute="disassemble {}".format(kernel))
  except:
    disassemble_array = cf.execute_command(gdb=gdb, to_execute="disassemble")
  listareg=set()
  listaregdst=set()
  listaregcond=set()
  for i in range(0, len(disassemble_array) - 1):
     line = disassemble_array[i]
     m=re.match(r".*:\t(\S+) .*",line)
#      print("ASSM_LINE:{}".format(l))
     todacadena="ASSM_LINE:{}".format(line)
     print(todacadena)
     lista=re.findall(r"R(\d+)", line)
     if (len(lista) > 0):   	
         listareg.update(lista)
         print (listareg)
         listaregdst.add (lista[0])
         print (listaregdst)
     lista=re.findall(r" P(\d+)", line)
     if (len(lista) > 0): 
         print (listaregcond)
         listaregcond.update(lista)
  #       if m and m.group(1) != '0':
  #       Print ("Encontrado"
German Leon's avatar
German Leon committed
48

German Leon's avatar
German Leon committed
49
50
51
52
53
54
55
  print ("Registros Visibles ({})".format(len(listareg)))
  print (listareg)
  print ("Registros destino ({})".format(len(listaregdst)))
  print (listaregdst)
  print ("Registros condicionales ({})".format(len(listaregcond)))
  print (listaregcond)
  return (len(listareg))
German Leon's avatar
German Leon committed
56
57
58
59
60
61
def set_event(event):
      global trun,ocurrencias,t,primera
      
      print ("Es mi primera vez"+ str(primera)+"  "+str(ocurrencias))
      if (isinstance(event, gdb.BreakpointEvent)):
        if (primera):
German Leon's avatar
German Leon committed
62
63
64
          
          t=time.time()
          print ("Tomo tiempo " + str (t))
German Leon's avatar
German Leon committed
65
66
          ocurrencias=ocurrencias+1
        else:  
German Leon's avatar
German Leon committed
67
68
          print ("Para tiempo " + str (time.time()))
          trun=(time.time()-t)
German Leon's avatar
German Leon committed
69
        primera=not primera  
German Leon's avatar
German Leon committed
70
71
    #  else:  
    #      trun=(time.clock()-t)  
German Leon's avatar
German Leon committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Main function
"""
def main():
  global ocurrencias,t,nosalir,trun,primera
  primera=True	;
  ocurrencias=0;


  # Initialize GDB to run the app
  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)

  # gdb_init_strings = str(os.environ["CAROL_FI_INFO"])
  gdb_init_strings = arg0
German Leon's avatar
German Leon committed
95
96
97
98
99
  cadena=gdb_init_strings.split(";",3)
 
  print >>sys.stderr, (cadena[0]) #,"-",cadena[0],"-",cadena[1],"-", cadena[2],"#". cadena[3])
  section =cadena[0]=="True" 
  onlycount=cadena[1]=="True" 
German Leon's avatar
German Leon committed
100
101
  #print ("B "+section+"ke "+kernel_end+" ....")
  #print (cadena[2].split(";"))
German Leon's avatar
German Leon committed
102
  for init_str in  cadena[3].split(";"):
German Leon's avatar
German Leon committed
103
     gdb.execute(init_str)
German Leon's avatar
German Leon committed
104
  max=0.  
German Leon's avatar
German Leon committed
105
  gdb.execute("r")
German Leon's avatar
German Leon committed
106
107
108
  if (onlycount):     
    ks=cadena[2].split(",",1)
    max=numreg(ks[0])
German Leon's avatar
German Leon committed
109
  else:
German Leon's avatar
German Leon committed
110
111
112
113
     if (section):
       gdb.execute("c")
     else:
       gdb.execute("finish")
German Leon's avatar
German Leon committed
114
  
German Leon's avatar
German Leon committed
115
116
117
118
     f=open("tmpxxx_return_profiler.conf","w")
     f.write("[DEFAULT] \nOcurrencias = "+str(ocurrencias)+"\nTiempo = "+str(trun)+"\n")
     f.close()	
  sys.exit(max)  
German Leon's avatar
German Leon committed
119
120

main()