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

Use as a library #110

Closed
sophiebits-humu opened this issue Apr 17, 2019 · 1 comment
Closed

Use as a library #110

sophiebits-humu opened this issue Apr 17, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@sophiebits-humu
Copy link

Similar to #74 – for building infrastructure on top of py-spy it would be nice if there was a supported programmatic API for using py-spy functionality from a larger Rust program.

(In my case, I was thinking of taking occasional samples from running processes and logging them to a central database for "global profiling" analysis across many machines and a long time period.)

@benfred benfred added the enhancement New feature or request label May 5, 2019
benfred added a commit that referenced this issue Jul 7, 2019
This change lets py-spy be used as a rust library. This allows you to write
rust code to connect to a python program and take a stack trace from it.

Most of this change is in adding some basic documentation on how to do this,
and adding a src/lib.rs that exports a couple of the core py-spy classes.
Note that we're only exposing a very minimal set of functionality right now,
and leaving things like the consoleviewer/flamegraph code out of this library.

#110
@benfred
Copy link
Owner

benfred commented Jul 7, 2019

Thanks! I think this is a great idea, and just exposing as a rust library isn't a big change at all.

You can use py-spy 0.1.11 as a library with that last PR (#126). The exposed API is pretty basic and only covers the core use case of getting samples from a target process, and doesn't include things like the flamegraph/console code . The API's here might change a bit until we hit a 1.0 release, but by limiting the exposed public API I'm hoping to minimize breaking changes to anyone that might use this crate.

I've created an example https://github.com/benfred/py-spy/blob/master/examples/dump_traces.rs that shows how to use this, and there is some very basic documentation on the exposed API's here https://docs.rs/py-spy/0.1.11/py_spy/

I've also been thinking about exposing a python api w/ py03 (and even wrote up a blog post about the approach last year) - but exposing py-spy as a rust library will let anyone who is interested build the python bindings themselves using the steps in that post.

edit: moved repo to file in examples/ folder

@benfred benfred closed this as completed Jul 7, 2019
benfred added a commit to benfred/remoteprocess that referenced this issue Nov 17, 2019
This change lets py-spy be used as a rust library. This allows you to write
rust code to connect to a python program and take a stack trace from it.

Most of this change is in adding some basic documentation on how to do this,
and adding a src/lib.rs that exports a couple of the core py-spy classes.
Note that we're only exposing a very minimal set of functionality right now,
and leaving things like the consoleviewer/flamegraph code out of this library.

benfred/py-spy#110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants