Extensions: Add some content verification UMA.
For computed_hashes.json and verified_contents.json:
Time how long it takes of successfully reading the files and
serializing them. Also record how frequently serialization
fails.
ComputedHashesInitTime/ComputedHashesReadResult
VerifiedContentsInitTime/VerifiedContentsInitResult
Record if fetching verified_contents succeeds or fails.
And the most important one "ReadContentHashTime", would give a
high level overview of how much time we spend on just "getting the
stuff", discarding any oddities around file missing and such.
Bug: 859729
Change-Id: Iaef0d495a55bd910811b7cd3b8a560ed6b52c719
Reviewed-on: https://chromium-review.googlesource.com/1121382
Commit-Queue: Istiaque Ahmed <[email protected]>
Reviewed-by: Ilya Sherman <[email protected]>
Reviewed-by: Devlin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#573054}
diff --git a/extensions/browser/computed_hashes.cc b/extensions/browser/computed_hashes.cc
index cfe0a9e8..e0a365b 100644
--- a/extensions/browser/computed_hashes.cc
+++ b/extensions/browser/computed_hashes.cc
@@ -12,7 +12,9 @@
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
+#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
+#include "base/timer/elapsed_timer.h"
#include "base/values.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
@@ -28,6 +30,43 @@
const int kVersion = 2;
} // namespace computed_hashes
+namespace {
+
+// Helper to record UMA for ComputedHashes::Reader::InitFromFile.
+// Records failure UMA if RecordSuccess() isn't explicitly called.
+class ScopedUMARecorder {
+ public:
+ ScopedUMARecorder() = default;
+
+ ~ScopedUMARecorder() {
+ if (recorded_)
+ return;
+ RecordImpl(false);
+ }
+
+ void RecordSuccess() {
+ recorded_ = true;
+ RecordImpl(true);
+ }
+
+ private:
+ void RecordImpl(bool succeeded) {
+ UMA_HISTOGRAM_BOOLEAN(
+ "Extensions.ContentVerification.ComputedHashesReadResult", succeeded);
+ if (succeeded) {
+ UMA_HISTOGRAM_TIMES(
+ "Extensions.ContentVerification.ComputedHashesInitTime",
+ timer_.Elapsed());
+ }
+ }
+
+ bool recorded_ = false;
+ base::ElapsedTimer timer_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedUMARecorder);
+};
+
+} // namespace
+
ComputedHashes::Reader::Reader() {
}
@@ -35,6 +74,7 @@
}
bool ComputedHashes::Reader::InitFromFile(const base::FilePath& path) {
+ ScopedUMARecorder uma_recorder;
std::string contents;
if (!base::ReadFileToString(path, &contents))
return false;
@@ -96,6 +136,7 @@
}
}
}
+ uma_recorder.RecordSuccess();
return true;
}