ah- / anne-key

Firmware for Anne Pro Keyboard written in Rust
Apache License 2.0
567 stars 32 forks source link

Misc cleanup #31

Closed hdhoang closed 6 years ago

hdhoang commented 6 years ago

Side note: cargo-bloat is a case where extra arguments for each run is useful, should we add support for those?

ah- commented 6 years ago

Thanks!

ah- commented 6 years ago

Side note: cargo-bloat is a case where extra arguments for each run is useful, should we add support for those?

How would that look like?

hdhoang commented 6 years ago

That would look like so:

➤ make bloat BLOAT_ARGS="--crates"
xargo bloat --release --target thumbv7m-none-eabi --crates
    Finished release [optimized + debuginfo] target(s) in 0.0 secs
File  .text   Size Name
0.6%  40.6% 2.4KiB cortex_m_rt
0.5%  36.1% 2.1KiB anne_key
0.2%  13.0%   772B stm32l151
0.1%  10.3%   612B std
1.4% 100.0% 5.8KiB .text section size, the file size is 418.4KiB

➤ make bloat BLOAT_ARGS="--filter anne_key"
xargo bloat --release --target thumbv7m-none-eabi --filter anne_key
    Finished release [optimized + debuginfo] target(s) in 0.0 secs
File  .text   Size Name
0.9%  63.9% 3.7KiB [34 Others]
0.3%  23.6% 1.4KiB anne_key::init
0.1%   4.5%   270B <anne_key::serial::Serial<'a, USART>>::send
0.1%   4.3%   258B <anne_key::serial::Serial<'a, USART>>::send
0.1%   3.7%   218B anne_key::main
1.4% 100.0% 5.8KiB .text section size, the file size is 418.4KiB

➤ make bloat
xargo bloat --release --target thumbv7m-none-eabi
    Finished release [optimized + debuginfo] target(s) in 0.0 secs
File  .text   Size Name
0.0%   2.7%   158B [18 Others]
0.4%  31.9% 1.9KiB SYS_TICK
0.3%  23.6% 1.4KiB anne_key::init
0.1%   7.1%   424B cortex_m_rt::reset_handler
0.1%   6.9%   410B DMA1_CHANNEL6
0.1%   4.5%   270B <anne_key::serial::Serial<'a, USART>>::send
0.1%   4.3%   258B <anne_key::serial::Serial<'a, USART>>::send
0.1%   3.7%   218B anne_key::main
0.0%   3.2%   192B DMA1_CHANNEL3
0.0%   3.1%   186B __aeabi_memcpy4
0.0%   2.8%   166B __aeabi_memset4
0.0%   1.7%   100B memset
0.0%   1.6%    96B memcpy
0.0%   0.6%    38B DMA1_CHANNEL7
0.0%   0.6%    36B DMA1_CHANNEL2
0.0%   0.3%    16B EXTI9_5
0.0%   0.3%    16B EXTI4
0.0%   0.3%    16B EXTI1
0.0%   0.3%    16B EXTI0
0.0%   0.3%    16B EXTI2
0.0%   0.3%    16B EXTI3
1.4% 100.0% 5.8KiB .text section size, the file size is 418.4KiB

When we use more crates (eg bitfields for #27), this could be useful.

ah- commented 6 years ago

Interesting. The other thing I wanted to try out around cargo bloat was to make it show more granular information. Because of all the LTO all the code ends up in SYS_TICK and anne_key, which is great for getting the smallest binary but doesn't really tell you much if you're trying to keep it slim.

I tried running cargo bloat with --debug, but then the binary is just too big, so we'd need to either hack the linker file to fake more memory than the stm32l1 actually has, or somehow still build in release mode but disable LTO.