Skip to content

Commit 83229dd

Browse files
Generate links to flamegraph and crox
1 parent 9a53e53 commit 83229dd

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bytes = "0.5.6"
4242
url = "2"
4343
analyzeme = { git = "https://github.com/rust-lang/measureme" }
4444
tar = "0.4"
45-
inferno = { version="0.9.1", default-features = false }
45+
inferno = { version="0.10", default-features = false }
4646
mime = "0.3"
4747

4848
[dependencies.collector]

site/src/flamegraph.svg

Whitespace-only changes.

site/src/self_profile.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,36 @@ type Response = http::Response<hyper::Body>;
1414
pub mod crox;
1515
pub mod flamegraph;
1616

17+
pub struct Output {
18+
pub data: Vec<u8>,
19+
pub filename: &'static str,
20+
pub is_download: bool,
21+
}
22+
1723
pub fn generate(
24+
title: &str,
1825
pieces: Pieces,
1926
mut params: HashMap<String, String>,
20-
) -> anyhow::Result<(&'static str, Vec<u8>)> {
27+
) -> anyhow::Result<Output> {
2128
let removed = params.remove("type");
2229
match removed.as_deref() {
2330
Some("crox") => {
2431
let opt = serde_json::from_str(&serde_json::to_string(&params).unwrap())
2532
.context("crox opts")?;
26-
Ok((
27-
"chrome_profiler.json",
28-
crox::generate(pieces, opt).context("crox")?,
29-
))
33+
Ok(Output {
34+
filename: "chrome_profiler.json",
35+
data: crox::generate(pieces, opt).context("crox")?,
36+
is_download: true,
37+
})
3038
}
3139
Some("flamegraph") => {
3240
let opt = serde_json::from_str(&serde_json::to_string(&params).unwrap())
3341
.context("flame opts")?;
34-
Ok((
35-
"flamegraph.svg",
36-
flamegraph::generate(pieces, opt).context("flame")?,
37-
))
42+
Ok(Output {
43+
filename: "flamegraph.svg",
44+
data: flamegraph::generate(title, pieces, opt).context("flame")?,
45+
is_download: false,
46+
})
3847
}
3948
_ => anyhow::bail!("Unknown type, specify type={crox,flamegraph}"),
4049
}

site/src/self_profile/flamegraph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use inferno::flamegraph::{from_lines, Options as FlamegraphOptions};
55
#[derive(serde::Deserialize, Debug)]
66
pub struct Opt {}
77

8-
pub fn generate(pieces: super::Pieces, _: Opt) -> anyhow::Result<Vec<u8>> {
8+
pub fn generate(title: &str, pieces: super::Pieces, _: Opt) -> anyhow::Result<Vec<u8>> {
99
let profiling_data =
1010
ProfilingData::from_buffers(pieces.string_data, pieces.string_index, pieces.events)
1111
.map_err(|e| anyhow::format_err!("{:?}", e))?;
@@ -17,6 +17,7 @@ pub fn generate(pieces: super::Pieces, _: Opt) -> anyhow::Result<Vec<u8>> {
1717

1818
let mut file = Vec::new();
1919
let mut flamegraph_options = FlamegraphOptions::default();
20+
flamegraph_options.title = title.to_owned();
2021

2122
from_lines(
2223
&mut flamegraph_options,

site/src/server.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,15 @@ pub async fn handle_self_profile_processed_download(
790790
params: HashMap<String, String>,
791791
data: &InputData,
792792
) -> Response {
793+
let title = format!("{}: {} {}", body.commit, body.benchmark, body.run_name);
793794
let start = Instant::now();
794795
let pieces = match crate::self_profile::get_pieces(body, data).await {
795796
Ok(v) => v,
796797
Err(e) => return e,
797798
};
798799
log::trace!("got pieces {:?} in {:?}", pieces, start.elapsed());
799800

800-
let (filename, json) = match crate::self_profile::generate(pieces, params) {
801+
let output = match crate::self_profile::generate(&title, pieces, params) {
801802
Ok(c) => c,
802803
Err(e) => {
803804
log::error!("Failed to generate json {:?}", e);
@@ -807,22 +808,24 @@ pub async fn handle_self_profile_processed_download(
807808
}
808809
};
809810
let mut builder = http::Response::builder()
810-
.header_typed(if filename.ends_with("json") {
811+
.header_typed(if output.filename.ends_with("json") {
811812
ContentType::json()
812813
} else {
813814
ContentType::from("image/svg+xml".parse::<mime::Mime>().unwrap())
814815
})
815816
.status(StatusCode::OK);
816817

817-
builder.headers_mut().unwrap().insert(
818-
hyper::header::CONTENT_DISPOSITION,
819-
hyper::header::HeaderValue::from_maybe_shared(format!(
820-
"attachment; filename=\"{}\"",
821-
filename,
822-
))
823-
.expect("valid header"),
824-
);
825-
builder.body(hyper::Body::from(json)).unwrap()
818+
if output.is_download {
819+
builder.headers_mut().unwrap().insert(
820+
hyper::header::CONTENT_DISPOSITION,
821+
hyper::header::HeaderValue::from_maybe_shared(format!(
822+
"attachment; filename=\"{}\"",
823+
output.filename,
824+
))
825+
.expect("valid header"),
826+
);
827+
}
828+
builder.body(hyper::Body::from(output.data)).unwrap()
826829
}
827830

828831
pub async fn handle_self_profile_raw_download(

site/static/detailed-query.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,22 @@ <h3 id="title"></h3>
127127
let url = dl_url(commit, bench, run);
128128
return `<a href="${url}">Download raw results for ${commit.substring(0, 10)}</a>`;
129129
};
130+
let processed_link = (commit, bench, run, ty) => {
131+
let url = `/perf/processed-self-profile?commit=${commit}&benchmark=${bench}&run_name=${run}&type=${ty}`;
132+
return `<a href="${url}">Download/view ${ty} results for ${commit.substring(0, 10)}</a>`;
133+
};
130134
txt = dl_link(state.commit, state.benchmark, state.run_name);
135+
txt += "<br>";
136+
txt += processed_link(state.commit, state.benchmark, state.run_name, "flamegraph");
137+
txt += "<br>";
138+
txt += processed_link(state.commit, state.benchmark, state.run_name, "crox");
131139
if (state.base_commit) {
140+
txt += "<br>";
132141
txt += dl_link(state.base_commit, state.benchmark, state.run_name);
142+
txt += "<br>";
143+
txt += processed_link(state.base_commit, state.benchmark, state.run_name, "flamegraph");
144+
txt += "<br>";
145+
txt += processed_link(state.base_commit, state.benchmark, state.run_name, "crox");
133146
}
134147
document.querySelector("#raw-urls").innerHTML = txt;
135148
let sort_idx = state.sort_idx;

0 commit comments

Comments
 (0)