databend icon indicating copy to clipboard operation
databend copied to clipboard

refactor(base): add stacktrace to replace backtrace

Open zhang2014 opened this issue 1 year ago โ€ข 1 comments

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

refactor(base): add stacktrace to replace backtrace

Tests

  • [x] Unit Test
  • [x] Logic Test
  • [ ] Benchmark Test
  • [x] No Test - ci build pass

Type of change

  • [ ] Bug Fix (non-breaking change which fixes an issue)
  • [ ] New Feature (non-breaking change which adds functionality)
  • [ ] Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • [ ] Documentation Update
  • [x] Refactoring
  • [ ] Performance Improvement
  • [ ] Other (please describe):

This change isโ€‚Reviewable

zhang2014 avatar Oct 19 '24 10:10 zhang2014

binary size:

ls -lsh ./target/release/databend-query*
332M -rwxr-xr-x 2 ubuntu ubuntu 332M Oct 19 11:07 ./target/release/databend-query
1.2G -rw-r--r-- 1 ubuntu ubuntu 1.2G Oct 19 11:16 ./target/release/databend-query.debug

default:

./target/release/databend-query


   0: backtrace::backtrace::libunwind::trace[inlined]
             at /opt/rust/cargo/git/checkouts/backtrace-rs-fb1f822361417489/72265be/src/backtrace/libunwind.rs:116:5
   1: backtrace::backtrace::trace_unsynchronized[inlined]
             at /opt/rust/cargo/git/checkouts/backtrace-rs-fb1f822361417489/72265be/src/backtrace/mod.rs:66:5
   2: databend_common_exception::exception_backtrace::StackTrace::capture_frames[inlined]
             at /workspace/src/common/exception/src/exception_backtrace.rs:150:13
   3: databend_common_exception::exception_backtrace::StackTrace::capture@50cee64
             at /workspace/src/common/exception/src/exception_backtrace.rs:143:9
   4: databend_query::main@9194388
             at /workspace/src/binaries/query/ee_main.rs:42:23
   5: core::ops::function::FnOnce::call_once[inlined]
             at /rustc/cf2df68d1f5e56803c97d91e2b1a9f1c9923c533/library/core/src/ops/function.rs:250:5
   6: std::sys::backtrace::__rust_begin_short_backtrace@9194c24

remove debug file

rm ./target/release/databend-query.debug 
./target/release/databend-query


   0: <unknown>@50cee64
   1: databend_query::main::hb7b11b0ec1f24acb@9194388
   2: <unknown>@9194c24
   3: <unknown>@919d644
   4: <unknown>@a677100
   5: <unknown>@9194844
   6: <unknown>@284c4
   7: __libc_start_main@28598
   8: <unknown>@414d034

use addr2line to parse address

addr2line -e  ./target/databend-query.debug -a 50cee64 -a 9194388 -a 9194c24 -f -i -C
0x00000000050cee64
databend_common_exception::exception_backtrace::StackTrace::capture
/workspace/src/common/exception/src/exception_backtrace.rs:144
0x0000000009194388
databend_query::main
/workspace/src/binaries/query/ee_main.rs:44
0x0000000009194c24
std::sys::backtrace::__rust_begin_short_backtrace
/rustc/cf2df68d1f5e56803c97d91e2b1a9f1c9923c533/library/std/src/sys/backtrace.rs:161

restore debug file

cp target/databend-query.debug target/release/databend-query.debug
./target/release/databend-query


   0: backtrace::backtrace::libunwind::trace[inlined]
             at /opt/rust/cargo/git/checkouts/backtrace-rs-fb1f822361417489/72265be/src/backtrace/libunwind.rs:116:5
   1: backtrace::backtrace::trace_unsynchronized[inlined]
             at /opt/rust/cargo/git/checkouts/backtrace-rs-fb1f822361417489/72265be/src/backtrace/mod.rs:66:5
   2: databend_common_exception::exception_backtrace::StackTrace::capture_frames[inlined]
             at /workspace/src/common/exception/src/exception_backtrace.rs:150:13
   3: databend_common_exception::exception_backtrace::StackTrace::capture@50cee64
             at /workspace/src/common/exception/src/exception_backtrace.rs:143:9
   4: databend_query::main@9194388
             at /workspace/src/binaries/query/ee_main.rs:42:23
   5: core::ops::function::FnOnce::call_once[inlined]
             at /rustc/cf2df68d1f5e56803c97d91e2b1a9f1c9923c533/library/core/src/ops/function.rs:250:5
   6: std::sys::backtrace::__rust_begin_short_backtrace@9194c24

zhang2014 avatar Oct 19 '24 11:10 zhang2014

aarch64-unknown-linux-gnu and x86_64-unknown-linux-musl test passed.

zhang2014 avatar Nov 08 '24 01:11 zhang2014

@zhang2014 Good job! Will you consider to publish it as a crate?

andylokandy avatar Nov 08 '24 03:11 andylokandy

@zhang2014 Good job! Will you consider to publish it as a crate?

Itโ€˜s only rewritten for ELF, so I think it may not be able to handle all scenarios.

zhang2014 avatar Nov 08 '24 03:11 zhang2014

be able to handle all scenarios.

A crate doesn't need to handle all scenarios. It's quite useful even if itโ€™s only rewritten for ELF. I encourage publishing a crate for us, which may attract other contributors and make it much easier to test and reuse.

Xuanwo avatar Nov 08 '24 03:11 Xuanwo