#!/usr/bin/python # # Demonstration script to count the number of GlusterFS (I/O) procedures. # # Two steps are needed: # 1) get the descroption and values for the procedure calls # 2) analyze each packet and increase the counter for the procedure call # # Author: Niels de Vos # Date: Sat, 23 Feb 2013 # import sys import os if len(sys.argv) != 2: print "Usage: %s " % sys.argv[0] sys.exit(1) filename = sys.argv[1] # build a dict of procedures { "PROCNUM" : ["PROCNAME", 0] } # the counter in ["PROCNAME", 0] list increase with each matching procedure procs = dict() # Gather the procedures and their procnum values, filter on "glusterfs" output = os.popen("tshark -G values") for line in output: # a line looks like: "V glusterfs.proc 0 NULL" parts = line.split() if parts[1] == "glusterfs.proc": procs[parts[2]] = ["%s (%s)" % (parts[3].strip(), parts[2]), 0] # tshark command that prints all procedure calls (procnum values) tshark_command = "tshark -T fields -e glusterfs.proc -r %s" % filename # filter RPC Calls for GlusterFS tshark_command += " 'rpc.msgtyp == 0 && glusterfs'" # read the output from the tshark command output = os.popen(tshark_command) for line in output: # Bug in certain Wireshark versions causing extra line of output if line.startswith("libwireshark.so"): continue procnum = line.strip() procs[procnum][1] += 1 # simple sort function for the proc = ["NAME", count] def proc_sort(a, b): # reverse sort, normal would be: cmp(a, b) return cmp(b[1], a[1]) sorted_procs = procs.values() sorted_procs.sort(proc_sort) # print a table with the results print " count | Procedure" print "---------+-----------" for proc in sorted_procs: # skip procedures that were not called if proc[1] > 0: print "%8d | %s" % (proc[1], proc[0])