pprof-rs
pprof-rs copied to clipboard
Support protobuf as message encoder
As tikv use rust-protobuf
by default, pprof-rs
should support rust-protobuf
to reduce unnecessary dependency.
Any progress on this?
So the pprof
example in the README does not work (yet)? It seems to be not compiling with the example:
// main.rs
use pprof;
use prost::message::Message;
fn main() {
let pprof_guard = pprof::ProfilerGuard::new(100).unwrap();
// Do something here...
if let Ok(report) = pprof_guard.report().build() {
let mut report_file = File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();
let mut profile_data = vec![];
profile.encode(&mut profile_data).unwrap();
report_file.write_all(&profile_data).unwrap();
println!("Request profiled");
}
}
together with this Cargo.toml
:
[package]
name = "test"
version = "0.1.0"
authors = ["i <[email protected]>"]
edition = "2018"
[dependencies]
pprof = { version = "0.3", features = ["protobuf", "flamegraph"]}
The error was:
error[E0433]: failed to resolve: use of undeclared type or module `prost`
--> src/main.rs:22:5
|
1 | use prost::message::Message;
| ^^^^^ use of undeclared type or module `prost`
error[E0599]: no method named `encode` found for type `pprof::protos::Profile` in the current scope
--> src/main.rs:124:17
|
14 | profile.encode(&mut profile_data).unwrap();
| ^^^^^^ method not found in `pprof::protos::Profile`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
3 | use prost::message::Message;
|
error: aborting due to 2 previous errors
@JokerQyou Sorry. I forget to update example (after #13). This is because you should import pprof::protos::Message
rather than prost::message::Message
to avoid dependency conflict.
Replace use prost::message::Message
with use pprof::protos::Message
can make this example work.
Currently, in version 0.11.1, the last commented part about using use pprof::protos::Message
still does not work, the error remains:
error[E0599]: no method named `encode` found for struct `Profile` in the current scope
--> client/src/main.rs:55:17
|
55 | profile.encode(&mut content).unwrap();
| ^^^^^^ method not found in `Profile`
I'm using:
pprof = { version = "0.11.1", features = ["protobuf-codec", "flamegraph"] }
and
fn main() {
let frequency = 1000;
let guard = pprof::ProfilerGuard::new(frequency).unwrap();
// Do something here...
if let Ok(report) = guard.report().build() {
let profile = report.pprof().unwrap();
let mut content = Vec::new();
profile.encode(&mut content).unwrap();
file.write_all(&content).unwrap();
println!("report: {:#?}", &report);
process::exit(0);
};
}
Currently, in version 0.11.1, the last commented part about using use
pprof::protos::Message
still does not work, the error remains:error[E0599]: no method named `encode` found for struct `Profile` in the current scope --> client/src/main.rs:55:17 | 55 | profile.encode(&mut content).unwrap(); | ^^^^^^ method not found in `Profile`
I'm using:
pprof = { version = "0.11.1", features = ["protobuf-codec", "flamegraph"] }
and
fn main() { let frequency = 1000; let guard = pprof::ProfilerGuard::new(frequency).unwrap(); // Do something here... if let Ok(report) = guard.report().build() { let profile = report.pprof().unwrap(); let mut content = Vec::new(); profile.encode(&mut content).unwrap(); file.write_all(&content).unwrap(); println!("report: {:#?}", &report); process::exit(0); }; }
Have you been able to solve this problem? I have the same.
Currently, in version 0.11.1, the last commented part about using use
pprof::protos::Message
still does not work, the error remains:error[E0599]: no method named `encode` found for struct `Profile` in the current scope --> client/src/main.rs:55:17 | 55 | profile.encode(&mut content).unwrap(); | ^^^^^^ method not found in `Profile`
I'm using:
pprof = { version = "0.11.1", features = ["protobuf-codec", "flamegraph"] }
and
fn main() { let frequency = 1000; let guard = pprof::ProfilerGuard::new(frequency).unwrap(); // Do something here... if let Ok(report) = guard.report().build() { let profile = report.pprof().unwrap(); let mut content = Vec::new(); profile.encode(&mut content).unwrap(); file.write_all(&content).unwrap(); println!("report: {:#?}", &report); process::exit(0); }; }
Have you been able to solve this problem? I have the same.
I have the same