Skip to content

ENH: add support for python3.6 memory tracing #8885

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

Merged
merged 2 commits into from
Apr 30, 2017

Conversation

juliantaylor
Copy link
Contributor

Python 3.6 added a private API for tracing arbitrary memory allocations
so the tracemalloc module [0] can be used with numpy.

closes gh-4663

As it is a private api it might not be mergeable (though its not the first private api we are using), but people may want to play around with it now.

[0] https://docs.python.org/3/library/tracemalloc.html

@charris
Copy link
Member

charris commented Apr 3, 2017

@juliantaylor Could you add a release note?

@juliantaylor
Copy link
Contributor Author

bigger question is whether we want to merge use of a private api?
I guess if we add an extra check on the existence of the function it's probably reasonable.

@charris
Copy link
Member

charris commented Apr 3, 2017

OK, let's put this off to 1.14. At this point I'm just waiting on __array_ufunc__ before branching 1.13.

@juliantaylor
Copy link
Contributor Author

I don't think this is particularly risky. We can also put a version == 3.6 check that we update each release.

@vstinner
Copy link
Contributor

"#define NPY_TRACE_DOMAIN 389047" why 389047 and not 0?

I added a domain parameter because @njsmith said that numpy may allocate memory in the GPU, and CPU and GPU address spaces can overlap:
http://bugs.python.org/issue26530#msg261630

About the version: CPython 3.7 will likely rename the track/untrack functions to make them public, but it will be trivial to update your patch for this change.
http://bugs.python.org/issue30054

For CPython 3.6: I'm the author and the functions and I don't plan to modify or remove them in a stable release.

@juliantaylor
Copy link
Contributor Author

My though was to allow easy filtering of all allocations that numpy does. numpy allocations are usually large while python (domain 0) are loads of small things.

@vstinner
Copy link
Contributor

tracemalloc allows you to filter by filename:
https://docs.python.org/dev/library/tracemalloc.html#tracemalloc.Snapshot.filter_traces

Domains is something new in Python 3.6, I didn't use it to track a memory leak. Not all tracemalloc support domains. For example, tracemalloc.get_traced_memory() counts traces of all the domain.

It's up to you to use a different domain.

@juliantaylor
Copy link
Contributor Author

I find using domains for this is more elegant than filename filters. It doesn't prevent you from using them either as long as traceutils doesn't filter out domains unless you ask it to.

@vstinner
Copy link
Contributor

vstinner commented Apr 12, 2017 via email

@juliantaylor
Copy link
Contributor Author

Sure you could make it configurable. Not sure if its worth the effort though. Why would you want to configure it?

@vstinner
Copy link
Contributor

vstinner commented Apr 12, 2017 via email

@juliantaylor
Copy link
Contributor Author

Would using domain 0 for numpy bring any advantages?
Only thing I can think of an other library you don't want to see uses a gpu memory domain and you might then filter only on domain 0 and miss the numpy memory domain. But that error pretty easy to discover by putting domain into the Statistic representation, currently it does not store the domain at all.

@juliantaylor juliantaylor force-pushed the tracemalloc branch 2 times, most recently from ab28cda to 181b309 Compare April 22, 2017 11:26
@juliantaylor juliantaylor added this to the 1.13.0 release milestone Apr 22, 2017
@juliantaylor
Copy link
Contributor Author

I think this should still be in 1.13, it is pretty simple and it will be a public api in python3.7 so we can pretty safely use it now.

@charris
Copy link
Member

charris commented Apr 22, 2017

@juliantaylor Needs a release note.

@charris charris added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Apr 22, 2017
@charris
Copy link
Member

charris commented Apr 24, 2017

@juliantaylor Could you update the release notes?

Python 3.6 added a private API for tracing arbitrary memory allocations
so the tracemalloc module [0] can be used with numpy.

closes numpygh-4663

[0] https://docs.python.org/3/library/tracemalloc.html
add numpy.distutils and tracemalloc changes and fix some issues.

[ci skip]
@juliantaylor juliantaylor removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Apr 28, 2017
@charris charris merged commit 590faca into numpy:master Apr 30, 2017
@charris
Copy link
Member

charris commented Apr 30, 2017

Thanks Julian.

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

Successfully merging this pull request may close these issues.

Switch to routing allocations through Python's allocators on py35
3 participants