Commit 2a0318b4 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

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