OLD | NEW |
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" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // We use a spinlock to make locking this in a signal handler _somewhat_ safe. | 121 // We use a spinlock to make locking this in a signal handler _somewhat_ safe. |
122 static SkSpinlock gMutex; | 122 static SkSpinlock gMutex; |
123 static int32_t gPending; | 123 static int32_t gPending; |
124 static SkTArray<SkString> gRunning; | 124 static SkTArray<SkString> gRunning; |
125 | 125 |
126 static void done(const char* config, const char* src, const char* srcOptions, co
nst char* name) { | 126 static void done(const char* config, const char* src, const char* srcOptions, co
nst char* name) { |
127 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); | 127 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
128 vlog("done %s\n", id.c_str()); | 128 vlog("done %s\n", id.c_str()); |
129 int pending; | 129 int pending; |
130 { | 130 { |
131 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 131 SkAutoMutexAcquire lock(gMutex); |
132 for (int i = 0; i < gRunning.count(); i++) { | 132 for (int i = 0; i < gRunning.count(); i++) { |
133 if (gRunning[i] == id) { | 133 if (gRunning[i] == id) { |
134 gRunning.removeShuffle(i); | 134 gRunning.removeShuffle(i); |
135 break; | 135 break; |
136 } | 136 } |
137 } | 137 } |
138 pending = --gPending; | 138 pending = --gPending; |
139 } | 139 } |
140 // We write our dm.json file every once in a while in case we crash. | 140 // We write our dm.json file every once in a while in case we crash. |
141 // Notice this also handles the final dm.json when pending == 0. | 141 // Notice this also handles the final dm.json when pending == 0. |
142 if (pending % 500 == 0) { | 142 if (pending % 500 == 0) { |
143 JsonWriter::DumpJson(); | 143 JsonWriter::DumpJson(); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 static void start(const char* config, const char* src, const char* srcOptions, c
onst char* name) { | 147 static void start(const char* config, const char* src, const char* srcOptions, c
onst char* name) { |
148 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); | 148 SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
149 vlog("start %s\n", id.c_str()); | 149 vlog("start %s\n", id.c_str()); |
150 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 150 SkAutoMutexAcquire lock(gMutex); |
151 gRunning.push_back(id); | 151 gRunning.push_back(id); |
152 } | 152 } |
153 | 153 |
154 static void print_status() { | 154 static void print_status() { |
155 int curr = sk_tools::getCurrResidentSetSizeMB(), | 155 int curr = sk_tools::getCurrResidentSetSizeMB(), |
156 peak = sk_tools::getMaxResidentSetSizeMB(); | 156 peak = sk_tools::getMaxResidentSetSizeMB(); |
157 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs); | 157 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - kStartMs); |
158 | 158 |
159 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 159 SkAutoMutexAcquire lock(gMutex); |
160 info("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", | 160 info("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", |
161 elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, p
eak); | 161 elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, p
eak); |
162 for (auto& task : gRunning) { | 162 for (auto& task : gRunning) { |
163 info("\t%s\n", task.c_str()); | 163 info("\t%s\n", task.c_str()); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 #if defined(SK_BUILD_FOR_WIN32) | 167 #if defined(SK_BUILD_FOR_WIN32) |
168 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) { | 168 static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) { |
169 static const struct { | 169 static const struct { |
170 const char* name; | 170 const char* name; |
171 DWORD code; | 171 DWORD code; |
172 } kExceptions[] = { | 172 } kExceptions[] = { |
173 #define _(E) {#E, E} | 173 #define _(E) {#E, E} |
174 _(EXCEPTION_ACCESS_VIOLATION), | 174 _(EXCEPTION_ACCESS_VIOLATION), |
175 _(EXCEPTION_BREAKPOINT), | 175 _(EXCEPTION_BREAKPOINT), |
176 _(EXCEPTION_INT_DIVIDE_BY_ZERO), | 176 _(EXCEPTION_INT_DIVIDE_BY_ZERO), |
177 _(EXCEPTION_STACK_OVERFLOW), | 177 _(EXCEPTION_STACK_OVERFLOW), |
178 // TODO: more? | 178 // TODO: more? |
179 #undef _ | 179 #undef _ |
180 }; | 180 }; |
181 | 181 |
182 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 182 SkAutoMutexAcquire lock(gMutex); |
183 | 183 |
184 const DWORD code = e->ExceptionRecord->ExceptionCode; | 184 const DWORD code = e->ExceptionRecord->ExceptionCode; |
185 info("\nCaught exception %u", code); | 185 info("\nCaught exception %u", code); |
186 for (const auto& exception : kExceptions) { | 186 for (const auto& exception : kExceptions) { |
187 if (exception.code == code) { | 187 if (exception.code == code) { |
188 info(" %s", exception.name); | 188 info(" %s", exception.name); |
189 } | 189 } |
190 } | 190 } |
191 info(", was running:\n"); | 191 info(", was running:\n"); |
192 for (auto& task : gRunning) { | 192 for (auto& task : gRunning) { |
193 info("\t%s\n", task.c_str()); | 193 info("\t%s\n", task.c_str()); |
194 } | 194 } |
195 fflush(stdout); | 195 fflush(stdout); |
196 | 196 |
197 // Execute default exception handler... hopefully, exit. | 197 // Execute default exception handler... hopefully, exit. |
198 return EXCEPTION_EXECUTE_HANDLER; | 198 return EXCEPTION_EXECUTE_HANDLER; |
199 } | 199 } |
200 static void setup_crash_handler() { SetUnhandledExceptionFilter(crash_handle
r); } | 200 static void setup_crash_handler() { SetUnhandledExceptionFilter(crash_handle
r); } |
201 | 201 |
202 #elif !defined(SK_BUILD_FOR_ANDROID) | 202 #elif !defined(SK_BUILD_FOR_ANDROID) |
203 #include <execinfo.h> | 203 #include <execinfo.h> |
204 #include <signal.h> | 204 #include <signal.h> |
205 #include <stdlib.h> | 205 #include <stdlib.h> |
206 | 206 |
207 static void crash_handler(int sig) { | 207 static void crash_handler(int sig) { |
208 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 208 SkAutoMutexAcquire lock(gMutex); |
209 | 209 |
210 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig)); | 210 info("\nCaught signal %d [%s], was running:\n", sig, strsignal(sig)); |
211 for (auto& task : gRunning) { | 211 for (auto& task : gRunning) { |
212 info("\t%s\n", task.c_str()); | 212 info("\t%s\n", task.c_str()); |
213 } | 213 } |
214 | 214 |
215 void* stack[64]; | 215 void* stack[64]; |
216 int count = backtrace(stack, SK_ARRAY_COUNT(stack)); | 216 int count = backtrace(stack, SK_ARRAY_COUNT(stack)); |
217 char** symbols = backtrace_symbols(stack, count); | 217 char** symbols = backtrace_symbols(stack, count); |
218 info("\nStack trace:\n"); | 218 info("\nStack trace:\n"); |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 | 1293 |
1294 // Kick off as much parallel work as we can, making note of any serial work
we'll need to do. | 1294 // Kick off as much parallel work as we can, making note of any serial work
we'll need to do. |
1295 SkTaskGroup parallel; | 1295 SkTaskGroup parallel; |
1296 SkTArray<Task> serial; | 1296 SkTArray<Task> serial; |
1297 | 1297 |
1298 for (auto& sink : gSinks) | 1298 for (auto& sink : gSinks) |
1299 for (auto& src : gSrcs) { | 1299 for (auto& src : gSrcs) { |
1300 if (src->veto(sink->flags()) || | 1300 if (src->veto(sink->flags()) || |
1301 is_blacklisted(sink.tag.c_str(), src.tag.c_str(), | 1301 is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
1302 src.options.c_str(), src->name().c_str())) { | 1302 src.options.c_str(), src->name().c_str())) { |
1303 SkAutoTAcquire<SkSpinlock> lock(gMutex); | 1303 SkAutoMutexAcquire lock(gMutex); |
1304 gPending--; | 1304 gPending--; |
1305 continue; | 1305 continue; |
1306 } | 1306 } |
1307 | 1307 |
1308 Task task(src, sink); | 1308 Task task(src, sink); |
1309 if (src->serial() || sink->serial()) { | 1309 if (src->serial() || sink->serial()) { |
1310 serial.push_back(task); | 1310 serial.push_back(task); |
1311 } else { | 1311 } else { |
1312 parallel.add([task] { Task::Run(task); }); | 1312 parallel.add([task] { Task::Run(task); }); |
1313 } | 1313 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 #endif | 1404 #endif |
1405 } | 1405 } |
1406 } // namespace skiatest | 1406 } // namespace skiatest |
1407 | 1407 |
1408 #if !defined(SK_BUILD_FOR_IOS) | 1408 #if !defined(SK_BUILD_FOR_IOS) |
1409 int main(int argc, char** argv) { | 1409 int main(int argc, char** argv) { |
1410 SkCommandLineFlags::Parse(argc, argv); | 1410 SkCommandLineFlags::Parse(argc, argv); |
1411 return dm_main(); | 1411 return dm_main(); |
1412 } | 1412 } |
1413 #endif | 1413 #endif |
OLD | NEW |