[16] | 1 | #! /usr/bin/awk -f |
---|
| 2 | # /usr/lpp/mmfs/samples/util/tsinode $mountpoint > $fsname.files |
---|
| 3 | # (the output file will be about 170*#ofFiles, |
---|
| 4 | # so be sure you have plenty of space, or pipe it into tsfilehist.awk) |
---|
| 5 | # |
---|
| 6 | # Usage: tsfilehist.awk [variable-overrides] $fsname.files > $fsname.filesummary |
---|
| 7 | # nbuckets=#buckets-for-histogram (default 100) |
---|
| 8 | # blocksize=[16 64 256 384 512 1024 4096] (default 256) |
---|
| 9 | # availablespace=size-of-filesystem (bytes, or with suffix {s|k|m|g}) |
---|
| 10 | # (if specified, the AvSpace%ile column will show % of available space) |
---|
| 11 | # migrated=1 (if files could be migrated out by HSM) |
---|
| 12 | BEGIN { |
---|
| 13 | if (ARGC<1) |
---|
| 14 | { |
---|
| 15 | print "Usage: tsfilehist.awk [variable-overrides] $fsname.files > $fsname.filesummary" |
---|
| 16 | print " nbuckets=#buckets-for-histogram (default 100)" |
---|
| 17 | print " blocksize=[16 64 256 384 512 1024 4096] (default 256)" |
---|
| 18 | print " availablespace=size-of-filesystem (bytes, or with suffix {s|k|m|g})" |
---|
| 19 | print " migrated=1 (if files could be migrated out by HSM)" |
---|
| 20 | terminate=1 |
---|
| 21 | exit 1 |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | nbuckets=100 |
---|
| 25 | availablespace=0 # unknown at start |
---|
| 26 | migrated=0 |
---|
| 27 | # SIZ = logical size BKS = blocksize of filesystem SUB = sub-block size |
---|
| 28 | SIZ[4096]="4M"; BKS[4096]=4194304; SUB[4096]=131072 |
---|
| 29 | SIZ[1024]="1M"; BKS[1024]=1048576; SUB[1024]=32768 |
---|
| 30 | SIZ[512]="512K"; BKS[512]=524288; SUB[512]=16384 |
---|
| 31 | SIZ[384]="384K"; BKS[384]=393216; SUB[384]=12288 |
---|
| 32 | SIZ[256]="256K"; BKS[256]=262144; SUB[256]=8192 |
---|
| 33 | SIZ[64]="64K"; BKS[64]=65536; SUB[64]=2048 |
---|
| 34 | SIZ[16]="16K"; BKS[16]=16384; SUB[16]=512 |
---|
| 35 | } |
---|
| 36 | { |
---|
| 37 | # sample output: |
---|
| 38 | # inode gen uid gid size space mode nlink atime mtime ctime flags |
---|
| 39 | # 30721 65536 100 100 8037722 8044544 -rwxr-xr-x 1 1085616373.647071599 1085609949.810665286 1085609949.810665286 replmeta ind=2 |
---|
| 40 | # |
---|
| 41 | # parse input |
---|
| 42 | if ($1 == "inode") # first line |
---|
| 43 | { |
---|
| 44 | if (blocksize == 0) blocksize = 256 |
---|
| 45 | else if (SIZ[blocksize] == "") |
---|
| 46 | { |
---|
| 47 | print "Unexpected blocksize", blocksize |
---|
| 48 | exit 1 |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | else if ($1 == "" || index($0,"logfile") != 0 || index($0,"reserved") != 0) |
---|
| 52 | ; #throw away lines |
---|
| 53 | else if ((substr($7,1,1) == "-" || substr($7,1,1) == "l" || substr($7,1,1) == "d")) |
---|
| 54 | { |
---|
| 55 | entries += 1; |
---|
| 56 | |
---|
| 57 | if (substr($7,1,1) == "d") # directories |
---|
| 58 | { |
---|
| 59 | directories += 1; |
---|
| 60 | space=$6 |
---|
| 61 | if (availablespace != 0) |
---|
| 62 | totsize+=space; |
---|
| 63 | } |
---|
| 64 | else # files |
---|
| 65 | { |
---|
| 66 | files++ |
---|
| 67 | size=$5 |
---|
| 68 | space=$6 |
---|
| 69 | if (index($0,"repldata") != 0) space /= 2 |
---|
| 70 | if (size > maxsize) maxsize = size |
---|
| 71 | if (size == 0) |
---|
| 72 | zerolen++ |
---|
| 73 | else if (migrated && space == 0) # Presumed to be a migrated file |
---|
| 74 | { |
---|
| 75 | migratedfiles++ |
---|
| 76 | migratedsize+=size |
---|
| 77 | blks=int(size/BKS[blocksize]); |
---|
| 78 | frag=size%BKS[blocksize]; |
---|
| 79 | subb=int(frag/SUB[blocksize]); |
---|
| 80 | subf=size%SUB[blocksize]; |
---|
| 81 | if (subf > 0) |
---|
| 82 | subb += 1; |
---|
| 83 | if (blks == 0) |
---|
| 84 | msubblarray[subb] += 1; |
---|
| 85 | else if (blks == 1 && frag == 0) |
---|
| 86 | msubblarray[32] += 1; |
---|
| 87 | else if (blks <= nbuckets) |
---|
| 88 | mdiskarray[blks] += 1; |
---|
| 89 | else |
---|
| 90 | mdiskarray[nbuckets+1] += 1; |
---|
| 91 | } |
---|
| 92 | else # if (space > 0) |
---|
| 93 | { |
---|
| 94 | if (space > size) |
---|
| 95 | totalactualwaste += space-size |
---|
| 96 | totsize+=size; |
---|
| 97 | blks=int(size/BKS[blocksize]); |
---|
| 98 | frag=size%BKS[blocksize]; |
---|
| 99 | subb=int(frag/SUB[blocksize]); |
---|
| 100 | subf=size%SUB[blocksize]; |
---|
| 101 | if (subf > 0) |
---|
| 102 | { |
---|
| 103 | totwaste += SUB[blocksize]-subf; |
---|
| 104 | subb += 1; |
---|
| 105 | } |
---|
| 106 | if (blks == 0) |
---|
| 107 | subblarray[subb] += 1; |
---|
| 108 | else if (blks == 1 && frag == 0) |
---|
| 109 | subblarray[32] += 1; |
---|
| 110 | else if (blks <= nbuckets) |
---|
| 111 | diskarray[blks] += 1; |
---|
| 112 | else |
---|
| 113 | diskarray[nbuckets+1] += 1; |
---|
| 114 | if (blks > 67) ind64++ |
---|
| 115 | if (blks > 32) ind32++ |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | else |
---|
| 120 | entries += 1; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | END { |
---|
| 124 | if (terminate) exit 1 |
---|
| 125 | unit[1]="GB"; |
---|
| 126 | unit[2]="TB"; |
---|
| 127 | unit[3]="PB"; |
---|
| 128 | printf ("\nAll: Files = %14d\n",files) |
---|
| 129 | if (availablespace != 0) |
---|
| 130 | { |
---|
| 131 | lastav=substr(availablespace,length(availablespace)) |
---|
| 132 | if (lastav == "s" || lastav == "S") availablespace *= 512 |
---|
| 133 | else if (lastav == "k" || lastav == "K") availablespace *= 1024 |
---|
| 134 | else if (lastav == "m" || lastav == "M") availablespace *= 1024*1024 |
---|
| 135 | else if (lastav == "g" || lastav == "G") availablespace *= 1024*1024*1024 |
---|
| 136 | printf ("Available space = %14d",availablespace) |
---|
| 137 | tot=int((availablespace+500000000)/1000000000) |
---|
| 138 | for (i=1; (tot > 0) && (i <= 3); i++) |
---|
| 139 | { |
---|
| 140 | printf ("%12d %s",tot, unit[i]) |
---|
| 141 | tot=int((tot+500)/1000) |
---|
| 142 | } |
---|
| 143 | printf ("\n") |
---|
| 144 | } |
---|
| 145 | printf ("Total Size = %14d",totsize) |
---|
| 146 | tot=int((totsize+500000000)/1000000000) |
---|
| 147 | for (i=1; (tot > 0) && (i <= 3); i++) |
---|
| 148 | { |
---|
| 149 | printf ("%12d %s",tot, unit[i]) |
---|
| 150 | tot=int((tot+500)/1000) |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | printf ("\nLargest File = %14d\n",maxsize); |
---|
| 154 | printf ("Average Size = %14d\n",totsize/files); |
---|
| 155 | printf ("\nNon-zero: Files = %14d\n",files-zerolen); |
---|
| 156 | printf ("Average NZ size = %14d\n",totsize/(files-zerolen)); |
---|
| 157 | if (migratedsize > 0) |
---|
| 158 | { |
---|
| 159 | printf ("\nMigrated: Files = %14d\n",migratedfiles); |
---|
| 160 | printf ("Total Mig size = %14d",migratedsize); |
---|
| 161 | tot=int((migratedsize+500000000)/1000000000); |
---|
| 162 | for (i=1; (tot > 0) && (i <= 3); i++) |
---|
| 163 | { |
---|
| 164 | printf ("%12d %s",tot, unit[i]); |
---|
| 165 | tot=int((tot+500)/1000); |
---|
| 166 | } |
---|
| 167 | printf ("\nAverage Mig size = %14d\n",migratedsize/migratedfiles); |
---|
| 168 | printf ("Average All size = %14d\n",(totsize+migratedsize)/files); |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | printf ("\nDirectories = %11d\n",directories); |
---|
| 172 | printf ("Avg Entries per dir = %11.1f\n",(entries-1)/directories); |
---|
| 173 | |
---|
| 174 | printf ("\nFiles with indirect blocks = %11d\n", ind64); |
---|
| 175 | printf ("Files with indirect blocks (wide) = %11d\n", ind32); |
---|
| 176 | |
---|
| 177 | printf ("\nFile%%ile represents the cummulative percentage of files.\n"); |
---|
| 178 | printf ("Space%%ile represents the cummulative percentage of total space used.\n"); |
---|
| 179 | printf ("AvlSpc%%ile represents the cummulative percentage used of total available space.\n"); |
---|
| 180 | printf ("\nHistogram of files <= one %s block in size\n", SIZ[blocksize]) |
---|
| 181 | printf ("Subblocks Count File%%ile Space%%ile"); |
---|
| 182 | if (availablespace > 0) |
---|
| 183 | printf (" AvlSpc%%ile"); |
---|
| 184 | printf ("\n--------- -------- ---------- ----------"); |
---|
| 185 | if (availablespace > 0) printf (" ----------"); |
---|
| 186 | printf ("\n"); |
---|
| 187 | subblarray[0] = zerolen; |
---|
| 188 | for (j=0; j<=32; j++) |
---|
| 189 | { |
---|
| 190 | Faccum += subblarray[j]; |
---|
| 191 | Baccum += j*subblarray[j]*SUB[blocksize]; |
---|
| 192 | printf ("%9d%9d", j, subblarray[j]); |
---|
| 193 | printf ("%10.2f%%%10.2f%%", 100*Faccum/(files-migratedfiles), 100*Baccum/totsize); |
---|
| 194 | if (availablespace > 0) |
---|
| 195 | printf (" %10.2f%%", 100*Baccum/availablespace); |
---|
| 196 | printf ("\n"); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | printf ("\nHistogram of files with N %s blocks (plus end fragment)\n", SIZ[blocksize]); |
---|
| 200 | printf (" Blocks Count File%%ile Space%%ile"); |
---|
| 201 | if (availablespace > 0) |
---|
| 202 | printf (" AvlSpc%%ile"); |
---|
| 203 | printf ("\n--------- -------- ---------- ----------"); |
---|
| 204 | if (availablespace > 0) printf (" ----------"); |
---|
| 205 | printf ("\n"); |
---|
| 206 | for (j=1; j<=nbuckets; j++) |
---|
| 207 | { |
---|
| 208 | if (diskarray[j] > 0) |
---|
| 209 | { |
---|
| 210 | printf ("%9d",j); |
---|
| 211 | printf("%9d", diskarray[j]); |
---|
| 212 | Faccum += diskarray[j]; |
---|
| 213 | Baccum += j*diskarray[j]*BKS[blocksize]; |
---|
| 214 | printf ("%10.2f%%%10.2f%%", 100*Faccum/(files-migratedfiles), 100*Baccum/totsize); |
---|
| 215 | if (availablespace > 0) |
---|
| 216 | printf (" %10.2f%%", 100*Baccum/availablespace); |
---|
| 217 | printf ("\n"); |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | printf ("Number of files with more than %d %s blocks\n", nbuckets, SIZ[blocksize]); |
---|
| 222 | j=nbuckets+1 |
---|
| 223 | printf ("%8d+",j); |
---|
| 224 | printf("%9d", diskarray[j]); |
---|
| 225 | Faccum += diskarray[j]; |
---|
| 226 | Baccum = totsize; |
---|
| 227 | if (availablespace > 0) |
---|
| 228 | printf ("%10.2f%%%10.2f%% %10.2f%%\n", 100*Faccum/(files-migratedfiles), 100*Baccum/totsize, 100*Baccum/availablespace); |
---|
| 229 | else |
---|
| 230 | printf ("%10.2f%%%10.2f%%\n", 100*Faccum/(files-migratedfiles), 100*Baccum/totsize); |
---|
| 231 | |
---|
| 232 | if (migratedsize > 0) |
---|
| 233 | { |
---|
| 234 | printf ("\nHistogram of migrated files <= one %s block in size\n",SIZ[blocksize]) |
---|
| 235 | printf ("Subblocks Count File%%ile Space%%ile"); |
---|
| 236 | if (availablespace > 0) |
---|
| 237 | printf (" AvlSpc%%ile"); |
---|
| 238 | printf ("\n--------- -------- ---------- ----------"); |
---|
| 239 | if (availablespace > 0) printf (" ----------"); |
---|
| 240 | printf ("\n"); |
---|
| 241 | msubblarray[0] = 0; |
---|
| 242 | for (j=0; j<=32; j++) |
---|
| 243 | { |
---|
| 244 | if (allhist || msubblarray[j] > 0) |
---|
| 245 | { |
---|
| 246 | printf ("%9d",j); |
---|
| 247 | printf("%9d", msubblarray[j]); |
---|
| 248 | mFaccum += msubblarray[j]; |
---|
| 249 | mBaccum += j*msubblarray[j]*SUB[blocksize]; |
---|
| 250 | if (availablespace > 0) |
---|
| 251 | printf ("%10.2f%%%10.2f%% %10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize, 100*mBaccum/availablespace); |
---|
| 252 | else |
---|
| 253 | printf ("%10.2f%%%10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize); |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | printf ("\nHistogram of migrated files with N %s blocks (plus end fragment)\n", SIZ[blocksize]); |
---|
| 258 | printf (" Blocks Count File%%ile Space%%ile"); |
---|
| 259 | if (availablespace > 0) |
---|
| 260 | printf (" AvlSpc%%ile"); |
---|
| 261 | printf ("\n--------- -------- ---------- ----------"); |
---|
| 262 | if (availablespace > 0) printf (" ----------"); |
---|
| 263 | printf ("\n"); |
---|
| 264 | for (j=1; j<=nbuckets; j++) |
---|
| 265 | { |
---|
| 266 | if (mdiskarray[j] > 0) |
---|
| 267 | { |
---|
| 268 | printf ("%9d",j); |
---|
| 269 | printf("%9d", mdiskarray[j]); |
---|
| 270 | mFaccum += mdiskarray[j]; |
---|
| 271 | mBaccum += j*mdiskarray[j]*BKS[blocksize]; |
---|
| 272 | if (availablespace > 0) |
---|
| 273 | printf ("%10.2f%%%10.2f%% %10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize, 100*mBaccum/availablespace); |
---|
| 274 | else |
---|
| 275 | printf ("%10.2f%%%10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize); |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | printf ("Number of migrated files with more than %d %s blocks\n", nbuckets, SIZ[blocksize]); |
---|
| 280 | j=nbuckets+1 |
---|
| 281 | printf ("%8d+",j); |
---|
| 282 | printf("%9d", mdiskarray[j]); |
---|
| 283 | mFaccum += mdiskarray[j]; |
---|
| 284 | mBaccum = migratedsize; |
---|
| 285 | if (availablespace > 0) |
---|
| 286 | printf ("%10.2f%%%10.2f%% %10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize, 100*mBaccum/availablespace); |
---|
| 287 | else |
---|
| 288 | printf ("%10.2f%%%10.2f%%\n", 100*mFaccum/migratedfiles, 100*mBaccum/totsize); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | #printf ("\nBlockSize Waste %% Waste Avg Waste per File\n"); |
---|
| 292 | #printf ( "--------- ------------ ------- ------------------\n"); |
---|
| 293 | #printf (" %s %12d %6.2f%% %17d\n",SIZ[blocksize],totwaste,100*totwaste/totsize,totwaste/(files-zerolen-migratedfiles)); |
---|
| 294 | #printf (" %s %12d %6.2f%% %17d\n","Real",totalactualwaste,100*totalactualwaste/totsize,totalactualwaste/(files-zerolen-migratedfiles)); |
---|
| 295 | |
---|
| 296 | } |
---|