<s> from __future__ import print_function <EOL> from bcc import BPF <EOL> from time import sleep , strftime <EOL> import argparse <EOL> import signal <EOL> examples = """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" , <EOL> formatter_class = argparse . RawDescriptionHelpFormatter , <EOL> epilog = examples ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> pattern = args . pattern <EOL> if not args . regexp : <EOL> pattern = pattern . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> pattern = '<STR_LIT>' + pattern + '<STR_LIT:$>' <EOL> offset = args . offset <EOL> verbose = args . verbose <EOL> debug = <NUM_LIT:0> <EOL> maxdepth = <NUM_LIT:10> <EOL> def signal_ignore ( signal , frame ) : <EOL> print ( ) <EOL> bpf_text = """<STR_LIT>""" <EOL> if args . pid : <EOL> bpf_text = bpf_text . replace ( '<STR_LIT>' , <EOL> ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) % ( args . pid ) ) <EOL> else : <EOL> bpf_text = bpf_text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if debug : <EOL> print ( bpf_text ) <EOL> b = BPF ( text = bpf_text ) <EOL> b . attach_kprobe ( event_re = pattern , fn_name = "<STR_LIT>" ) <EOL> matched = b . num_open_kprobes ( ) <EOL> if matched == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" % args . pattern ) <EOL> exit ( ) <EOL> print ( "<STR_LIT>" % <EOL> ( matched , args . pattern ) ) <EOL> def print_frame ( addr ) : <EOL> print ( "<STR_LIT:U+0020>" , end = "<STR_LIT>" ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" % addr , end = "<STR_LIT>" ) <EOL> if offset : <EOL> print ( "<STR_LIT:%s>" % b . ksymaddr ( addr ) ) <EOL> else : <EOL> print ( "<STR_LIT:%s>" % b . ksym ( addr ) ) <EOL> exiting = <NUM_LIT:0> if args . interval else <NUM_LIT:1> <EOL> while ( <NUM_LIT:1> ) : <EOL> try : <EOL> sleep ( int ( args . interval ) ) <EOL> except KeyboardInterrupt : <EOL> exiting = <NUM_LIT:1> <EOL> signal . signal ( signal . SIGINT , signal_ignore ) <EOL> print ( ) <EOL> if args . timestamp : <EOL> print ( "<STR_LIT>" % strftime ( "<STR_LIT>" ) , end = "<STR_LIT>" ) <EOL> counts = b [ "<STR_LIT>" ] <EOL> stack_traces = b [ "<STR_LIT>" ] <EOL> for k , v in sorted ( counts . items ( ) , key = lambda counts : counts [ <NUM_LIT:1> ] . value ) : <EOL> for addr in stack_traces . walk ( k . value ) : <EOL> print_frame ( addr ) <EOL> print ( "<STR_LIT>" % v . value ) <EOL> counts . clear ( ) <EOL> if exiting : <EOL> print ( "<STR_LIT>" ) <EOL> exit ( ) </s>
