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

Unified Diff: chrome/browser/performance_monitor/performance_monitor.cc

Issue 10829342: Add BytesRead metric to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Requested changes 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/performance_monitor/performance_monitor.cc
diff --git a/chrome/browser/performance_monitor/performance_monitor.cc b/chrome/browser/performance_monitor/performance_monitor.cc
index 38f7192ca207bead318ace9cd48800521db71a54..99a1faeb5970873152d12964eee234b14a68faf4 100644
--- a/chrome/browser/performance_monitor/performance_monitor.cc
+++ b/chrome/browser/performance_monitor/performance_monitor.cc
@@ -34,6 +34,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/web_contents.h"
+#include "net/url_request/url_request.h"
using content::BrowserThread;
using extensions::Extension;
@@ -61,6 +62,12 @@ bool StringToTime(std::string time, base::Time* output) {
namespace performance_monitor {
+bool PerformanceMonitor::initialized_ = false;
+
+PerformanceMonitor::PerformanceDataForIOThread::PerformanceDataForIOThread()
+ : network_bytes_read(0) {
+}
+
PerformanceMonitor::PerformanceMonitor() : database_(NULL) {
}
@@ -94,6 +101,14 @@ void PerformanceMonitor::Start() {
void PerformanceMonitor::InitOnBackgroundThread() {
CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
database_ = Database::Create(database_path_);
+
+ // Initialize the io thread's performance data to the value in the database;
+ // if there isn't a recording in the database, the value stays at 0.
+ MetricInfo info;
+ if (database_->GetRecentStatsForActivityAndMetric(METRIC_NETWORK_BYTES_READ,
+ &info)) {
+ performance_data_for_io_thread_.network_bytes_read = info.value;
battre 2012/08/22 19:23:02 you access the variable on the UI thread. Sorry th
Devlin 2012/08/22 20:34:55 Well, I've been wrong on threading every step of t
battre 2012/08/22 20:50:24 Maybe you can move the check whether initialzed_ i
Devlin 2012/08/23 16:41:02 Done.
+ }
}
void PerformanceMonitor::FinishInit() {
@@ -244,6 +259,8 @@ void PerformanceMonitor::NotifyInitialized() {
chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
content::Source<PerformanceMonitor>(this),
content::NotificationService::NoDetails());
+
+ initialized_ = true;
}
void PerformanceMonitor::GatherStatisticsOnBackgroundThread() {
@@ -362,6 +379,45 @@ void PerformanceMonitor::UpdateLiveProfilesHelper(
void PerformanceMonitor::DoTimedCollections() {
UpdateLiveProfiles();
+
+ BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
+ base::Unretained(this)));
+
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitor::CallInsertIOData,
+ base::Unretained(this)));
+}
+
+void PerformanceMonitor::CallInsertIOData() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitor::InsertIOData,
+ base::Unretained(this),
+ performance_data_for_io_thread_));
+}
+
+void PerformanceMonitor::InsertIOData(
+ PerformanceDataForIOThread performance_data_for_io_thread) {
+ CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ database_->AddMetric(
+ METRIC_NETWORK_BYTES_READ,
+ base::Uint64ToString(performance_data_for_io_thread.network_bytes_read));
+}
+
+void PerformanceMonitor::BytesReadOnIOThread(const net::URLRequest& request,
+ const int bytes_read) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (!request.url().SchemeIsFile())
+ performance_data_for_io_thread_.network_bytes_read += bytes_read;
}
void PerformanceMonitor::Observe(int type,

Powered by Google App Engine
This is Rietveld 408576698