Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Side by Side Diff: dm/DM.cpp

Issue 1725543002: Add a handler to DM to print out what was running when we crash. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "CrashHandler.h" 8 #include "CrashHandler.h"
9 #include "DMJsonWriter.h" 9 #include "DMJsonWriter.h"
10 #include "DMSrcSink.h" 10 #include "DMSrcSink.h"
11 #include "DMSrcSinkAndroid.h" 11 #include "DMSrcSinkAndroid.h"
12 #include "OverwriteLine.h" 12 #include "OverwriteLine.h"
13 #include "ProcStats.h" 13 #include "ProcStats.h"
14 #include "SkBBHFactory.h" 14 #include "SkBBHFactory.h"
15 #include "SkChecksum.h" 15 #include "SkChecksum.h"
16 #include "SkCodec.h" 16 #include "SkCodec.h"
17 #include "SkCommonFlags.h" 17 #include "SkCommonFlags.h"
18 #include "SkCommonFlagsConfig.h" 18 #include "SkCommonFlagsConfig.h"
19 #include "SkFontMgr.h" 19 #include "SkFontMgr.h"
20 #include "SkForceLinking.h" 20 #include "SkForceLinking.h"
21 #include "SkGraphics.h" 21 #include "SkGraphics.h"
22 #include "SkMD5.h" 22 #include "SkMD5.h"
23 #include "SkMutex.h" 23 #include "SkMutex.h"
24 #include "SkOSFile.h" 24 #include "SkOSFile.h"
25 #include "SkSpinlock.h"
25 #include "SkTHash.h" 26 #include "SkTHash.h"
26 #include "SkTaskGroup.h" 27 #include "SkTaskGroup.h"
27 #include "SkThreadUtils.h" 28 #include "SkThreadUtils.h"
28 #include "Test.h" 29 #include "Test.h"
29 #include "Timer.h" 30 #include "Timer.h"
30 #include "sk_tool_utils.h" 31 #include "sk_tool_utils.h"
31 32
32 #ifdef SK_PDF_IMAGE_STATS 33 #ifdef SK_PDF_IMAGE_STATS
33 extern void SkPDFImageDumpStats(); 34 extern void SkPDFImageDumpStats();
34 #endif 35 #endif
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 static SkTArray<SkString> gFailures; 77 static SkTArray<SkString> gFailures;
77 78
78 static void fail(ImplicitString err) { 79 static void fail(ImplicitString err) {
79 SkAutoMutexAcquire lock(gFailuresMutex); 80 SkAutoMutexAcquire lock(gFailuresMutex);
80 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); 81 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
81 gFailures.push_back(err); 82 gFailures.push_back(err);
82 } 83 }
83 84
84 static int32_t gPending = 0; // Atomic. Total number of running and queued tas ks. 85 static int32_t gPending = 0; // Atomic. Total number of running and queued tas ks.
85 86
86 SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex); 87 // We use a spinlock to make locking this in a signal handler _somewhat_ safe.
88 SK_DECLARE_STATIC_SPINLOCK(gRunningAndTallyMutex);
87 static SkTArray<SkString> gRunning; 89 static SkTArray<SkString> gRunning;
88 static SkTHashMap<SkString, int> gNoteTally; 90 static SkTHashMap<SkString, int> gNoteTally;
89 91
90 static void done(double ms, 92 static void done(double ms,
91 ImplicitString config, ImplicitString src, ImplicitString srcOp tions, 93 ImplicitString config, ImplicitString src, ImplicitString srcOp tions,
92 ImplicitString name, ImplicitString note, ImplicitString log) { 94 ImplicitString name, ImplicitString note, ImplicitString log) {
93 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), 95 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
94 srcOptions.c_str(), name.c_str() ); 96 srcOptions.c_str(), name.c_str() );
95 { 97 {
96 SkAutoMutexAcquire lock(gRunningAndTallyMutex); 98 SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
97 for (int i = 0; i < gRunning.count(); i++) { 99 for (int i = 0; i < gRunning.count(); i++) {
98 if (gRunning[i] == id) { 100 if (gRunning[i] == id) {
99 gRunning.removeShuffle(i); 101 gRunning.removeShuffle(i);
100 break; 102 break;
101 } 103 }
102 } 104 }
103 if (!note.isEmpty()) { 105 if (!note.isEmpty()) {
104 if (int* tally = gNoteTally.find(note)) { 106 if (int* tally = gNoteTally.find(note)) {
105 *tally += 1; 107 *tally += 1;
106 } else { 108 } else {
(...skipping 18 matching lines...) Expand all
125 // Notice this also handles the final dm.json when pending == 0. 127 // Notice this also handles the final dm.json when pending == 0.
126 if (pending % 500 == 0) { 128 if (pending % 500 == 0) {
127 JsonWriter::DumpJson(); 129 JsonWriter::DumpJson();
128 } 130 }
129 } 131 }
130 132
131 static void start(ImplicitString config, ImplicitString src, 133 static void start(ImplicitString config, ImplicitString src,
132 ImplicitString srcOptions, ImplicitString name) { 134 ImplicitString srcOptions, ImplicitString name) {
133 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), 135 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
134 srcOptions.c_str(), name.c_str() ); 136 srcOptions.c_str(), name.c_str() );
135 SkAutoMutexAcquire lock(gRunningAndTallyMutex); 137 SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
136 gRunning.push_back(id); 138 gRunning.push_back(id);
137 } 139 }
138 140
141 #if defined(SK_BUILD_FOR_WIN32)
142 static void setup_crash_handler() {
143 // TODO: custom crash handler like below to print out what was running
144 SetupCrashHandler();
145 }
146
147 #else
148 #include <signal.h>
149 static void setup_crash_handler() {
150 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
151 for (int sig : kSignals) {
152 signal(sig, [](int sig) {
153 SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
154 SkDebugf("\nCaught signal %d [%s] while running %d tasks:\n",
155 sig, strsignal(sig), gRunning.count());
156 for (auto& task : gRunning) {
157 SkDebugf("\t%s\n", task.c_str());
158 }
159 });
160 }
161 }
162 #endif
163
139 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 164 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
140 165
141 struct Gold : public SkString { 166 struct Gold : public SkString {
142 Gold() : SkString("") {} 167 Gold() : SkString("") {}
143 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions, 168 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
144 ImplicitString name, ImplicitString md5) 169 ImplicitString name, ImplicitString md5)
145 : SkString("") { 170 : SkString("") {
146 this->append(sink); 171 this->append(sink);
147 this->append(src); 172 this->append(src);
148 this->append(srcOptions); 173 this->append(srcOptions);
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 static void forever(void*) { 1117 static void forever(void*) {
1093 for (;;) { 1118 for (;;) {
1094 static const int kSec = 300; 1119 static const int kSec = 300;
1095 #if defined(SK_BUILD_FOR_WIN) 1120 #if defined(SK_BUILD_FOR_WIN)
1096 Sleep(kSec * 1000); 1121 Sleep(kSec * 1000);
1097 #else 1122 #else
1098 sleep(kSec); 1123 sleep(kSec);
1099 #endif 1124 #endif
1100 SkString running; 1125 SkString running;
1101 { 1126 {
1102 SkAutoMutexAcquire lock(gRunningAndTallyMutex); 1127 SkAutoTAcquire<SkPODSpinlock> lock(gRunningAndTallyMutex);
1103 for (int i = 0; i < gRunning.count(); i++) { 1128 for (int i = 0; i < gRunning.count(); i++) {
1104 running.appendf("\n\t%s", gRunning[i].c_str()); 1129 running.appendf("\n\t%s", gRunning[i].c_str());
1105 } 1130 }
1106 } 1131 }
1107 SkDebugf("\nCurrently running:%s\n", running.c_str()); 1132 SkDebugf("\nCurrently running:%s\n", running.c_str());
1108 } 1133 }
1109 } 1134 }
1110 }; 1135 };
1111 static SkThread* intentionallyLeaked = new SkThread(Loop::forever); 1136 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1112 intentionallyLeaked->start(); 1137 intentionallyLeaked->start();
1113 } 1138 }
1114 1139
1115 #define PORTABLE_FONT_PREFIX "Toy Liberation " 1140 #define PORTABLE_FONT_PREFIX "Toy Liberation "
1116 1141
1117 static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style s tyle) { 1142 static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style s tyle) {
1118 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) 1143 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1119 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_P REFIX) - 1)) { 1144 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_P REFIX) - 1)) {
1120 return sk_tool_utils::create_portable_typeface(familyName, style); 1145 return sk_tool_utils::create_portable_typeface(familyName, style);
1121 } 1146 }
1122 return nullptr; 1147 return nullptr;
1123 } 1148 }
1124 1149
1125 #undef PORTABLE_FONT_PREFIX 1150 #undef PORTABLE_FONT_PREFIX
1126 1151
1127 extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) ; 1152 extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) ;
1128 1153
1129 int dm_main(); 1154 int dm_main();
1130 int dm_main() { 1155 int dm_main() {
1131 SetupCrashHandler(); 1156 setup_crash_handler();
1132 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing. 1157 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
1133 SkAutoGraphics ag; 1158 SkAutoGraphics ag;
1134 SkTaskGroup::Enabler enabled(FLAGS_threads); 1159 SkTaskGroup::Enabler enabled(FLAGS_threads);
1135 gCreateTypefaceDelegate = &create_from_name; 1160 gCreateTypefaceDelegate = &create_from_name;
1136 1161
1137 start_keepalive(); 1162 start_keepalive();
1138 1163
1139 gather_gold(); 1164 gather_gold();
1140 gather_uninteresting_hashes(); 1165 gather_uninteresting_hashes();
1141 1166
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 Reporter* reporter, 1316 Reporter* reporter,
1292 GrContextFactory* fac tory); 1317 GrContextFactory* fac tory);
1293 } // namespace skiatest 1318 } // namespace skiatest
1294 1319
1295 #if !defined(SK_BUILD_FOR_IOS) 1320 #if !defined(SK_BUILD_FOR_IOS)
1296 int main(int argc, char** argv) { 1321 int main(int argc, char** argv) {
1297 SkCommandLineFlags::Parse(argc, argv); 1322 SkCommandLineFlags::Parse(argc, argv);
1298 return dm_main(); 1323 return dm_main();
1299 } 1324 }
1300 #endif 1325 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698