This commit is contained in:
Mahdi Dibaiee 2022-06-16 12:50:08 +01:00
commit 9b41b7ce44
9 changed files with 1108 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

304
Cargo.lock generated Normal file
View File

@ -0,0 +1,304 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "dhat"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47003dc9f6368a88e85956c3b2573a7e6872746a3e5d762a8885da3a136a0381"
dependencies = [
"backtrace",
"lazy_static",
"parking_lot",
"rustc-hash",
"serde",
"serde_json",
"thousands",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "instant"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
"cfg-if",
]
[[package]]
name = "itoa"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "lock_api"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "miniz_oxide"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.28.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424"
dependencies = [
"memchr",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]]
name = "proc-macro2"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "smallvec"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "syn"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thousands"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
[[package]]
name = "unicode-ident"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zero-copy-deserialize"
version = "0.1.0"
dependencies = [
"dhat",
]

16
Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "zero-copy-deserialize"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dhat = "0.3.0"
[profile.release]
debug = 1
[features]
dhat-heap = [] # if you are doing heap profiling
dhat-ad-hoc = [] # if you are doing ad hoc profiling

39
dhat-ad-hoc.json Normal file
View File

@ -0,0 +1,39 @@
{
"dhatFileVersion": 2,
"mode": "rust-ad-hoc",
"verb": "Allocated",
"bklt": false,
"bkacc": false,
"bu": "unit",
"bsu": "units",
"bksu": "events",
"tu": "µs",
"Mtu": "s",
"cmd": "target/debug/zero-copy-deserialize",
"pid": 42993,
"te": 250,
"pps": [
{
"tb": 100,
"tbk": 1,
"fs": [
1,
2
]
},
{
"tb": 100,
"tbk": 1,
"fs": [
1,
3
]
}
],
"ftbl": [
"[root]",
"0x100047454: dhat::ad_hoc_event (dhat-0.3.0/src/lib.rs:1322:18)",
"0x10003dd08: zero_copy_deserialize::main (zero-copy-deserialize/src/main.rs:36:5)",
"0x10003dde4: zero_copy_deserialize::main (zero-copy-deserialize/src/main.rs:44:5)"
]
}

237
dhat-heap.json Normal file
View File

