Whamcloud - gitweb
LU-13090 utils: fix lfs_migrate -p for file with pool
[fs/lustre-release.git] / contrib / scripts / lioprof / parser.sh
1 #!/bin/bash
2 #
3 # This file is provided under a dual BSD/GPLv2 license.  When using or
4 # redistributing this file, you may do so under either license.
5 #
6 # GPL LICENSE SUMMARY
7 #
8 # Copyright(c) 2016 Intel Corporation.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
18 #
19 # Contact Information:
20 # Cong Xu, cong.xu@intel.com
21 #
22 # BSD LICENSE
23 #
24 # Copyright(c) 2016 Intel Corporation.
25 #
26 # Redistribution and use in source and binary forms, with or without
27 # modification, are permitted provided that the following conditions
28 # are met:
29 #
30 # * Redistributions of source code must retain the above copyright
31 # notice, this list of conditions and the following disclaimer.
32 # * Redistributions in binary form must reproduce the above copyright
33 # notice, this list of conditions and the following disclaimer in
34 # the documentation and/or other materials provided with the
35 # distribution.
36 # * Neither the name of Intel Corporation nor the names of its
37 # contributors may be used to endorse or promote products derived
38 # from this software without specific prior written permission.
39 #
40 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
52
53
54
55 function usage() {
56         cat << EOF
57 Usage: $0 [-i] [-x] [-y] [-t]
58         -i  path to LIOProf rpc tracing logs
59         -x  lowest Lustre Client [IB IP Address]
60         -y  highest Lustre Client [IB IP Address]
61         -t  Type of Operation Code (OPC) (OST_READ 3, OST_WRITE 4)
62 EOF
63         exit 0
64 }
65
66
67 while getopts ":i:x:y:t:" o; do
68         case "${o}" in
69                 i)
70                         i=${OPTARG};;
71                 x)
72                         x=${OPTARG};;
73                 y)
74                         y=${OPTARG};;
75                 t)
76                         t=${OPTARG};;
77                 *)
78                         usage;;
79         esac
80 done
81 shift $((OPTIND-1))
82
83 if [ -z "${i}" ] || [ -z "${x}" ] || [ -z "${y}" ] || [ -z "${t}" ]; then
84         usage
85 fi
86
87
88 # Cluster Name
89 cluster_name=$(cut -d- -f1 <<<"${x}")
90
91 # Lustre Clients
92 CLIENT_PRE=$(cut -d. -f 1-3 <<<"${x}")
93 CLIENT_MIN=$(cut -d. -f4 <<<"${x}")
94 CLIENT_MAX=$(cut -d. -f4 <<<"${y}")
95
96 # Type of Operation Code (OPC) (Defined in lustre/include/lustre/lustre_idl.h)
97 OPC_TYPE=${t}
98
99 # Input directory
100 IN_PUT=${i}
101
102 # Output directory
103 OUT_PUT=${i}-out
104 rm -rf $OUT_PUT
105 mkdir -p $OUT_PUT
106
107 for f in ${IN_PUT}/*
108 do
109         echo "Processing ${f}"
110         for ((c = $CLIENT_MIN; c <= $CLIENT_MAX; c = c + 1))
111         do
112                 ip=${CLIENT_PRE}.$c
113                 CUR_OST=$(echo "${f}" | rev | cut -d'/' -f1 | rev)
114
115                 cat ${f} | grep "Handling RPC pname" | grep "ll_ost_io" | \
116                 grep o2ib:${OPC_TYPE} | grep ${ip} | \
117                 awk 'BEGIN{FS=":"}{print $4}' | sort -n | \
118                 awk 'BEGIN {count = 0; line = 0; FS="."} {
119                         if (NR == 1) {curval = $1};
120                         if($1 <= curval) {
121                                 count = count + 1;
122                         } else {
123                                 print line "\t" count;
124                                 curval = curval + 1;
125                                 line = line + 1;
126                                 count = 1;
127                                 while(curval < $1) {
128                                         print line "\t" 0;
129                                         curval = curval + 1;
130                                         line = line + 1;
131                                 }
132                         }
133                 } END {
134                         print line "\t" count;
135                 }' \
136                 > ${OUT_PUT}/$CUR_OST-Client-$c &
137         done
138 done
139
140 # Wait for completion
141 wait
142
143
144 # If the lines of the files are different, fill the end of files with zeros to
145 # guarantee all the files have the same number of lines.
146
147 # Get max line
148 MAX_LINE=-1
149 for f in ${OUT_PUT}/*
150 do
151         LINE=$(wc -l < ${f})
152         if [ "$MAX_LINE" -lt "$LINE" ]
153         then
154                 MAX_LINE=${LINE}
155         fi
156 done
157
158 # Append zeros
159 for f in  ${OUT_PUT}/*
160 do
161         LINE=$(wc -l < ${f})
162         for ((i = $LINE; i < $MAX_LINE; i = i + 1))
163         do
164                 printf  "0\t0\n" >> ${f} &
165         done
166 done