Matthew Suozzo added the comment:
One of the problems with my proposed solution that I glossed over was how and
where to count the primitive call. If the primitive call is only registered on
RETURN (i.e. after all yields), a generator that is incompletely exhausted
would have 0 primitive cal
New submission from Matthew Suozzo :
# Issue
When profiling a generator function, the initial call and all subsequent yields
are aggregated into the same "ncalls" metric by cProfile.
## Example
>>> cProfile.run("""
... def foo():
... yield 1
... yield 2
... assert tuple(foo()) == (1, 2)