@ -0,0 +1,237 @@
{
"dhatFileVersion": 2,
"mode": "rust-heap",
"verb": "Allocated",
"bklt": true,
"bkacc": false,
"tu": "µs",
"Mtu": "s",
"tuth": 10,
"cmd": "target/debug/zero-copy-deserialize",
"pid": 43081,
"tg": 272,
"te": 291,
"pps": [
{
"tb": 8192,
"tbk": 1,
"tl": 112,
"mb": 8192,
"mbk": 1,
"gb": 8192,
"gbk": 1,
"eb": 8192,
"ebk": 1,
"fs": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18
]
},
{
"tb": 8,
"tbk": 1,
"tl": 51,
"mb": 8,
"mbk": 1,
"gb": 0,
"gbk": 0,
"eb": 0,
"ebk": 0,
"fs": [
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
18
]
},
{
"tb": 64,
"tbk": 1,
"tl": 95,
"mb": 64,
"mbk": 1,
"gb": 64,
"gbk": 1,
"eb": 64,
"ebk": 1,
"fs": [
35,
36,
37,
38,
39,
40,
41,
42,
43,
11,
12,
13,
14,
15,
16,
17,
18
]
},
{
"tb": 4,
"tbk": 1,
"tl": 34,
"mb": 4,
"mbk": 1,
"gb": 4,
"gbk": 1,
"eb": 0,
"ebk": 0,
"fs": [
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
18
]
},
{
"tb": 1024,
"tbk": 1,
"tl": 19,
"mb": 1024,
"mbk": 1,
"gb": 1024,
"gbk": 1,
"eb": 1024,
"ebk": 1,
"fs": [
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
11,
66,
67,
68,
69,
70,
71
]
}
],
"ftbl": [
"[root]",
"0x10488971c: <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc/src/alloc.rs:231:9)",
"0x10488971c: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc/src/raw_vec.rs:185:45)",
"0x10488971c: alloc::raw_vec::RawVec<T,A>::with_capacity_in (alloc/src/raw_vec.rs:132:9)",
"0x10488971c: alloc::raw_vec::RawVec<T>::with_capacity (alloc/src/raw_vec.rs:93:9)",
"0x10488971c: alloc::boxed::Box<[T]>::new_uninit_slice (alloc/src/boxed.rs:616:18)",
"0x10488971c: std::io::buffered::bufreader::BufReader<R>::with_capacity (io/buffered/bufreader.rs:96:19)",
"0x10488971c: std::io::stdio::stdin::{{closure}} (src/io/stdio.rs:324:24)",
"0x10488971c: std::lazy::SyncOnceCell<T>::get_or_init::{{closure}} (std/src/lazy.rs:281:50)",
"0x10488971c: std::lazy::SyncOnceCell<T>::initialize::{{closure}} (std/src/lazy.rs:462:19)",
"0x10488971c: std::sync::once::Once::call_once_force::{{closure}} (src/sync/once.rs:334:40)",
"0x1048a67c4: std::sync::once::Once::call_inner (src/sync/once.rs:434:21)",
"0x1048a691c: std::sync::once::Once::call_once_force (src/sync/once.rs:334:9)",
"0x1048a691c: std::lazy::SyncOnceCell<T>::initialize (std/src/lazy.rs:461:9)",
"0x1048865b4: std::lazy::SyncOnceCell<T>::get_or_try_init (std/src/lazy.rs:328:9)",
"0x1048865b4: std::lazy::SyncOnceCell<T>::get_or_init (std/src/lazy.rs:281:15)",
"0x1048865b4: std::io::stdio::stdin (src/io/stdio.rs:323:16)",
"0x104766b58: zero_copy_deserialize::mamad (zero-copy-deserialize/src/main.rs:19:17)",
"0x104766c20: zero_copy_deserialize::main (zero-copy-deserialize/src/main.rs:32:13)",
"0x104766d88: __rg_alloc (zero-copy-deserialize/src/main.rs:5:15)",
"0x1048761d8: alloc::raw_vec::finish_grow (alloc/src/raw_vec.rs:0:0)",
"0x1048a6210: alloc::raw_vec::RawVec<T,A>::grow_amortized (alloc/src/raw_vec.rs:400:19)",
"0x1048a6210: alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle (alloc/src/raw_vec.rs:285:28)",
"0x104887d40: alloc::raw_vec::RawVec<T,A>::reserve (alloc/src/raw_vec.rs:289:13)",
"0x104887d40: alloc::vec::Vec<T,A>::reserve (src/vec/mod.rs:813:9)",
"0x104887d40: alloc::vec::Vec<T,A>::append_elements (src/vec/mod.rs:1798:9)",
"0x104887d40: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<&T,core::slice::iter::Iter<T>>>::spec_extend (src/vec/spec_extend.rs:85:18)",
"0x104887d40: alloc::vec::Vec<T,A>::extend_from_slice (src/vec/mod.rs:2236:9)",
"0x104887d40: std::io::read_until (src/io/mod.rs:1892:21)",
"0x1048866c0: std::io::BufRead::read_line::{{closure}} (src/io/mod.rs:2176:44)",
"0x1048866c0: std::io::append_to_string (src/io/mod.rs:336:15)",
"0x1048866c0: std::io::BufRead::read_line (src/io/mod.rs:2176:18)",
"0x1048866c0: <std::io::stdio::StdinLock as std::io::BufRead>::read_line (src/io/stdio.rs:493:9)",
"0x104886620: std::io::stdio::Stdin::read_line (src/io/stdio.rs:386:9)",
"0x104766b94: zero_copy_deserialize::mamad (zero-copy-deserialize/src/main.rs:20:5)",
"0x10488a528: alloc::alloc::exchange_malloc (alloc/src/alloc.rs:320:11)",
"0x10488a528: alloc::boxed::Box<T>::new (alloc/src/boxed.rs:195:9)",
"0x10488a528: <alloc::boxed::Box<T> as core::convert::From<T>>::from (alloc/src/boxed.rs:1386:9)",
"0x10488a528: std::sys_common::mutex::MovableMutex::new (src/sys_common/mutex.rs:64:25)",
"0x104889734: std::sync::mutex::Mutex<T>::new (src/sync/mutex.rs:218:20)",
"0x104889734: std::io::stdio::stdin::{{closure}} (src/io/stdio.rs:324:13)",
"0x104889734: std::lazy::SyncOnceCell<T>::get_or_init::{{closure}} (std/src/lazy.rs:281:50)",
"0x104889734: std::lazy::SyncOnceCell<T>::initialize::{{closure}} (std/src/lazy.rs:462:19)",
"0x104889734: std::sync::once::Once::call_once_force::{{closure}} (src/sync/once.rs:334:40)",
"0x10489bd58: <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc/src/alloc.rs:231:9)",
"0x10489bd58: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc/src/raw_vec.rs:185:45)",
"0x10489bd58: alloc::raw_vec::RawVec<T,A>::with_capacity_in (alloc/src/raw_vec.rs:132:9)",
"0x10489bd58: alloc::vec::Vec<T,A>::with_capacity_in (src/vec/mod.rs:613:20)",
"0x10489bd58: <T as alloc::slice::hack::ConvertVec>::to_vec (alloc/src/slice.rs:227:25)",
"0x10489bd58: alloc::slice::hack::to_vec (alloc/src/slice.rs:176:9)",
"0x10489bd58: alloc::slice::<impl [T]>::to_vec_in (alloc/src/slice.rs:507:9)",
"0x10489bd58: <alloc::vec::Vec<T,A> as core::clone::Clone>::clone (src/vec/mod.rs:2485:9)",
"0x10489bd58: <alloc::string::String as core::clone::Clone>::clone (alloc/src/string.rs:1861:23)",
"0x104766ad4: zero_copy_deserialize::parse (zero-copy-deserialize/src/main.rs:13:15)",
"0x104766bcc: zero_copy_deserialize::mamad (zero-copy-deserialize/src/main.rs:24:5)",
"0x1048897e8: <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc/src/alloc.rs:231:9)",
"0x1048897e8: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc/src/raw_vec.rs:185:45)",
"0x1048897e8: alloc::raw_vec::RawVec<T,A>::with_capacity_in (alloc/src/raw_vec.rs:132:9)",
"0x1048897e8: alloc::vec::Vec<T,A>::with_capacity_in (src/vec/mod.rs:613:20)",
"0x1048897e8: alloc::vec::Vec<T>::with_capacity (src/vec/mod.rs:470:9)",
"0x1048897e8: std::io::buffered::bufwriter::BufWriter<W>::with_capacity (io/buffered/bufwriter.rs:115:33)",
"0x1048897e8: std::io::buffered::linewriter::LineWriter<W>::with_capacity (io/buffered/linewriter.rs:109:29)",
"0x1048897e8: std::io::buffered::linewriter::LineWriter<W>::new (io/buffered/linewriter.rs:89:9)",
"0x1048897e8: std::io::stdio::stdout::{{closure}} (src/io/stdio.rs:609:58)",
"0x1048897e8: std::lazy::SyncOnceCell<T>::get_or_init_pin::{{closure}} (std/src/lazy.rs:375:25)",
"0x1048897e8: std::sync::once::Once::call_once_force::{{closure}} (src/sync/once.rs:334:40)",
"0x104886e20: std::sync::once::Once::call_once_force (src/sync/once.rs:334:9)",
"0x104886e20: std::lazy::SyncOnceCell<T>::get_or_init_pin (std/src/lazy.rs:374:9)",
"0x104886e20: std::io::stdio::stdout (src/io/stdio.rs:608:16)",
"0x104886e20: std::io::stdio::print_to (src/io/stdio.rs:1016:21)",
"0x104886e20: std::io::stdio::_print (src/io/stdio.rs:1029:5)",
"0x104766cc0: zero_copy_deserialize::main (zero-copy-deserialize/src/main.rs:34:5)"
]
}

