diff options
author | Alon Levy <alevy@redhat.com> | 2010-09-05 16:33:28 +0300 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2010-09-05 16:33:28 +0300 |
commit | 5c9ba3dde1001ba4572ac5ec746b10494a2a0278 (patch) | |
tree | f4dd0981c1528ecc48b66d770d882943c9b3cd5c | |
parent | 1a7cfff4bef9c305b96840aa734677aeeb54ff19 (diff) |
spicedump: add filter option
-rwxr-xr-x | spicedump.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/spicedump.py b/spicedump.py index 3fcab25..e4b5baa 100755 --- a/spicedump.py +++ b/spicedump.py @@ -53,13 +53,14 @@ class SurfaceStatistics(object): for i, l in enumerate(textwrap.wrap(','.join(map(str, v)), width=40)): yield '%20s: %s' % (k if i == 0 else '', l) -def spicedump(p, stdscr=None): +def spicedump(p, opts, stdscr=None): import pcapspice spice = pcapspice.spice_iter(p) hist = Histogram() surface_stat = SurfaceStatistics() last_print = start_time = time() messages = [] + filter = opts.filter if stdscr: stdscr.erase() # replace the "for d in spice:" loop with a select @@ -71,6 +72,13 @@ def spicedump(p, stdscr=None): d = spice.next() result_name = d.msg.data.result_name result_value = d.msg.data.result_value + if filter and result_name not in filter: + continue + if hasattr(p, 'drop_next'): + pass + #if result_name == 'draw_copy': + # print "dropping %s" % result_name + # p.drop_next() if (any(x in result_name for x in ['surface', 'stream']) and not result_name in ['stream_data', 'stream_clip', 'stream_destroy', 'stream_destroy_all']): @@ -85,18 +93,18 @@ def spicedump(p, stdscr=None): messages.extend(str(d).split('\n')) old_time, old_count = hist[result_name] hist[result_name] = (cur_time, old_count + 1) - if cur_time - last_print > dt: + if True or cur_time - last_print > dt: show(hist.show(), surface_stat.show()) print '\n'.join(messages[-20:]) last_print = cur_time -def frompcap(stdscr=None): +def frompcap(opts, stdscr=None): p = pcaputil.packet_iter('lo') - return spicedump(p, stdscr) + return spicedump(p, opts, stdscr) -def fromproxy(stdscr, local_port, remote_addr): +def fromproxy(stdscr, local_port, remote_addr, opts): p = proxy(local_port=local_port, remote_addr=remote_addr) - return spicedump(p, stdscr=stdscr) + return spicedump(p, opts, stdscr=stdscr) if __name__ == '__main__': parser = OptionParser() @@ -106,6 +114,7 @@ if __name__ == '__main__': parser.add_option('-r', '--remoteaddr', dest='remote_addr', help='set proxy remote address') parser.add_option('-v', '--verbose', dest='verbose', action='count', help='verbosity', default=0) parser.add_option('-c', '--curses', dest='curses', action='store_true', help='use curses') + parser.add_option('-f', '--filter', dest='filter', help='filter messages') opts, rest = parser.parse_args(sys.argv[1:]) if opts.verbose >= 2 in sys.argv: logging.basicConfig(filename='spicedump.log', level=logging.DEBUG) @@ -114,17 +123,17 @@ if __name__ == '__main__': local_port = int(opts.local_port) remote_addr = opts.remote_addr.split(':') remote_addr = (remote_addr[0], int(remote_addr[1])) - main = (lambda stdscr, local_port=local_port, remote_addr=remote_addr: - fromproxy(stdscr, local_port, remote_addr)) + main = (lambda stdscr, opts, local_port=local_port, remote_addr=remote_addr: + fromproxy(stdscr, local_port, remote_addr, opts)) else: main = frompcap verbose = opts.verbose try: if opts.curses in sys.argv: import curses - curses.wrapper(main) + curses.wrapper(lambda stdscr, opts=opts: main(stdscr=stdscr, opts=opts)) else: - main(None) + main(stdscr=None, opts=opts) except KeyboardInterrupt, e: # XXX - ctrl-c doesn't reach here :( closeallsockets() |