1#!/usr/bin/env @PYTHON_SHEBANG@ 2# 3# Print out ZFS ARC Statistics exported via kstat(1) 4# For a definition of fields, or usage, use arcstat -v 5# 6# This script was originally a fork of the original arcstat.pl (0.1) 7# by Neelakanth Nadgir, originally published on his Sun blog on 8# 09/18/2007 9# http://blogs.sun.com/realneel/entry/zfs_arc_statistics 10# 11# A new version aimed to improve upon the original by adding features 12# and fixing bugs as needed. This version was maintained by Mike 13# Harsch and was hosted in a public open source repository: 14# http://github.com/mharsch/arcstat 15# 16# but has since moved to the illumos-gate repository. 17# 18# This Python port was written by John Hixson for FreeNAS, introduced 19# in commit e2c29f: 20# https://github.com/freenas/freenas 21# 22# and has been improved by many people since. 23# 24# CDDL HEADER START 25# 26# The contents of this file are subject to the terms of the 27# Common Development and Distribution License, Version 1.0 only 28# (the "License"). You may not use this file except in compliance 29# with the License. 30# 31# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 32# or https://opensource.org/licenses/CDDL-1.0. 33# See the License for the specific language governing permissions 34# and limitations under the License. 35# 36# When distributing Covered Code, include this CDDL HEADER in each 37# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 38# If applicable, add the following below this CDDL HEADER, with the 39# fields enclosed by brackets "[]" replaced with your own identifying 40# information: Portions Copyright [yyyy] [name of copyright owner] 41# 42# CDDL HEADER END 43# 44# 45# Fields have a fixed width. Every interval, we fill the "v" 46# hash with its corresponding value (v[field]=value) using calculate(). 47# @hdr is the array of fields that needs to be printed, so we 48# just iterate over this array and print the values using our pretty printer. 49# 50# This script must remain compatible with Python 3.6+. 51# 52 53import sys 54import time 55import getopt 56import re 57import copy 58 59from signal import signal, SIGINT, SIGWINCH, SIG_DFL 60 61 62cols = { 63 # HDR: [Size, Scale, Description] 64 "time": [8, -1, "Time"], 65 "hits": [4, 1000, "ARC hits per second"], 66 "iohs": [4, 1000, "ARC I/O hits per second"], 67 "miss": [4, 1000, "ARC misses per second"], 68 "read": [4, 1000, "Total ARC accesses per second"], 69 "hit%": [4, 100, "ARC hit percentage"], 70 "ioh%": [4, 100, "ARC I/O hit percentage"], 71 "miss%": [5, 100, "ARC miss percentage"], 72 "dhit": [4, 1000, "Demand hits per second"], 73 "dioh": [4, 1000, "Demand I/O hits per second"], 74 "dmis": [4, 1000, "Demand misses per second"], 75 "dh%": [3, 100, "Demand hit percentage"], 76 "di%": [3, 100, "Demand I/O hit percentage"], 77 "dm%": [3, 100, "Demand miss percentage"], 78 "ddhit": [5, 1000, "Demand data hits per second"], 79 "ddioh": [5, 1000, "Demand data I/O hits per second"], 80 "ddmis": [5, 1000, "Demand data misses per second"], 81 "ddh%": [4, 100, "Demand data hit percentage"], 82 "ddi%": [4, 100, "Demand data I/O hit percentage"], 83 "ddm%": [4, 100, "Demand data miss percentage"], 84 "dmhit": [5, 1000, "Demand metadata hits per second"], 85 "dmioh": [5, 1000, "Demand metadata I/O hits per second"], 86 "dmmis": [5, 1000, "Demand metadata misses per second"], 87 "dmh%": [4, 100, "Demand metadata hit percentage"], 88 "dmi%": [4, 100, "Demand metadata I/O hit percentage"], 89 "dmm%": [4, 100, "Demand metadata miss percentage"], 90 "phit": [4, 1000, "Prefetch hits per second"], 91 "pioh": [4, 1000, "Prefetch I/O hits per second"], 92 "pmis": [4, 1000, "Prefetch misses per second"], 93 "ph%": [3, 100, "Prefetch hits percentage"], 94 "pi%": [3, 100, "Prefetch I/O hits percentage"], 95 "pm%": [3, 100, "Prefetch miss percentage"], 96 "pdhit": [5, 1000, "Prefetch data hits per second"], 97 "pdioh": [5, 1000, "Prefetch data I/O hits per second"], 98 "pdmis": [5, 1000, "Prefetch data misses per second"], 99 "pdh%": [4, 100, "Prefetch data hits percentage"], 100 "pdi%": [4, 100, "Prefetch data I/O hits percentage"], 101 "pdm%": [4, 100, "Prefetch data miss percentage"], 102 "pmhit": [5, 1000, "Prefetch metadata hits per second"], 103 "pmioh": [5, 1000, "Prefetch metadata I/O hits per second"], 104 "pmmis": [5, 1000, "Prefetch metadata misses per second"], 105 "pmh%": [4, 100, "Prefetch metadata hits percentage"], 106 "pmi%": [4, 100, "Prefetch metadata I/O hits percentage"], 107 "pmm%": [4, 100, "Prefetch metadata miss percentage"], 108 "mhit": [4, 1000, "Metadata hits per second"], 109 "mioh": [4, 1000, "Metadata I/O hits per second"], 110 "mmis": [4, 1000, "Metadata misses per second"], 111 "mread": [5, 1000, "Metadata accesses per second"], 112 "mh%": [3, 100, "Metadata hit percentage"], 113 "mi%": [3, 100, "Metadata I/O hit percentage"], 114 "mm%": [3, 100, "Metadata miss percentage"], 115 "arcsz": [5, 1024, "ARC size"], 116 "size": [5, 1024, "ARC size"], 117 "c": [5, 1024, "ARC target size"], 118 "mfu": [4, 1000, "MFU list hits per second"], 119 "mru": [4, 1000, "MRU list hits per second"], 120 "mfug": [4, 1000, "MFU ghost list hits per second"], 121 "mrug": [4, 1000, "MRU ghost list hits per second"], 122 "unc": [4, 1000, "Uncached list hits per second"], 123 "eskip": [5, 1000, "evict_skip per second"], 124 "el2skip": [7, 1000, "evict skip, due to l2 writes, per second"], 125 "el2cach": [7, 1024, "Size of L2 cached evictions per second"], 126 "el2el": [5, 1024, "Size of L2 eligible evictions per second"], 127 "el2mfu": [6, 1024, "Size of L2 eligible MFU evictions per second"], 128 "el2mru": [6, 1024, "Size of L2 eligible MRU evictions per second"], 129 "el2inel": [7, 1024, "Size of L2 ineligible evictions per second"], 130 "mtxmis": [6, 1000, "mutex_miss per second"], 131 "dread": [5, 1000, "Demand accesses per second"], 132 "ddread": [6, 1000, "Demand data accesses per second"], 133 "dmread": [6, 1000, "Demand metadata accesses per second"], 134 "pread": [5, 1000, "Prefetch accesses per second"], 135 "pdread": [6, 1000, "Prefetch data accesses per second"], 136 "pmread": [6, 1000, "Prefetch metadata accesses per second"], 137 "l2hits": [6, 1000, "L2ARC hits per second"], 138 "l2miss": [6, 1000, "L2ARC misses per second"], 139 "l2read": [6, 1000, "Total L2ARC accesses per second"], 140 "l2hit%": [6, 100, "L2ARC access hit percentage"], 141 "l2miss%": [7, 100, "L2ARC access miss percentage"], 142 "l2pref": [6, 1024, "L2ARC prefetch allocated size"], 143 "l2mfu": [5, 1024, "L2ARC MFU allocated size"], 144 "l2mru": [5, 1024, "L2ARC MRU allocated size"], 145 "l2data": [6, 1024, "L2ARC data allocated size"], 146 "l2meta": [6, 1024, "L2ARC metadata allocated size"], 147 "l2pref%": [7, 100, "L2ARC prefetch percentage"], 148 "l2mfu%": [6, 100, "L2ARC MFU percentage"], 149 "l2mru%": [6, 100, "L2ARC MRU percentage"], 150 "l2data%": [7, 100, "L2ARC data percentage"], 151 "l2meta%": [7, 100, "L2ARC metadata percentage"], 152 "l2asize": [7, 1024, "Actual (compressed) size of the L2ARC"], 153 "l2size": [6, 1024, "Size of the L2ARC"], 154 "l2bytes": [7, 1024, "Bytes read per second from the L2ARC"], 155 "grow": [4, 1000, "ARC grow disabled"], 156 "need": [5, 1024, "ARC reclaim need"], 157 "free": [5, 1024, "ARC free memory"], 158 "avail": [5, 1024, "ARC available memory"], 159 "waste": [5, 1024, "Wasted memory due to round up to pagesize"], 160 "ztotal": [6, 1000, "zfetch total prefetcher calls per second"], 161 "zhits": [5, 1000, "zfetch stream hits per second"], 162 "zahead": [6, 1000, "zfetch hits ahead of streams per second"], 163 "zpast": [5, 1000, "zfetch hits behind streams per second"], 164 "zmisses": [7, 1000, "zfetch stream misses per second"], 165 "zmax": [4, 1000, "zfetch limit reached per second"], 166 "zfuture": [7, 1000, "zfetch stream future per second"], 167 "zstride": [7, 1000, "zfetch stream strides per second"], 168 "zissued": [7, 1000, "zfetch prefetches issued per second"], 169 "zactive": [7, 1000, "zfetch prefetches active per second"], 170} 171 172v = {} 173hdr = ["time", "read", "ddread", "ddh%", "dmread", "dmh%", "pread", "ph%", 174 "size", "c", "avail"] 175xhdr = ["time", "mfu", "mru", "mfug", "mrug", "unc", "eskip", "mtxmis", 176 "dread", "pread", "read"] 177zhdr = ["time", "ztotal", "zhits", "zahead", "zpast", "zmisses", "zmax", 178 "zfuture", "zstride", "zissued", "zactive"] 179sint = 1 # Default interval is 1 second 180count = 1 # Default count is 1 181hdr_intr = 20 # Print header every 20 lines of output 182opfile = None 183sep = " " # Default separator is 2 spaces 184l2exist = False 185cmd = ("Usage: arcstat [-havxp] [-f fields] [-o file] [-s string] [interval " 186 "[count]]\n") 187cur = {} 188d = {} 189out = None 190kstat = None 191pretty_print = True 192 193 194if sys.platform.startswith('freebsd'): 195 # Requires py-sysctl on FreeBSD 196 import sysctl 197 198 def kstat_update(): 199 global kstat 200 201 k = [ctl for ctl in sysctl.filter('kstat.zfs.misc.arcstats') 202 if ctl.type != sysctl.CTLTYPE_NODE] 203 k += [ctl for ctl in sysctl.filter('kstat.zfs.misc.zfetchstats') 204 if ctl.type != sysctl.CTLTYPE_NODE] 205 206 if not k: 207 sys.exit(1) 208 209 kstat = {} 210 211 for s in k: 212 if not s: 213 continue 214 215 name, value = s.name, s.value 216 217 if "arcstats" in name: 218 # Trims 'kstat.zfs.misc.arcstats' from the name 219 kstat[name[24:]] = int(value) 220 else: 221 kstat["zfetch_" + name[27:]] = int(value) 222 223elif sys.platform.startswith('linux'): 224 def kstat_update(): 225 global kstat 226 227 k1 = [line.strip() for line in open('/proc/spl/kstat/zfs/arcstats')] 228 229 k2 = ["zfetch_" + line.strip() for line in 230 open('/proc/spl/kstat/zfs/zfetchstats')] 231 232 if k1 is None or k2 is None: 233 sys.exit(1) 234 235 del k1[0:2] 236 del k2[0:2] 237 k = k1 + k2 238 kstat = {} 239 240 for s in k: 241 if not s: 242 continue 243 244 name, unused, value = s.split() 245 kstat[name] = int(value) 246 247 248def detailed_usage(): 249 sys.stderr.write("%s\n" % cmd) 250 sys.stderr.write("Field definitions are as follows:\n") 251 for key in cols: 252 sys.stderr.write("%11s : %s\n" % (key, cols[key][2])) 253 sys.stderr.write("\n") 254 255 sys.exit(0) 256 257 258def usage(): 259 sys.stderr.write("%s\n" % cmd) 260 sys.stderr.write("\t -h : Print this help message\n") 261 sys.stderr.write("\t -a : Print all possible stats\n") 262 sys.stderr.write("\t -v : List all possible field headers and definitions" 263 "\n") 264 sys.stderr.write("\t -x : Print extended stats\n") 265 sys.stderr.write("\t -z : Print zfetch stats\n") 266 sys.stderr.write("\t -f : Specify specific fields to print (see -v)\n") 267 sys.stderr.write("\t -o : Redirect output to the specified file\n") 268 sys.stderr.write("\t -s : Override default field separator with custom " 269 "character or string\n") 270 sys.stderr.write("\t -p : Disable auto-scaling of numerical fields\n") 271 sys.stderr.write("\nExamples:\n") 272 sys.stderr.write("\tarcstat -o /tmp/a.log 2 10\n") 273 sys.stderr.write("\tarcstat -s \",\" -o /tmp/a.log 2 10\n") 274 sys.stderr.write("\tarcstat -v\n") 275 sys.stderr.write("\tarcstat -f time,hit%,dh%,ph%,mh% 1\n") 276 sys.stderr.write("\n") 277 278 sys.exit(1) 279 280 281def snap_stats(): 282 global cur 283 global kstat 284 285 prev = copy.deepcopy(cur) 286 kstat_update() 287 288 cur = kstat 289 for key in cur: 290 if re.match(key, "class"): 291 continue 292 if key in prev: 293 d[key] = cur[key] - prev[key] 294 else: 295 d[key] = cur[key] 296 297 298def prettynum(sz, scale, num=0): 299 suffix = [' ', 'K', 'M', 'G', 'T', 'P', 'E', 'Z'] 300 index = 0 301 save = 0 302 303 # Special case for date field 304 if scale == -1: 305 return "%s" % num 306 307 # Rounding error, return 0 308 elif 0 < num < 1: 309 num = 0 310 311 while abs(num) > scale and index < 5: 312 save = num 313 num = num / scale 314 index += 1 315 316 if index == 0: 317 return "%*d" % (sz, num) 318 319 if abs(save / scale) < 10: 320 return "%*.1f%s" % (sz - 1, num, suffix[index]) 321 else: 322 return "%*d%s" % (sz - 1, num, suffix[index]) 323 324 325def print_values(): 326 global hdr 327 global sep 328 global v 329 global pretty_print 330 331 if pretty_print: 332 fmt = lambda col: prettynum(cols[col][0], cols[col][1], v[col]) 333 else: 334 fmt = lambda col: str(v[col]) 335 336 sys.stdout.write(sep.join(fmt(col) for col in hdr)) 337 sys.stdout.write("\n") 338 sys.stdout.flush() 339 340 341def print_header(): 342 global hdr 343 global sep 344 global pretty_print 345 346 if pretty_print: 347 fmt = lambda col: "%*s" % (cols[col][0], col) 348 else: 349 fmt = lambda col: col 350 351 sys.stdout.write(sep.join(fmt(col) for col in hdr)) 352 sys.stdout.write("\n") 353 354 355def get_terminal_lines(): 356 try: 357 import fcntl 358 import termios 359 import struct 360 data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234') 361 sz = struct.unpack('hh', data) 362 return sz[0] 363 except Exception: 364 pass 365 366 367def update_hdr_intr(): 368 global hdr_intr 369 370 lines = get_terminal_lines() 371 if lines and lines > 3: 372 hdr_intr = lines - 3 373 374 375def resize_handler(signum, frame): 376 update_hdr_intr() 377 378 379def init(): 380 global sint 381 global count 382 global hdr 383 global xhdr 384 global zhdr 385 global opfile 386 global sep 387 global out 388 global l2exist 389 global pretty_print 390 391 desired_cols = None 392 aflag = False 393 xflag = False 394 hflag = False 395 vflag = False 396 zflag = False 397 i = 1 398 399 try: 400 opts, args = getopt.getopt( 401 sys.argv[1:], 402 "axzo:hvs:f:p", 403 [ 404 "all", 405 "extended", 406 "zfetch", 407 "outfile", 408 "help", 409 "verbose", 410 "separator", 411 "columns", 412 "parsable" 413 ] 414 ) 415 except getopt.error as msg: 416 sys.stderr.write("Error: %s\n" % str(msg)) 417 usage() 418 opts = None 419 420 for opt, arg in opts: 421 if opt in ('-a', '--all'): 422 aflag = True 423 if opt in ('-x', '--extended'): 424 xflag = True 425 if opt in ('-o', '--outfile'): 426 opfile = arg 427 i += 1 428 if opt in ('-h', '--help'): 429 hflag = True 430 if opt in ('-v', '--verbose'): 431 vflag = True 432 if opt in ('-s', '--separator'): 433 sep = arg 434 i += 1 435 if opt in ('-f', '--columns'): 436 desired_cols = arg 437 i += 1 438 if opt in ('-p', '--parsable'): 439 pretty_print = False 440 if opt in ('-z', '--zfetch'): 441 zflag = True 442 i += 1 443 444 argv = sys.argv[i:] 445 sint = int(argv[0]) if argv else sint 446 count = int(argv[1]) if len(argv) > 1 else (0 if len(argv) > 0 else 1) 447 448 if hflag or (xflag and zflag) or ((zflag or xflag) and desired_cols): 449 usage() 450 451 if vflag: 452 detailed_usage() 453 454 if xflag: 455 hdr = xhdr 456 457 if zflag: 458 hdr = zhdr 459 460 update_hdr_intr() 461 462 # check if L2ARC exists 463 snap_stats() 464 l2_size = cur.get("l2_size") 465 if l2_size: 466 l2exist = True 467 468 if desired_cols: 469 hdr = desired_cols.split(",") 470 471 invalid = [] 472 incompat = [] 473 for ele in hdr: 474 if ele not in cols: 475 invalid.append(ele) 476 elif not l2exist and ele.startswith("l2"): 477 sys.stdout.write("No L2ARC Here\n%s\n" % ele) 478 incompat.append(ele) 479 480 if len(invalid) > 0: 481 sys.stderr.write("Invalid column definition! -- %s\n" % invalid) 482 usage() 483 484 if len(incompat) > 0: 485 sys.stderr.write("Incompatible field specified! -- %s\n" % 486 incompat) 487 usage() 488 489 if aflag: 490 if l2exist: 491 hdr = cols.keys() 492 else: 493 hdr = [col for col in cols.keys() if not col.startswith("l2")] 494 495 if opfile: 496 try: 497 out = open(opfile, "w") 498 sys.stdout = out 499 500 except IOError: 501 sys.stderr.write("Cannot open %s for writing\n" % opfile) 502 sys.exit(1) 503 504 505def calculate(): 506 global d 507 global v 508 global l2exist 509 510 v = dict() 511 v["time"] = time.strftime("%H:%M:%S", time.localtime()) 512 v["hits"] = d["hits"] // sint 513 v["iohs"] = d["iohits"] // sint 514 v["miss"] = d["misses"] // sint 515 v["read"] = v["hits"] + v["iohs"] + v["miss"] 516 v["hit%"] = 100 * v["hits"] // v["read"] if v["read"] > 0 else 0 517 v["ioh%"] = 100 * v["iohs"] // v["read"] if v["read"] > 0 else 0 518 v["miss%"] = 100 - v["hit%"] - v["ioh%"] if v["read"] > 0 else 0 519 520 v["dhit"] = (d["demand_data_hits"] + d["demand_metadata_hits"]) // sint 521 v["dioh"] = (d["demand_data_iohits"] + d["demand_metadata_iohits"]) // sint 522 v["dmis"] = (d["demand_data_misses"] + d["demand_metadata_misses"]) // sint 523 524 v["dread"] = v["dhit"] + v["dioh"] + v["dmis"] 525 v["dh%"] = 100 * v["dhit"] // v["dread"] if v["dread"] > 0 else 0 526 v["di%"] = 100 * v["dioh"] // v["dread"] if v["dread"] > 0 else 0 527 v["dm%"] = 100 - v["dh%"] - v["di%"] if v["dread"] > 0 else 0 528 529 v["ddhit"] = d["demand_data_hits"] // sint 530 v["ddioh"] = d["demand_data_iohits"] // sint 531 v["ddmis"] = d["demand_data_misses"] // sint 532 533 v["ddread"] = v["ddhit"] + v["ddioh"] + v["ddmis"] 534 v["ddh%"] = 100 * v["ddhit"] // v["ddread"] if v["ddread"] > 0 else 0 535 v["ddi%"] = 100 * v["ddioh"] // v["ddread"] if v["ddread"] > 0 else 0 536 v["ddm%"] = 100 - v["ddh%"] - v["ddi%"] if v["ddread"] > 0 else 0 537 538 v["dmhit"] = d["demand_metadata_hits"] // sint 539 v["dmioh"] = d["demand_metadata_iohits"] // sint 540 v["dmmis"] = d["demand_metadata_misses"] // sint 541 542 v["dmread"] = v["dmhit"] + v["dmioh"] + v["dmmis"] 543 v["dmh%"] = 100 * v["dmhit"] // v["dmread"] if v["dmread"] > 0 else 0 544 v["dmi%"] = 100 * v["dmioh"] // v["dmread"] if v["dmread"] > 0 else 0 545 v["dmm%"] = 100 - v["dmh%"] - v["dmi%"] if v["dmread"] > 0 else 0 546 547 v["phit"] = (d["prefetch_data_hits"] + d["prefetch_metadata_hits"]) // sint 548 v["pioh"] = (d["prefetch_data_iohits"] + 549 d["prefetch_metadata_iohits"]) // sint 550 v["pmis"] = (d["prefetch_data_misses"] + 551 d["prefetch_metadata_misses"]) // sint 552 553 v["pread"] = v["phit"] + v["pioh"] + v["pmis"] 554 v["ph%"] = 100 * v["phit"] // v["pread"] if v["pread"] > 0 else 0 555 v["pi%"] = 100 * v["pioh"] // v["pread"] if v["pread"] > 0 else 0 556 v["pm%"] = 100 - v["ph%"] - v["pi%"] if v["pread"] > 0 else 0 557 558 v["pdhit"] = d["prefetch_data_hits"] // sint 559 v["pdioh"] = d["prefetch_data_iohits"] // sint 560 v["pdmis"] = d["prefetch_data_misses"] // sint 561 562 v["pdread"] = v["pdhit"] + v["pdioh"] + v["pdmis"] 563 v["pdh%"] = 100 * v["pdhit"] // v["pdread"] if v["pdread"] > 0 else 0 564 v["pdi%"] = 100 * v["pdioh"] // v["pdread"] if v["pdread"] > 0 else 0 565 v["pdm%"] = 100 - v["pdh%"] - v["pdi%"] if v["pdread"] > 0 else 0 566 567 v["pmhit"] = d["prefetch_metadata_hits"] // sint 568 v["pmioh"] = d["prefetch_metadata_iohits"] // sint 569 v["pmmis"] = d["prefetch_metadata_misses"] // sint 570 571 v["pmread"] = v["pmhit"] + v["pmioh"] + v["pmmis"] 572 v["pmh%"] = 100 * v["pmhit"] // v["pmread"] if v["pmread"] > 0 else 0 573 v["pmi%"] = 100 * v["pmioh"] // v["pmread"] if v["pmread"] > 0 else 0 574 v["pmm%"] = 100 - v["pmh%"] - v["pmi%"] if v["pmread"] > 0 else 0 575 576 v["mhit"] = (d["prefetch_metadata_hits"] + 577 d["demand_metadata_hits"]) // sint 578 v["mioh"] = (d["prefetch_metadata_iohits"] + 579 d["demand_metadata_iohits"]) // sint 580 v["mmis"] = (d["prefetch_metadata_misses"] + 581 d["demand_metadata_misses"]) // sint 582 583 v["mread"] = v["mhit"] + v["mioh"] + v["mmis"] 584 v["mh%"] = 100 * v["mhit"] // v["mread"] if v["mread"] > 0 else 0 585 v["mi%"] = 100 * v["mioh"] // v["mread"] if v["mread"] > 0 else 0 586 v["mm%"] = 100 - v["mh%"] - v["mi%"] if v["mread"] > 0 else 0 587 588 v["arcsz"] = cur["size"] 589 v["size"] = cur["size"] 590 v["c"] = cur["c"] 591 v["mfu"] = d["mfu_hits"] // sint 592 v["mru"] = d["mru_hits"] // sint 593 v["mrug"] = d["mru_ghost_hits"] // sint 594 v["mfug"] = d["mfu_ghost_hits"] // sint 595 v["unc"] = d["uncached_hits"] // sint 596 v["eskip"] = d["evict_skip"] // sint 597 v["el2skip"] = d["evict_l2_skip"] // sint 598 v["el2cach"] = d["evict_l2_cached"] // sint 599 v["el2el"] = d["evict_l2_eligible"] // sint 600 v["el2mfu"] = d["evict_l2_eligible_mfu"] // sint 601 v["el2mru"] = d["evict_l2_eligible_mru"] // sint 602 v["el2inel"] = d["evict_l2_ineligible"] // sint 603 v["mtxmis"] = d["mutex_miss"] // sint 604 v["ztotal"] = (d["zfetch_hits"] + d["zfetch_future"] + d["zfetch_stride"] + 605 d["zfetch_past"] + d["zfetch_misses"]) // sint 606 v["zhits"] = d["zfetch_hits"] // sint 607 v["zahead"] = (d["zfetch_future"] + d["zfetch_stride"]) // sint 608 v["zpast"] = d["zfetch_past"] // sint 609 v["zmisses"] = d["zfetch_misses"] // sint 610 v["zmax"] = d["zfetch_max_streams"] // sint 611 v["zfuture"] = d["zfetch_future"] // sint 612 v["zstride"] = d["zfetch_stride"] // sint 613 v["zissued"] = d["zfetch_io_issued"] // sint 614 v["zactive"] = d["zfetch_io_active"] // sint 615 616 if l2exist: 617 v["l2hits"] = d["l2_hits"] // sint 618 v["l2miss"] = d["l2_misses"] // sint 619 v["l2read"] = v["l2hits"] + v["l2miss"] 620 v["l2hit%"] = 100 * v["l2hits"] // v["l2read"] if v["l2read"] > 0 else 0 621 622 v["l2miss%"] = 100 - v["l2hit%"] if v["l2read"] > 0 else 0 623 v["l2asize"] = cur["l2_asize"] 624 v["l2size"] = cur["l2_size"] 625 v["l2bytes"] = d["l2_read_bytes"] // sint 626 627 v["l2pref"] = cur["l2_prefetch_asize"] 628 v["l2mfu"] = cur["l2_mfu_asize"] 629 v["l2mru"] = cur["l2_mru_asize"] 630 v["l2data"] = cur["l2_bufc_data_asize"] 631 v["l2meta"] = cur["l2_bufc_metadata_asize"] 632 v["l2pref%"] = 100 * v["l2pref"] // v["l2asize"] 633 v["l2mfu%"] = 100 * v["l2mfu"] // v["l2asize"] 634 v["l2mru%"] = 100 * v["l2mru"] // v["l2asize"] 635 v["l2data%"] = 100 * v["l2data"] // v["l2asize"] 636 v["l2meta%"] = 100 * v["l2meta"] // v["l2asize"] 637 638 v["grow"] = 0 if cur["arc_no_grow"] else 1 639 v["need"] = cur["arc_need_free"] 640 v["free"] = cur["memory_free_bytes"] 641 v["avail"] = cur["memory_available_bytes"] 642 v["waste"] = cur["abd_chunk_waste_size"] 643 644 645def main(): 646 global sint 647 global count 648 global hdr_intr 649 650 i = 0 651 count_flag = 0 652 653 init() 654 if count > 0: 655 count_flag = 1 656 657 signal(SIGINT, SIG_DFL) 658 signal(SIGWINCH, resize_handler) 659 while True: 660 if i == 0: 661 print_header() 662 663 snap_stats() 664 calculate() 665 print_values() 666 667 if count_flag == 1: 668 if count <= 1: 669 break 670 count -= 1 671 672 i = 0 if i >= hdr_intr else i + 1 673 time.sleep(sint) 674 675 if out: 676 out.close() 677 678 679if __name__ == '__main__': 680 main() 681