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

Unified Diff: third_party/leveldatabase/env_chromium.cc

Issue 2858133002: Add uma stats to help evaluate the impact of changes to the quota allocation logic. (Closed)
Patch Set: xml Created 3 years, 8 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: third_party/leveldatabase/env_chromium.cc
diff --git a/third_party/leveldatabase/env_chromium.cc b/third_party/leveldatabase/env_chromium.cc
index b4daa541479b695c7b525c20973bc233a9d4da2c..f7689a230ba6795d41b65ea97b171f8befb5a490 100644
--- a/third_party/leveldatabase/env_chromium.cc
+++ b/third_party/leveldatabase/env_chromium.cc
@@ -102,6 +102,29 @@ static base::File::Error GetDirectoryEntries(const FilePath& dir_param,
#endif
}
+// To avoid a dependency on storage_histograms.h and the storageLib,
+// we re-implement the BytesCountHistogram functions here.
+base::HistogramBase* GetBytesCountHistogram(const std::string& name) {
+ const int kMin = 1;
+ const int kMax = 10000000;
+ const int kNumBuckets = 50;
+ return base::Histogram::FactoryGet(
+ name, kMin, kMax, kNumBuckets,
+ base::Histogram::kUmaTargetedHistogramFlag);
+}
+
+void RecordStorageBytesWritten(const char* label, int amount) {
+ std::string name("Storage.BytesWritten.");
+ name.append(label);
+ GetBytesCountHistogram(name)->Add(amount);
+}
+
+void RecordStorageBytesRead(const char* label, int amount) {
+ std::string name("Storage.BytesRead.");
+ name.append(label);
+ GetBytesCountHistogram(name)->Add(amount);
+}
+
class ChromiumFileLock : public FileLock {
public:
ChromiumFileLock(base::File file, const std::string& name)
@@ -177,6 +200,8 @@ class ChromiumSequentialFile : public leveldb::SequentialFile {
return MakeIOError(filename_, base::File::ErrorToString(error),
kSequentialFileRead, error);
} else {
+ if (bytes_read > 0)
+ uma_logger_->RecordBytesRead(bytes_read);
*result = Slice(scratch, bytes_read);
return Status::OK();
}
@@ -215,16 +240,16 @@ class ChromiumRandomAccessFile : public leveldb::RandomAccessFile {
char* scratch) const override {
TRACE_EVENT2("leveldb", "ChromiumRandomAccessFile::Read", "offset", offset,
"size", n);
- Status s;
- int r = file_.Read(offset, scratch, n);
- *result = Slice(scratch, (r < 0) ? 0 : r);
- if (r < 0) {
- // An error: return a non-ok status
- s = MakeIOError(filename_, "Could not perform read",
- kRandomAccessFileRead);
+ int bytes_read = file_.Read(offset, scratch, n);
+ *result = Slice(scratch, (bytes_read < 0) ? 0 : bytes_read);
+ if (bytes_read < 0) {
uma_logger_->RecordErrorAt(kRandomAccessFileRead);
+ return MakeIOError(filename_, "Could not perform read",
+ kRandomAccessFileRead);
}
- return s;
+ if (bytes_read > 0)
+ uma_logger_->RecordBytesRead(bytes_read);
+ return Status::OK();
}
private:
@@ -303,7 +328,8 @@ Status ChromiumWritableFile::Append(const Slice& data) {
return MakeIOError(filename_, base::File::ErrorToString(error),
kWritableFileAppend, error);
}
-
+ if (bytes_written > 0)
+ uma_logger_->RecordBytesWritten(bytes_written);
return Status::OK();
}
@@ -912,10 +938,6 @@ void ChromiumEnv::RecordErrorAt(MethodID method) const {
GetMethodIOErrorHistogram()->Add(method);
}
-void ChromiumEnv::RecordLockFileAncestors(int num_missing_ancestors) const {
- GetLockFileAncestorHistogram()->Add(num_missing_ancestors);
-}
-
void ChromiumEnv::RecordOSError(MethodID method,
base::File::Error error) const {
DCHECK_LT(error, 0);
@@ -923,6 +945,18 @@ void ChromiumEnv::RecordOSError(MethodID method,
GetOSErrorHistogram(method, -base::File::FILE_ERROR_MAX)->Add(-error);
}
+void ChromiumEnv::RecordBytesRead(int amount) const {
+ RecordStorageBytesRead(name_.c_str(), amount);
+}
+
+void ChromiumEnv::RecordBytesWritten(int amount) const {
+ RecordStorageBytesWritten(name_.c_str(), amount);
+}
+
+void ChromiumEnv::RecordLockFileAncestors(int num_missing_ancestors) const {
+ GetLockFileAncestorHistogram()->Add(num_missing_ancestors);
+}
+
base::HistogramBase* ChromiumEnv::GetOSErrorHistogram(MethodID method,
int limit) const {
std::string uma_name;

Powered by Google App Engine
This is Rietveld 408576698