forked from cms-externals/frontier_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontierqueries
executable file
·130 lines (128 loc) · 3.48 KB
/
frontierqueries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
#
# Copyright (c) 2009, FERMI NATIONAL ACCELERATOR LABORATORY
# All rights reserved.
#
# For details of the Fermitools (BSD) license see Fermilab-2009.txt or
# http://fermitools.fnal.gov/about/terms.html
#
# Parse a log file created by setting FRONTIER_LOG_LEVEL=debug and
# FRONTIER_LOG_FILE=filename and print to stdout one query per line.
# The query result size is also printed in the form (NNN/XX%) where NNN
# is the full size in bytes and optionally /XX% is the compression ratio
# if it was compressed. The size is by default at the end of the
# line but with a -sizefirst option it is at the beginning.
# Before the query will be a hyphen (-) if the query is satisfied from
# the frontier internal cache, an asterisk (*) if it is a "short"
# time-to-live query that is sent out, a plus (+) if it is a "forever"
# time-to-live query, or a blank if it is a "long" time-to-live query.
# The -sort option sorts the output by full size. Implies -sizefirst.
# The -secsfirst option prints the elapsed seconds first. Otherwise the
# elapsed seconds always follows the size
# Written by Dave Dykstra
# $Id$
#
SORT=cat
if [ "$1" = "-sizefirst" ]; then
PRINTORDER="size, elapsedseconds, mark, query"
shift
elif [ "$1" = "-sort" ]; then
# sort by size
PRINTORDER="size, elapsedseconds, mark, query"
SORT="sort -t( -k 2 -n"
shift
elif [ "$1" = "-secsfirst" ]; then
PRINTORDER="elapsedseconds, size, mark, query"
shift
else
PRINTORDER="mark, query, size, elapsedseconds"
fi
if [ $# != 1 ]; then
echo "Usage: $0 [-sizefirst|-sort|-secsfirst] frontier_client.log" >&2
exit 1
fi
awk '
BEGIN{
inquery=0
query=""
}
function parsetime(mon,day,hhmmss,year) {
split(hhmmss,times,":")
if (mon == "Jan") {month="01"}
else if (mon == "Feb") {month="02"}
else if (mon == "Mar") {month="03"}
else if (mon == "Apr") {month="04"}
else if (mon == "May") {month="05"}
else if (mon == "Jun") {month="06"}
else if (mon == "Jul") {month="07"}
else if (mon == "Aug") {month="08"}
else if (mon == "Sep") {month="09"}
else if (mon == "Oct") {month="10"}
else if (mon == "Nov") {month="11"}
else if (mon == "Dec") {month="12"}
return mktime(year " " month " " day " " times[1] " " times[2] " " times[3])
}
/querying on chan/{
starttime=parsetime($9,$10,$11,$12)
}
/chan .* response .* finished at/{
elapsedseconds=parsetime($10,$11,$12,$13)-starttime
}
/encoding request/{
if (query != "") {
print '"$PRINTORDER"'
}
mark=" "
start=index($0, "t [")
query=substr($0,start+3)
end=index(query, "]")
if (end==0) {
end=length(query)+1
inquery=1
}
query=substr(query,1,end-1)
if (inquery==1)
next
}
(inquery==1){
end=index($0, "]")
if (end==0) {
end=length($0)+1
}
else {
inquery=0
}
query=query substr($0,1,end-1)
}
/<GET .*&ttl=forever/{
mark="+"
}
/<GET .*&ttl=short/{
mark="*"
}
/HIT .* client cache/{
mark="-"
}
/full size/{
start=index($0,"full size")
fullsize=substr($0,start+10)
end=index(fullsize,")")
fullsize=substr(fullsize,1,end-1)
start=index($0,"uncompressing")
if (start != 0) {
compressedsize=substr($0,start+14)
end=index(compressedsize," ")
compressedsize=substr(compressedsize,1,end-1)
compressedpercent=sprintf("/%.1f%%",(compressedsize*100/fullsize))
}
else {
compressedpercent=""
}
size="(" fullsize compressedpercent ")"
}
END{
if (query != "") {
print '"$PRINTORDER"'
}
}
' $1 | $SORT