OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/crash/core/common/crash_keys.h" | 5 #include "components/crash/core/common/crash_keys.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
8 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/logging.h" | |
9 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | |
12 | 15 |
13 namespace crash_keys { | 16 namespace crash_keys { |
14 | 17 |
15 #if defined(OS_MACOSX) | 18 #if defined(OS_MACOSX) |
16 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID | 19 // Crashpad owns the "guid" key. Chrome's metrics client ID is a separate ID |
17 // carried in a distinct "metrics_client_id" field. | 20 // carried in a distinct "metrics_client_id" field. |
18 const char kMetricsClientId[] = "metrics_client_id"; | 21 const char kMetricsClientId[] = "metrics_client_id"; |
19 #else | 22 #else |
20 const char kClientId[] = "guid"; | 23 const char kClientId[] = "guid"; |
21 #endif | 24 #endif |
22 | 25 |
23 const char kChannel[] = "channel"; | 26 const char kChannel[] = "channel"; |
24 | 27 |
25 const char kNumVariations[] = "num-experiments"; | 28 const char kNumVariations[] = "num-experiments"; |
26 const char kVariations[] = "variations"; | 29 const char kVariations[] = "variations"; |
27 | 30 |
31 const char kSwitchFormat[] = "switch-%" PRIuS; | |
32 const char kNumSwitches[] = "num-switches"; | |
33 | |
28 const char kBug464926CrashKey[] = "bug-464926-info"; | 34 const char kBug464926CrashKey[] = "bug-464926-info"; |
29 | 35 |
30 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
31 namespace mac { | 37 namespace mac { |
32 | 38 |
33 const char kZombie[] = "zombie"; | 39 const char kZombie[] = "zombie"; |
34 const char kZombieTrace[] = "zombie_dealloc_bt"; | 40 const char kZombieTrace[] = "zombie_dealloc_bt"; |
35 | 41 |
36 } // namespace mac | 42 } // namespace mac |
37 #endif | 43 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // Do not truncate an individual experiment. | 91 // Do not truncate an individual experiment. |
86 if (variations_string.size() + variation.size() >= kLargeSize) | 92 if (variations_string.size() + variation.size() >= kLargeSize) |
87 break; | 93 break; |
88 variations_string += variation; | 94 variations_string += variation; |
89 variations_string += ","; | 95 variations_string += ","; |
90 } | 96 } |
91 | 97 |
92 base::debug::SetCrashKeyValue(kVariations, variations_string); | 98 base::debug::SetCrashKeyValue(kVariations, variations_string); |
93 } | 99 } |
94 | 100 |
101 void GetCrashKeysForCommandLineSwitches( | |
102 std::vector<base::debug::CrashKey>* keys) { | |
103 DCHECK(keys); | |
104 base::debug::CrashKey crash_key = { kNumSwitches, kSmallSize }; | |
105 keys->push_back(crash_key); | |
106 | |
107 // The fixed_keys names are string constants. Use static storage for | |
Robert Sesek
2015/11/30 16:08:12
|fixed_keys| ?
Joe Mason
2015/11/30 17:23:55
Actually the first part of the comment is obsolete
| |
108 // formatted key names as well, since they will persist for the duration of | |
109 // the program. | |
110 static char formatted_keys[kSwitchesMaxCount][sizeof(kSwitchFormat) + 1] = | |
111 {{ 0 }}; | |
112 const size_t formatted_key_len = sizeof(formatted_keys[0]); | |
113 | |
114 // sizeof(kSwitchFormat) is platform-dependent, so make sure formatted_keys | |
115 // actually have space for a 2-digit switch number plus null-terminator. | |
116 static_assert(formatted_key_len >= 10, | |
117 "insufficient space for \"switch-NN\""); | |
118 | |
119 for (size_t i = 0; i < kSwitchesMaxCount; ++i) { | |
120 // Name the keys using 1-based indexing. | |
121 int n = base::snprintf(formatted_keys[i], formatted_key_len, kSwitchFormat, | |
122 i + 1); | |
123 DCHECK_GT(n, 0); | |
124 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize }; | |
125 keys->push_back(crash_key); | |
126 } | |
127 } | |
128 | |
129 void SetSwitchesFromCommandLine(const base::CommandLine& command_line, | |
130 SwitchFilterFunction skip_filter) { | |
131 const base::CommandLine::StringVector& argv = command_line.argv(); | |
132 | |
133 // Set the number of switches in case size > kNumSwitches. | |
134 base::debug::SetCrashKeyValue(kNumSwitches, | |
135 base::StringPrintf("%" PRIuS, argv.size() - 1)); | |
136 | |
137 size_t key_i = 1; // Key names are 1-indexed. | |
138 | |
139 // Go through the argv, skipping the exec path. Stop if there are too many | |
140 // switches to hold in crash keys. | |
141 for (size_t i = 1; i < argv.size() && key_i <= crash_keys::kSwitchesMaxCount; | |
142 ++i) { | |
143 #if defined(OS_WIN) | |
144 std::string switch_str = base::WideToUTF8(argv[i]); | |
145 #else | |
146 std::string switch_str = argv[i]; | |
147 #endif | |
148 | |
149 // Skip uninteresting switches. | |
150 if (skip_filter && (*skip_filter)(switch_str)) | |
151 continue; | |
152 | |
153 std::string key = base::StringPrintf(kSwitchFormat, key_i++); | |
154 base::debug::SetCrashKeyValue(key, switch_str); | |
155 } | |
156 | |
157 // Clear any remaining switches. | |
158 for (; key_i <= kSwitchesMaxCount; ++key_i) | |
159 base::debug::ClearCrashKey(base::StringPrintf(kSwitchFormat, key_i)); | |
160 } | |
161 | |
95 } // namespace crash_keys | 162 } // namespace crash_keys |
OLD | NEW |