Skip to content

Commit

Permalink
Name .coverage.jit with timestamp to prevent loss of stats (pytorch#5…
Browse files Browse the repository at this point in the history
…6829)

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: pytorch#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
  • Loading branch information
janeyx99 authored and facebook-github-bot committed Apr 26, 2021
1 parent 689d3a7 commit 1e51c05
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 1e51c05

Please sign in to comment.