aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DM.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-02-23 10:39:36 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-23 10:39:36 -0800
commit246ba3a8b488eb1cecb98fa0cd657b62c9801a51 (patch)
treeda5a8f7032f1ddeea9ac184ea78d1b71da651d21 /dm/DM.cpp
parent5a70bc7f3cd32aaccc137c7d650cea613baa2443 (diff)
Add a handler to DM to print out what was running when we crash.
This is an experiment to see if we can use something like this rather than today's extremely verbose logging. Now, hopefully something crashes. BUG=skia:4978 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1725543002 Review URL: https://codereview.chromium.org/1725543002
Diffstat (limited to 'dm/DM.cpp')
-rw-r--r--dm/DM.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index c7c3628d8a..a046421908 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -22,6 +22,7 @@
#include "SkMD5.h"
#include "SkMutex.h"
#include "SkOSFile.h"
+#include "SkSpinlock.h"
#include "SkTHash.h"
#include "SkTaskGroup.h"
#include "SkThreadUtils.h"
@@ -83,7 +84,8 @@ static void fail(ImplicitString err) {
static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
-SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex);
+// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
+SK_DECLARE_STATIC_SPINLOCK(gRunningAndTallyMutex);
static SkTArray<SkString> gRunning;
static SkTHashMap<SkString, int> gNoteTally;
@@ -93,7 +95,7 @@ static void done(double ms,
SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
srcOptions.c_str(), name.c_str());
{
- SkAutoMutexAcquire lock(gRunningAndTallyMutex);
+ SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
for (int i = 0; i < gRunning.count(); i++) {
if (gRunning[i] == id) {
gRunning.removeShuffle(i);
@@ -132,10 +134,33 @@ static void start(ImplicitString config, ImplicitString src,
ImplicitString srcOptions, ImplicitString name) {
SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
srcOptions.c_str(), name.c_str());
- SkAutoMutexAcquire lock(gRunningAndTallyMutex);
+ SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
gRunning.push_back(id);
}
+#if defined(SK_BUILD_FOR_WIN32)
+ static void setup_crash_handler() {
+ // TODO: custom crash handler like below to print out what was running
+ SetupCrashHandler();
+ }
+
+#else
+ #include <signal.h>
+ static void setup_crash_handler() {
+ const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
+ for (int sig : kSignals) {
+ signal(sig, [](int sig) {
+ SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
+ SkDebugf("\nCaught signal %d [%s] while running %d tasks:\n",
+ sig, strsignal(sig), gRunning.count());
+ for (auto& task : gRunning) {
+ SkDebugf("\t%s\n", task.c_str());
+ }
+ });
+ }
+ }
+#endif
+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
struct Gold : public SkString {
@@ -1101,7 +1126,7 @@ static void start_keepalive() {
#endif
SkString running;
{
- SkAutoMutexAcquire lock(gRunningAndTallyMutex);
+ SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
for (int i = 0; i < gRunning.count(); i++) {
running.appendf("\n\t%s", gRunning[i].c_str());
}
@@ -1130,7 +1155,7 @@ extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style )
int dm_main();
int dm_main() {
- SetupCrashHandler();
+ setup_crash_handler();
JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
SkAutoGraphics ag;
SkTaskGroup::Enabler enabled(FLAGS_threads);