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

Side by Side Diff: chrome/common/crash_keys.cc

Issue 1481933002: Move crash keys for command-line switches to components/crash so they can be set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@installer_crash_keys
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/common/crash_keys.h" 5 #include "chrome/common/crash_keys.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h"
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/format_macros.h" 10 #include "base/format_macros.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "components/flags_ui/flags_ui_switches.h" 16 #include "components/flags_ui/flags_ui_switches.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "ipc/ipc_switches.h" 18 #include "ipc/ipc_switches.h"
19 19
20 #if defined(OS_CHROMEOS) 20 #if defined(OS_CHROMEOS)
21 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "gpu/command_buffer/service/gpu_switches.h" 22 #include "gpu/command_buffer/service/gpu_switches.h"
23 #include "ui/gl/gl_switches.h" 23 #include "ui/gl/gl_switches.h"
24 #endif 24 #endif
25 25
26 namespace crash_keys { 26 namespace crash_keys {
27 27
28 const char kActiveURL[] = "url-chunk"; 28 const char kActiveURL[] = "url-chunk";
29 29
30 const char kFontKeyName[] = "font_key_name"; 30 const char kFontKeyName[] = "font_key_name";
31 31
32 const char kSwitch[] = "switch-%" PRIuS;
33 const char kNumSwitches[] = "num-switches";
34
35 const char kExtensionID[] = "extension-%" PRIuS; 32 const char kExtensionID[] = "extension-%" PRIuS;
36 const char kNumExtensionsCount[] = "num-extensions"; 33 const char kNumExtensionsCount[] = "num-extensions";
37 34
38 const char kShutdownType[] = "shutdown-type"; 35 const char kShutdownType[] = "shutdown-type";
39 36
40 #if !defined(OS_ANDROID) 37 #if !defined(OS_ANDROID)
41 const char kGPUVendorID[] = "gpu-venid"; 38 const char kGPUVendorID[] = "gpu-venid";
42 const char kGPUDeviceID[] = "gpu-devid"; 39 const char kGPUDeviceID[] = "gpu-devid";
43 #endif 40 #endif
44 const char kGPUDriverVersion[] = "gpu-driver"; 41 const char kGPUDriverVersion[] = "gpu-driver";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // The following keys may be chunked by the underlying crash logging system, 84 // The following keys may be chunked by the underlying crash logging system,
88 // but ultimately constitute a single key-value pair. 85 // but ultimately constitute a single key-value pair.
89 base::debug::CrashKey fixed_keys[] = { 86 base::debug::CrashKey fixed_keys[] = {
90 #if defined(OS_MACOSX) 87 #if defined(OS_MACOSX)
91 { kMetricsClientId, kSmallSize }, 88 { kMetricsClientId, kSmallSize },
92 #else 89 #else
93 { kClientId, kSmallSize }, 90 { kClientId, kSmallSize },
94 #endif 91 #endif
95 { kChannel, kSmallSize }, 92 { kChannel, kSmallSize },
96 { kActiveURL, kLargeSize }, 93 { kActiveURL, kLargeSize },
97 { kNumSwitches, kSmallSize },
98 { kNumVariations, kSmallSize }, 94 { kNumVariations, kSmallSize },
99 { kVariations, kLargeSize }, 95 { kVariations, kLargeSize },
100 { kNumExtensionsCount, kSmallSize }, 96 { kNumExtensionsCount, kSmallSize },
101 { kShutdownType, kSmallSize }, 97 { kShutdownType, kSmallSize },
102 #if !defined(OS_ANDROID) 98 #if !defined(OS_ANDROID)
103 { kGPUVendorID, kSmallSize }, 99 { kGPUVendorID, kSmallSize },
104 { kGPUDeviceID, kSmallSize }, 100 { kGPUDeviceID, kSmallSize },
105 #endif 101 #endif
106 { kGPUDriverVersion, kSmallSize }, 102 { kGPUDriverVersion, kSmallSize },
107 { kGPUPixelShaderVersion, kSmallSize }, 103 { kGPUPixelShaderVersion, kSmallSize },
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 { kBug464926CrashKey, kSmallSize }, 143 { kBug464926CrashKey, kSmallSize },
148 { kViewCount, kSmallSize }, 144 { kViewCount, kSmallSize },
149 { kZeroEncodeDetails, kSmallSize }, 145 { kZeroEncodeDetails, kSmallSize },
150 }; 146 };
151 147
152 // This dynamic set of keys is used for sets of key value pairs when gathering 148 // This dynamic set of keys is used for sets of key value pairs when gathering
153 // a collection of data, like command line switches or extension IDs. 149 // a collection of data, like command line switches or extension IDs.
154 std::vector<base::debug::CrashKey> keys( 150 std::vector<base::debug::CrashKey> keys(
155 fixed_keys, fixed_keys + arraysize(fixed_keys)); 151 fixed_keys, fixed_keys + arraysize(fixed_keys));
156 152
157 // Register the switches. 153 crash_keys::GetCrashKeysForCommandLineSwitches(&keys);
158 {
159 // The fixed_keys names are string constants. Use static storage for
160 // formatted key names as well, since they will persist for the duration of
161 // the program.
162 static char formatted_keys[kSwitchesMaxCount][sizeof(kSwitch) + 1] =
163 {{ 0 }};
164 const size_t formatted_key_len = sizeof(formatted_keys[0]);
165 for (size_t i = 0; i < kSwitchesMaxCount; ++i) {
166 // Name the keys using 1-based indexing.
167 int n = base::snprintf(
168 formatted_keys[i], formatted_key_len, kSwitch, i + 1);
169 DCHECK_GT(n, 0);
170 base::debug::CrashKey crash_key = { formatted_keys[i], kSmallSize };
171 keys.push_back(crash_key);
172 }
173 }
174 154
175 // Register the extension IDs. 155 // Register the extension IDs.
176 { 156 {
177 static char formatted_keys[kExtensionIDMaxCount][sizeof(kExtensionID) + 1] = 157 static char formatted_keys[kExtensionIDMaxCount][sizeof(kExtensionID) + 1] =
178 {{ 0 }}; 158 {{ 0 }};
179 const size_t formatted_key_len = sizeof(formatted_keys[0]); 159 const size_t formatted_key_len = sizeof(formatted_keys[0]);
180 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) { 160 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) {
181 int n = base::snprintf( 161 int n = base::snprintf(
182 formatted_keys[i], formatted_key_len, kExtensionID, i + 1); 162 formatted_keys[i], formatted_key_len, kExtensionID, i + 1);
183 DCHECK_GT(n, 0); 163 DCHECK_GT(n, 0);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (flag.compare(2, len, kIgnoreSwitches[i]) == 0) 245 if (flag.compare(2, len, kIgnoreSwitches[i]) == 0)
266 return true; 246 return true;
267 } 247 }
268 return false; 248 return false;
269 } 249 }
270 250
271 void SetSwitchesFromCommandLine(const base::CommandLine* command_line) { 251 void SetSwitchesFromCommandLine(const base::CommandLine* command_line) {
272 DCHECK(command_line); 252 DCHECK(command_line);
273 if (!command_line) 253 if (!command_line)
274 return; 254 return;
275 255 return SetSwitchesFromCommandLine(*command_line,
grt (UTC plus 2) 2015/11/27 18:51:21 hmm, the name collision here is a bit confusing. w
Joe Mason 2015/11/27 21:16:47 Done.
276 const base::CommandLine::StringVector& argv = command_line->argv(); 256 base::Bind(&IsBoringSwitch));
277
278 // Set the number of switches in case size > kNumSwitches.
279 base::debug::SetCrashKeyValue(kNumSwitches,
280 base::StringPrintf("%" PRIuS, argv.size() - 1));
281
282 size_t key_i = 1; // Key names are 1-indexed.
283
284 // Go through the argv, skipping the exec path.
285 for (size_t i = 1; i < argv.size(); ++i) {
286 #if defined(OS_WIN)
287 std::string switch_str = base::WideToUTF8(argv[i]);
288 #else
289 std::string switch_str = argv[i];
290 #endif
291
292 // Skip uninteresting switches.
293 if (IsBoringSwitch(switch_str))
294 continue;
295
296 // Stop if there are too many switches.
297 if (i > crash_keys::kSwitchesMaxCount)
298 break;
299
300 std::string key = base::StringPrintf(kSwitch, key_i++);
301 base::debug::SetCrashKeyValue(key, switch_str);
302 }
303
304 // Clear any remaining switches.
305 for (; key_i <= kSwitchesMaxCount; ++key_i) {
306 base::debug::ClearCrashKey(base::StringPrintf(kSwitch, key_i));
307 }
308 } 257 }
309 258
310 void SetActiveExtensions(const std::set<std::string>& extensions) { 259 void SetActiveExtensions(const std::set<std::string>& extensions) {
311 base::debug::SetCrashKeyValue(kNumExtensionsCount, 260 base::debug::SetCrashKeyValue(kNumExtensionsCount,
312 base::StringPrintf("%" PRIuS, extensions.size())); 261 base::StringPrintf("%" PRIuS, extensions.size()));
313 262
314 std::set<std::string>::const_iterator it = extensions.begin(); 263 std::set<std::string>::const_iterator it = extensions.begin();
315 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) { 264 for (size_t i = 0; i < kExtensionIDMaxCount; ++i) {
316 std::string key = base::StringPrintf(kExtensionID, i + 1); 265 std::string key = base::StringPrintf(kExtensionID, i + 1);
317 if (it == extensions.end()) { 266 if (it == extensions.end()) {
(...skipping 18 matching lines...) Expand all
336 } 285 }
337 286
338 ScopedPrinterInfo::~ScopedPrinterInfo() { 287 ScopedPrinterInfo::~ScopedPrinterInfo() {
339 for (size_t i = 0; i < kPrinterInfoCount; ++i) { 288 for (size_t i = 0; i < kPrinterInfoCount; ++i) {
340 std::string key = base::StringPrintf(kPrinterInfo, i + 1); 289 std::string key = base::StringPrintf(kPrinterInfo, i + 1);
341 base::debug::ClearCrashKey(key); 290 base::debug::ClearCrashKey(key);
342 } 291 }
343 } 292 }
344 293
345 } // namespace crash_keys 294 } // namespace crash_keys
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698