Skip to content

Commit

Permalink
skipzeros based on hits instead of time
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Aug 17, 2023
1 parent 5ae8585 commit ebb1110
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changes

4.1.0
~~~~
* FIX: skipzeros now checks for zero hits instead of zero time
* FIX: Fixed errors in Python 3.11 with duplicate functions.
* FIX: ``show_text`` now increases column sizes or switches to scientific notation to maintain alignment
* ENH: ``show_text`` now has new options: sort and summarize
Expand Down
7 changes: 6 additions & 1 deletion line_profiler/_line_profiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This is the Cython backend used in :py:mod:`line_profiler.line_profiler`.
"""
from .python25 cimport PyFrameObject, PyObject, PyStringObject
from sys import byteorder
import sys
cimport cython
from cpython.version cimport PY_VERSION_HEX
from libc.stdint cimport int64_t
Expand Down Expand Up @@ -238,8 +239,12 @@ cdef class LineProfiler:
NOP_VALUE: int = 9
# Op code should be 2 bytes as stated in
# https://docs.python.org/3/library/dis.html
# if sys.version_info[0:2] >= (3, 11):
NOP_BYTES = NOP_VALUE.to_bytes(2, byteorder=byteorder)
co_padding = NOP_BYTES * len(self.dupes_map[code.co_code])
# else:
# NOP_BYTES = NOP_VALUE.to_bytes(1, byteorder=byteorder)

co_padding = NOP_BYTES * (len(self.dupes_map[code.co_code]) + 1)
co_code = code.co_code + co_padding
CodeType = type(code)
code = _code_replace(func, co_code=co_code)
Expand Down
4 changes: 3 additions & 1 deletion line_profiler/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,10 @@ def show_func(filename, start_lineno, func_name, timings, unit,
if stream is None:
stream = sys.stdout

total_hits = sum(t[1] for t in timings)
total_time = sum(t[2] for t in timings)
if stripzeros and total_time == 0:

if stripzeros and total_hits == 0:
return

if rich:
Expand Down

0 comments on commit ebb1110

Please sign in to comment.