first version for blog
This commit is contained in:
parent
9b41b7ce44
commit
7e9e16690e
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
||||
/target
|
||||
target
|
||||
|
18
Cargo.lock
generated
18
Cargo.lock
generated
@ -77,6 +77,13 @@ version = "0.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
|
||||
|
||||
[[package]]
|
||||
name = "heap-program"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dhat",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.12"
|
||||
@ -251,6 +258,10 @@ version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||
|
||||
[[package]]
|
||||
name = "stack-program"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.96"
|
||||
@ -295,10 +306,3 @@ 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",
|
||||
]
|
||||
|
18
Cargo.toml
18
Cargo.toml
@ -1,16 +1,2 @@
|
||||
[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
|
||||
[workspace]
|
||||
members = ["stack-program", "heap-program"]
|
||||
|
@ -1,39 +0,0 @@
|
||||
{
|
||||
"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
237
dhat-heap.json
@ -1,237 +0,0 @@
|
||||
{
|
||||
"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
414
flamegraph.svg
@ -1,414 +0,0 @@
|
||||
<?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>
|
Before Width: | Height: | Size: 19 KiB |
10
heap-program/Cargo.toml
Normal file
10
heap-program/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "heap-program"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dhat = "0.3.0"
|
||||
|
||||
[features]
|
||||
dhat-heap = [] # if you are doing heap profiling
|
35
heap-program/src/main.rs
Normal file
35
heap-program/src/main.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::io::{self, Read};
|
||||
|
||||
fn stdin_boxed_str() -> Box<str> {
|
||||
let mut buff = [0; 10];
|
||||
let mut stdin = io::stdin(); // We get `Stdin` here.
|
||||
stdin.read(&mut buff).unwrap();
|
||||
let s = std::str::from_utf8(&buff).unwrap();
|
||||
|
||||
s.into()
|
||||
}
|
||||
|
||||
fn stdin_string() -> String {
|
||||
let mut buff = String::new();
|
||||
std::io::stdin().read_line(&mut buff).unwrap();
|
||||
|
||||
buff
|
||||
}
|
||||
|
||||
fn my_simple_program(a: i32) -> i32 {
|
||||
let b = 10;
|
||||
a + b
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("{}", my_simple_program(5));
|
||||
|
||||
let boxed_str = stdin_boxed_str();
|
||||
|
||||
println!("boxed_str: {}", boxed_str);
|
||||
|
||||
let stdin_str = stdin_string();
|
||||
|
||||
println!("stdin_str: {}", stdin_str);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
#![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
43
src/main.rs
@ -1,43 +0,0 @@
|
||||
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));
|
||||
}
|
7
stack-program/Cargo.lock
generated
Normal file
7
stack-program/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "stack-program"
|
||||
version = "0.1.0"
|
4
stack-program/Cargo.toml
Normal file
4
stack-program/Cargo.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[package]
|
||||
name = "stack-program"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
9
stack-program/src/main.rs
Normal file
9
stack-program/src/main.rs
Normal file
@ -0,0 +1,9 @@
|
||||
fn add_ten(a: u8) -> u8 {
|
||||
let b = 10;
|
||||
a + b
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("{}", add_ten(9));
|
||||
}
|
Loading…
Reference in New Issue
Block a user