1
2 """Example for profiling MOSP simulation stuff"""
3
4 import time
5 import sys
6 sys.path.append("..")
7
8 from mosp.core import Simulation, action, start_action
9 from mosp.geo import osm
10
11 from mosp_examples.zombie_wiggler import ZombieWiggler
12
13 __author__ = "B. Henne"
14 __contact__ = "henne@dcsec.uni-hannover.de"
15 __copyright__ = "(c) 2011, DCSec, Leibniz Universitaet Hannover, Germany"
16 __license__ = "GPLv3"
17
18
20 """What to profile is defined here."""
21 ticks = 100
22 zombies = 1000
23 osm_file = '../data/chicago1.osm'
24
25 print 'Loading geo & routing ... '
26 s = Simulation(geo=osm.OSMModel(osm_file, grid_size=50), rel_speed=20)
27 s.add_persons(ZombieWiggler, zombies, args={"infected":True, "speed":0.7})
28 t = time.time()
29 print 'Go! '
30 s.run(until=ticks, real_time=False, monitor=False)
31 print 'Done %s with %s zombies on map %s' % (ticks, zombies, osm_file)
32 print 'Duration: ', time.time() - t
33
34
35 if __name__ == '__main__':
36
37 import cProfile
38 import pstats
39 cProfile.run('main()', '/tmp/stats')
40 p = pstats.Stats('/tmp/stats')
41 p.strip_dirs()
42 p.sort_stats('cumulative')
43 p.print_stats()
44
45
46
47
48