llogiq / flame

An intrusive flamegraph profiling tool for rust.
Apache License 2.0
694 stars 30 forks source link

Cross-crate flamegraph #37

Closed sharksforarms closed 6 years ago

sharksforarms commented 6 years ago

Hello, I'm trying to use this across multiple crates, is this possible?

TyOverby commented 6 years ago

Yes; if both crates have the same flame version, then everything should work out.

sharksforarms commented 6 years ago

Ok so if I do nightly only without feature-guarding it it works, but with feature guards it doesn't

https://github.com/sharksforarms/testflame

cargo +nightly run --features flame_it

Doesn't seem to get the flame'd functions which aren't in the main crate i.e. myothercrate::hello_world_from_other

sharksforarms commented 6 years ago

Maybe related? https://github.com/rust-lang/cargo/issues/4106

TyOverby commented 6 years ago

Your repo only has a readme file in it. Can you publish again?

sharksforarms commented 6 years ago

Done

TyOverby commented 6 years ago

I think that the problem is that this line where you import your subcrate needs to enable it's own feature.

the features that are both named flame_it are not the same between crates.

sharksforarms commented 6 years ago

Right, I changed it to this myothercrate = { path = "./myothercrate", features = ["flame_it"] }

And it works. But now that means that the dependency myothercrate is always compiling with the flame_it feature

sharksforarms commented 6 years ago

I think I got it!

Using the / syntax in features = [], funny enough I found out about this syntax in this ticket: https://github.com/rust-lang/cargo/issues/5139

[package]
name = "testflame"
version = "0.1.0"
authors = ["sharks"]

[workspace]
members = [
    "myothercrate"
]

[dependencies]
myothercrate = {path = "./myothercrate", version = "0.1.0"}
flame = {version = "0.2.2", optional = true}
flamer = {version = "^0.2.1", optional = true}

[features]
default = []
flame_it = ["flame", "flamer", "myothercrate/flame_it"]
TyOverby commented 6 years ago

oh nice! Yeah, I gotta say I've never used features beyond the most trivial.

Looks like I can close this for now; if you run into anything else feel free to re-open or make a new issue!