From 1e51c05b718ccd707c406e6e5e1681532dbf64cf Mon Sep 17 00:00:00 2001 From: Jane Xu Date: Mon, 26 Apr 2021 08:41:53 -0700 Subject: [PATCH] Name .coverage.jit with timestamp to prevent loss of stats (#56829) Summary: The reason we were not seeing so many wins was because .coverage.jit would overwrite itself every coverage run. (What a noob mistake who wrote that code?!?!) This should fix that. Pull Request resolved: https://github.com/pytorch/pytorch/pull/56829 Test Plan: Coverage in CI should audibly increase. It does, somewhat: Check out https://codecov.io/github/pytorch/pytorch/commit/f8a475b056cb913844461a8bc2a3097e997b372e! New covered files include: Classes in torch/distributed/optim torch/utils/mkldnn.py Reviewed By: walterddr Differential Revision: D27984427 Pulled By: janeyx99 fbshipit-source-id: e82d074c2b4a60a5204a73efc2823824384c8bf5 --- .../src/coverage_plugins/jit_plugin.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/coverage_plugins_package/src/coverage_plugins/jit_plugin.py b/tools/coverage_plugins_package/src/coverage_plugins/jit_plugin.py index f8bc98a8538048..8f2a66ce865794 100644 --- a/tools/coverage_plugins_package/src/coverage_plugins/jit_plugin.py +++ b/tools/coverage_plugins_package/src/coverage_plugins/jit_plugin.py @@ -10,11 +10,12 @@ from coverage import CoveragePlugin, CoverageData from inspect import ismodule, isclass, ismethod, isfunction, iscode, getsourcefile, getsourcelines +from time import time # All coverage stats resulting from this plug-in will be in a separate .coverage file that should be merged later with # `coverage combine`. The convention seems to be .coverage.dotted.suffix based on the following link: # https://coverage.readthedocs.io/en/coverage-5.5/cmd.html#combining-data-files-coverage-combine -cov_data = CoverageData(basename='.coverage.jit') +cov_data = CoverageData(basename=f'.coverage.jit.{time()}') def is_not_builtin_class(obj): @@ -38,9 +39,11 @@ def dynamic_context(self, frame): # built-in modules or functions as those do not seem to be JIT'd either. if is_not_builtin_class(obj) or ismodule(obj) or ismethod(obj) or isfunction(obj) or iscode(obj): filename = getsourcefile(obj) - sourcelines, starting_lineno = getsourcelines(obj) - line_data = {filename: range(starting_lineno, starting_lineno + len(sourcelines))} - cov_data.add_lines(line_data) + # We don't want to report for filename = None + if filename: + sourcelines, starting_lineno = getsourcelines(obj) + line_data = {filename: range(starting_lineno, starting_lineno + len(sourcelines))} + cov_data.add_lines(line_data) super().dynamic_context(frame) def coverage_init(reg, options):