complete version

This commit is contained in:
Mahdi Dibaiee 2022-06-17 13:42:33 +01:00
parent 7e9e16690e
commit 3d2a9c67e7
17 changed files with 205 additions and 44 deletions

36
Cargo.lock generated
View File

@ -44,6 +44,20 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "box-str-dhat"
version = "0.1.0"
dependencies = [
"dhat",
]
[[package]]
name = "box-str-program"
version = "0.1.0"
dependencies = [
"dhat",
]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.73" version = "1.0.73"
@ -77,13 +91,6 @@ version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "heap-program"
version = "0.1.0"
dependencies = [
"dhat",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.12" version = "0.1.12"
@ -258,10 +265,25 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "stack-and-heap-program"
version = "0.1.0"
[[package]] [[package]]
name = "stack-program" name = "stack-program"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "string-dhat"
version = "0.1.0"
dependencies = [
"dhat",
]
[[package]]
name = "string-program"
version = "0.1.0"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.96" version = "1.0.96"

View File

@ -1,2 +1,2 @@
[workspace] [workspace]
members = ["stack-program", "heap-program"] members = ["stack-program", "stack-and-heap-program", "string-program", "box-str-program", "string-dhat", "box-str-dhat"]

View File

@ -1,5 +1,5 @@
[package] [package]
name = "heap-program" name = "box-str-dhat"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

10
box-str-dhat/src/main.rs Normal file
View File

@ -0,0 +1,10 @@
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() {
let _profiler = dhat::Profiler::new_heap();
let boxed_str: Box<str> = "hello".into();
println!("boxed_str: {}", boxed_str);
}

View File

@ -0,0 +1,10 @@
[package]
name = "box-str-program"
version = "0.1.0"
edition = "2021"
[dependencies]
dhat = "0.3.0"
[features]
dhat-heap = [] # if you are doing heap profiling

View File

@ -0,0 +1,6 @@
fn main() {
let boxed_str: Box<str> = "hello".into();
println!("boxed_str: {}", boxed_str);
println!("size of boxed_str on stack: {}", std::mem::size_of_val(&boxed_str));
}

93
dhat-heap.json Normal file
View File

@ -0,0 +1,93 @@
{
"dhatFileVersion": 2,
"mode": "rust-heap",
"verb": "Allocated",
"bklt": true,
"bkacc": false,
"tu": "µs",
"Mtu": "s",
"tuth": 10,
"cmd": "target/debug/box-str-dhat",
"pid": 76713,
"tg": 177,
"te": 209,
"pps": [
{
"tb": 5,
"tbk": 1,
"tl": 63,
"mb": 5,
"mbk": 1,
"gb": 5,
"gbk": 1,
"eb": 0,
"ebk": 0,
"fs": [
1,
2,
3,
4,
5,
6
]
},
{
"tb": 1024,
"tbk": 1,
"tl": 32,
"mb": 1024,
"mbk": 1,
"gb": 1024,
"gbk": 1,
"eb": 1024,
"ebk": 1,
"fs": [
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24
]
}
],
"ftbl": [
"[root]",
"0x1047ca668: <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc/src/alloc.rs:231:9)",
"0x1047c97bc: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc/src/raw_vec.rs:185:45)",
"0x1047c9d5c: alloc::raw_vec::RawVec<T,A>::with_capacity_in (alloc/src/raw_vec.rs:132:9)",
"0x104792bf8: alloc::raw_vec::RawVec<T>::with_capacity (alloc/src/raw_vec.rs:93:9)",
"0x104793128: <alloc::boxed::Box<[T]> as core::convert::From<&[T]>>::from (alloc/src/boxed.rs:1422:19)",
"0x1047928e4: <alloc::boxed::Box<str> as core::convert::From<&str>>::from (alloc/src/boxed.rs:1464:44)",
"0x1048b5920: <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc/src/alloc.rs:231:9)",
"0x1048b5920: alloc::raw_vec::RawVec<T,A>::allocate_in (alloc/src/raw_vec.rs:185:45)",
"0x1048b5920: alloc::raw_vec::RawVec<T,A>::with_capacity_in (alloc/src/raw_vec.rs:132:9)",
"0x1048b5920: alloc::vec::Vec<T,A>::with_capacity_in (src/vec/mod.rs:613:20)",
"0x1048b5920: alloc::vec::Vec<T>::with_capacity (src/vec/mod.rs:470:9)",
"0x1048b5920: std::io::buffered::bufwriter::BufWriter<W>::with_capacity (io/buffered/bufwriter.rs:115:33)",
"0x1048b5920: std::io::buffered::linewriter::LineWriter<W>::with_capacity (io/buffered/linewriter.rs:109:29)",
"0x1048b5920: std::io::buffered::linewriter::LineWriter<W>::new (io/buffered/linewriter.rs:89:9)",
"0x1048b5920: std::io::stdio::stdout::{{closure}} (src/io/stdio.rs:609:58)",
"0x1048b5920: std::lazy::SyncOnceCell<T>::get_or_init_pin::{{closure}} (std/src/lazy.rs:375:25)",
"0x1048b5920: std::sync::once::Once::call_once_force::{{closure}} (src/sync/once.rs:334:40)",
"0x1048d28fc: std::sync::once::Once::call_inner (src/sync/once.rs:434:21)",
"0x1048b3378: std::sync::once::Once::call_once_force (src/sync/once.rs:334:9)",
"0x1048b3378: std::lazy::SyncOnceCell<T>::get_or_init_pin (std/src/lazy.rs:374:9)",
"0x1048b3378: std::io::stdio::stdout (src/io/stdio.rs:608:16)",
"0x1048b3378: std::io::stdio::print_to (src/io/stdio.rs:1016:21)",
"0x1048b3378: std::io::stdio::_print (src/io/stdio.rs:1029:5)",
"0x104792d58: box_str_dhat::main (box-str-dhat/src/main.rs:9:5)"
]
}

View File

@ -1,35 +0,0 @@
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);
}

7
stack-and-heap-program/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "stack-and-heap-program"
version = "0.1.0"

View File

@ -0,0 +1,4 @@
[package]
name = "stack-and-heap-program"
version = "0.1.0"
edition = "2021"

View File

@ -0,0 +1,5 @@
fn main() {
let a = Box::new(5_u8);
let b = 10_u8;
println!("{}, {}", a, b);
}

7
string-dhat/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "string-dhat"
version = "0.1.0"

7
string-dhat/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "string-dhat"
version = "0.1.0"
edition = "2021"
[dependencies]
dhat = "0.3.0"

9
string-dhat/src/main.rs Normal file
View File

@ -0,0 +1,9 @@
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() {
let _profiler = dhat::Profiler::new_heap();
let s = String::from("hello");
println!("{}", s);
}

7
string-program/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "string-program"
version = "0.1.0"

View File

@ -0,0 +1,4 @@
[package]
name = "string-program"
version = "0.1.0"
edition = "2021"

View File

@ -0,0 +1,5 @@
fn main() {
let s = String::from("hello!");
println!("{}", s);
println!("size of string on stack: {}", std::mem::size_of_val(&s));
}