Skip to content

pprof example does not compile #273

Open
@LanHikari22

Description

@LanHikari22

The example in https://github.com/tikv/pprof-rs?tab=readme-ov-file#use-with-pprof does not compile. I had to make some changes:

First, we need to enable the prost-codec instead of protobuf feature in Cargo.toml (but documentation mentions to use protobuf):

pprof = { version = "0.15.0", features = ["prost-codec"] }

for the report println, had to change {} to {:?} because the report does not implement Display

Then in the code,

use pprof::protos::Message;
use std::fs::File;
use std::io::Write;

[...]

// Added in program start
let guard = pprof::ProfilerGuardBuilder::default().frequency(1000).blocklist(&["libc", "libgcc", "pthread", "vdso"]).build().unwrap();

[...]

// For output in profile.proto format:
match guard.report().build() {
    Ok(report) => {
        let mut file = File::create("profile.pb").unwrap();
        let profile = report.pprof().unwrap();

        let mut content = Vec::new();
        profile.encode(&mut content).unwrap();
        file.write_all(&content).unwrap();

        println!("report: {:?}", &report);
    }
    Err(_) => {}
};

This works. But if we had used protobuf feature, or did not include pprof::protos::Message we would have issue with profile.encode not being found.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions