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

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 + separation for disk/network reads 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..372ab3b9892c312330dd27f68083ef45bb8d90e1 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,10 @@ bool StringToTime(std::string time, base::Time* output) {
namespace performance_monitor {
+bool PerformanceMonitor::initialized_ = false;
+
+PerformanceMonitor::ByteCount::ByteCount() : disk(0), network(0) { }
+
PerformanceMonitor::PerformanceMonitor() : database_(NULL) {
}
@@ -94,6 +99,18 @@ void PerformanceMonitor::Start() {
void PerformanceMonitor::InitOnBackgroundThread() {
CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
database_ = Database::Create(database_path_);
+
+ // Initialize each member of bytes_read_ 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_DISK_BYTES_READ,
+ &info)) {
+ bytes_read_.disk = info.value;
+ }
+ if (database_->GetRecentStatsForActivityAndMetric(METRIC_NETWORK_BYTES_READ,
+ &info)) {
+ bytes_read_.network = info.value;
+ }
}
void PerformanceMonitor::FinishInit() {
@@ -244,11 +261,18 @@ void PerformanceMonitor::NotifyInitialized() {
chrome::NOTIFICATION_PERFORMANCE_MONITOR_INITIALIZED,
content::Source<PerformanceMonitor>(this),
content::NotificationService::NoDetails());
+
+ initialized_ = true;
}
void PerformanceMonitor::GatherStatisticsOnBackgroundThread() {
CHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ database_->AddMetric(METRIC_DISK_BYTES_READ,
+ base::Int64ToString(bytes_read_.disk));
battre 2012/08/21 20:37:33 If you access bytes_read_ here, you must be on the
Devlin 2012/08/21 22:51:52 Done.
+ database_->AddMetric(METRIC_NETWORK_BYTES_READ,
+ base::Int64ToString(bytes_read_.network));
+
// Because the CPU usage is gathered as an average since the last time the
// function was called, while the memory usage is gathered as an instantaneous
// usage, the CPU usage is gathered before the metrics map is wiped.
@@ -362,6 +386,28 @@ void PerformanceMonitor::UpdateLiveProfilesHelper(
void PerformanceMonitor::DoTimedCollections() {
UpdateLiveProfiles();
+
+ BrowserThread::PostBlockingPoolSequencedTask(
+ Database::kDatabaseSequenceToken,
+ FROM_HERE,
+ base::Bind(&PerformanceMonitor::GatherStatisticsOnBackgroundThread,
+ base::Unretained(this)));
+}
+
+void PerformanceMonitor::BytesRead(const net::URLRequest& request,
+ const int bytes_read) {
+ // Strictly speaking, we don't care that this is done on the I/O thread - we
+ // only care that it is always done on the *same* thread. This should be the
+ // only place which modifies the value of bytes_read_; thus we avoid race
+ // conditions (inserting into the database is not a race condition, because if
+ // it is not inserted in one iteration, it will be in the next, and it was
+ // close enough to justify being in either one).
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+
+ if (request.url().SchemeIsFile())
+ bytes_read_.disk += bytes_read;
+ else
+ bytes_read_.network += bytes_read;
}
void PerformanceMonitor::Observe(int type,

Powered by Google App Engine
This is Rietveld 408576698