Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update dependendies (ahash, quick-xml) #258

Merged
merged 8 commits into from Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 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 Cargo.toml
Expand Up @@ -22,7 +22,7 @@ multithreaded = ["dashmap", "crossbeam-utils", "crossbeam-channel", "num_cpus"]
nameattr = ["indexmap"]

[dependencies]
ahash = "0.7"
ahash = "0.8"
atty = "0.2"
crossbeam-utils = { version = "0.8", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
Expand All @@ -33,7 +33,7 @@ itoa = "1"
log = "0.4"
num_cpus = { version = "1.10", optional = true }
num-format = { version = "0.4.3", default-features = false }
quick-xml = { version = "0.23", default-features = false }
quick-xml = { version = "0.26", default-features = false }
rgb = "0.8.13"
str_stack = "0.1"
clap = { version = "3.0.1", optional = true, features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion src/flamegraph/color/mod.rs
Expand Up @@ -205,7 +205,7 @@ impl FromStr for StrokeColor {
return Ok(StrokeColor::None);
}
parse_flat_bgcolor(s)
.map(|c| StrokeColor::Color(c))
.map(StrokeColor::Color)
.ok_or_else(|| format!("unknown color: {}", s))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/flamegraph/color/palettes.rs
Expand Up @@ -73,7 +73,7 @@ pub(super) mod python {
part.strip_prefix("python")
.or_else(|| part.strip_prefix("Python"))
.map_or(false, |version| {
version.chars().all(|c| c.is_digit(10) || c == '.')
version.chars().all(|c| c.is_ascii_digit() || c == '.')
})
}) || name.starts_with("<built-in")
|| name.starts_with("<method")
Expand Down
36 changes: 17 additions & 19 deletions src/flamegraph/mod.rs
Expand Up @@ -478,7 +478,7 @@ where
extra: None,
},
)?;
svg.write_event(Event::End(BytesEnd::borrowed(b"svg")))?;
svg.write_event(Event::End(BytesEnd::new("svg")))?;
svg.write_event(Event::Eof)?;
return Err(quick_xml::Error::Io(io::Error::new(
io::ErrorKind::InvalidData,
Expand Down Expand Up @@ -526,23 +526,21 @@ where
let mut thread_rng = rand::thread_rng();

// structs to reuse across loops to avoid allocations
let mut cache_g = Event::Start(BytesStart::owned_name("g"));
let mut cache_a = Event::Start(BytesStart::owned_name("a"));
let mut cache_rect = Event::Empty(BytesStart::owned_name("rect"));
let cache_g_end = Event::End(BytesEnd::borrowed(b"g"));
let cache_a_end = Event::End(BytesEnd::borrowed(b"a"));
let mut cache_g = Event::Start(BytesStart::new("g"));
let mut cache_a = Event::Start(BytesStart::new("a"));
let mut cache_rect = Event::Empty(BytesStart::new("rect"));
let cache_g_end = Event::End(BytesEnd::new("g"));
let cache_a_end = Event::End(BytesEnd::new("a"));

// create frames container
let container_x = format!("{}", XPAD);
let container_width = format!("{}", image_width as usize - XPAD - XPAD);
svg.write_event(Event::Start(
BytesStart::borrowed_name(b"svg").with_attributes(vec![
("id", "frames"),
("x", &container_x),
("width", &container_width),
("total_samples", &format!("{}", timemax)),
]),
))?;
svg.write_event(Event::Start(BytesStart::new("svg").with_attributes(vec![
("id", "frames"),
("x", &container_x),
("width", &container_width),
("total_samples", &format!("{}", timemax)),
])))?;

// draw frames
let mut samples_txt_buffer = num_format::Buffer::default();
Expand Down Expand Up @@ -625,9 +623,9 @@ where
&buffer[info],
)?;

svg.write_event(Event::Start(BytesStart::borrowed_name(b"title")))?;
svg.write_event(Event::Text(BytesText::from_plain_str(title)))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"title")))?;
svg.write_event(Event::Start(BytesStart::new("title")))?;
svg.write_event(Event::Text(BytesText::new(title)))?;
svg.write_event(Event::End(BytesEnd::new("title")))?;

// select the color of the rectangle
let color = if frame.location.function == "--" {
Expand Down Expand Up @@ -710,8 +708,8 @@ where
}
}

svg.write_event(Event::End(BytesEnd::borrowed(b"svg")))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"svg")))?;
svg.write_event(Event::End(BytesEnd::new("svg")))?;
svg.write_event(Event::End(BytesEnd::new("svg")))?;
svg.write_event(Event::Eof)?;

