forked from cms-externals/frontier_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontierqueries
executable file
·102 lines (100 loc) · 2.43 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
#!/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.
# Written by Dave Dykstra
# $Id$
#
SORT=cat
if [ "$1" = "-sizefirst" ]; then
PRINTORDER="size, mark, query"
shift
elif [ "$1" = "-sort" ]; then
PRINTORDER="size, mark, query"
SORT="sort -t( -k 2 -n"
shift
else
PRINTORDER="mark, query, size"
fi
if [ $# != 1 ]; then
echo "Usage: $0 [-sizefirst|-sort] frontier_client.log" >&2
exit 1
fi
awk '
BEGIN{
inquery=0
query=""
}
/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