Apply clang-format to folly/experimental/exception_tracer/
authorYedidya Feldblum <yfeldblum@fb.com>
Tue, 29 Aug 2017 02:59:43 +0000 (19:59 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 29 Aug 2017 03:10:13 +0000 (20:10 -0700)
Summary: [Folly] Apply `clang-format` to `folly/experimental/exception_tracer/`.

Reviewed By: Orvid

Differential Revision: D5722994

fbshipit-source-id: 2e52c920119ba58d123aaffd59491d7561c37c17

folly/experimental/exception_tracer/ExceptionAbi.h
folly/experimental/exception_tracer/ExceptionCounterLib.cpp
folly/experimental/exception_tracer/ExceptionTracer.cpp
folly/experimental/exception_tracer/ExceptionTracer.h
folly/experimental/exception_tracer/ExceptionTracerLib.cpp
folly/experimental/exception_tracer/StackTrace.cpp
folly/experimental/exception_tracer/StackTrace.h
folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp
folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp

index 845fcdbec1606945e74c859091d88e366216b4b4..0e4623ba8695ea560d64a2c7c08c1c2da80ccee6 100644 (file)
@@ -28,7 +28,7 @@ namespace __cxxabiv1 {
 
 struct __cxa_exception {
   std::type_info* exceptionType;
-  void (*exceptionDestructor) (void*);
+  void (*exceptionDestructor)(void*);
   std::unexpected_handler unexpectedHandler;
   std::terminate_handler terminateHandler;
   __cxa_exception* nextException;
index c1a59cfb519b3e6bd856c6b659808d4645d2cee9..967a010c09706f50a8a87454c7808592c095ddbe 100644 (file)
@@ -77,11 +77,12 @@ std::vector<ExceptionStats> getExceptionStatistics() {
     result.push_back(std::move(item.second));
   }
 
-  std::sort(result.begin(),
-            result.end(),
-            [](const ExceptionStats& lhs, const ExceptionStats& rhs) {
-              return lhs.count > rhs.count;
-            });
+  std::sort(
+      result.begin(),
+      result.end(),
+      [](const ExceptionStats& lhs, const ExceptionStats& rhs) {
+        return lhs.count > rhs.count;
+      });
 
   return result;
 }
@@ -133,7 +134,9 @@ void throwHandler(void*, std::type_info* exType, void (*)(void*)) noexcept {
 }
 
 struct Initializer {
-  Initializer() { registerCxaThrowCallback(throwHandler); }
+  Initializer() {
+    registerCxaThrowCallback(throwHandler);
+  }
 };
 
 Initializer initializer;
index 232b09fc653a083827063324e9d1983f4383379c..bae1c8753a44b05acf7e9e284c2321d3ba6b0a42 100644 (file)
@@ -61,8 +61,7 @@ void printExceptionInfo(
     out << "(unknown type)";
   }
   out << " (" << info.frames.size()
-      << (info.frames.size() == 1 ? " frame" : " frames")
-      << ")\n";
+      << (info.frames.size() == 1 ? " frame" : " frames") << ")\n";
   try {
     size_t frameCount = info.frames.size();
 
@@ -104,9 +103,7 @@ namespace {
 bool isAbiCppException(const __cxa_exception* exc) {
   // The least significant four bytes must be "C++\0"
   static const uint64_t cppClass =
-    ((uint64_t)'C' << 24) |
-    ((uint64_t)'+' << 16) |
-    ((uint64_t)'+' << 8);
+      ((uint64_t)'C' << 24) | ((uint64_t)'+' << 16) | ((uint64_t)'+' << 8);
   return (exc->unwindHeader.exception_class & 0xffffffff) == cppClass;
 }
 
@@ -120,9 +117,8 @@ std::vector<ExceptionInfo> getCurrentExceptions() {
 
       if (!getExceptionStackTraceStackFn) {
         // Nope, see if it's in a shared library
-        getExceptionStackTraceStackFn =
-          (GetExceptionStackTraceStackType)dlsym(
-              RTLD_NEXT, "getExceptionStackTraceStack");
+        getExceptionStackTraceStackFn = (GetExceptionStackTraceStackType)dlsym(
+            RTLD_NEXT, "getExceptionStackTraceStack");
       }
     }
   };
@@ -139,14 +135,14 @@ std::vector<ExceptionInfo> getCurrentExceptions() {
     static bool logged = false;
     if (!logged) {
       LOG(WARNING)
-        << "Exception tracer library not linked, stack traces not available";
+          << "Exception tracer library not linked, stack traces not available";
       logged = true;
     }
   } else if ((traceStack = getExceptionStackTraceStackFn()) == nullptr) {
     static bool logged = false;
     if (!logged) {
       LOG(WARNING)
-        << "Exception stack trace invalid, stack traces not available";
+          << "Exception stack trace invalid, stack traces not available";
       logged = true;
     }
   }
@@ -158,10 +154,9 @@ std::vector<ExceptionInfo> getCurrentExceptions() {
     // standard ABI __cxa_exception objects, and are correctly labeled as
     // such in the exception_class field.  We could try to extract the
     // primary exception type in horribly hacky ways, but, for now, nullptr.
-    info.type =
-      isAbiCppException(currentException) ?
-      currentException->exceptionType :
-      nullptr;
+    info.type = isAbiCppException(currentException)
+        ? currentException->exceptionType
+        : nullptr;
 
     if (traceStack) {
       LOG_IF(DFATAL, !trace)
index 03c51b3db960efc4f387014097fe1fd199e76e09..a68ffd9a826d7811a5d8c9d49f9e3983cfb4a38d 100644 (file)
@@ -32,7 +32,7 @@ struct ExceptionInfo {
   // The values in frames are IP (instruction pointer) addresses.
   // They are only filled if the low-level exception tracer library is
   // linked in or LD_PRELOADed.
-  std::vector<uintptr_t> frames;  // front() is top of stack
+  std::vector<uintptr_t> frames; // front() is top of stack
 };
 
 void printExceptionInfo(
index dcee56921e918d1c17bb173e6db2ab2f7d034be2..07b13585222fe894703e0fd04854784b93b2a2af 100644 (file)
@@ -47,7 +47,9 @@ template <typename Function>
 class CallbackHolder {
  public:
   void registerCallback(Function f) {
-    SYNCHRONIZED(callbacks_) { callbacks_.push_back(std::move(f)); }
+    SYNCHRONIZED(callbacks_) {
+      callbacks_.push_back(std::move(f));
+    }
   }
 
   // always inline to enforce kInternalFramesNumber
@@ -93,14 +95,15 @@ DECLARE_CALLBACK(RethrowException);
 // calls need to go away. Everything else is messy though, so just
 // #define it to an empty macro under Clang and be done with it.
 #ifdef __clang__
-# define __builtin_unreachable()
+#define __builtin_unreachable()
 #endif
 
 namespace __cxxabiv1 {
 
-void __cxa_throw(void* thrownException,
-                 std::type_info* type,
-                 void (*destructor)(void*)) {
+void __cxa_throw(
+    void* thrownException,
+    std::type_info* type,
+    void (*destructor)(void*)) {
   static auto orig_cxa_throw =
       reinterpret_cast<decltype(&__cxa_throw)>(dlsym(RTLD_NEXT, "__cxa_throw"));
   getCxaThrowCallbacks().invoke(thrownException, type, destructor);
@@ -146,9 +149,9 @@ void rethrow_exception(std::exception_ptr ep) {
   // TODO(tudorb): Dicey, as it relies on the fact that std::exception_ptr
   // is typedef'ed to a type in namespace __exception_ptr
   static auto orig_rethrow_exception =
-      reinterpret_cast<decltype(&rethrow_exception)>(
-          dlsym(RTLD_NEXT,
-                "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE"));
+      reinterpret_cast<decltype(&rethrow_exception)>(dlsym(
+          RTLD_NEXT,
+          "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE"));
   getRethrowExceptionCallbacks().invoke(ep);
   orig_rethrow_exception(ep);
   __builtin_unreachable(); // orig_rethrow_exception never returns
index afa5dc17496f8db80488f0932d99601619c88b49..07fdc14775fc006f78a636dea8e3f0b4609e7780 100644 (file)
@@ -22,7 +22,8 @@
 
 #include <folly/experimental/symbolizer/StackTrace.h>
 
-namespace folly { namespace exception_tracer {
+namespace folly {
+namespace exception_tracer {
 
 class StackTraceStack::Node : public StackTrace {
  public:
@@ -32,8 +33,8 @@ class StackTraceStack::Node : public StackTrace {
   Node* next;
 
  private:
-  Node() : next(nullptr) { }
-  ~Node() { }
+  Node() : next(nullptr) {}
+  ~Node() {}
 };
 
 auto StackTraceStack::Node::allocate() -> Node* {
@@ -107,5 +108,5 @@ StackTrace* StackTraceStack::next(StackTrace* p) {
   assert(p);
   return static_cast<Node*>(p)->next;
 }
-
-}}  // namespaces
+} // namespace exception_tracer
+} // namespace folly
index 6c7657639021d9d67dd5450134de223511616e4c..ac100d31163cd2711b7ab4224cd40b0d54f4dee8 100644 (file)
 #include <cstddef>
 #include <cstdint>
 
-namespace folly { namespace exception_tracer {
+namespace folly {
+namespace exception_tracer {
 
 constexpr size_t kMaxFrames = 500;
 
 struct StackTrace {
-  StackTrace() : frameCount(0) { }
+  StackTrace() : frameCount(0) {}
 
   size_t frameCount;
   uintptr_t addresses[kMaxFrames];
@@ -35,6 +36,7 @@ struct StackTrace {
 // A StackTraceStack MUST be placed in zero-initialized memory.
 class StackTraceStack {
   class Node;
+
  public:
   /**
    * Push the current stack trace onto the stack.
@@ -64,7 +66,9 @@ class StackTraceStack {
   /**
    * Is the stack empty?
    */
-  bool empty() const { return !top_; }
+  bool empty() const {
+    return !top_;
+  }
 
   /**
    * Return the top stack trace, or nullptr if the stack is empty.
@@ -94,5 +98,5 @@ class StackTraceStack {
   uintptr_t guard2_;
 #endif
 };
-
-}}  // namespaces
+} // namespace exception_tracer
+} // namespace folly
index 93f464efd1f2b4d22a2b4c5e7348e12624f8358a..2ef8eb327df5de0cbaae0cb742b5dd15d10bf7a6 100644 (file)
@@ -111,8 +111,8 @@ TEST(ExceptionCounter, multyThreads) {
 
   {
     std::unique_lock<std::mutex> lock(preparedMutex);
-    preparedBarrier.wait(lock,
-                         [&]() { return preparedThreads == kNumThreads; });
+    preparedBarrier.wait(
+        lock, [&]() { return preparedThreads == kNumThreads; });
   }
 
   auto stats = getExceptionStatistics();
index 2e7b88cdf7271075242637565b68012143f395b7..35f536fc33994a3f71d42da45c3e06deec0dacb6 100644 (file)
@@ -29,7 +29,7 @@ void recurse(int level) {
     throw std::runtime_error("");
   }
   recurse(level - 1);
-  folly::doNotOptimizeAway(0);  // prevent tail recursion
+  folly::doNotOptimizeAway(0); // prevent tail recursion
 }
 
 void loop(int iters) {
@@ -47,7 +47,7 @@ BENCHMARK(ExceptionTracer, iters) {
   constexpr size_t kNumThreads = 10;
   threads.resize(10);
   for (auto& t : threads) {
-    t = std::thread([iters] () { loop(iters); });
+    t = std::thread([iters]() { loop(iters); });
   }
   for (auto& t : threads) {
     t.join();