Allow usage of Symbolizer options for ExceptionStats printing
authorDmitry Pleshkov <bort@fb.com>
Wed, 6 Apr 2016 04:39:18 +0000 (21:39 -0700)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Wed, 6 Apr 2016 04:50:22 +0000 (21:50 -0700)
Summary: For exceptions aggregation conveniece

Reviewed By: philippv

Differential Revision: D3128132

fb-gh-sync-id: 48c72df364228c1d2c8f29161c2b85c131b4fea8
fbshipit-source-id: 48c72df364228c1d2c8f29161c2b85c131b4fea8

folly/experimental/exception_tracer/ExceptionTracer.cpp
folly/experimental/exception_tracer/ExceptionTracer.h
folly/experimental/symbolizer/Symbolizer.cpp
folly/experimental/symbolizer/Symbolizer.h

index f59d427bd066c8a6e4b00fd967a27626d9afc057..1e3159a568fe795f188dce83cbe864f3d861de1f 100644 (file)
@@ -44,6 +44,14 @@ namespace folly {
 namespace exception_tracer {
 
 std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
+  printExceptionInfo(out, info, SymbolizePrinter::COLOR_IF_TTY);
+  return out;
+}
+
+void printExceptionInfo(
+    std::ostream& out,
+    const ExceptionInfo& info,
+    int options) {
   out << "Exception type: ";
   if (info.type) {
     out << folly::demangle(*info.type);
@@ -68,7 +76,7 @@ std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
       Symbolizer symbolizer;
       symbolizer.symbolize(addresses, frames.data(), frameCount);
 
-      OStreamSymbolizePrinter osp(out, SymbolizePrinter::COLOR_IF_TTY);
+      OStreamSymbolizePrinter osp(out, options);
       osp.println(addresses, frames.data(), frameCount);
     }
   } catch (const std::exception& e) {
@@ -76,7 +84,6 @@ std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info) {
   } catch (...) {
     out << "\n !!! caught unexpected exception\n";
   }
-  return out;
 }
 
 namespace {
index f356b9bb6d2300fdb6442a594d54b13fa7cab6a9..febe9f2412b4bf160ed7d5498c097a3ef44195e9 100644 (file)
@@ -35,6 +35,10 @@ struct ExceptionInfo {
   std::vector<uintptr_t> frames;  // front() is top of stack
 };
 
+void printExceptionInfo(
+    std::ostream& out,
+    const ExceptionInfo& info,
+    int options);
 std::ostream& operator<<(std::ostream& out, const ExceptionInfo& info);
 
 /**
index f89482e4849c47d215e950850943b50a579aca30..926e5ffe99e99cb292fee230aa409e23b702b3ed 100644 (file)
@@ -345,10 +345,12 @@ void SymbolizePrinter::print(uintptr_t address, const SymbolizedFrame& frame) {
 
   SCOPE_EXIT { color(Color::DEFAULT); };
 
-  color(kAddressColor);
+  if (!(options_ & NO_FRAME_ADDRESS)) {
+    color(kAddressColor);
 
-  AddressFormatter formatter;
-  doPrint(formatter.format(address));
+    AddressFormatter formatter;
+    doPrint(formatter.format(address));
+  }
 
   const char padBuf[] = "                       ";
   folly::StringPiece pad(padBuf,
index 232cb30bed9dd5f9311f589633c9331aeb58130e..2914af832dc4828daabdaee535ba535ad72d477a 100644 (file)
@@ -203,6 +203,9 @@ class SymbolizePrinter {
 
     // Colorize output only if output is printed to a TTY (ANSI escape code)
     COLOR_IF_TTY = 1 << 3,
+
+    // Skip frame address information
+    NO_FRAME_ADDRESS = 1 << 4,
   };
 
   // NOTE: enum values used as indexes in kColorMap.