414
flamegraph.svg Normal file
View File

@ -0,0 +1,414 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="1200" height="310" onload="init(evt)" viewBox="0 0 1200 310" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fg="http://github.com/jonhoo/inferno"><!--Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for latest version, and http://www.brendangregg.com/flamegraphs.html for examples.--><!--NOTES: --><defs><linearGradient id="background" y1="0" y2="1" x1="0" x2="0"><stop stop-color="#eeeeee" offset="5%"/><stop stop-color="#eeeeb0" offset="95%"/></linearGradient></defs><style type="text/css">
text { font-family:"Verdana"; font-size:12px; fill:rgb(0,0,0); }
#title { text-anchor:middle; font-size:17px; }
#search { opacity:0.1; cursor:pointer; }
#search:hover, #search.show { opacity:1; }
#subtitle { text-anchor:middle; font-color:rgb(160,160,160); }
#unzoom { cursor:pointer; }
#frames > *:hover { stroke:black; stroke-width:0.5; cursor:pointer; }
.hide { display:none; }
.parent { opacity:0.5; }
</style><script type="text/ecmascript"><![CDATA[
var nametype = 'Function:';
var fontsize = 12;
var fontwidth = 0.59;
var xpad = 10;
var inverted = false;
var searchcolor = 'rgb(230,0,230)';
var fluiddrawing = true;
var truncate_text_right = false;
]]><![CDATA["use strict";
var details, searchbtn, unzoombtn, matchedtxt, svg, searching, frames;
function init(evt) {
details = document.getElementById("details").firstChild;
searchbtn = document.getElementById("search");
unzoombtn = document.getElementById("unzoom");
matchedtxt = document.getElementById("matched");
svg = document.getElementsByTagName("svg")[0];
frames = document.getElementById("frames");
total_samples = parseInt(frames.attributes.total_samples.value);
searching = 0;
// Use GET parameters to restore a flamegraph's state.
var restore_state = function() {
var params = get_params();
if (params.x && params.y)
zoom(find_group(document.querySelector('[*|x="' + params.x + '"][y="' + params.y + '"]')));
if (params.s)
search(params.s);
};
if (fluiddrawing) {
// Make width dynamic so the SVG fits its parent's width.
svg.removeAttribute("width");
// Edge requires us to have a viewBox that gets updated with size changes.
var isEdge = /Edge\/\d./i.test(navigator.userAgent);
var update_for_width_change = function() {
if (isEdge) {
svg.attributes.viewBox.value = "0 0 " + svg.width.baseVal.value + " " + svg.height.baseVal.value;
}
// Keep consistent padding on left and right of frames container.
frames.attributes.width.value = svg.width.baseVal.value - xpad * 2;
// Text truncation needs to be adjusted for the current width.
var el = frames.children;
for(var i = 0; i < el.length; i++) {
update_text(el[i]);
}
// Keep search elements at a fixed distance from right edge.
var svgWidth = svg.width.baseVal.value;
searchbtn.attributes.x.value = svgWidth - xpad - 100;
matchedtxt.attributes.x.value = svgWidth - xpad - 100;
};
window.addEventListener('resize', function() {
update_for_width_change();
});
// This needs to be done asynchronously for Safari to work.
setTimeout(function() {
unzoom();
update_for_width_change();
restore_state();
if (!isEdge) {
svg.removeAttribute("viewBox");
}
}, 0);
} else {
restore_state();
}
}
// event listeners
window.addEventListener("click", function(e) {
var target = find_group(e.target);
if (target) {
if (target.nodeName == "a") {
if (e.ctrlKey === false) return;
e.preventDefault();
}
if (target.classList.contains("parent")) unzoom();
zoom(target);
// set parameters for zoom state
var el = target.querySelector("rect");
if (el && el.attributes && el.attributes.y && el.attributes["fg:x"]) {
var params = get_params()
params.x = el.attributes["fg:x"].value;
params.y = el.attributes.y.value;
history.replaceState(null, null, parse_params(params));
}
}
else if (e.target.id == "unzoom") {
unzoom();
// remove zoom state
var params = get_params();
if (params.x) delete params.x;
if (params.y) delete params.y;
history.replaceState(null, null, parse_params(params));
}
else if (e.target.id == "search") search_prompt();
}, false)
// mouse-over for info
// show
window.addEventListener("mouseover", function(e) {
var target = find_group(e.target);
if (target) details.nodeValue = nametype + " " + g_to_text(target);
}, false)
// clear
window.addEventListener("mouseout", function(e) {
var target = find_group(e.target);
if (target) details.nodeValue = ' ';
}, false)
// ctrl-F for search
window.addEventListener("keydown",function (e) {
if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
e.preventDefault();
search_prompt();
}
}, false)
// functions
function get_params() {
var params = {};
var paramsarr = window.location.search.substr(1).split('&');
for (var i = 0; i < paramsarr.length; ++i) {
var tmp = paramsarr[i].split("=");
if (!tmp[0] || !tmp[1]) continue;
params[tmp[0]] = decodeURIComponent(tmp[1]);
}
return params;
}
function parse_params(params) {
var uri = "?";
for (var key in params) {
uri += key + '=' + encodeURIComponent(params[key]) + '&';
}
if (uri.slice(-1) == "&")
uri = uri.substring(0, uri.length - 1);
if (uri == '?')
uri = window.location.href.split('?')[0];
return uri;
}
function find_child(node, selector) {
var children = node.querySelectorAll(selector);
if (children.length) return children[0];
return;
}
function find_group(node) {
var parent = node.parentElement;
if (!parent) return;
if (parent.id == "frames") return node;
return find_group(parent);
}
function orig_save(e, attr, val) {
if (e.attributes["fg:orig_" + attr] != undefined) return;
if (e.attributes[attr] == undefined) return;
if (val == undefined) val = e.attributes[attr].value;
e.setAttribute("fg:orig_" + attr, val);
}
function orig_load(e, attr) {
if (e.attributes["fg:orig_"+attr] == undefined) return;
e.attributes[attr].value = e.attributes["fg:orig_" + attr].value;
e.removeAttribute("fg:orig_" + attr);
}
function g_to_text(e) {
var text = find_child(e, "title").firstChild.nodeValue;
return (text)
}
function g_to_func(e) {
var func = g_to_text(e);
// if there's any manipulation we want to do to the function
// name before it's searched, do it here before returning.
return (func);
}
function update_text(e) {
var r = find_child(e, "rect");
var t = find_child(e, "text");
var w = parseFloat(r.attributes.width.value) * frames.attributes.width.value / 100 - 3;
var txt = find_child(e, "title").textContent.replace(/\([^(]*\)$/,"");
t.attributes.x.value = format_percent((parseFloat(r.attributes.x.value) + (100 * 3 / frames.attributes.width.value)));
// Smaller than this size won't fit anything
if (w < 2 * fontsize * fontwidth) {
t.textContent = "";
return;
}
t.textContent = txt;
// Fit in full text width
if (/^ *\$/.test(txt) || t.getComputedTextLength() < w)
return;
if (truncate_text_right) {
// Truncate the right side of the text.
for (var x = txt.length - 2; x > 0; x--) {
if (t.getSubStringLength(0, x + 2) <= w) {
t.textContent = txt.substring(0, x) + "..";
return;
}
}
} else {
// Truncate the left side of the text.
for (var x = 2; x < txt.length; x++) {
if (t.getSubStringLength(x - 2, txt.length) <= w) {
t.textContent = ".." + txt.substring(x, txt.length);
return;
}
}
}
t.textContent = "";
}
// zoom
function zoom_reset(e) {
if (e.tagName == "rect") {
e.attributes.x.value = format_percent(100 * parseInt(e.attributes["fg:x"].value) / total_samples);
e.attributes.width.value = format_percent(100 * parseInt(e.attributes["fg:w"].value) / total_samples);
}
if (e.childNodes == undefined) return;
for(var i = 0, c = e.childNodes; i < c.length; i++) {
zoom_reset(c[i]);
}
}
function zoom_child(e, x, zoomed_width_samples) {
if (e.tagName == "text") {
var parent_x = parseFloat(find_child(e.parentNode, "rect[x]").attributes.x.value);
e.attributes.x.value = format_percent(parent_x + (100 * 3 / frames.attributes.width.value));
} else if (e.tagName == "rect") {
e.attributes.x.value = format_percent(100 * (parseInt(e.attributes["fg:x"].value) - x) / zoomed_width_samples);
e.attributes.width.value = format_percent(100 * parseInt(e.attributes["fg:w"].value) / zoomed_width_samples);
}
if (e.childNodes == undefined) return;
for(var i = 0, c = e.childNodes; i < c.length; i++) {
zoom_child(c[i], x, zoomed_width_samples);
}
}
function zoom_parent(e) {
if (e.attributes) {
if (e.attributes.x != undefined) {
e.attributes.x.value = "0.0%";
}
if (e.attributes.width != undefined) {
e.attributes.width.value = "100.0%";
}
}
if (e.childNodes == undefined) return;
for(var i = 0, c = e.childNodes; i < c.length; i++) {
zoom_parent(c[i]);
}
}
function zoom(node) {
var attr = find_child(node, "rect").attributes;
var width = parseInt(attr["fg:w"].value);
var xmin = parseInt(attr["fg:x"].value);
var xmax = xmin + width;
var ymin = parseFloat(attr.y.value);
unzoombtn.classList.remove("hide");
var el = frames.children;
for (var i = 0; i < el.length; i++) {
var e = el[i];
var a = find_child(e, "rect").attributes;
var ex = parseInt(a["fg:x"].value);
var ew = parseInt(a["fg:w"].value);
// Is it an ancestor
if (!inverted) {
var upstack = parseFloat(a.y.value) > ymin;
} else {
var upstack = parseFloat(a.y.value) < ymin;
}
if (upstack) {
// Direct ancestor
if (ex <= xmin && (ex+ew) >= xmax) {
e.classList.add("parent");
zoom_parent(e);
update_text(e);
}
// not in current path
else
e.classList.add("hide");
}
// Children maybe
else {
// no common path
if (ex < xmin || ex >= xmax) {
e.classList.add("hide");
}
else {
zoom_child(e, xmin, width);
update_text(e);
}
}
}
}
function unzoom() {
unzoombtn.classList.add("hide");
var el = frames.children;
for(var i = 0; i < el.length; i++) {
el[i].classList.remove("parent");
el[i].classList.remove("hide");
zoom_reset(el[i]);
update_text(el[i]);
}
}
// search
function reset_search() {
var el = document.querySelectorAll("#frames rect");
for (var i = 0; i < el.length; i++) {
orig_load(el[i], "fill")
}
var params = get_params();
delete params.s;
history.replaceState(null, null, parse_params(params));
}
function search_prompt() {
if (!searching) {
var term = prompt("Enter a search term (regexp " +
"allowed, eg: ^ext4_)", "");
if (term != null) {
search(term)
}
} else {
reset_search();
searching = 0;
searchbtn.classList.remove("show");
searchbtn.firstChild.nodeValue = "Search"
matchedtxt.classList.add("hide");
matchedtxt.firstChild.nodeValue = ""
}
}
function search(term) {
var re = new RegExp(term);
var el = frames.children;
var matches = new Object();
var maxwidth = 0;
for (var i = 0; i < el.length; i++) {
var e = el[i];
// Skip over frames which are either not visible, or below the zoomed-to frame
if (e.classList.contains("hide") || e.classList.contains("parent")) {
continue;
}
var func = g_to_func(e);
var rect = find_child(e, "rect");
if (func == null || rect == null)
continue;
// Save max width. Only works as we have a root frame
var w = parseInt(rect.attributes["fg:w"].value);
if (w > maxwidth)
maxwidth = w;
if (func.match(re)) {
// highlight
var x = parseInt(rect.attributes["fg:x"].value);
orig_save(rect, "fill");
rect.attributes.fill.value = searchcolor;
// remember matches
if (matches[x] == undefined) {
matches[x] = w;
} else {
if (w > matches[x]) {
// overwrite with parent
matches[x] = w;
}
}
searching = 1;
}
}
if (!searching)
return;
var params = get_params();
params.s = term;
history.replaceState(null, null, parse_params(params));
searchbtn.classList.add("show");
searchbtn.firstChild.nodeValue = "Reset Search";
// calculate percent matched, excluding vertical overlap
var count = 0;
var lastx = -1;
var lastw = 0;
var keys = Array();
for (k in matches) {
if (matches.hasOwnProperty(k))
keys.push(k);
}
// sort the matched frames by their x location
// ascending, then width descending
keys.sort(function(a, b){
return a - b;
});
// Step through frames saving only the biggest bottom-up frames
// thanks to the sort order. This relies on the tree property
// where children are always smaller than their parents.
for (var k in keys) {
var x = parseInt(keys[k]);
var w = matches[keys[k]];
if (x >= lastx + lastw) {
count += w;
lastx = x;
lastw = w;
}
}
// display matched percent
matchedtxt.classList.remove("hide");
var pct = 100 * count / maxwidth;
if (pct != 100) pct = pct.toFixed(1);
matchedtxt.firstChild.nodeValue = "Matched: " + pct + "%";
}
function format_percent(n) {
return n.toFixed(4) + "%";
}
]]></script><rect x="0" y="0" width="100%" height="310" fill="url(#background)"/><text id="title" x="50.0000%" y="24.00">Flame Graph</text><text id="details" x="10" y="293.00"> </text><text id="unzoom" class="hide" x="10" y="24.00">Reset Zoom</text><text id="search" x="1090" y="24.00">Search</text><text id="matched" x="1090" y="293.00"> </text><svg id="frames" x="10" width="1180" total_samples="2"><g><title>dyld`start (1 samples, 50.00%)</title><rect x="0.0000%" y="245" width="50.0000%" height="15" fill="rgb(227,0,7)" fg:x="0" fg:w="1"/><text x="0.2500%" y="255.50">dyld`start</text></g><g><title>zero-copy-deserialize`main (1 samples, 50.00%)</title><rect x="0.0000%" y="229" width="50.0000%" height="15" fill="rgb(217,0,24)" fg:x="0" fg:w="1"/><text x="0.2500%" y="239.50">zero-copy-deserialize`main</text></g><g><title>zero-copy-deserialize`std::rt::lang_start_internal (1 samples, 50.00%)</title><rect x="0.0000%" y="213" width="50.0000%" height="15" fill="rgb(221,193,54)" fg:x="0" fg:w="1"/><text x="0.2500%" y="223.50">zero-copy-deserialize`std::rt::lang_start_internal</text></g><g><title>zero-copy-deserialize`std::rt::lang_start::_{{closure}} (1 samples, 50.00%)</title><rect x="0.0000%" y="197" width="50.0000%" height="15" fill="rgb(248,212,6)" fg:x="0" fg:w="1"/><text x="0.2500%" y="207.50">zero-copy-deserialize`std::rt::lang_start::_{{closure}}</text></g><g><title>zero-copy-deserialize`std::sys_common::backtrace::__rust_begin_short_backtrace (1 samples, 50.00%)</title><rect x="0.0000%" y="181" width="50.0000%" height="15" fill="rgb(208,68,35)" fg:x="0" fg:w="1"/><text x="0.2500%" y="191.50">zero-copy-deserialize`std::sys_common::backtrace::__rust_begin_short_backtrace</text></g><g><title>zero-copy-deserialize`zero_copy_deserialize::main (1 samples, 50.00%)</title><rect x="0.0000%" y="165" width="50.0000%" height="15" fill="rgb(232,128,0)" fg:x="0" fg:w="1"/><text x="0.2500%" y="175.50">zero-copy-deserialize`zero_copy_deserialize::main</text></g><g><title>zero-copy-deserialize`std::io::stdio::_print (1 samples, 50.00%)</title><rect x="0.0000%" y="149" width="50.0000%" height="15" fill="rgb(207,160,47)" fg:x="0" fg:w="1"/><text x="0.2500%" y="159.50">zero-copy-deserialize`std::io::stdio::_print</text></g><g><title>zero-copy-deserialize`std::sync::once::Once::call_inner (1 samples, 50.00%)</title><rect x="0.0000%" y="133" width="50.0000%" height="15" fill="rgb(228,23,34)" fg:x="0" fg:w="1"/><text x="0.2500%" y="143.50">zero-copy-deserialize`std::sync::once::Once::call_inner</text></g><g><title>zero-copy-deserialize`std::sync::once::Once::call_once_force::_{{closure}} (1 samples, 50.00%)</title><rect x="0.0000%" y="117" width="50.0000%" height="15" fill="rgb(218,30,26)" fg:x="0" fg:w="1"/><text x="0.2500%" y="127.50">zero-copy-deserialize`std::sync::once::Once::call_once_force::_{{closure}}</text></g><g><title>libsystem_malloc.dylib`_malloc_zone_malloc (1 samples, 50.00%)</title><rect x="0.0000%" y="101" width="50.0000%" height="15" fill="rgb(220,122,19)" fg:x="0" fg:w="1"/><text x="0.2500%" y="111.50">libsystem_malloc.dylib`_malloc_zone_malloc</text></g><g><title>libsystem_malloc.dylib`szone_malloc_should_clear (1 samples, 50.00%)</title><rect x="0.0000%" y="85" width="50.0000%" height="15" fill="rgb(250,228,42)" fg:x="0" fg:w="1"/><text x="0.2500%" y="95.50">libsystem_malloc.dylib`szone_malloc_should_clear</text></g><g><title>libsystem_malloc.dylib`small_malloc_should_clear (1 samples, 50.00%)</title><rect x="0.0000%" y="69" width="50.0000%" height="15" fill="rgb(240,193,28)" fg:x="0" fg:w="1"/><text x="0.2500%" y="79.50">libsystem_malloc.dylib`small_malloc_should_clear</text></g><g><title>libsystem_malloc.dylib`mvm_allocate_pages (1 samples, 50.00%)</title><rect x="0.0000%" y="53" width="50.0000%" height="15" fill="rgb(216,20,37)" fg:x="0" fg:w="1"/><text x="0.2500%" y="63.50">libsystem_malloc.dylib`mvm_allocate_pages</text></g><g><title>libsystem_kernel.dylib`_kernelrpc_mach_vm_map_trap (1 samples, 50.00%)</title><rect x="0.0000%" y="37" width="50.0000%" height="15" fill="rgb(206,188,39)" fg:x="0" fg:w="1"/><text x="0.2500%" y="47.50">libsystem_kernel.dylib`_kernelrpc_mach_vm_map_trap</text></g><g><title>all (2 samples, 100%)</title><rect x="0.0000%" y="261" width="100.0000%" height="15" fill="rgb(217,207,13)" fg:x="0" fg:w="2"/><text x="0.2500%" y="271.50"></text></g><g><title>libsystem_kernel.dylib`__exit (1 samples, 50.00%)</title><rect x="50.0000%" y="245" width="50.0000%" height="15" fill="rgb(231,73,38)" fg:x="1" fg:w="1"/><text x="50.2500%" y="255.50">libsystem_kernel.dylib`__exit</text></g></svg></svg>

