Skip to content

Commit

Permalink
Add performance profiling of individual registrations to SSS
Browse files Browse the repository at this point in the history
The --profile-registration command-line argument will enable performance profiling of each registration separately
  • Loading branch information
rrlapointe committed Mar 24, 2021
1 parent e9d10a0 commit aa1c033
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sss/sss.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def __init__(self, sss, conn, addr):
self.registered = False
self.runtime_cert = None
self.datetime_start = None
self.profile = None

def new_conn(self, conn):
self.conn = conn
Expand All @@ -205,6 +206,14 @@ def reset(self):
else:
logging.debug(f'Session with {self.addr} took {duration}.')
self.datetime_start = None
if args.profile_registration and self.profile is not None:
self.profile.disable()
sio = io.StringIO()
sortby = pstats.SortKey.CUMULATIVE
ps = pstats.Stats(self.profile, stream=sio).sort_stats(sortby)
ps.print_stats()
logging.info(f'Results of performance profiling for transaction with peer {self.addr}:' + sio.getvalue())
self.profile = None
self.handshake_complete = False

def handle(self):
Expand Down Expand Up @@ -244,6 +253,10 @@ def handshake(self):
except tls.HelloVerifyRequest:
logging.debug(f'Hello verification requested.')
self.datetime_start = datetime.now()
if args.profile_registration:
logging.info(f'Beginning performance profiling for transaction with peer {self.addr}.')
self.profile = cProfile.Profile()
self.profile.enable()
except TLSError as err:
if err.err != 30976:
logging.exception(f'Handshake with {self.addr} failed.')
Expand Down Expand Up @@ -272,6 +285,11 @@ def handle_transaction(self):
self.registered = True
logging.info(f'Client {self.addr} registered.')
elif op == DEREG:
if args.profile_registration and self.profile is not None:
# This transaction turned out to be a deregistration, not a registration, so shut down the profiler.
self.profile.disable()
self.profile = None
logging.info(f'Aborted performance profiling for transaction with peer {self.addr}.')
if self.registered:
resp = self.deregister()
self.registered = False
Expand Down Expand Up @@ -426,6 +444,7 @@ def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('sockf', help='Path to socket to bind the SSS to')
parser.add_argument('--profile', dest='profile', action='store_true')
parser.add_argument('--profile-registration', dest='profile_registration', action='store_true')
return parser.parse_args()


Expand Down

0 comments on commit aa1c033

Please sign in to comment.