<s> from __future__ import print_function <EOL> from bcc import BPF <EOL> from ctypes import c_int <EOL> from time import sleep , strftime <EOL> from sys import argv <EOL> def usage ( ) : <EOL> print ( "<STR_LIT>" % argv [ <NUM_LIT:0> ] ) <EOL> exit ( ) <EOL> interval = <NUM_LIT:1> <EOL> count = - <NUM_LIT:1> <EOL> if len ( argv ) > <NUM_LIT:1> : <EOL> try : <EOL> interval = int ( argv [ <NUM_LIT:1> ] ) <EOL> if interval == <NUM_LIT:0> : <EOL> raise <EOL> if len ( argv ) > <NUM_LIT:2> : <EOL> count = int ( argv [ <NUM_LIT:2> ] ) <EOL> except : <EOL> usage ( ) <EOL> bpf_text = """<STR_LIT>""" <EOL> b = BPF ( text = bpf_text ) <EOL> b . attach_kprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> b . attach_kretprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> stats = { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:3> <EOL> } <EOL> print ( "<STR_LIT>" % "<STR_LIT>" , end = "<STR_LIT>" ) <EOL> for stype , idx in sorted ( stats . items ( ) , key = lambda k_v : ( k_v [ <NUM_LIT:1> ] , k_v [ <NUM_LIT:0> ] ) ) : <EOL> print ( "<STR_LIT>" % ( stype + "<STR_LIT>" ) , end = "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % "<STR_LIT>" ) <EOL> i = <NUM_LIT:0> <EOL> while ( <NUM_LIT:1> ) : <EOL> if count > <NUM_LIT:0> : <EOL> i += <NUM_LIT:1> <EOL> if i > count : <EOL> exit ( ) <EOL> try : <EOL> sleep ( interval ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> exit ( ) <EOL> print ( "<STR_LIT>" % strftime ( "<STR_LIT>" ) , end = "<STR_LIT>" ) <EOL> for stype , idx in sorted ( stats . items ( ) , key = lambda k_v : ( k_v [ <NUM_LIT:1> ] , k_v [ <NUM_LIT:0> ] ) ) : <EOL> try : <EOL> val = b [ "<STR_LIT>" ] [ c_int ( idx ) ] . value / interval <EOL> print ( "<STR_LIT>" % val , end = "<STR_LIT>" ) <EOL> except : <EOL> print ( "<STR_LIT>" % <NUM_LIT:0> , end = "<STR_LIT>" ) <EOL> try : <EOL> ref = b [ "<STR_LIT>" ] [ c_int ( stats [ "<STR_LIT>" ] ) ] . value <EOL> miss = b [ "<STR_LIT>" ] [ c_int ( stats [ "<STR_LIT>" ] ) ] . value <EOL> hit = ref - miss <EOL> pct = float ( <NUM_LIT:100> ) * hit / ref <EOL> print ( "<STR_LIT>" % pct ) <EOL> except : <EOL> print ( "<STR_LIT>" % "<STR_LIT:->" ) <EOL> b [ "<STR_LIT>" ] . clear ( ) </s>