After

Width:  |  Height:  |  Size: 19 KiB

54
main-expanded.rs Normal file
View File

@ -0,0 +1,54 @@
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use std::io;
struct T {
name: String,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for T {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
T {
name: ref __self_0_0,
} => {
let debug_trait_builder = &mut ::core::fmt::Formatter::debug_struct(f, "T");
let _ =
::core::fmt::DebugStruct::field(debug_trait_builder, "name", &&(*__self_0_0));
::core::fmt::DebugStruct::finish(debug_trait_builder)
}
}
}
}
fn parse(s: &String) -> T {
T { name: s.clone() }
}
fn mamad(s: String) -> T {
parse(&s)
}
fn main() {
let mut buffer = String::new();
let stdin = io::stdin();
stdin.read_line(&mut buffer).unwrap();
let t = mamad(buffer);
{
::std::io::_print(::core::fmt::Arguments::new_v1_formatted(
&["", "\n"],
&[::core::fmt::ArgumentV1::new_debug(&t)],
&[::core::fmt::rt::v1::Argument {
position: 0usize,
format: ::core::fmt::rt::v1::FormatSpec {
fill: ' ',
align: ::core::fmt::rt::v1::Alignment::Unknown,
flags: 4u32,
precision: ::core::fmt::rt::v1::Count::Implied,
width: ::core::fmt::rt::v1::Count::Implied,
},
}],
unsafe { ::core::fmt::UnsafeArg::new() },
));
};
}

43
src/main.rs Normal file
View File

@ -0,0 +1,43 @@
use std::io;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
struct T {
name: String
}
fn parse(s: String) -> T {
T {
name: s.clone()
}
}
fn mamad() -> T {
let mut buff = String::new();
let stdin = io::stdin(); // We get `Stdin` here.
stdin.read_line(&mut buff).unwrap();
//let name = Box::new(s);
//parse(&name)
parse(buff)
}
fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let t = mamad();
println!("name: {}", t.name);
std::thread::sleep(std::time::Duration::from_secs(10));
drop(t);
println!("done");
std::thread::sleep(std::time::Duration::from_secs(10));
}

0
src/test.rs Normal file
View File