aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DM.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-02-15 09:26:54 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-16 15:46:36 +0000
commitc7278ad1d9cfc0495743fa1d626a64f6974dd80d (patch)
tree5ace8853564042198b71dd16bbf866d215b435df /dm/DM.cpp
parent2a8c48be4ff65d873d9d5ba65ecef989d82dd0be (diff)
register SIGTERM handler in DM
This should make it clear when we are terminated, and print out our memory usage on the way out the door. There's no way to register a handler for SIGKILL, so if we're being cut down that way, we'll have to restructure DM quite a bit internally to spawn processes instead of threads. The parent process should be able to at least notice that child processes have been SIGKILL'd. (This would be nice anyway, so one crash doesn't ruin our whole run.) Here's a demo with a slightly hacked up DM to make the demo easy: ~/skia (sig↑1|✔) $ ninja -C out dm; and out/dm ninja: Entering directory `out' [2/2] link dm my pid is 65360 We have been politely asked to die by Terminated: 15 (15). Currently using 11MB RAM, peak 11MB. fish: 'and out/dm' terminated by signal SIGTERM (Polite quit request) Bug: skia:7614 Change-Id: Ie43be78fa766433a9d7cf391d78801d4355e635c Reviewed-on: https://skia-review.googlesource.com/107720 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'dm/DM.cpp')
-rw-r--r--dm/DM.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index f61f52150d..1a72b2236d 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -263,7 +263,7 @@ static void find_culprit() {
return x > max_of(rest...) ? x : max_of(rest...);
}
- static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
+ static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV,SIGTERM)+1])(int);
static void crash_handler(int sig) {
SkAutoMutexAcquire lock(gMutex);
@@ -289,11 +289,21 @@ static void find_culprit() {
raise(sig);
}
+ static void term_handler(int sig) {
+ info("\nWe have been politely asked to die by %s (%d)."
+ "\nCurrently using %dMB RAM, peak %dMB.\n",
+ strsignal(sig), sig,
+ sk_tools::getCurrResidentSetSizeMB(), sk_tools::getMaxResidentSetSizeMB());
+ signal(sig, previous_handler[sig]);
+ raise(sig);
+ }
+
static void setup_crash_handler() {
const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
for (int sig : kSignals) {
previous_handler[sig] = signal(sig, crash_handler);
}
+ previous_handler[SIGTERM] = signal(SIGTERM, term_handler);
if (FLAGS_ignoreSigInt) {
signal(SIGINT, SIG_IGN);