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 f8a475b056! 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
This commit is contained in:
Jane Xu
2021-04-26 08:41:53 -07:00
committed by Facebook GitHub Bot
parent 689d3a70aa
commit 1e51c05b71

View File

@ -10,11 +10,12 @@ marked as covered.
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 @@ class JitPlugin(CoveragePlugin):
# 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):