diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd54b1b..edfcdce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed + - Don't quote generic font families in CSS. [#252](https://github.com/jonhoo/inferno/pull/252) ### Removed diff --git a/src/flamegraph/svg.rs b/src/flamegraph/svg.rs index aab0e689..67f5684e 100644 --- a/src/flamegraph/svg.rs +++ b/src/flamegraph/svg.rs @@ -9,6 +9,9 @@ use str_stack::StrStack; use super::{Direction, Options, TextTruncateDirection}; +/// The generic font families should not have quotes around them in the CSS. +const GENERIC_FONT_FAMILIES: &[&str] = &["cursive", "fantasy", "monospace", "serif", "sans-serif"]; + pub(super) enum TextArgument<'a> { String(Cow<'a, str>), FromBuffer(usize), @@ -116,13 +119,19 @@ where BytesStart::borrowed_name(b"style").with_attributes(iter::once(("type", "text/css"))), ))?; + let font_type: Cow = if GENERIC_FONT_FAMILIES.contains(&opt.font_type.as_str()) { + Cow::Borrowed(&opt.font_type) + } else { + Cow::Owned(enquote('\"', &opt.font_type)) + }; + let titlesize = &opt.font_size + 5; svg.write_event(Event::Text(BytesText::from_escaped_str(&format!( " text {{ font-family:{}; font-size:{}px; fill:rgb(0,0,0); }} #title {{ text-anchor:middle; font-size:{}px; }} {}", - enquote('\"', &opt.font_type), + font_type, &opt.font_size, titlesize, include_str!("flamegraph.css") diff --git a/tests/data/flamegraph/options/font_type_cursive.svg b/tests/data/flamegraph/options/font_type_cursive.svg new file mode 100644 index 00000000..2ba810cc --- /dev/null +++ b/tests/data/flamegraph/options/font_type_cursive.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Flame Graph + + Reset Zoom + Search + + + + _start (56 samples, 10.92%; 0.00%) + + _start + + + __libc_start_main (56 samples, 10.92%; 0.00%) + + __libc_start_main + + + main (56 samples, 10.92%; 0.00%) + + main + + + cksum (56 samples, 10.92%; +4.87%) + + cksum + + + cksum (5 samples, 0.97%; -0.78%) + + + + + __GI___fread_unlocked (3 samples, 0.58%; 0.00%) + + + + + _IO_file_xsgetn (3 samples, 0.58%; 0.00%) + + + + + _IO_file_read (3 samples, 0.58%; 0.00%) + + + + + entry_SYSCALL_64_fastpath (3 samples, 0.58%; 0.00%) + + + + + sys_read (3 samples, 0.58%; 0.00%) + + + + + vfs_read (3 samples, 0.58%; 0.00%) + + + + + __vfs_read (3 samples, 0.58%; 0.00%) + + + + + ext4_file_read_iter (3 samples, 0.58%; +0.39%) + + + + + cksum (96 samples, 18.71%; 0.00%) + + cksum + + + main (35 samples, 6.82%; 0.00%) + + main + + + cksum (35 samples, 6.82%; +3.12%) + + cksum + + + [unknown] (2 samples, 0.39%; 0.00%) + + + + + all (513 samples, 100%) + + + + + noploop (417 samples, 81.29%; 0.00%) + + noploop + + + main (415 samples, 80.90%; +27.49%) + + main + + + diff --git a/tests/data/flamegraph/options/font_type_fantasy.svg b/tests/data/flamegraph/options/font_type_fantasy.svg new file mode 100644 index 00000000..9599066f --- /dev/null +++ b/tests/data/flamegraph/options/font_type_fantasy.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Flame Graph + + Reset Zoom + Search + + + + _start (56 samples, 10.92%; 0.00%) + + _start + + + __libc_start_main (56 samples, 10.92%; 0.00%) + + __libc_start_main + + + main (56 samples, 10.92%; 0.00%) + + main + + + cksum (56 samples, 10.92%; +4.87%) + + cksum + + + cksum (5 samples, 0.97%; -0.78%) + + + + + __GI___fread_unlocked (3 samples, 0.58%; 0.00%) + + + + + _IO_file_xsgetn (3 samples, 0.58%; 0.00%) + + + + + _IO_file_read (3 samples, 0.58%; 0.00%) + + + + + entry_SYSCALL_64_fastpath (3 samples, 0.58%; 0.00%) + + + + + sys_read (3 samples, 0.58%; 0.00%) + + + + + vfs_read (3 samples, 0.58%; 0.00%) + + + + + __vfs_read (3 samples, 0.58%; 0.00%) + + + + + ext4_file_read_iter (3 samples, 0.58%; +0.39%) + + + + + cksum (96 samples, 18.71%; 0.00%) + + cksum + + + main (35 samples, 6.82%; 0.00%) + + main + + + cksum (35 samples, 6.82%; +3.12%) + + cksum + + + [unknown] (2 samples, 0.39%; 0.00%) + + + + + all (513 samples, 100%) + + + + + noploop (417 samples, 81.29%; 0.00%) + + noploop + + + main (415 samples, 80.90%; +27.49%) + + main + + + diff --git a/tests/data/flamegraph/options/font_type_monospace.svg b/tests/data/flamegraph/options/font_type_monospace.svg new file mode 100644 index 00000000..6d8a9565 --- /dev/null +++ b/tests/data/flamegraph/options/font_type_monospace.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Flame Graph + + Reset Zoom + Search + + + + _start (56 samples, 10.92%; 0.00%) + + _start + + + __libc_start_main (56 samples, 10.92%; 0.00%) + + __libc_start_main + + + main (56 samples, 10.92%; 0.00%) + + main + + + cksum (56 samples, 10.92%; +4.87%) + + cksum + + + cksum (5 samples, 0.97%; -0.78%) + + + + + __GI___fread_unlocked (3 samples, 0.58%; 0.00%) + + + + + _IO_file_xsgetn (3 samples, 0.58%; 0.00%) + + + + + _IO_file_read (3 samples, 0.58%; 0.00%) + + + + + entry_SYSCALL_64_fastpath (3 samples, 0.58%; 0.00%) + + + + + sys_read (3 samples, 0.58%; 0.00%) + + + + + vfs_read (3 samples, 0.58%; 0.00%) + + + + + __vfs_read (3 samples, 0.58%; 0.00%) + + + + + ext4_file_read_iter (3 samples, 0.58%; +0.39%) + + + + + cksum (96 samples, 18.71%; 0.00%) + + cksum + + + main (35 samples, 6.82%; 0.00%) + + main + + + cksum (35 samples, 6.82%; +3.12%) + + cksum + + + [unknown] (2 samples, 0.39%; 0.00%) + + + + + all (513 samples, 100%) + + + + + noploop (417 samples, 81.29%; 0.00%) + + noploop + + + main (415 samples, 80.90%; +27.49%) + + main + + + diff --git a/tests/data/flamegraph/options/font_type_sans-serif.svg b/tests/data/flamegraph/options/font_type_sans-serif.svg new file mode 100644 index 00000000..2c3a66dc --- /dev/null +++ b/tests/data/flamegraph/options/font_type_sans-serif.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Flame Graph + + Reset Zoom + Search + + + + _start (56 samples, 10.92%; 0.00%) + + _start + + + __libc_start_main (56 samples, 10.92%; 0.00%) + + __libc_start_main + + + main (56 samples, 10.92%; 0.00%) + + main + + + cksum (56 samples, 10.92%; +4.87%) + + cksum + + + cksum (5 samples, 0.97%; -0.78%) + + + + + __GI___fread_unlocked (3 samples, 0.58%; 0.00%) + + + + + _IO_file_xsgetn (3 samples, 0.58%; 0.00%) + + + + + _IO_file_read (3 samples, 0.58%; 0.00%) + + + + + entry_SYSCALL_64_fastpath (3 samples, 0.58%; 0.00%) + + + + + sys_read (3 samples, 0.58%; 0.00%) + + + + + vfs_read (3 samples, 0.58%; 0.00%) + + + + + __vfs_read (3 samples, 0.58%; 0.00%) + + + + + ext4_file_read_iter (3 samples, 0.58%; +0.39%) + + + + + cksum (96 samples, 18.71%; 0.00%) + + cksum + + + main (35 samples, 6.82%; 0.00%) + + main + + + cksum (35 samples, 6.82%; +3.12%) + + cksum + + + [unknown] (2 samples, 0.39%; 0.00%) + + + + + all (513 samples, 100%) + + + + + noploop (417 samples, 81.29%; 0.00%) + + noploop + + + main (415 samples, 80.90%; +27.49%) + + main + + + diff --git a/tests/data/flamegraph/options/font_type_serif.svg b/tests/data/flamegraph/options/font_type_serif.svg new file mode 100644 index 00000000..d5df4011 --- /dev/null +++ b/tests/data/flamegraph/options/font_type_serif.svg @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Flame Graph + + Reset Zoom + Search + + + + _start (56 samples, 10.92%; 0.00%) + + _start + + + __libc_start_main (56 samples, 10.92%; 0.00%) + + __libc_start_main + + + main (56 samples, 10.92%; 0.00%) + + main + + + cksum (56 samples, 10.92%; +4.87%) + + cksum + + + cksum (5 samples, 0.97%; -0.78%) + + + + + __GI___fread_unlocked (3 samples, 0.58%; 0.00%) + + + + + _IO_file_xsgetn (3 samples, 0.58%; 0.00%) + + + + + _IO_file_read (3 samples, 0.58%; 0.00%) + + + + + entry_SYSCALL_64_fastpath (3 samples, 0.58%; 0.00%) + + + + + sys_read (3 samples, 0.58%; 0.00%) + + + + + vfs_read (3 samples, 0.58%; 0.00%) + + + + + __vfs_read (3 samples, 0.58%; 0.00%) + + + + + ext4_file_read_iter (3 samples, 0.58%; +0.39%) + + + + + cksum (96 samples, 18.71%; 0.00%) + + cksum + + + main (35 samples, 6.82%; 0.00%) + + main + + + cksum (35 samples, 6.82%; +3.12%) + + cksum + + + [unknown] (2 samples, 0.39%; 0.00%) + + + + + all (513 samples, 100%) + + + + + noploop (417 samples, 81.29%; 0.00%) + + noploop + + + main (415 samples, 80.90%; +27.49%) + + main + + + diff --git a/tests/flamegraph.rs b/tests/flamegraph.rs index b3c275ec..b9cd2ba2 100644 --- a/tests/flamegraph.rs +++ b/tests/flamegraph.rs @@ -681,6 +681,23 @@ fn flamegraph_font_type_with_quote() { test_flamegraph(input_file, expected_result_file, options).unwrap(); } +#[test] +fn flamegraph_font_type_generic_families() { + let input_file = + "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; + + let generic_families = &["cursive", "fantasy", "monospace", "serif", "sans-serif"]; + for family in generic_families { + let expected_result_file = + format!("./tests/data/flamegraph/options/font_type_{}.svg", family); + + let mut options = flamegraph::Options::default(); + options.font_type = family.to_string(); + + test_flamegraph(input_file, &expected_result_file, options).unwrap(); + } +} + #[test] fn search_color_non_default() { let input_file =