tikv / pprof-rs

A Rust CPU profiler implemented with the help of backtrace-rs
Apache License 2.0
1.32k stars 104 forks source link

Error: Could not find protos in pprof #104

Closed shippomx closed 2 years ago

shippomx commented 2 years ago

Env

$ cargo --version
cargo 1.58.0 (f01b232bc 2022-01-19)

I create a new project with cargo new test command. And replace the test/src/main.rs with examples/profile_proto.rs. Then add the pprof = "0.6.2" to Cargo.toml like this:

[dependencies]
pprof = "0.6.2"

But I got the result after run the test project:

$ cargo run
   Compiling learn v0.1.0 (/home/echo/workspace/rust/test)
error[E0432]: unresolved import `pprof::protos`
 --> src/main.rs:4:12
  |
4 | use pprof::protos::Message;
  |            ^^^^^^ could not find `protos` in `pprof`

error[E0599]: no method named `pprof` found for struct `Report` in the current scope
   --> src/main.rs:108:34
    |
108 |             let profile = report.pprof().unwrap();
    |                                  ^^^^^ method not found in `Report`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `learn` due to 2 previous errors

What should I do to solve this problem?

YangKeao commented 2 years ago

Please enable the feature protobuf

shippomx commented 2 years ago

Please enable the feature protobuf

If add the param --feateure="protobuf" and fix the Cargo.toml like this:

[features]
protobuf = ["prost", "prost-derive", "prost-build"]

[dependencies]
pprof = "0.6.2"
prost = { version = "0.9", optional = true }
prost-derive = { version = "0.9", optional = true }
criterion = {version = "0.3", optional = true}

[build-dependencies]
prost-build = { version = "0.9", optional = true }

it will produce the error at the same. Can you show me the your Cargo.toml in a totally new project ?

YangKeao commented 2 years ago
pprof = { version = "0.6.2", features = ["protobuf"] }

@shippomx

shippomx commented 2 years ago

thanks, it works!