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

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor.cc

Issue 10915318: Revert 157168 - Add guards to metric values; erase bad events/metrics from db (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 FROM_HERE, 271 FROM_HERE,
272 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread, 272 base::Bind(&PerformanceMonitor::AddEventOnBackgroundThread,
273 base::Unretained(this), 273 base::Unretained(this),
274 base::Passed(event.Pass()))); 274 base::Passed(event.Pass())));
275 } 275 }
276 276
277 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) { 277 void PerformanceMonitor::AddEventOnBackgroundThread(scoped_ptr<Event> event) {
278 database_->AddEvent(*event.get()); 278 database_->AddEvent(*event.get());
279 } 279 }
280 280
281 void PerformanceMonitor::AddMetricOnBackgroundThread(Metric metric) { 281 void PerformanceMonitor::AddMetricOnBackgroundThread(MetricType type,
282 const std::string& value) {
282 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 283 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
283 database_->AddMetric(metric); 284 database_->AddMetric(type, value);
284 } 285 }
285 286
286 void PerformanceMonitor::NotifyInitialized() { 287 void PerformanceMonitor::NotifyInitialized() {
287 content::NotificationService::current()->Notify( 288 content::NotificationService::current()->Notify(
288 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED, 289 chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
289 content::Source<PerformanceMonitor>(this), 290 content::Source<PerformanceMonitor>(this),
290 content::NotificationService::NoDetails()); 291 content::NotificationService::NoDetails());
291 292
292 initialized_ = true; 293 initialized_ = true;
293 } 294 }
(...skipping 10 matching lines...) Expand all
304 } 305 }
305 306
306 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() { 307 void PerformanceMonitor::GatherCPUUsageOnBackgroundThread() {
307 if (metrics_map_->size()) { 308 if (metrics_map_->size()) {
308 double cpu_usage = 0; 309 double cpu_usage = 0;
309 for (MetricsMap::const_iterator iter = metrics_map_->begin(); 310 for (MetricsMap::const_iterator iter = metrics_map_->begin();
310 iter != metrics_map_->end(); ++iter) { 311 iter != metrics_map_->end(); ++iter) {
311 cpu_usage += iter->second->GetCPUUsage(); 312 cpu_usage += iter->second->GetCPUUsage();
312 } 313 }
313 314
314 database_->AddMetric(Metric(METRIC_CPU_USAGE, 315 database_->AddMetric(METRIC_CPU_USAGE, base::DoubleToString(cpu_usage));
315 base::Time::Now(),
316 cpu_usage));
317 } 316 }
318 } 317 }
319 318
320 void PerformanceMonitor::GatherMemoryUsageOnBackgroundThread() { 319 void PerformanceMonitor::GatherMemoryUsageOnBackgroundThread() {
321 size_t private_memory_sum = 0; 320 size_t private_memory_sum = 0;
322 size_t shared_memory_sum = 0; 321 size_t shared_memory_sum = 0;
323 for (MetricsMap::const_iterator iter = metrics_map_->begin(); 322 for (MetricsMap::const_iterator iter = metrics_map_->begin();
324 iter != metrics_map_->end(); ++iter) { 323 iter != metrics_map_->end(); ++iter) {
325 size_t private_memory = 0; 324 size_t private_memory = 0;
326 size_t shared_memory = 0; 325 size_t shared_memory = 0;
327 if (iter->second->GetMemoryBytes(&private_memory, &shared_memory)) { 326 if (iter->second->GetMemoryBytes(&private_memory, &shared_memory)) {
328 private_memory_sum += private_memory; 327 private_memory_sum += private_memory;
329 shared_memory_sum += shared_memory; 328 shared_memory_sum += shared_memory;
330 } else { 329 } else {
331 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)"; 330 LOG(WARNING) << "GetMemoryBytes returned NULL (platform-specific error)";
332 } 331 }
333 } 332 }
334 333
335 database_->AddMetric(Metric(METRIC_PRIVATE_MEMORY_USAGE, 334 database_->AddMetric(METRIC_PRIVATE_MEMORY_USAGE,
336 base::Time::Now(), 335 base::Uint64ToString(private_memory_sum));
337 static_cast<double>(private_memory_sum))); 336 database_->AddMetric(METRIC_SHARED_MEMORY_USAGE,
338 database_->AddMetric(Metric(METRIC_SHARED_MEMORY_USAGE, 337 base::Uint64ToString(shared_memory_sum));
339 base::Time::Now(),
340 static_cast<double>(shared_memory_sum)));
341 } 338 }
342 339
343 void PerformanceMonitor::UpdateMetricsMapOnBackgroundThread() { 340 void PerformanceMonitor::UpdateMetricsMapOnBackgroundThread() {
344 MetricsMap* new_map = new MetricsMap; 341 MetricsMap* new_map = new MetricsMap;
345 342
346 base::ProcessId browser_pid = base::GetCurrentProcId(); 343 base::ProcessId browser_pid = base::GetCurrentProcId();
347 ChromeProcessList chrome_processes(GetRunningChromeProcesses(browser_pid)); 344 ChromeProcessList chrome_processes(GetRunningChromeProcesses(browser_pid));
348 for (ChromeProcessList::const_iterator pid_iter = chrome_processes.begin(); 345 for (ChromeProcessList::const_iterator pid_iter = chrome_processes.begin();
349 pid_iter != chrome_processes.end(); ++pid_iter) { 346 pid_iter != chrome_processes.end(); ++pid_iter) {
350 base::ProcessHandle handle; 347 base::ProcessHandle handle;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 FROM_HERE, 425 FROM_HERE,
429 base::Bind(&PerformanceMonitor::InsertIOData, 426 base::Bind(&PerformanceMonitor::InsertIOData,
430 base::Unretained(this), 427 base::Unretained(this),
431 performance_data_for_io_thread_)); 428 performance_data_for_io_thread_));
432 } 429 }
433 430
434 void PerformanceMonitor::InsertIOData( 431 void PerformanceMonitor::InsertIOData(
435 PerformanceDataForIOThread performance_data_for_io_thread) { 432 PerformanceDataForIOThread performance_data_for_io_thread) {
436 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 433 CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
437 database_->AddMetric( 434 database_->AddMetric(
438 Metric(METRIC_NETWORK_BYTES_READ, 435 METRIC_NETWORK_BYTES_READ,
439 base::Time::Now(), 436 base::Uint64ToString(performance_data_for_io_thread.network_bytes_read));
440 static_cast<double>(
441 performance_data_for_io_thread.network_bytes_read)));
442 } 437 }
443 438
444 void PerformanceMonitor::BytesReadOnIOThread(const net::URLRequest& request, 439 void PerformanceMonitor::BytesReadOnIOThread(const net::URLRequest& request,
445 const int bytes_read) { 440 const int bytes_read) {
446 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 441 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
447 442
448 if (initialized_ && !request.url().SchemeIsFile()) 443 if (initialized_ && !request.url().SchemeIsFile())
449 performance_data_for_io_thread_.network_bytes_read += bytes_read; 444 performance_data_for_io_thread_.network_bytes_read += bytes_read;
450 } 445 }
451 446
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 const content::LoadNotificationDetails* load_details = 514 const content::LoadNotificationDetails* load_details =
520 content::Details<content::LoadNotificationDetails>(details).ptr(); 515 content::Details<content::LoadNotificationDetails>(details).ptr();
521 if (!load_details) 516 if (!load_details)
522 break; 517 break;
523 BrowserThread::PostBlockingPoolSequencedTask( 518 BrowserThread::PostBlockingPoolSequencedTask(
524 Database::kDatabaseSequenceToken, 519 Database::kDatabaseSequenceToken,
525 FROM_HERE, 520 FROM_HERE,
526 base::Bind( 521 base::Bind(
527 &PerformanceMonitor::AddMetricOnBackgroundThread, 522 &PerformanceMonitor::AddMetricOnBackgroundThread,
528 base::Unretained(this), 523 base::Unretained(this),
529 Metric(METRIC_PAGE_LOAD_TIME, 524 METRIC_PAGE_LOAD_TIME,
530 base::Time::Now(), 525 base::Int64ToString(load_details->load_time.ToInternalValue())));
531 static_cast<double>(
532 load_details->load_time.ToInternalValue()))));
533 break; 526 break;
534 } 527 }
535 default: { 528 default: {
536 NOTREACHED(); 529 NOTREACHED();
537 break; 530 break;
538 } 531 }
539 } 532 }
540 } 533 }
541 534
542 void PerformanceMonitor::AddExtensionEvent(EventType type, 535 void PerformanceMonitor::AddExtensionEvent(EventType type,
(...skipping 22 matching lines...) Expand all
565 558
566 // Determine the type of crash. 559 // Determine the type of crash.
567 EventType type = 560 EventType type =
568 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? 561 details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
569 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH; 562 EVENT_KILLED_BY_OS_CRASH : EVENT_RENDERER_CRASH;
570 563
571 AddEvent(util::CreateCrashEvent(base::Time::Now(), type)); 564 AddEvent(util::CreateCrashEvent(base::Time::Now(), type));
572 } 565 }
573 566
574 } // namespace performance_monitor 567 } // namespace performance_monitor
OLDNEW
« no previous file with comments | « chrome/browser/performance_monitor/performance_monitor.h ('k') | chrome/browser/performance_monitor/startup_timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698