#!/usr/bin/env python import sys, string #import os import re """ * refazStFd.py: * application syscall tracer and io analyser perfile based * * Critical Domains * Peformance Evaluation * Dez 2013 (c) Antonio Pina pina@di.uminho.pt """ """ strace -ttt -T -e trace=open,read,write,close -o serial.test ./io-test """ """ ./refazStFd.py.py strace.rsf Para distinguir fases diferents de acesso ao mesmo ficheiro: 1. no tracado original sempre que o mesmo ficheiro e reaberto, a chamda "open" e actualizado com um sufixo "_versao" 2. o identificador fD - File Descriptor- e alterado de forma apropriada: 3. Todas as chamada ao sistema relacionadas: close, write, read,fsync sao tambem adaptadas para usar o novo descritor """ """ Exemplo: 1353873689.889395 open("iozone.dat", O_RDWR) = 3 <0.000014> e substituido por: 1353873689.889395 open("iozone.dat_65", O_RDWR) = 58 <0.000014> """ if __name__ == "__main__": fInp=sys.stdin fSt=sys.stderr rex2='^[0-9]+:[0-9]+:[0-9]+.([0-9]+) ([a-z0-9]+)\((.*)\) +(= -?[0-9]+)( .*)(<.+>$)' #rex='^[0-9]+:[0-9]+:[0-9]+.([0-9]+) ([a-z0-9]+)(\(.*\)) += (-?[0-9]+)( .*)<(.+)>$' #ORI #rex1='^[0-9]+\.([0-9]+) ([a-z0-9]+)(\(.*\)) += (-?[0-9]+)( .*)<(.+)>$' #NOVO #rex= '^\d+:\d+:\d+.(\d+) (\w+)\((.*)\) += (-?\d+)( .*)<(.+)>$' # date #rex= '^\s*(\d+\.\d+) (\w+)\((.*)\) += (-?\d+)( .*)<(.+)>$' # -r rex= ' *(\d+\.\d+) (\w+)\((.*)\) += (-?\d+)( .*)<(.+)>$' # eopch -ttt fi=re.compile(rex) line=fInp.readline() linha=fi.match(line) dicN=dict(); dicN['stdin']="";dicN['stdout']="";dicN['stdout']="" dicF=dict(); dicF[0]=0;dicF[1]=1;dicF[2]=2; rPar=re.compile('\"(.*)\", (O_[A-Z]+)(\|O_[A-Z]+)*') curFd=2 while len(line) !=0: if linha: termos=linha.groups() if termos[1]=='open'and int(termos[3])!=-1: curFd+=1 fd=int (termos[3]) par=rPar.match(termos[2]) nm=par.groups()[0] if dicN.has_key(nm): vers=dicN[nm] suf="_"+str(vers) vers+=1 curFd+=1 last=curFd else: vers=0 suf="" dicN[nm]=vers newName=nm+suf newLine=line.replace(nm,nm+suf).strip('\n'); dicF[fd]=curFd if vers==0: print newLine.strip('\n') else: print newLine.replace('= '+str(fd),'= '+str(curFd)).strip('\n'); elif termos[1]=='close' and int(termos[3])!=-1: fd=int(termos[2]) if fd == dicF[fd]: print "%s" %line.strip('\n'); curFd-=1 else: fC=dicF[fd] print "%s" %line.replace('('+str(fd),'('+str(fC)).strip('\n'); if fC==last: curFd-=1 elif termos[1]=='read' and int(termos[3])!=-1: fd=int(termos[2][0]) fC=dicF[fd] print "%s" %line.replace('('+str(fd),'('+str(fC)).strip('\n'); elif termos[1]=='write' and int(termos[3])!=-1: fd=int(termos[2][0]) fC=dicF[fd] print "%s" %line.replace('('+str(fd),'('+str(fC)).strip('\n'); elif termos[1]=='lseek' and int(termos[3])!=-1: fd=int(termos[2][0]) fC=dicF[fd] print "%s" %line.replace('('+str(fd),'('+str(fC)).strip('\n'); elif termos[1]=='fsync' and int(termos[3])!=-1: fd=int(termos[2][0]) fC=dicF[fd] print "%s" %line.replace('('+str(fd),'('+str(fC)).strip('\n'); else: print "%s" %line.strip('\n'); else: print "%s" %line.strip('\n'); line=fInp.readline() linha=fi.match(line) fInp.close() fSt.close()