{"action":"created","comment":{"url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/comments/57513859","id":57513859,"diff_hunk":"@@ -0,0 +1,196 @@\n+from __future__ import absolute_import, division, print_function\n+\n+import os.path\n+try:\n+    from builtins import __dict__ as builtins\n+except ImportError:  # Python 2\n+    from __builtin__ import __dict__ as builtins\n+\n+import py\n+import pytest\n+\n+from .data import gen_dict, load_benchmarks\n+from .plot import make_plot\n+\n+\n+BENCH_DIR = py.path.local(__file__).dirpath('bench')\n+\n+\n+mode_args_map = {\n+    'default':   [],\n+    'noplugin':  ['-pno:pytest_catchlog'],\n+    'noprint':   ['--no-print-logs'],\n+    'nocapture': ['-s'],\n+}\n+\n+\n+def pytest_configure(config):\n+    if (config.getoption('run_perf') in ('yes', 'only') and\n+        config.getoption('perf_graph_name')):\n+\n+        expr = config.getoption('perf_expr_primary')\n+        expr2 = config.getoption('perf_expr_secondary')\n+        if not (expr or expr2):\n+            raise pytest.UsageError('perf-graph: Nothing to plot, '\n+                                    'see --perf-expr')\n+\n+\n+def path_in_dir(path, dir=py.path.local(__file__).dirpath()):\n+    return (dir.common(path) == dir)\n+\n+\n+def pytest_ignore_collect(path):\n+    if path_in_dir(path, BENCH_DIR):\n+        # Tests from that directory never run through test discovery.\n+        #\n+        # Instead, they run either with the BENCH_DIR specified explicitly\n+        # both as a target and a 'confcutdir' or when the BENCH_DIR itself\n+        # is a 'rootdir' (CWD). In any case this conftest is not processed\n+        # at all, and this hook doesn't run when running tests from the\n+        # BENCH_DIR.\n+        return True\n+\n+\n+def pytest_itemcollected(item):\n+    \"\"\"This is only called for local tests (under tests/perf_runner/).\"\"\"\n+    if path_in_dir(item.fspath):\n+        item.add_marker('_perf_test')\n+\n+\n+def pytest_collection_modifyitems(session, config, items):\n+    \"\"\"This is called after collection (of all tests) has been performed.\"\"\"\n+    run_perf = config.getoption('run_perf')\n+    if run_perf in ('yes', 'check'):\n+        return\n+    perf_only = (run_perf == 'only')\n+\n+    items[:] = [item\n+                for item in items\n+                if bool(item.get_marker('_perf_test')) == perf_only]\n+\n+\n+def pytest_terminal_summary(terminalreporter):\n+    \"\"\"Add additional section in terminal summary reporting.\"\"\"\n+    config = terminalreporter.config\n+\n+    if config.getoption('run_perf') in ('yes', 'only'):\n+        passed = terminalreporter.stats.get('passed', [])\n+        for rep in passed:\n+            if '_perf_test' not in rep.keywords:\n+                continue\n+\n+            out = '\\n'.join(s for _, s in rep.get_sections('Captured stdout'))\n+            if out:\n+                fspath, lineno, name = rep.location\n+                terminalreporter.write_sep(\"-\", 'Report from {0}'.format(name))\n+                terminalreporter.write(out)\n+\n+    handle_perf_graph(config, terminalreporter)\n+\n+\n+def handle_perf_graph(config, terminalreporter):\n+    output_file = config.getoption('perf_graph_name')\n+    if not output_file:\n+        return\n+\n+    bench_storage = config.getoption('--benchmark-storage')\n+    output_file = os.path.join(bench_storage, output_file)\n+\n+    trial_names, benchmarks = load_benchmarks(bench_storage,\n+                                              modes=sorted(mode_args_map))\n+    if not trial_names:\n+        terminalreporter.write_line(\n+            'perf-graph: No benchmarks found in {0}'.format(bench_storage),\n+            yellow=True, bold=True)\n+        return\n+\n+    expr = config.getoption('perf_expr_primary')\n+    expr2 = config.getoption('perf_expr_secondary')\n+\n+    history = eval_benchmark_expr(expr, benchmarks)\n+    history2 = eval_benchmark_expr(expr2, benchmarks)\n+\n+    plot = make_plot(\n+        trial_names=trial_names,\n+        history=history,\n+        history2=history2,\n+        expr=expr,\n+        expr2=expr2,\n+    )\n+    plot.render_to_file(output_file)\n+\n+    terminalreporter.write_line(\n+        'perf-graph: Saved graph into {0}'.format(output_file),\n+        green=True, bold=True)\n+\n+\n+@gen_dict\n+def eval_benchmark_expr(expr, benchenvs, **kwargs):\n+    for mode, envlist in benchenvs.items():\n+        yield mode, [BenchmarkEnv(benchenv, **kwargs).evaluate(expr)","path":"tests/perf/conftest.py","position":130,"original_position":130,"commit_id":"aeeb2bc587a6b7b563d285adaeae21fdb6f48336","original_commit_id":"aeeb2bc587a6b7b563d285adaeae21fdb6f48336","user":{"login":"ionelmc","id":129501,"avatar_url":"https://avatars.githubusercontent.com/u/129501?v=3","gravatar_id":"","url":"https://api.github.com/users/ionelmc","html_url":"https://github.com/ionelmc","followers_url":"https://api.github.com/users/ionelmc/followers","following_url":"https://api.github.com/users/ionelmc/following{/other_user}","gists_url":"https://api.github.com/users/ionelmc/gists{/gist_id}","starred_url":"https://api.github.com/users/ionelmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ionelmc/subscriptions","organizations_url":"https://api.github.com/users/ionelmc/orgs","repos_url":"https://api.github.com/users/ionelmc/repos","events_url":"https://api.github.com/users/ionelmc/events{/privacy}","received_events_url":"https://api.github.com/users/ionelmc/received_events","type":"User","site_admin":false},"body":"`evaluate` can return `None`. Shouldn't this filter those values?","created_at":"2016-03-26T13:54:55Z","updated_at":"2016-03-26T13:54:55Z","html_url":"https://github.com/eisensheng/pytest-catchlog/pull/40#discussion_r57513859","pull_request_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/comments/57513859"},"html":{"href":"https://github.com/eisensheng/pytest-catchlog/pull/40#discussion_r57513859"},"pull_request":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40","id":64221350,"html_url":"https://github.com/eisensheng/pytest-catchlog/pull/40","diff_url":"https://github.com/eisensheng/pytest-catchlog/pull/40.diff","patch_url":"https://github.com/eisensheng/pytest-catchlog/pull/40.patch","issue_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/40","number":40,"state":"open","locked":false,"title":"Performance test harness","user":{"login":"abusalimov","id":530396,"avatar_url":"https://avatars.githubusercontent.com/u/530396?v=3","gravatar_id":"","url":"https://api.github.com/users/abusalimov","html_url":"https://github.com/abusalimov","followers_url":"https://api.github.com/users/abusalimov/followers","following_url":"https://api.github.com/users/abusalimov/following{/other_user}","gists_url":"https://api.github.com/users/abusalimov/gists{/gist_id}","starred_url":"https://api.github.com/users/abusalimov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abusalimov/subscriptions","organizations_url":"https://api.github.com/users/abusalimov/orgs","repos_url":"https://api.github.com/users/abusalimov/repos","events_url":"https://api.github.com/users/abusalimov/events{/privacy}","received_events_url":"https://api.github.com/users/abusalimov/received_events","type":"User","site_admin":false},"body":"Measure an overhead of having the pytest-catchlog plugin activated, namely:\r\n  - `(caplog - stub)` the cost of requesting a `caplog` fixture (minus an overhead incurred by pytest to proved an empty fixture)\r\n  - `log_emit` the cost of emitting a log message\r\n\r\nThese costs are evaluated in 4 different scenarios:\r\n  - default\r\n  - noplugin - when catchlog is not activated, i.e. running with `-pno:pytest_catchlog`\r\n  - noprint - when logs are not reported, i.e. running with `--no-print-logs`\r\n  - nocapture - when running with `-s`\r\n\r\nAlso add a cmdline option to plot multiple measurements for comparison. For example, to estimate how each commit in a branch affects performance and at the same time ensure branch bisectability before pushing it to submit a PR:\r\n```console\r\n$ rm -rf ./.benchmarks  # clean up old measurements, if any\r\n$ git rebase upstream/develop -i --exec 'tox -eperf'  # save and close an editor\r\n...  # wait until done\r\n$ tox -eperf -- --collect-only --perf-graph\r\n```\r\nA graph.svg file will be saved somewhere like ./.benchmarks/Linux-CPython-2.7-64bit/\r\n\r\n@The-Compiler @eisensheng I'd like this to be merged ASAP at least since it doesn't affect any logic besides tests. Your feedback will be appreciated!","created_at":"2016-03-26T00:12:03Z","updated_at":"2016-03-26T13:54:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3fe5eb100f37e2828ecb6b2626742da3e3290f1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40/commits","review_comments_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40/comments","review_comment_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/40/comments","statuses_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/statuses/aeeb2bc587a6b7b563d285adaeae21fdb6f48336","head":{"label":"abusalimov:perf-tests","ref":"perf-tests","sha":"aeeb2bc587a6b7b563d285adaeae21fdb6f48336","user":{"login":"abusalimov","id":530396,"avatar_url":"https://avatars.githubusercontent.com/u/530396?v=3","gravatar_id":"","url":"https://api.github.com/users/abusalimov","html_url":"https://github.com/abusalimov","followers_url":"https://api.github.com/users/abusalimov/followers","following_url":"https://api.github.com/users/abusalimov/following{/other_user}","gists_url":"https://api.github.com/users/abusalimov/gists{/gist_id}","starred_url":"https://api.github.com/users/abusalimov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abusalimov/subscriptions","organizations_url":"https://api.github.com/users/abusalimov/orgs","repos_url":"https://api.github.com/users/abusalimov/repos","events_url":"https://api.github.com/users/abusalimov/events{/privacy}","received_events_url":"https://api.github.com/users/abusalimov/received_events","type":"User","site_admin":false},"repo":{"id":41974293,"name":"pytest-catchlog","full_name":"abusalimov/pytest-catchlog","owner":{"login":"abusalimov","id":530396,"avatar_url":"https://avatars.githubusercontent.com/u/530396?v=3","gravatar_id":"","url":"https://api.github.com/users/abusalimov","html_url":"https://github.com/abusalimov","followers_url":"https://api.github.com/users/abusalimov/followers","following_url":"https://api.github.com/users/abusalimov/following{/other_user}","gists_url":"https://api.github.com/users/abusalimov/gists{/gist_id}","starred_url":"https://api.github.com/users/abusalimov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abusalimov/subscriptions","organizations_url":"https://api.github.com/users/abusalimov/orgs","repos_url":"https://api.github.com/users/abusalimov/repos","events_url":"https://api.github.com/users/abusalimov/events{/privacy}","received_events_url":"https://api.github.com/users/abusalimov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abusalimov/pytest-catchlog","description":"py.test plugin to catch log messages. Forked from pytest-capturelog. Pull Requests are welcome!","fork":true,"url":"https://api.github.com/repos/abusalimov/pytest-catchlog","forks_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/forks","keys_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/teams","hooks_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/hooks","issue_events_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/issues/events{/number}","events_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/events","assignees_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/assignees{/user}","branches_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/branches{/branch}","tags_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/tags","blobs_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/git/refs{/sha}","trees_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/statuses/{sha}","languages_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/languages","stargazers_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/stargazers","contributors_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/contributors","subscribers_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/subscribers","subscription_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/subscription","commits_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/commits{/sha}","git_commits_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/git/commits{/sha}","comments_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/comments{/number}","issue_comment_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/issues/comments{/number}","contents_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/contents/{+path}","compare_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/merges","archive_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/downloads","issues_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/issues{/number}","pulls_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/pulls{/number}","milestones_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/milestones{/number}","notifications_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/labels{/name}","releases_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/releases{/id}","deployments_url":"https://api.github.com/repos/abusalimov/pytest-catchlog/deployments","created_at":"2015-09-05T20:18:50Z","updated_at":"2015-09-05T20:18:51Z","pushed_at":"2016-03-25T23:46:28Z","git_url":"git://github.com/abusalimov/pytest-catchlog.git","ssh_url":"git@github.com:abusalimov/pytest-catchlog.git","clone_url":"https://github.com/abusalimov/pytest-catchlog.git","svn_url":"https://github.com/abusalimov/pytest-catchlog","homepage":"https://pypi.python.org/pypi/pytest-catchlog/","size":135,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"eisensheng:develop","ref":"develop","sha":"01ab1edfcca8c3176593bee1ebefaa992d0b6f59","user":{"login":"eisensheng","id":72146,"avatar_url":"https://avatars.githubusercontent.com/u/72146?v=3","gravatar_id":"","url":"https://api.github.com/users/eisensheng","html_url":"https://github.com/eisensheng","followers_url":"https://api.github.com/users/eisensheng/followers","following_url":"https://api.github.com/users/eisensheng/following{/other_user}","gists_url":"https://api.github.com/users/eisensheng/gists{/gist_id}","starred_url":"https://api.github.com/users/eisensheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eisensheng/subscriptions","organizations_url":"https://api.github.com/users/eisensheng/orgs","repos_url":"https://api.github.com/users/eisensheng/repos","events_url":"https://api.github.com/users/eisensheng/events{/privacy}","received_events_url":"https://api.github.com/users/eisensheng/received_events","type":"User","site_admin":false},"repo":{"id":27728976,"name":"pytest-catchlog","full_name":"eisensheng/pytest-catchlog","owner":{"login":"eisensheng","id":72146,"avatar_url":"https://avatars.githubusercontent.com/u/72146?v=3","gravatar_id":"","url":"https://api.github.com/users/eisensheng","html_url":"https://github.com/eisensheng","followers_url":"https://api.github.com/users/eisensheng/followers","following_url":"https://api.github.com/users/eisensheng/following{/other_user}","gists_url":"https://api.github.com/users/eisensheng/gists{/gist_id}","starred_url":"https://api.github.com/users/eisensheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eisensheng/subscriptions","organizations_url":"https://api.github.com/users/eisensheng/orgs","repos_url":"https://api.github.com/users/eisensheng/repos","events_url":"https://api.github.com/users/eisensheng/events{/privacy}","received_events_url":"https://api.github.com/users/eisensheng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eisensheng/pytest-catchlog","description":"py.test plugin to catch log messages. Forked from pytest-capturelog. Pull Requests are welcome!","fork":false,"url":"https://api.github.com/repos/eisensheng/pytest-catchlog","forks_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/forks","keys_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/teams","hooks_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/hooks","issue_events_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/events{/number}","events_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/events","assignees_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/assignees{/user}","branches_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/branches{/branch}","tags_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/tags","blobs_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/git/refs{/sha}","trees_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/statuses/{sha}","languages_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/languages","stargazers_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/stargazers","contributors_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/contributors","subscribers_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/subscribers","subscription_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/subscription","commits_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/commits{/sha}","git_commits_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/git/commits{/sha}","comments_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/comments{/number}","issue_comment_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/comments{/number}","contents_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/contents/{+path}","compare_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/merges","archive_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/downloads","issues_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues{/number}","pulls_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls{/number}","milestones_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/milestones{/number}","notifications_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/labels{/name}","releases_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/releases{/id}","deployments_url":"https://api.github.com/repos/eisensheng/pytest-catchlog/deployments","created_at":"2014-12-08T18:36:23Z","updated_at":"2016-03-13T11:00:55Z","pushed_at":"2016-03-26T00:12:03Z","git_url":"git://github.com/eisensheng/pytest-catchlog.git","ssh_url":"git@github.com:eisensheng/pytest-catchlog.git","clone_url":"https://github.com/eisensheng/pytest-catchlog.git","svn_url":"https://github.com/eisensheng/pytest-catchlog","homepage":"https://pypi.python.org/pypi/pytest-catchlog/","size":91,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":13,"forks":6,"open_issues":13,"watchers":16,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40"},"html":{"href":"https://github.com/eisensheng/pytest-catchlog/pull/40"},"issue":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/40"},"comments":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/eisensheng/pytest-catchlog/statuses/aeeb2bc587a6b7b563d285adaeae21fdb6f48336"}}}}