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/browser/performance_monitor/performance_monitor.cc

Issue 10829078: CPM Page Load timing (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_event_refactor
Patch Set: Created 8 years, 4 months 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) 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 #include "chrome/browser/performance_monitor/performance_monitor.h" 5 #include "chrome/browser/performance_monitor/performance_monitor.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_shutdown.h" 16 #include "chrome/browser/browser_shutdown.h"
17 #include "chrome/browser/extensions/crx_installer.h" 17 #include "chrome/browser/extensions/crx_installer.h"
18 #include "chrome/browser/performance_monitor/constants.h" 18 #include "chrome/browser/performance_monitor/constants.h"
19 #include "chrome/browser/performance_monitor/database.h" 19 #include "chrome/browser/performance_monitor/database.h"
20 #include "chrome/browser/performance_monitor/performance_monitor_util.h" 20 #include "chrome/browser/performance_monitor/performance_monitor_util.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 24 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_version_info.h" 26 #include "chrome/common/chrome_version_info.h"
27 #include "chrome/common/extensions/extension.h" 27 #include "chrome/common/extensions/extension.h"
28 #include "chrome/common/extensions/extension_constants.h" 28 #include "chrome/common/extensions/extension_constants.h"
29 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/load_notification_details.h"
30 #include "content/public/browser/notification_service.h" 31 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/notification_types.h" 32 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 34
34 using content::BrowserThread; 35 using content::BrowserThread;
35 using extensions::Extension; 36 using extensions::Extension;
36 37
37 namespace { 38 namespace {
38 39
39 std::string TimeToString(base::Time time) { 40 std::string TimeToString(base::Time time) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 133
133 // Crashes 134 // Crashes
134 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG, 135 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_HANG,
135 content::NotificationService::AllSources()); 136 content::NotificationService::AllSources());
136 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 137 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
137 content::NotificationService::AllSources()); 138 content::NotificationService::AllSources());
138 139
139 // Profiles (for unclean exit) 140 // Profiles (for unclean exit)
140 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 141 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
141 content::NotificationService::AllSources()); 142 content::NotificationService::AllSources());
143
144 // Page load times
145 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
146 content::NotificationService::AllSources());
142 } 147 }
143 148
144 // We check if profiles exited cleanly initialization time in case they were 149 // We check if profiles exited cleanly initialization time in case they were
145 // loaded prior to PerformanceMonitor's initialization. Later profiles will be 150 // loaded prior to PerformanceMonitor's initialization. Later profiles will be
146 // checked through the PROFILE_ADDED notification. 151 // checked through the PROFILE_ADDED notification.
147 void PerformanceMonitor::CheckForUncleanExits() { 152 void PerformanceMonitor::CheckForUncleanExits() {
148 std::vector<Profile*> profiles = 153 std::vector<Profile*> profiles =
149 g_browser_process->profile_manager()->GetLoadedProfiles(); 154 g_browser_process->profile_manager()->GetLoadedProfiles();
150 155
151 for (std::vector<Profile*>::const_iterator iter = profiles.begin(); 156 for (std::vector<Profile*>::const_iterator iter = profiles.begin();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 FROM_HERE, 219 FROM_HERE,
215 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, 220 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread,
216 base::Unretained(this), 221 base::Unretained(this),
217 base::Passed(event.Pass()))); 222 base::Passed(event.Pass())));
218 } 223 }
219 224
220 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { 225 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) {
221 database_->AddEvent(*event.get()); 226 database_->AddEvent(*event.get());
222 } 227 }
223 228
229 void PerformanceMonitor::AddMetricOnBackgroundThread(MetricType type,
230 const std::string& value) {
231 database_->AddMetric(type, value);
Yoyo Zhou 2012/08/10 18:34:04 Maybe DCHECK that you're on the right thread?
Devlin 2012/08/11 18:22:25 Done.
232 }
233
224 void PerformanceMonitor::GetStateValueOnBackgroundThread( 234 void PerformanceMonitor::GetStateValueOnBackgroundThread(
225 const std::string& key, 235 const std::string& key,
226 const StateValueCallback& callback) { 236 const StateValueCallback& callback) {
227 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
228 std::string state_value = database_->GetStateValue(key); 238 std::string state_value = database_->GetStateValue(key);
229 239
230 BrowserThread::PostTask(BrowserThread::UI, 240 BrowserThread::PostTask(BrowserThread::UI,
231 FROM_HERE, 241 FROM_HERE,
232 base::Bind(callback, state_value)); 242 base::Bind(callback, state_value));
233 } 243 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 BrowserThread::PostBlockingPoolSequencedTask( 342 BrowserThread::PostBlockingPoolSequencedTask(
333 Database::kDatabaseSequenceToken, 343 Database::kDatabaseSequenceToken,
334 FROM_HERE, 344 FROM_HERE,
335 base::Bind( 345 base::Bind(
336 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread, 346 &PerformanceMonitor::AddUncleanExitEventOnBackgroundThread,
337 base::Unretained(this), 347 base::Unretained(this),
338 profile->GetDebugName())); 348 profile->GetDebugName()));
339 } 349 }
340 break; 350 break;
341 } 351 }
352 case content::NOTIFICATION_LOAD_STOP: {
353 const content::LoadNotificationDetails* load_details =
354 content::Details<content::LoadNotificationDetails>(details).ptr();
355 if (!load_details)
356 break;
357 BrowserThread::PostBlockingPoolSequencedTask(
358 Database::kDatabaseSequenceToken,
359 FROM_HERE,
360 base::Bind(
361 &PerformanceMonitor::AddMetricOnBackgroundThread,
362 base::Unretained(this),
363 METRIC_PAGE_LOAD_TIME,
364 base::Int64ToString(load_details->load_time.ToInternalValue())));
365 break;
366 }
342 default: { 367 default: {
343 NOTREACHED(); 368 NOTREACHED();
344 break; 369 break;
345 } 370 }
346 } 371 }
347 } 372 }
348 373
349 void PerformanceMonitor::HandleExtensionEvent(EventType type, 374 void PerformanceMonitor::HandleExtensionEvent(EventType type,
350 const Extension* extension) { 375 const Extension* extension) {
351 DCHECK(type == EVENT_EXTENSION_INSTALL || 376 DCHECK(type == EVENT_EXTENSION_INSTALL ||
(...skipping 20 matching lines...) Expand all
372 397
373 // Determine the type of crash. 398 // Determine the type of crash.
374 EventType type = 399 EventType type =
375 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? 400 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
376 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; 401 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH;
377 402
378 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); 403 AddEvent(util::CreateCrashEvent(base::Time::Now(), type));
379 } 404 }
380 405
381 } // namespace performance_monitor 406 } // namespace performance_monitor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698