'Run reactor under the cProfile profiler.'

def run(self, reactor):

    try:
        import cProfile
        import pstats
    except ImportError as e:
        self._reportImportError('cProfile', e)
    p = cProfile.Profile()
    p.runcall(reactor.run)
    if self.saveStats:
        p.dump_stats(self.profileOutput)
    else:
        with open(self.profileOutput, 'w') as stream:
            s = pstats.Stats(p, stream=stream)
            s.strip_dirs()
            s.sort_stats((-1))
            s.print_stats()
