Skip to content

Commit ebb1110

Browse files
committed
skipzeros based on hits instead of time
1 parent 5ae8585 commit ebb1110

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Changes
33

44
4.1.0
55
~~~~
6+
* FIX: skipzeros now checks for zero hits instead of zero time
67
* FIX: Fixed errors in Python 3.11 with duplicate functions.
78
* FIX: ``show_text`` now increases column sizes or switches to scientific notation to maintain alignment
89
* ENH: ``show_text`` now has new options: sort and summarize

line_profiler/_line_profiler.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This is the Cython backend used in :py:mod:`line_profiler.line_profiler`.
44
"""
55
from .python25 cimport PyFrameObject, PyObject, PyStringObject
66
from sys import byteorder
7+
import sys
78
cimport cython
89
from cpython.version cimport PY_VERSION_HEX
910
from libc.stdint cimport int64_t
@@ -238,8 +239,12 @@ cdef class LineProfiler:
238239
NOP_VALUE: int = 9
239240
# Op code should be 2 bytes as stated in
240241
# https://docs.python.org/3/library/dis.html
242+
# if sys.version_info[0:2] >= (3, 11):
241243
NOP_BYTES = NOP_VALUE.to_bytes(2, byteorder=byteorder)
242-
co_padding = NOP_BYTES * len(self.dupes_map[code.co_code])
244+
# else:
245+
# NOP_BYTES = NOP_VALUE.to_bytes(1, byteorder=byteorder)
246+
247+
co_padding = NOP_BYTES * (len(self.dupes_map[code.co_code]) + 1)
243248
co_code = code.co_code + co_padding
244249
CodeType = type(code)
245250
code = _code_replace(func, co_code=co_code)

line_profiler/line_profiler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ def show_func(filename, start_lineno, func_name, timings, unit,
286286
if stream is None:
287287
stream = sys.stdout
288288

289+
total_hits = sum(t[1] for t in timings)
289290
total_time = sum(t[2] for t in timings)
290-
if stripzeros and total_time == 0:
291+
292+
if stripzeros and total_hits == 0:
291293
return
292294

293295
if rich:

0 commit comments

Comments
 (0)