Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

1 - Porting FlameGraph to rust

When running an application in Linux, you can use these commands before your application to understasnd more about where the CPU actually spending time when running your applicaation:

  • perf stat
  • perf record -g
    • After you are done with command, you can run perf report which reads the report for you! However, it is not much usefull!
  • perf record -g –call-graph dwarf

What is better for this? Use FlameGraph! :)

On MAC you can use dTrace instead of perf:

First run you application when running dTrace:

sudo dtrace -n 'profile-997 /pid == $target/ { @[ustack()] = count(); }' -c "./target/release/your_app" -o out.stacks

Then you need to run flamegraph:

./Flamegraph/stackcollapse.pl out.stacks > out.folded
./Flamegraph/flamegraph.pl out.folded > flamegraph.svg

Hardware and Softwares :D :

look at Firefox multi-account container look at j command


Question: What is the difference between using as usize or usze::form?

#![allow(unused)]
fn main() {
fn new(rows: u16, columns: u16) -> Self {
    Self {
        cells: vec![b' '; usize::from(rows)]
    }
}
}

In the code above, if instead of using usize::from we use rows as u16, in case function parameter type changes to u128, using as would compile without any issue. But, usize::from would not!


Video on 1BR

When you read the file, assuming you have a HashMap<String, String>, using .to_string() allocates memory in heap which is quite expensive for 1 billion row.

Since the README of this project states that the temperatures are real temperature (ascii code), we can use utf8_unchecked that saves all the runtime check

mmap crate helps you to have a file completely in the memory!

In this example if we have an if statement that checks whether there is - sign exists in the begining of a string, it will be 50-50 chance that the if is a hit or miss!

1