-
Notifications
You must be signed in to change notification settings - Fork 395
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
feat(profiling): new memory profiler #1673
Conversation
5b1dde8
to
bb119be
Compare
bb119be
to
4c17fa8
Compare
This is a new memory allocation profiler that directly leverages the CPython memory API. It tracks memory allocation events.
This adds a environment variable to opt-int to the new memory profiler.
4c17fa8
to
7148e04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor questions
# _memalloc buffer to our Recorder. This is fine for now, but we might want to store the nanoseconds | ||
# timestamp in C and then return it via iter_events. | ||
return ( | ||
tuple( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason here to use tuple
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're smaller and we don't need to modify the result, therefore tuple is good enough :)
) | ||
|
||
nevents = len(events) | ||
sampling_ratio_avg = sum(event.capture_pct for event in events) / nevents / 100.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could shave off some effort by collapsing these three iterations over events into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd think so…
l = list(range(10_000_000))
def v1():
return sum(l), sum(l), sum(l)
def v2():
x = y = z = 0
for v in l:
x += v
y += v
z += v
return x, y, z
assert v1() == v2()
import timeit
print(timeit.timeit("v1()", number=10, globals=globals()))
print(timeit.timeit("v2()", number=10, globals=globals()))
v2 is 6 times slower:
$ python3 t.py
2.568303665
14.879553143
So I'm not sure it'd be a win even here 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have actually tested out my suggestion before making it! 🔬
Funny but my initial thought was to use functools.reduce
but that's even slower:
def v3():
return functools.reduce(lambda x,y: (x[0]+y, x[1]+y, x[2]+y), l, (0,0,0))
Which takes ~21s.
* feat(profiling): introduce memalloc collector This is a new memory allocation profiler that directly leverages the CPython memory API. It tracks memory allocation events. * feat(profiling): export MemoryAllocSampleEvent to pprof * feat(profiling): allow to use memalloc collector This adds a environment variable to opt-int to the new memory profiler. Co-authored-by: Tahir H. Butt <tahir.butt@datadoghq.com>
* feat(profiling): introduce memalloc collector This is a new memory allocation profiler that directly leverages the CPython memory API. It tracks memory allocation events. * feat(profiling): export MemoryAllocSampleEvent to pprof * feat(profiling): allow to use memalloc collector This adds a environment variable to opt-int to the new memory profiler. Co-authored-by: Tahir H. Butt <tahir.butt@datadoghq.com>
feat(profiling): introduce memalloc collector
This is a new memory allocation profiler that directly leverages the CPython
memory API. It tracks memory allocation events.
feat(profiling): export MemoryAllocSampleEvent to pprof
feat(profiling): allow to use memalloc collector