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

Respect stripzeros in summary report #260

Merged
merged 2 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changes

4.1.3
~~~~~
* FIX: duration summary now respects the stripzeros argument.

4.1.2
~~~~~
Expand All @@ -15,7 +16,7 @@ Changes
* FIX: ``get_stats`` is no longer slowed down when profiling many code sections #236

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
Expand Down
5 changes: 3 additions & 2 deletions line_profiler/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ def show_text(stats, unit, output_unit=None, stream=None, stripzeros=False,
# Summarize the total time for each function
for (fn, lineno, name), timings in stats_order:
total_time = sum(t[2] for t in timings) * unit
line = '%6.2f seconds - %s:%s - %s\n' % (total_time, fn, lineno, name)
stream.write(line)
if not stripzeros or total_time:
line = '%6.2f seconds - %s:%s - %s\n' % (total_time, fn, lineno, name)
stream.write(line)


def load_stats(filename):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def test_show_func_column_formatting():
def get_func_linenos(func):
import sys
if sys.version_info[0:2] >= (3, 10):
return sorted(set([t[2] for t in func.__code__.co_lines()]))
return sorted(set([t[0] if t[2] is None else t[2]
for t in func.__code__.co_lines()]))
else:
import dis
return sorted(set([t[1] for t in dis.findlinestarts(func.__code__)]))
Expand Down
Loading