|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #include <string> |
|
6 #include <sstream> |
|
7 #include <stdlib.h> |
|
8 #include <stdio.h> |
|
9 |
|
10 #ifdef XP_WIN |
|
11 #include <process.h> |
|
12 #define getpid _getpid |
|
13 #else |
|
14 #include <unistd.h> |
|
15 #endif |
|
16 |
|
17 #ifndef mozilla_IntentionalCrash_h |
|
18 #define mozilla_IntentionalCrash_h |
|
19 |
|
20 namespace mozilla { |
|
21 |
|
22 inline void |
|
23 NoteIntentionalCrash(const char* processType) |
|
24 { |
|
25 char* f = getenv("XPCOM_MEM_BLOAT_LOG"); |
|
26 |
|
27 if (!f) |
|
28 return; |
|
29 |
|
30 fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f); |
|
31 |
|
32 std::string bloatLog(f); |
|
33 |
|
34 bool hasExt = false; |
|
35 if (bloatLog.size() >= 4 && |
|
36 0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) { |
|
37 hasExt = true; |
|
38 bloatLog.erase(bloatLog.size() - 4, 4); |
|
39 } |
|
40 |
|
41 std::ostringstream bloatName; |
|
42 bloatName << bloatLog << "_" << processType << "_pid" << getpid(); |
|
43 if (hasExt) |
|
44 bloatName << ".log"; |
|
45 |
|
46 fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str()); |
|
47 |
|
48 FILE* processfd = fopen(bloatName.str().c_str(), "a"); |
|
49 fprintf(processfd, "==> process %d will purposefully crash\n", getpid()); |
|
50 fclose(processfd); |
|
51 } |
|
52 |
|
53 } // namespace mozilla |
|
54 |
|
55 #endif // mozilla_IntentionalCrash_h |