From 2a0318b45560f840479547b64b9032da49be16f0 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Mon, 28 Aug 2017 19:59:43 -0700 Subject: [PATCH] Apply clang-format to folly/experimental/exception_tracer/ Summary: [Folly] Apply `clang-format` to `folly/experimental/exception_tracer/`. Reviewed By: Orvid Differential Revision: D5722994 fbshipit-source-id: 2e52c920119ba58d123aaffd59491d7561c37c17 --- .../exception_tracer/ExceptionAbi.h | 2 +- .../exception_tracer/ExceptionCounterLib.cpp | 15 +++++++----- .../exception_tracer/ExceptionTracer.cpp | 23 ++++++++----------- .../exception_tracer/ExceptionTracer.h | 2 +- .../exception_tracer/ExceptionTracerLib.cpp | 19 ++++++++------- .../exception_tracer/StackTrace.cpp | 11 +++++---- .../exception_tracer/StackTrace.h | 14 +++++++---- .../test/ExceptionCounterTest.cpp | 4 ++-- .../test/ExceptionTracerBenchmark.cpp | 4 ++-- 9 files changed, 50 insertions(+), 44 deletions(-) diff --git a/folly/experimental/exception_tracer/ExceptionAbi.h b/folly/experimental/exception_tracer/ExceptionAbi.h index 845fcdbe..0e4623ba 100644 --- a/folly/experimental/exception_tracer/ExceptionAbi.h +++ b/folly/experimental/exception_tracer/ExceptionAbi.h @@ -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; diff --git a/folly/experimental/exception_tracer/ExceptionCounterLib.cpp b/folly/experimental/exception_tracer/ExceptionCounterLib.cpp index c1a59cfb..967a010c 100644 --- a/folly/experimental/exception_tracer/ExceptionCounterLib.cpp +++ b/folly/experimental/exception_tracer/ExceptionCounterLib.cpp @@ -77,11 +77,12 @@ std::vector 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; diff --git a/folly/experimental/exception_tracer/ExceptionTracer.cpp b/folly/experimental/exception_tracer/ExceptionTracer.cpp index 232b09fc..bae1c875 100644 --- a/folly/experimental/exception_tracer/ExceptionTracer.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracer.cpp @@ -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 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 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 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) diff --git a/folly/experimental/exception_tracer/ExceptionTracer.h b/folly/experimental/exception_tracer/ExceptionTracer.h index 03c51b3d..a68ffd9a 100644 --- a/folly/experimental/exception_tracer/ExceptionTracer.h +++ b/folly/experimental/exception_tracer/ExceptionTracer.h @@ -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 frames; // front() is top of stack + std::vector frames; // front() is top of stack }; void printExceptionInfo( diff --git a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp index dcee5692..07b13585 100644 --- a/folly/experimental/exception_tracer/ExceptionTracerLib.cpp +++ b/folly/experimental/exception_tracer/ExceptionTracerLib.cpp @@ -47,7 +47,9 @@ template 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(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( - dlsym(RTLD_NEXT, - "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE")); + reinterpret_cast(dlsym( + RTLD_NEXT, + "_ZSt17rethrow_exceptionNSt15__exception_ptr13exception_ptrE")); getRethrowExceptionCallbacks().invoke(ep); orig_rethrow_exception(ep); __builtin_unreachable(); // orig_rethrow_exception never returns diff --git a/folly/experimental/exception_tracer/StackTrace.cpp b/folly/experimental/exception_tracer/StackTrace.cpp index afa5dc17..07fdc147 100644 --- a/folly/experimental/exception_tracer/StackTrace.cpp +++ b/folly/experimental/exception_tracer/StackTrace.cpp @@ -22,7 +22,8 @@ #include -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(p)->next; } - -}} // namespaces +} // namespace exception_tracer +} // namespace folly diff --git a/folly/experimental/exception_tracer/StackTrace.h b/folly/experimental/exception_tracer/StackTrace.h index 6c765763..ac100d31 100644 --- a/folly/experimental/exception_tracer/StackTrace.h +++ b/folly/experimental/exception_tracer/StackTrace.h @@ -20,12 +20,13 @@ #include #include -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 diff --git a/folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp b/folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp index 93f464ef..2ef8eb32 100644 --- a/folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp +++ b/folly/experimental/exception_tracer/test/ExceptionCounterTest.cpp @@ -111,8 +111,8 @@ TEST(ExceptionCounter, multyThreads) { { std::unique_lock lock(preparedMutex); - preparedBarrier.wait(lock, - [&]() { return preparedThreads == kNumThreads; }); + preparedBarrier.wait( + lock, [&]() { return preparedThreads == kNumThreads; }); } auto stats = getExceptionStatistics(); diff --git a/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp b/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp index 2e7b88cd..35f536fc 100644 --- a/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp +++ b/folly/experimental/exception_tracer/test/ExceptionTracerBenchmark.cpp @@ -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(); -- 2.34.1