proxygen
folly::symbolizer::FastStackTracePrinter Class Reference

#include <Symbolizer.h>

Public Member Functions

 FastStackTracePrinter (std::unique_ptr< SymbolizePrinter > printer, size_t elfCacheSize=0, size_t symbolCacheSize=kDefaultSymbolCacheSize)
 
 ~FastStackTracePrinter ()
 
FOLLY_NOINLINE void printStackTrace (bool symbolize)
 
void flush ()
 

Static Public Attributes

static constexpr size_t kDefaultSymbolCacheSize = 10000
 

Private Attributes

const std::unique_ptr< ElfCacheelfCache_
 
const std::unique_ptr< SymbolizePrinterprinter_
 
Symbolizer symbolizer_
 

Static Private Attributes

static constexpr size_t kMaxStackTraceDepth = 100
 

Detailed Description

Use this class to print a stack trace from normal code. It will malloc and won't flush or sync.

These methods are thread safe, through locking. However, they are not signal safe.

Definition at line 397 of file Symbolizer.h.

Constructor & Destructor Documentation

folly::symbolizer::FastStackTracePrinter::FastStackTracePrinter ( std::unique_ptr< SymbolizePrinter printer,
size_t  elfCacheSize = 0,
size_t  symbolCacheSize = kDefaultSymbolCacheSize 
)
explicit

Definition at line 463 of file Symbolizer.cpp.

References folly::symbolizer::countLoadedElfFiles(), elfCache_, folly::symbolizer::Dwarf::FULL, max, folly::gen::move, printer_, and symbolizer_.

467  : elfCache_(
468  elfCacheSize == 0
469  ? nullptr
470  : new ElfCache{std::max(countLoadedElfFiles(), elfCacheSize)}),
471  printer_(std::move(printer)),
472  symbolizer_(
473  elfCache_ ? elfCache_.get() : defaultElfCache(),
475  symbolCacheSize) {}
const std::unique_ptr< SymbolizePrinter > printer_
Definition: Symbolizer.h:420
LogLevel max
Definition: LogLevel.cpp:31
const std::unique_ptr< ElfCache > elfCache_
Definition: Symbolizer.h:419
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t countLoadedElfFiles()
Definition: ElfCache.cpp:32
folly::symbolizer::FastStackTracePrinter::~FastStackTracePrinter ( )

Definition at line 477 of file Symbolizer.cpp.

477 {}

Member Function Documentation

void folly::symbolizer::FastStackTracePrinter::flush ( )

Definition at line 505 of file Symbolizer.cpp.

References addr, and printer_.

505  {
506  printer_->flush();
507 }
const std::unique_ptr< SymbolizePrinter > printer_
Definition: Symbolizer.h:420
void folly::symbolizer::FastStackTracePrinter::printStackTrace ( bool  symbolize)

This is NOINLINE to make sure it shows up in the stack we grab, which makes it easy to skip printing it.

Definition at line 479 of file Symbolizer.cpp.

References folly::symbolizer::FrameArray< N >::addresses, folly::symbolizer::AddressFormatter::format(), folly::symbolizer::FrameArray< N >::frameCount, folly::symbolizer::getStackTraceSafe(), i, printer_, SCOPE_EXIT, folly::symbolizer::Symbolizer::symbolize(), and symbolizer_.

479  {
480  SCOPE_EXIT {
481  printer_->flush();
482  };
483 
484  FrameArray<kMaxStackTraceDepth> addresses;
485 
486  if (!getStackTraceSafe(addresses)) {
487  printer_->print("(error retrieving stack trace)\n");
488  } else if (symbolize) {
489  symbolizer_.symbolize(addresses);
490 
491  // Skip the top 2 frames:
492  // getStackTraceSafe
493  // FastStackTracePrinter::printStackTrace (here)
494  printer_->println(addresses, 2);
495  } else {
496  printer_->print("(safe mode, symbolizer not available)\n");
497  AddressFormatter formatter;
498  for (size_t i = 0; i < addresses.frameCount; ++i) {
499  printer_->print(formatter.format(addresses.addresses[i]));
500  printer_->print("\n");
501  }
502  }
503 }
const std::unique_ptr< SymbolizePrinter > printer_
Definition: Symbolizer.h:420
ssize_t getStackTraceSafe(uintptr_t *addresses, size_t maxAddresses)
Definition: StackTrace.cpp:53
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
void symbolize(const uintptr_t *addresses, SymbolizedFrame *frames, size_t frameCount)
Definition: Symbolizer.cpp:94

Member Data Documentation

const std::unique_ptr<ElfCache> folly::symbolizer::FastStackTracePrinter::elfCache_
private

Definition at line 419 of file Symbolizer.h.

Referenced by FastStackTracePrinter().

constexpr size_t folly::symbolizer::FastStackTracePrinter::kDefaultSymbolCacheSize = 10000
static

Definition at line 399 of file Symbolizer.h.

constexpr size_t folly::symbolizer::FastStackTracePrinter::kMaxStackTraceDepth = 100
staticprivate

Definition at line 417 of file Symbolizer.h.

const std::unique_ptr<SymbolizePrinter> folly::symbolizer::FastStackTracePrinter::printer_
private

Definition at line 420 of file Symbolizer.h.

Referenced by FastStackTracePrinter(), flush(), and printStackTrace().

Symbolizer folly::symbolizer::FastStackTracePrinter::symbolizer_
private

Definition at line 421 of file Symbolizer.h.

Referenced by FastStackTracePrinter(), and printStackTrace().


The documentation for this class was generated from the following files: