Skip to content

Commit

Permalink
feat(common-pprof): use prost
Browse files Browse the repository at this point in the history
  • Loading branch information
evenyag committed Jun 2, 2023
1 parent 9af12fb commit 751c3ba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/common/pprof/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ license.workspace = true
common-error = { path = "../error" }
pprof = { version = "0.11.1", features = [
"flamegraph",
"protobuf-codec",
"prost-codec",
"protobuf",
] }
protobuf = "2"
prost.workspace = true
snafu.workspace = true
tokio.workspace = true
9 changes: 2 additions & 7 deletions src/common/pprof/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::any::Any;
use std::time::Duration;

use common_error::prelude::{ErrorExt, StatusCode};
use pprof::protos::Message;
use prost::Message;
use snafu::{ResultExt, Snafu};

#[derive(Debug, Snafu)]
Expand All @@ -32,9 +32,6 @@ pub enum Error {

#[snafu(display("Failed to create pprof report, source: {}", source))]
ReportPprof { source: pprof::Error },

#[snafu(display("Failed to write report, source: {}", source))]
WriteReport { source: protobuf::ProtobufError },
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -93,12 +90,10 @@ impl Profiling {

/// Profiles and returns a generated proto.
pub async fn dump_proto(&self) -> Result<Vec<u8>> {
let mut body: Vec<u8> = Vec::new();

let report = self.report().await?;
// Generate google’s pprof format report.
let profile = report.pprof().context(ReportPprofSnafu)?;
profile.write_to_vec(&mut body).context(WriteReportSnafu)?;
let body = profile.encode_to_vec();

Ok(body)
}
Expand Down

0 comments on commit 751c3ba

Please sign in to comment.