(netflow, flowd aggregate) add profile support, replace deepcopy for cheaper copy

This commit is contained in:
Ad Schellevis 2016-04-20 15:47:34 +02:00
parent 8872e1c783
commit 8adc1d83bf

View File

@ -74,7 +74,7 @@ def aggregate_flowd(do_vacuum=False):
for stream_agg_object in stream_agg_objects:
# class add() may change the flow contents for processing, its better to isolate
# paremeters here.
flow_record_cpy = copy.deepcopy(flow_record)
flow_record_cpy = copy.copy(flow_record)
stream_agg_object.add(flow_record_cpy)
prev_recv = flow_record['recv']
@ -164,7 +164,23 @@ class Main(object):
if len(sys.argv) > 1 and 'console' in sys.argv[1:]:
# command line start
Main()
if 'profile' in sys.argv[1:]:
# start with profiling
import cProfile
import StringIO
import pstats
pr = cProfile.Profile(builtins=False)
pr.enable()
Main()
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print s.getvalue()
else:
Main()
else:
# Daemonize flowd aggregator
daemon = Daemonize(app="flowd_aggregate", pid='/var/run/flowd_aggregate.pid', action=Main)