Skip to content

Commit

Permalink
Use stack trace implementation in common/process on fbcode (#56400)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #56400

See #56399

I don't have time to fix this properly, so this is just to stem the
bleeding.  Someone should go and figure out what it is that common/process
is doing better.
ghstack-source-id: 126868405

Test Plan:
I manually patched this into D27765125 and triggered a
exception and observed that everything symbolized good:

```
[9]   what():  new_refcount != 1INTERNAL ASSERT FAILED at "caffe2/c10/util/intrusive_ptr.h":234, please report a bug to PyTorch. intrusive_ptr: Cannot increase refcount after it reached zero.
Exception raised from retain_ at caffe2/c10/util/intrusive_ptr.h:234 (most recent call first):
# 0  c10::get_backtrace[abi:cxx11](unsigned long, unsigned long, bool)
# 1  c10::(anonymous namespace)::GetFetchStackTrace[abi:cxx11]()::$_0::operator()[abi:cxx11]() const
# 2  std::_Function_handler<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > (), c10::(anonymous namespace)::Ge
tFetchStackTrace()::$_0>::_M_invoke(std::_Any_data const&)
# 3  std::function<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > ()>::operator()() const
# 4  c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)
# 5  c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocat
or<char> > const&)
# 6  c10::detail::torchInternalAssertFail(char const*, char const*, unsigned int, char const*, char const*)
# 7  c10::intrusive_ptr<c10d::ProcessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessGroup> >::retain_()
# 8  c10::intrusive_ptr<c10d::ProcessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessGroup> >::intrusive_ptr(c10::intrusiv
e_ptr<c10d::ProcessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessGroup> > const&)
# 9  c10::intrusive_ptr<c10d::ProcessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessGroup> >& c10::intrusive_ptr<c10d::Pr
ocessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessGroup> >::operator=<c10d::ProcessGroup, c10::detail::intrusive_target
_default_null_type<c10d::ProcessGroup> >(c10::intrusive_ptr<c10d::ProcessGroup, c10::detail::intrusive_target_default_null_type<c10d::ProcessG
roup> > const&) &
```

Reviewed By: driazati

Differential Revision: D27861908

fbshipit-source-id: 84c1dfb1ef28c460b020646f836c153562ad5c44
  • Loading branch information
ezyang authored and facebook-github-bot committed Apr 20, 2021
1 parent f096245 commit b1282bc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion c10/util/Backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <execinfo.h>
#endif

#ifdef FBCODE_CAFFE2
#include <common/process/StackTrace.h>
#endif

namespace c10 {

#if SUPPORTS_BACKTRACE
Expand Down Expand Up @@ -167,7 +171,14 @@ std::string get_backtrace(
size_t frames_to_skip,
size_t maximum_number_of_frames,
bool skip_python_frames) {
#if SUPPORTS_BACKTRACE
#ifdef FBCODE_CAFFE2
// For some reason, the stacktrace implementation in fbcode is
// better than ours, see https://github.com/pytorch/pytorch/issues/56399
// When it's available, just use that.
facebook::process::StackTrace st;
return st.toString();

#elif SUPPORTS_BACKTRACE

// We always skip this frame (backtrace).
frames_to_skip += 1;
Expand Down

0 comments on commit b1282bc

Please sign in to comment.