aboutsummaryrefslogtreecommitdiffstats
path: root/test/bench/profiler.py
blob: 9072e17d45742b714e3667161b226550a0c06ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cProfile
from mitmproxy import ctx


class Profile:
    """
        A simple profiler addon.
    """
    def __init__(self):
        self.pr = cProfile.Profile()

    def load(self, loader):
        loader.add_option(
            "profile_path",
            str,
            "/tmp/profile",
            "Destination for the run profile, saved at exit"
        )
        self.pr.enable()

    def done(self):
        self.pr.dump_stats(ctx.options.profile_path)


addons = [Profile()]