svg.into_inner().flush()?;
Expand Down
103 changes: 45 additions & 58 deletions src/flamegraph/svg.rs
Expand Up @@ -3,7 +3,7 @@ use std::cell::RefCell;
use std::io::prelude::*;
use std::iter;

use quick_xml::events::{BytesCData, BytesEnd, BytesStart, BytesText, Event};
use quick_xml::events::{BytesCData, BytesDecl, BytesEnd, BytesStart, BytesText, Event};
use quick_xml::Writer;
use str_stack::StrStack;

Expand Down Expand Up @@ -62,27 +62,25 @@ pub(super) fn write_header<W>(
where
W: Write,
{
svg.write(br#"<?xml version="1.0" standalone="no"?>"#)?;
svg.write(br#"<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">"#)?;
svg.write_event(Event::Decl(BytesDecl::new("1.0", None, Some("no"))))?;
svg.write_event(Event::DocType(BytesText::from_escaped(r#"svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd""#)))?;
let imagewidth = opt.image_width.unwrap_or(super::DEFAULT_IMAGE_WIDTH);
svg.write_event(Event::Start(
BytesStart::borrowed_name(b"svg").with_attributes(vec![
("version", "1.1"),
("width", &*format!("{}", imagewidth)),
("height", &*format!("{}", imageheight)),
("onload", "init(evt)"),
("viewBox", &*format!("0 0 {} {}", imagewidth, imageheight)),
("xmlns", "http://www.w3.org/2000/svg"),
("xmlns:xlink", "http://www.w3.org/1999/xlink"),
("xmlns:fg", "http://github.com/jonhoo/inferno"),
]),
))?;
svg.write_event(Event::Comment(BytesText::from_plain_str(
svg.write_event(Event::Start(BytesStart::new("svg").with_attributes(vec![
("version", "1.1"),
("width", &*format!("{}", imagewidth)),
("height", &*format!("{}", imageheight)),
("onload", "init(evt)"),
("viewBox", &*format!("0 0 {} {}", imagewidth, imageheight)),
("xmlns", "http://www.w3.org/2000/svg"),
("xmlns:xlink", "http://www.w3.org/1999/xlink"),
("xmlns:fg", "http://github.com/jonhoo/inferno"),
])))?;
svg.write_event(Event::Comment(BytesText::new(
"Flame graph stack visualization. \
See https://github.com/brendangregg/FlameGraph for latest version, \
and http://www.brendangregg.com/flamegraphs.html for examples.",
)))?;
svg.write_event(Event::Comment(BytesText::from_plain_str(
svg.write_event(Event::Comment(BytesText::new(
format!("NOTES: {}", opt.notes).as_str(),
)))?;
Ok(())
Expand All @@ -96,28 +94,22 @@ pub(super) fn write_prelude<'a, W>(
where
W: Write,
{
svg.write_event(Event::Start(BytesStart::borrowed_name(b"defs")))?;
svg.write_event(Event::Start(BytesStart::borrowed(
br#"linearGradient id="background" y1="0" y2="1" x1="0" x2="0""#,
svg.write_event(Event::Start(BytesStart::new("defs")))?;
svg.write_event(Event::Start(BytesStart::from_content(
r#"linearGradient id="background" y1="0" y2="1" x1="0" x2="0""#,
"linearGradient".len(),
)))?;
svg.write_event(Event::Empty(
BytesStart::borrowed_name(b"stop").with_attributes(
iter::once(("stop-color", &*style_options.bgcolor1))
.chain(iter::once(("offset", "5%"))),
),
))?;
svg.write_event(Event::Empty(
BytesStart::borrowed_name(b"stop").with_attributes(
iter::once(("stop-color", &*style_options.bgcolor2))
.chain(iter::once(("offset", "95%"))),
),
))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"linearGradient")))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"defs")))?;
svg.write_event(Event::Empty(BytesStart::new("stop").with_attributes(
iter::once(("stop-color", &*style_options.bgcolor1)).chain(iter::once(("offset", "5%"))),
)))?;
svg.write_event(Event::Empty(BytesStart::new("stop").with_attributes(
iter::once(("stop-color", &*style_options.bgcolor2)).chain(iter::once(("offset", "95%"))),
)))?;
svg.write_event(Event::End(BytesEnd::new("linearGradient")))?;
svg.write_event(Event::End(BytesEnd::new("defs")))?;

svg.write_event(Event::Start(
BytesStart::borrowed_name(b"style").with_attributes(iter::once(("type", "text/css"))),
BytesStart::new("style").with_attributes(iter::once(("type", "text/css"))),
))?;

let font_type: Cow<str> = if GENERIC_FONT_FAMILIES.contains(&opt.font_type.as_str()) {
Expand All @@ -127,29 +119,28 @@ where
};

let titlesize = &opt.font_size + 5;
svg.write_event(Event::Text(BytesText::from_escaped_str(&format!(
svg.write_event(Event::Text(BytesText::from_escaped(&format!(
"
text {{ font-family:{}; font-size:{}px; fill:rgb(0,0,0); }}
#title {{ text-anchor:middle; font-size:{}px; }}
",
font_type, &opt.font_size, titlesize,
))))?;
if let Some(strokecolor) = &style_options.strokecolor {
svg.write_event(Event::Text(BytesText::from_escaped_str(&format!(
svg.write_event(Event::Text(BytesText::from_escaped(&format!(
"#frames > g > rect {{ stroke:{}; stroke-width:1; }}\n",
strokecolor
))))?;
}
svg.write_event(Event::Text(BytesText::from_escaped_str(include_str!(
svg.write_event(Event::Text(BytesText::from_escaped(include_str!(
"flamegraph.css"
))))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"style")))?;
svg.write_event(Event::End(BytesEnd::new("style")))?;

svg.write_event(Event::Start(
BytesStart::borrowed_name(b"script")
.with_attributes(iter::once(("type", "text/ecmascript"))),
BytesStart::new("script").with_attributes(iter::once(("type", "text/ecmascript"))),
))?;
svg.write_event(Event::CData(BytesCData::from_str(&format!(
svg.write_event(Event::CData(BytesCData::new(&format!(
"
var nametype = {};
var fontsize = {};
Expand All @@ -169,21 +160,17 @@ text {{ font-family:{}; font-size:{}px; fill:rgb(0,0,0); }}
opt.text_truncate_direction == TextTruncateDirection::Right
))))?;
if !opt.no_javascript {
svg.write_event(Event::CData(BytesCData::from_str(include_str!(
"flamegraph.js"
))))?;
svg.write_event(Event::CData(BytesCData::new(include_str!("flamegraph.js"))))?;
}
svg.write_event(Event::End(BytesEnd::borrowed(b"script")))?;
svg.write_event(Event::End(BytesEnd::new("script")))?;

svg.write_event(Event::Empty(
BytesStart::borrowed_name(b"rect").with_attributes(vec![
("x", "0"),
("y", "0"),
("width", "100%"),
("height", &*format!("{}", style_options.imageheight)),
("fill", "url(#background)"),
]),
))?;
svg.write_event(Event::Empty(BytesStart::new("rect").with_attributes(vec![
("x", "0"),
("y", "0"),
("width", "100%"),
("height", &*format!("{}", style_options.imageheight)),
("fill", "url(#background)"),
])))?;

// We don't care too much about allocating just for the prelude
let mut buf = StrStack::new();
Expand Down Expand Up @@ -284,7 +271,7 @@ where

thread_local! {
// reuse for all text elements to avoid allocations
static TEXT: RefCell<Event<'static>> = RefCell::new(Event::Start(BytesStart::owned_name("text")))
static TEXT: RefCell<Event<'static>> = RefCell::new(Event::Start(BytesStart::new("text")))
};
TEXT.with(|start_event| {
if let Event::Start(ref mut text) = *start_event.borrow_mut() {
Expand All @@ -304,8 +291,8 @@ where
TextArgument::String(ref s) => s,
TextArgument::FromBuffer(i) => &buf[i],
};
svg.write_event(Event::Text(BytesText::from_plain_str(s)))?;
svg.write_event(Event::End(BytesEnd::borrowed(b"text")))
svg.write_event(Event::Text(BytesText::new(s)))?;
svg.write_event(Event::End(BytesEnd::new("text")))
}

// Imported from the `enquote` crate @ 1.0.3.
Expand Down
2 changes: 1 addition & 1 deletion tests/common/collapse.rs
Expand Up @@ -15,7 +15,7 @@ where
let mut line_num = 1;
for line in result.lines() {
let line = if strip_quotes {
line.unwrap().replace("\"", "").replace("'", "")
line.unwrap().replace('\"', "").replace('\'', "")
} else {
line.unwrap()
};
Expand Down
4 changes: 3 additions & 1 deletion tests/data/flamegraph/austin/flame.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/colors/async-profiler-java.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/colors/deterministic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/colors/java.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/colors/js.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/differential/diff-negated.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion tests/data/flamegraph/differential/diff.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.