Is there a preferred approach to profiling rust on...
# development
f
Is there a preferred approach to profiling rust on osx? I see some old messages recommending Instruments but I'm not really familiar with using that. I found https://github.com/tikv/pprof-rs which looks interesting, would integrating something like this into pants be helpful to others? In theory this can ship with pants so users could profile using a cli flag and output a flame graph
h
Assuming it doesn’t materially add to the build time of the engine, it could be a good idea. Although we try to be parsimonious in adding 3rdparty deps since every one is a vector for a supply chain attack.
@wide-midnight-78598 has opinions on this
So, I guess, we’d have to agree that this is worth it? Alternatively we can set things up so that it’s easy to build your own pants with the profiler, but it’s not in the distributed binary?
w
Oh, I have opinions all right… We’re already rocking about 60 cargo deps - so there’s that 😆 I haven’t dug into that specific library, but a couple thoughts: • Does that have any impact on runtime when it’s not in use? In my experience, profilers need to do a bunch of instrumentation, so can that be noop’d at runtime with a flag? • Does this open us up to “what about adding Profiler XYZ”? • Once it gets added and then exposed to a CLI, it’s basically a permanent fixture to Pants • What set of feature flags would we ship our binary with (I’m not entirely sure if pprof’s “features” are compile time or strictly runtime)? The pros/cons list on pprof wasn’t really convincing for me, but I do think there is a world where we have a feature gated profiling mode - which doesn’t ship with the Pants binary, but makes it easier to build from source with profilers integrated 🤷
I spent a lot of time profiling Pants last summer, and it wasn’t easy simple - so I’m absolutely all for improving that experience - but I also appreciate that each of these tools has their pros/cons, and different platforms have different tools which can be better situationally. A path forward, I guess, could be integrating pprof as a feature-gated thing when building from source, and seeing how valuable it is over a few releases… If we think it’s invaluable, then maybe consider exposing it to the world…
Also, this is the methodology I used mostly: https://www.pantsbuild.org/stable/docs/contributions/development/debugging-and-benchmarking Though, I might have swapped to Linux for a couple of tools - would have to check my notes
f
That guide has been helpful to me, definitely appreciate the work that went into it. My recollection of trying py-spy on osx was that native profiling didn't work. (I can dig up the issue if anyone is curious) Which is how I started looking for other ways to do this that didn't involve swapping my workstation out
w
Maybe it was py-spy for me, or I thought that one wanted sudo (which I don't give anything on my primary machine)