pprof-rs icon indicating copy to clipboard operation
pprof-rs copied to clipboard

Support protobuf as message encoder

Open YangKeao opened this issue 5 years ago • 6 comments

As tikv use rust-protobuf by default, pprof-rs should support rust-protobuf to reduce unnecessary dependency.

YangKeao avatar Feb 05 '20 10:02 YangKeao

Any progress on this?

BusyJay avatar Feb 10 '20 15:02 BusyJay

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 avatar Feb 28 '20 07:02 JokerQyou

@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.

YangKeao avatar Feb 28 '20 07:02 YangKeao

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);
      };
}

padinsky avatar May 08 '23 07:05 padinsky

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.

Megavolv avatar Jun 28 '23 07:06 Megavolv

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

Cheban1996 avatar Dec 22 '23 18:12 Cheban1996