Skip to content

Incorrect hit count on a multi-line call #441

Description

@sam-mosleh

Description

When a function call is split across several source lines, line_profiler reports twice as many hits on the opening f( line as there are actual executions of that call.

Reproducer

from line_profiler import LineProfiler
def main() -> None:
    for _ in range(100):
        print(
            1,
        )
if __name__ == "__main__":
    profile = LineProfiler(main)
    profile.runcall(main)
    profile.print_stats()

Output

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     2                                           def main() -> None:
     3       101      16000.0    158.4      9.0      for _ in range(100):
     4       200     152000.0    760.0     85.9          print(
     5       100       9000.0     90.0      5.1              1,
     6                                                   )

Expectation

print must show 100 hits not 200

Note

Happy to open a PR if maintainers allow me to do so.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions