Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
| 6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
| 7 // | 7 // |
| 8 // OVERVIEW | 8 // OVERVIEW |
| 9 // | 9 // |
| 10 // A MetricsService instance is typically created at application startup. It | 10 // A MetricsService instance is typically created at application startup. It |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 LogLoadStarted(); | 552 LogLoadStarted(); |
| 553 break; | 553 break; |
| 554 | 554 |
| 555 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { | 555 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { |
| 556 content::RenderProcessHost::RendererClosedDetails* process_details = | 556 content::RenderProcessHost::RendererClosedDetails* process_details = |
| 557 content::Details< | 557 content::Details< |
| 558 content::RenderProcessHost::RendererClosedDetails>( | 558 content::RenderProcessHost::RendererClosedDetails>( |
| 559 details).ptr(); | 559 details).ptr(); |
| 560 content::RenderProcessHost* host = | 560 content::RenderProcessHost* host = |
| 561 content::Source<content::RenderProcessHost>(source).ptr(); | 561 content::Source<content::RenderProcessHost>(source).ptr(); |
| 562 LogRendererCrash( | 562 LogRendererCrash(host, process_details->status, |
| 563 host, process_details->status, process_details->was_alive); | 563 process_details->was_alive, process_details->handle); |
| 564 } | 564 } |
| 565 break; | 565 break; |
| 566 | 566 |
| 567 case content::NOTIFICATION_RENDERER_PROCESS_HANG: | 567 case content::NOTIFICATION_RENDERER_PROCESS_HANG: |
| 568 LogRendererHang(); | 568 LogRendererHang(); |
| 569 break; | 569 break; |
| 570 | 570 |
| 571 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: | 571 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: |
| 572 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: | 572 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
| 573 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: | 573 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 } | 1361 } |
| 1362 | 1362 |
| 1363 void MetricsService::LogLoadStarted() { | 1363 void MetricsService::LogLoadStarted() { |
| 1364 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); | 1364 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); |
| 1365 IncrementPrefValue(prefs::kStabilityPageLoadCount); | 1365 IncrementPrefValue(prefs::kStabilityPageLoadCount); |
| 1366 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); | 1366 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); |
| 1367 // We need to save the prefs, as page load count is a critical stat, and it | 1367 // We need to save the prefs, as page load count is a critical stat, and it |
| 1368 // might be lost due to a crash :-(. | 1368 // might be lost due to a crash :-(. |
| 1369 } | 1369 } |
| 1370 | 1370 |
| 1371 #if defined(OS_WIN) | |
| 1372 static base::TimeDelta FromWinFileTime(FILETIME filetime) { | |
|
rvargas (doing something else)
2012/03/21 22:54:41
use Time::FromFileTime() instead
| |
| 1373 ULARGE_INTEGER large_integer; | |
| 1374 large_integer.LowPart = filetime.dwLowDateTime; | |
| 1375 large_integer.HighPart = filetime.dwHighDateTime; | |
| 1376 // Time is supplied in 100 nano-second counts. | |
| 1377 return base::TimeDelta::FromMicroseconds(large_integer.QuadPart / 10); | |
| 1378 } | |
| 1379 #endif // OS_WIN | |
| 1380 | |
| 1371 void MetricsService::LogRendererCrash(content::RenderProcessHost* host, | 1381 void MetricsService::LogRendererCrash(content::RenderProcessHost* host, |
| 1372 base::TerminationStatus status, | 1382 base::TerminationStatus status, |
| 1373 bool was_alive) { | 1383 bool was_alive, |
| 1384 base::ProcessHandle handle) { | |
| 1374 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 1385 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 1375 ExtensionService* service = profile->GetExtensionService(); | 1386 ExtensionService* service = profile->GetExtensionService(); |
| 1376 bool was_extension_process = | 1387 bool was_extension_process = |
| 1377 service && service->process_map()->Contains(host->GetID()); | 1388 service && service->process_map()->Contains(host->GetID()); |
| 1389 | |
| 1390 #if defined(OS_WIN) | |
| 1391 FILETIME win_creation_time; | |
| 1392 FILETIME win_exit_time; | |
| 1393 FILETIME win_kernel_time; | |
| 1394 FILETIME win_user_time; | |
| 1395 base::TimeDelta creation_time; | |
| 1396 base::TimeDelta exit_time; | |
| 1397 base::TimeDelta kernel_duration; | |
| 1398 base::TimeDelta user_duration; | |
| 1399 base::TimeDelta run_duration; | |
| 1400 bool have_process_times = (0 != GetProcessTimes(handle, &win_creation_time, | |
| 1401 &win_exit_time, &win_kernel_time, &win_user_time)); | |
| 1402 if (have_process_times) { | |
| 1403 creation_time = FromWinFileTime(win_creation_time); | |
| 1404 exit_time = FromWinFileTime(win_exit_time); | |
| 1405 kernel_duration = FromWinFileTime(win_kernel_time); | |
| 1406 user_duration = FromWinFileTime(win_user_time); | |
| 1407 run_duration = exit_time - creation_time; | |
| 1408 } else { | |
| 1409 DWORD an_error = GetLastError(); | |
| 1410 DLOG(ERROR) << "Error getting process data" << an_error; | |
| 1411 } | |
| 1412 #endif // OS_WIN | |
| 1413 | |
| 1378 if (status == base::TERMINATION_STATUS_PROCESS_CRASHED || | 1414 if (status == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 1379 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { | 1415 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { |
| 1380 if (was_extension_process) | 1416 if (was_extension_process) { |
| 1381 IncrementPrefValue(prefs::kStabilityExtensionRendererCrashCount); | 1417 IncrementPrefValue(prefs::kStabilityExtensionRendererCrashCount); |
| 1382 else | 1418 } else { |
| 1383 IncrementPrefValue(prefs::kStabilityRendererCrashCount); | 1419 IncrementPrefValue(prefs::kStabilityRendererCrashCount); |
| 1384 | 1420 |
| 1421 #if defined(OS_WIN) | |
| 1422 if (have_process_times) { | |
| 1423 if (status == base::TERMINATION_STATUS_PROCESS_CRASHED) { | |
| 1424 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.CrashedDuration", | |
| 1425 run_duration); | |
| 1426 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.CrashedKernelTime", | |
| 1427 kernel_duration); | |
| 1428 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.CrashedUserTime", | |
| 1429 user_duration); | |
| 1430 } else { | |
| 1431 DCHECK(status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION); | |
| 1432 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.AbnormalTermDuration", | |
| 1433 run_duration); | |
| 1434 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.AbnormalTermKernelTime", | |
| 1435 kernel_duration); | |
| 1436 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.AbnormalTermUserTime", | |
| 1437 user_duration); | |
| 1438 } | |
| 1439 } | |
| 1440 #endif // OS_WIN | |
| 1441 | |
| 1442 } | |
| 1443 | |
| 1444 // TODO(jar): These histograms should be small enumerated histograms. | |
| 1385 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashes", | 1445 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashes", |
| 1386 was_extension_process ? 2 : 1); | 1446 was_extension_process ? 2 : 1); |
| 1387 if (was_alive) { | 1447 if (was_alive) { |
| 1388 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashesWasAlive", | 1448 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildCrashesWasAlive", |
| 1389 was_extension_process ? 2 : 1); | 1449 was_extension_process ? 2 : 1); |
| 1390 } | 1450 } |
| 1391 } else if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { | 1451 } else if (status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1392 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills", | 1452 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills", |
| 1393 was_extension_process ? 2 : 1); | 1453 was_extension_process ? 2 : 1); |
| 1394 if (was_alive) { | 1454 if (was_alive) { |
| 1395 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKillsWasAlive", | 1455 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKillsWasAlive", |
| 1396 was_extension_process ? 2 : 1); | 1456 was_extension_process ? 2 : 1); |
| 1397 } | 1457 } |
| 1398 } | 1458 } |
| 1459 | |
| 1460 #if defined(OS_WIN) | |
| 1461 if (have_process_times && !was_extension_process && | |
| 1462 status != base::TERMINATION_STATUS_PROCESS_CRASHED && | |
| 1463 status != base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { | |
| 1464 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.NormalTermDuration", | |
| 1465 run_duration); | |
| 1466 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.NormalTermKernelTime", | |
| 1467 kernel_duration); | |
| 1468 UMA_HISTOGRAM_TIMES("BrowserRenderProcessHost.NormalTermUserTime", | |
| 1469 user_duration); | |
| 1470 } | |
| 1471 #endif // OS_WIN | |
| 1472 | |
| 1399 } | 1473 } |
| 1400 | 1474 |
| 1401 void MetricsService::LogRendererHang() { | 1475 void MetricsService::LogRendererHang() { |
| 1402 IncrementPrefValue(prefs::kStabilityRendererHangCount); | 1476 IncrementPrefValue(prefs::kStabilityRendererHangCount); |
| 1403 } | 1477 } |
| 1404 | 1478 |
| 1405 void MetricsService::LogNeedForCleanShutdown() { | 1479 void MetricsService::LogNeedForCleanShutdown() { |
| 1406 PrefService* pref = g_browser_process->local_state(); | 1480 PrefService* pref = g_browser_process->local_state(); |
| 1407 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); | 1481 pref->SetBoolean(prefs::kStabilityExitedCleanly, false); |
| 1408 // Redundant setting to be sure we call for a clean shutdown. | 1482 // Redundant setting to be sure we call for a clean shutdown. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1664 if (local_state) { | 1738 if (local_state) { |
| 1665 const PrefService::Preference* uma_pref = | 1739 const PrefService::Preference* uma_pref = |
| 1666 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1740 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1667 if (uma_pref) { | 1741 if (uma_pref) { |
| 1668 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1742 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1669 DCHECK(success); | 1743 DCHECK(success); |
| 1670 } | 1744 } |
| 1671 } | 1745 } |
| 1672 return result; | 1746 return result; |
| 1673 } | 1747 } |
| OLD | NEW |