diff --git a/.gitignore b/.gitignore index ea8c4bf..eb5a316 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/target +target diff --git a/Cargo.lock b/Cargo.lock index 37b9dd0..2d05054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", -] diff --git a/Cargo.toml b/Cargo.toml index 6467266..60fa435 100644 --- a/Cargo.toml +++ b/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"] diff --git a/dhat-ad-hoc.json b/dhat-ad-hoc.json deleted file mode 100644 index 6cf6b45..0000000 --- a/dhat-ad-hoc.json +++ /dev/null @@ -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)" -] -} \ No newline at end of file diff --git a/dhat-heap.json b/dhat-heap.json deleted file mode 100644 index ffa85cc..0000000 --- a/dhat-heap.json +++ /dev/null @@ -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: ::allocate (alloc/src/alloc.rs:231:9)", -"0x10488971c: alloc::raw_vec::RawVec::allocate_in (alloc/src/raw_vec.rs:185:45)", -"0x10488971c: alloc::raw_vec::RawVec::with_capacity_in (alloc/src/raw_vec.rs:132:9)", -"0x10488971c: alloc::raw_vec::RawVec::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::with_capacity (io/buffered/bufreader.rs:96:19)", -"0x10488971c: std::io::stdio::stdin::{{closure}} (src/io/stdio.rs:324:24)", -"0x10488971c: std::lazy::SyncOnceCell::get_or_init::{{closure}} (std/src/lazy.rs:281:50)", -"0x10488971c: std::lazy::SyncOnceCell::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::initialize (std/src/lazy.rs:461:9)", -"0x1048865b4: std::lazy::SyncOnceCell::get_or_try_init (std/src/lazy.rs:328:9)", -"0x1048865b4: std::lazy::SyncOnceCell::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::grow_amortized (alloc/src/raw_vec.rs:400:19)", -"0x1048a6210: alloc::raw_vec::RawVec::reserve::do_reserve_and_handle (alloc/src/raw_vec.rs:285:28)", -"0x104887d40: alloc::raw_vec::RawVec::reserve (alloc/src/raw_vec.rs:289:13)", -"0x104887d40: alloc::vec::Vec::reserve (src/vec/mod.rs:813:9)", -"0x104887d40: alloc::vec::Vec::append_elements (src/vec/mod.rs:1798:9)", -"0x104887d40: as alloc::vec::spec_extend::SpecExtend<&T,core::slice::iter::Iter>>::spec_extend (src/vec/spec_extend.rs:85:18)", -"0x104887d40: alloc::vec::Vec::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: ::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::new (alloc/src/boxed.rs:195:9)", -"0x10488a528: as core::convert::From>::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::new (src/sync/mutex.rs:218:20)", -"0x104889734: std::io::stdio::stdin::{{closure}} (src/io/stdio.rs:324:13)", -"0x104889734: std::lazy::SyncOnceCell::get_or_init::{{closure}} (std/src/lazy.rs:281:50)", -"0x104889734: std::lazy::SyncOnceCell::initialize::{{closure}} (std/src/lazy.rs:462:19)", -"0x104889734: std::sync::once::Once::call_once_force::{{closure}} (src/sync/once.rs:334:40)", -"0x10489bd58: ::allocate (alloc/src/alloc.rs:231:9)", -"0x10489bd58: alloc::raw_vec::RawVec::allocate_in (alloc/src/raw_vec.rs:185:45)", -"0x10489bd58: alloc::raw_vec::RawVec::with_capacity_in (alloc/src/raw_vec.rs:132:9)", -"0x10489bd58: alloc::vec::Vec::with_capacity_in (src/vec/mod.rs:613:20)", -"0x10489bd58: ::to_vec (alloc/src/slice.rs:227:25)", -"0x10489bd58: alloc::slice::hack::to_vec (alloc/src/slice.rs:176:9)", -"0x10489bd58: alloc::slice::::to_vec_in (alloc/src/slice.rs:507:9)", -"0x10489bd58: as core::clone::Clone>::clone (src/vec/mod.rs:2485:9)", -"0x10489bd58: ::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: ::allocate (alloc/src/alloc.rs:231:9)", -"0x1048897e8: alloc::raw_vec::RawVec::allocate_in (alloc/src/raw_vec.rs:185:45)", -"0x1048897e8: alloc::raw_vec::RawVec::with_capacity_in (alloc/src/raw_vec.rs:132:9)", -"0x1048897e8: alloc::vec::Vec::with_capacity_in (src/vec/mod.rs:613:20)", -"0x1048897e8: alloc::vec::Vec::with_capacity (src/vec/mod.rs:470:9)", -"0x1048897e8: std::io::buffered::bufwriter::BufWriter::with_capacity (io/buffered/bufwriter.rs:115:33)", -"0x1048897e8: std::io::buffered::linewriter::LineWriter::with_capacity (io/buffered/linewriter.rs:109:29)", -"0x1048897e8: std::io::buffered::linewriter::LineWriter::new (io/buffered/linewriter.rs:89:9)", -"0x1048897e8: std::io::stdio::stdout::{{closure}} (src/io/stdio.rs:609:58)", -"0x1048897e8: std::lazy::SyncOnceCell::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::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)" -] -} \ No newline at end of file diff --git a/flamegraph.svg b/flamegraph.svg deleted file mode 100644 index bd2a9c0..0000000 --- a/flamegraph.svg +++ /dev/null @@ -1,414 +0,0 @@ -Flame Graph Reset ZoomSearch dyld`start (1 samples, 50.00%)dyld`startzero-copy-deserialize`main (1 samples, 50.00%)zero-copy-deserialize`mainzero-copy-deserialize`std::rt::lang_start_internal (1 samples, 50.00%)zero-copy-deserialize`std::rt::lang_start_internalzero-copy-deserialize`std::rt::lang_start::_{{closure}} (1 samples, 50.00%)zero-copy-deserialize`std::rt::lang_start::_{{closure}}zero-copy-deserialize`std::sys_common::backtrace::__rust_begin_short_backtrace (1 samples, 50.00%)zero-copy-deserialize`std::sys_common::backtrace::__rust_begin_short_backtracezero-copy-deserialize`zero_copy_deserialize::main (1 samples, 50.00%)zero-copy-deserialize`zero_copy_deserialize::mainzero-copy-deserialize`std::io::stdio::_print (1 samples, 50.00%)zero-copy-deserialize`std::io::stdio::_printzero-copy-deserialize`std::sync::once::Once::call_inner (1 samples, 50.00%)zero-copy-deserialize`std::sync::once::Once::call_innerzero-copy-deserialize`std::sync::once::Once::call_once_force::_{{closure}} (1 samples, 50.00%)zero-copy-deserialize`std::sync::once::Once::call_once_force::_{{closure}}libsystem_malloc.dylib`_malloc_zone_malloc (1 samples, 50.00%)libsystem_malloc.dylib`_malloc_zone_malloclibsystem_malloc.dylib`szone_malloc_should_clear (1 samples, 50.00%)libsystem_malloc.dylib`szone_malloc_should_clearlibsystem_malloc.dylib`small_malloc_should_clear (1 samples, 50.00%)libsystem_malloc.dylib`small_malloc_should_clearlibsystem_malloc.dylib`mvm_allocate_pages (1 samples, 50.00%)libsystem_malloc.dylib`mvm_allocate_pageslibsystem_kernel.dylib`_kernelrpc_mach_vm_map_trap (1 samples, 50.00%)libsystem_kernel.dylib`_kernelrpc_mach_vm_map_trapall (2 samples, 100%)libsystem_kernel.dylib`__exit (1 samples, 50.00%)libsystem_kernel.dylib`__exit \ No newline at end of file diff --git a/heap-program/Cargo.toml b/heap-program/Cargo.toml new file mode 100644 index 0000000..53d8fe1 --- /dev/null +++ b/heap-program/Cargo.toml @@ -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 diff --git a/heap-program/src/main.rs b/heap-program/src/main.rs new file mode 100644 index 0000000..ee8eae7 --- /dev/null +++ b/heap-program/src/main.rs @@ -0,0 +1,35 @@ +use std::io::{self, Read}; + +fn stdin_boxed_str() -> Box { + 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); +} diff --git a/main-expanded.rs b/main-expanded.rs deleted file mode 100644 index 9d73013..0000000 --- a/main-expanded.rs +++ /dev/null @@ -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() }, - )); - }; -} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index bd4ada5..0000000 --- a/src/main.rs +++ /dev/null @@ -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)); -} diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index e69de29..0000000 diff --git a/stack-program/Cargo.lock b/stack-program/Cargo.lock new file mode 100644 index 0000000..ea20ae4 --- /dev/null +++ b/stack-program/Cargo.lock @@ -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" diff --git a/stack-program/Cargo.toml b/stack-program/Cargo.toml new file mode 100644 index 0000000..1620382 --- /dev/null +++ b/stack-program/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "stack-program" +version = "0.1.0" +edition = "2021" diff --git a/stack-program/src/main.rs b/stack-program/src/main.rs new file mode 100644 index 0000000..51145e1 --- /dev/null +++ b/stack-program/src/main.rs @@ -0,0 +1,9 @@ +fn add_ten(a: u8) -> u8 { + let b = 10; + a + b +} + + +fn main() { + println!("{}", add_ten(9)); +}