Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use python3.7's opcode tracing if possible #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use python3.7's opcode tracing if possible

  • Loading branch information
jvoisin committed Mar 28, 2020
commit b94e7d607601bbe4b135b579359c74c713d4c6b4
@@ -5,7 +5,32 @@
prev_filename = ''
data = collections.defaultdict(set)

def trace(frame, event, arg):
def trace_opcode(frame, event, arg):
if event != 'opcode':
return trace

global prev_line
global prev_filename

func_filename = frame.f_code.co_filename
func_line_no = frame.f_lineno
func_opcode = frame.f_code

if func_filename != prev_filename:
# We need a way to keep track of inter-files transferts,
# and since we don't really care about the details of the coverage,
# concatenating the two filenames in enough.
data[func_filename + prev_filename].add((prev_line, func_line_no, func_opcode))
else:
data[func_filename].add((prev_line, func_line_no, func_opcode))

prev_line = func_line_no
prev_filename = func_filename

return trace


def trace_default(frame, event, arg):
if event != 'line':
return trace

@@ -29,5 +54,9 @@ def trace(frame, event, arg):
return trace


trace = trace_default
if sys.version_info >= (3, 7):
trace = trace_opcode

def get_coverage():
return sum(map(len, data.values()))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.