|
发表于 2012-12-12 17:29:47
|
显示全部楼层
发个抽取TimingReport的AWK,或许在某些方面比perl更好实现
#! /usr/bin/gawk -f
###### check path for report_timing ######
###### author: steven ######
###### Date: 2012.05.28 ######
BEGIN{
slen=0
elen=0
plen=0
numbPath=0
pathflag=0
arr1[2] = 1
arr2[2] = 1
pathflag2=0
endpointflag=0
endpointflagnum=0
aak=0
system("grep -E 'Startpoint:|Endpoint:|Path Group:|nworst|max_paths' "ARGV[1]" > tmp_steven_report")
"wc -l tmp_steven_report" |getline aa
"grep nworst tmp_steven_report" |getline aa2
"grep max_paths tmp_steven_report" |getline aa3
if(length(aa2) > 0)
{
split(aa2,arr1)
}
if(length(aa3) > 0)
{
split(aa3,arr2)
}
split(aa,arr)
print "-------------------------------------------------------------------------------------------"
printf "# %-40s %-20s %-20s %-20s\n","PATH-GROUP-TYPE","TOTAL-NUM","REPORT-NUM","JUDGE"
print "-------------------------------------------------------------------------------------------"
for(i=1;i<=arr[1];i++)
{
getline < "tmp_steven_report"
if($1=="Startpoint:")
{
if(length($2) >= slen)
{
slen = length($2)
}
}
if($1=="Endpoint:")
{
if(length($2) >= elen)
{
elen = length($2)
}
if(endpointflag == 0)
{
endnamep=$2
endpointflag=1
endpointflagnum=0
}
if(endpointflag==1 && $2 == endnamep)
{
endpointflagnum++
}
if(endpointflag==1 && $2 != endnamep)
{
endpointflagnum=1
endnamep=$2
}
if(endpointflagnum >= arr1[2])
{
aak=1
norworstj="NG"
norworstk=">="
}
if(endpointflagnum < arr1[2])
{
norworstj="OK"
norworstk="<"
}
}
if($1=="Path" && $2=="Group:")
{
if(length($3) >= plen)
{
plen = length($3)
}
if(pathflag=="0")
{
spatht = $3
pathflag=1
numbPath=0
}
if(pathflag == "1" && $3 == spatht)
{
numbPath++
}
if(pathflag == "1" && $3 != spatht)
{
pathflag2++
if(numbPath < arr2[2])
{
printf "%s. %-40s %-20s %-20s %-20s\n",pathflag2,spatht,numbPath,arr2[2],"OK"
}
if(numbPath >= arr2[2])
{
printf "%s. %-40s %-20s %-20s %-20s\n",pathflag2,spatht,numbPath,arr2[2],"NG"
}
spatht = $3
numbPath=1
}
if(i==arr[1])
{
pathflag2++
if(numbPath < arr2[2])
{
printf "%s. %-40s %-20s %-20s %-20s\n",pathflag2,spatht,numbPath,arr2[2],"OK"
}
if(numbPath >= arr2[2])
{
printf "%s. %-40s %-20s %-20s %-20s\n",pathflag2,spatht,numbPath,arr2[2],"NG"
}
}
}
}
close("tmp_steven_report")
if(aak=1)
{
print ""
printf "E. %-40s %-20s %-20s %-20s\n","nworst",norworstk,arr1[2],norworstj
}
if(aak=0)
{
print ""
printf "E. %-40s %-20s %-20s %-20s\n","nworst",norworstk,arr1[2],norworstj
}
print "-------------------------------------------------------------------------------------------"
print ""
a0 = "Startpoint"
a1 = "Startclock"
a2 = "Endpoint"
a3 = "Endclock"
a4 = "PathGroup"
a5 = "Type"
a6 = "Slack"
a7 = "Value"
printf "%-"slen"s %-10s -> %-"elen"s %-10s %-"plen"s\t%-6s %-10s %-10s\n",a0,a1,a2,a3,a4,a5,a6,a7
print "--------"
flag_maxpath = 0
flag_nworst = 0
maxpath = 1
nworstpath = 1
}
{
if ($1 == "-max_paths")
{
maxpath = $2
flag_maxpath = 1
}
else if ($1 == "-nworst")
{
nworstpath = $2
flag_nworst = 1
}
else if ($1 == "Startpoint:")
{
spoint = $2
printf "%-"slen"s",spoint
if ($NF~/\)/)
{
sclock = $NF
printf " (%-10s ->",sclock
}
if ($NF!~/\)/)
{
getline
sclock = $NF
printf " (%-10s ->",sclock
}
}
else if ($1 == "Endpoint:")
{
epoint = $2
printf " %-"elen"s",epoint
if ($NF~/\)/)
{
eclock = $NF
printf " (%-10s",eclock
}
if ($NF!~/\)/)
{
getline
eclock = $NF
printf " (%-10s",eclock
}
}
else if ($1 == "Path" && $2 == "Group:")
{
pathg = $3
printf " %-"plen"s",pathg
}
else if ($1 == "Path" && $2 == "Type:")
{
ptype = $3
printf "\t%-6s",ptype
}
else if ($1 == "slack")
{
slack = $2
slack_value = $3
printf " %-10s",slack
printf " %-10s\n",slack_value
}
}
END {
system("rm tmp_steven_report")
} |
|