summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorkkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-11 14:46:45 +0000
committerkkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-11 14:46:45 +0000
commitc778687a545aeb1ef7df04038cb84b167565f77a (patch)
tree5055fe7135736791ddb40a661283cdd0637f7850 /base
parentfa01e47350050ca5be93589414a21d4dc5579107 (diff)
downloadchromium_src-c778687a545aeb1ef7df04038cb84b167565f77a.zip
chromium_src-c778687a545aeb1ef7df04038cb84b167565f77a.tar.gz
chromium_src-c778687a545aeb1ef7df04038cb84b167565f77a.tar.bz2
Let MetricsService know about some Android Activities
To tune our crash states more finely, we need to track which Activity is in the foreground when Chrome is killed. Add piping to let MetricsService know when Activities are swapped in and out by the user. The CL makes MetricsService track how many times particular Activities have been launched, as well as how often Chrome was improperly closed while one of these Activities was in the foreground (i.e. crashed). These numbers are concatenated into a histogram, which is then sent to the server. BUG=321346 Review URL: https://codereview.chromium.org/137623002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250410 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gyp1
-rw-r--r--base/metrics/histogram.h18
-rw-r--r--base/metrics/histogram_base.h19
-rw-r--r--base/metrics/histogram_delta_serialization.cc2
-rw-r--r--base/metrics/histogram_snapshot_manager.cc11
-rw-r--r--base/metrics/histogram_snapshot_manager.h10
-rw-r--r--base/metrics/histogram_snapshot_manager_unittest.cc106
-rw-r--r--base/metrics/statistics_recorder.h1
8 files changed, 149 insertions, 19 deletions
diff --git a/base/base.gyp b/base/base.gyp
index 4269485..78e6ddb 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -554,6 +554,7 @@
'metrics/field_trial_unittest.cc',
'metrics/histogram_base_unittest.cc',
'metrics/histogram_delta_serialization_unittest.cc',
+ 'metrics/histogram_snapshot_manager_unittest.cc',
'metrics/histogram_unittest.cc',
'metrics/sparse_histogram_unittest.cc',
'metrics/stats_table_unittest.cc',
diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h
index 9845362..7a6c688 100644
--- a/base/metrics/histogram.h
+++ b/base/metrics/histogram.h
@@ -190,6 +190,12 @@ class Lock;
base::Histogram::FactoryGet(name, min, max, bucket_count, \
base::HistogramBase::kNoFlags))
+// This is a helper macro used by other macros and shouldn't be used directly.
+#define HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary, flag) \
+ STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
+ base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1, \
+ flag))
+
#define HISTOGRAM_PERCENTAGE(name, under_one_hundred) \
HISTOGRAM_ENUMERATION(name, under_one_hundred, 101)
@@ -349,9 +355,15 @@ class Lock;
// The samples should always be strictly less than |boundary_value|. For more
// details, see the comment for the |HISTOGRAM_ENUMERATION| macro, above.
#define UMA_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \
- STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
- base::LinearHistogram::FactoryGet(name, 1, boundary_value, \
- boundary_value + 1, base::HistogramBase::kUmaTargetedHistogramFlag))
+ HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary_value, \
+ base::HistogramBase::kUmaTargetedHistogramFlag)
+
+// Similar to UMA_HISTOGRAM_ENUMERATION, but used for recording stability
+// histograms. Use this if recording a histogram that should be part of the
+// initial stability log.
+#define UMA_STABILITY_HISTOGRAM_ENUMERATION(name, sample, boundary_value) \
+ HISTOGRAM_ENUMERATION_WITH_FLAG(name, sample, boundary_value, \
+ base::HistogramBase::kUmaStabilityHistogramFlag)
#define UMA_HISTOGRAM_CUSTOM_ENUMERATION(name, sample, custom_ranges) \
STATIC_HISTOGRAM_POINTER_BLOCK(name, Add(sample), \
diff --git a/base/metrics/histogram_base.h b/base/metrics/histogram_base.h
index 11b9a45b..f3e9b46 100644
--- a/base/metrics/histogram_base.h
+++ b/base/metrics/histogram_base.h
@@ -56,13 +56,20 @@ class BASE_EXPORT HistogramBase {
enum Flags {
kNoFlags = 0,
- kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded.
- // Indicate that the histogram was pickled to be sent across an IPC Channel.
- // If we observe this flag on a histogram being aggregated into after IPC,
- // then we are running in a single process mode, and the aggregation should
- // not take place (as we would be aggregating back into the source
- // histogram!).
+ // Histogram should be UMA uploaded.
+ kUmaTargetedHistogramFlag = 0x1,
+
+ // Indicates that this is a stability histogram. This flag exists to specify
+ // which histograms should be included in the initial stability log. Please
+ // refer to |MetricsService::PrepareInitialStabilityLog|.
+ kUmaStabilityHistogramFlag = kUmaTargetedHistogramFlag | 0x2,
+
+ // Indicates that the histogram was pickled to be sent across an IPC
+ // Channel. If we observe this flag on a histogram being aggregated into
+ // after IPC, then we are running in a single process mode, and the
+ // aggregation should not take place (as we would be aggregating back into
+ // the source histogram!).
kIPCSerializationSourceFlag = 0x10,
// Only for Histogram and its sub classes: fancy bucket-naming support.
diff --git a/base/metrics/histogram_delta_serialization.cc b/base/metrics/histogram_delta_serialization.cc
index e40a6b6..e4aad13 100644
--- a/base/metrics/histogram_delta_serialization.cc
+++ b/base/metrics/histogram_delta_serialization.cc
@@ -66,7 +66,7 @@ void HistogramDeltaSerialization::PrepareAndSerializeDeltas(
// the histograms, so that the receiving process can distinguish them from the
// local histograms.
histogram_snapshot_manager_.PrepareDeltas(
- Histogram::kIPCSerializationSourceFlag, false);
+ Histogram::kIPCSerializationSourceFlag, Histogram::kNoFlags);
serialized_deltas_ = NULL;
}
diff --git a/base/metrics/histogram_snapshot_manager.cc b/base/metrics/histogram_snapshot_manager.cc
index cb594bd..b1e26da 100644
--- a/base/metrics/histogram_snapshot_manager.cc
+++ b/base/metrics/histogram_snapshot_manager.cc
@@ -25,18 +25,17 @@ HistogramSnapshotManager::~HistogramSnapshotManager() {
STLDeleteValues(&logged_samples_);
}
-void HistogramSnapshotManager::PrepareDeltas(HistogramBase::Flags flag_to_set,
- bool record_only_uma) {
+void HistogramSnapshotManager::PrepareDeltas(
+ HistogramBase::Flags flag_to_set,
+ HistogramBase::Flags required_flags) {
StatisticsRecorder::Histograms histograms;
StatisticsRecorder::GetHistograms(&histograms);
for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin();
histograms.end() != it;
++it) {
(*it)->SetFlags(flag_to_set);
- if (record_only_uma &&
- 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag))
- continue;
- PrepareDelta(**it);
+ if (((*it)->flags() & required_flags) == required_flags)
+ PrepareDelta(**it);
}
}
diff --git a/base/metrics/histogram_snapshot_manager.h b/base/metrics/histogram_snapshot_manager.h
index 3c70508..5a5f2e9 100644
--- a/base/metrics/histogram_snapshot_manager.h
+++ b/base/metrics/histogram_snapshot_manager.h
@@ -29,9 +29,13 @@ class BASE_EXPORT HistogramSnapshotManager {
virtual ~HistogramSnapshotManager();
// Snapshot all histograms, and ask |histogram_flattener_| to record the
- // delta. The arguments allow selecting only a subset of histograms for
- // recording, or to set a flag in each recorded histogram.
- void PrepareDeltas(HistogramBase::Flags flags_to_set, bool record_only_uma);
+ // delta. |flags_to_set| is used to set flags for each histogram.
+ // |required_flags| is used to select histograms to be recorded.
+ // Only histograms that have all the flags specified by the argument will be
+ // chosen. If all histograms should be recorded, set it to
+ // |Histogram::kNoFlags|.
+ void PrepareDeltas(HistogramBase::Flags flags_to_set,
+ HistogramBase::Flags required_flags);
private:
// Snapshot this histogram, and record the delta.
diff --git a/base/metrics/histogram_snapshot_manager_unittest.cc b/base/metrics/histogram_snapshot_manager_unittest.cc
new file mode 100644
index 0000000..e6672ea
--- /dev/null
+++ b/base/metrics/histogram_snapshot_manager_unittest.cc
@@ -0,0 +1,106 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/metrics/histogram_snapshot_manager.h"
+
+#include <string>
+#include <vector>
+
+#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_delta_serialization.h"
+#include "base/metrics/statistics_recorder.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+class HistogramFlattenerDeltaRecorder : public HistogramFlattener {
+ public:
+ HistogramFlattenerDeltaRecorder() {}
+
+ virtual void RecordDelta(const HistogramBase& histogram,
+ const HistogramSamples& snapshot) OVERRIDE {
+ recorded_delta_histogram_names_.push_back(histogram.histogram_name());
+ }
+
+ virtual void InconsistencyDetected(
+ HistogramBase::Inconsistency problem) OVERRIDE {
+ ASSERT_TRUE(false);
+ }
+
+ virtual void UniqueInconsistencyDetected(
+ HistogramBase::Inconsistency problem) OVERRIDE {
+ ASSERT_TRUE(false);
+ }
+
+ virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE {
+ ASSERT_TRUE(false);
+ }
+
+ std::vector<std::string> GetRecordedDeltaHistogramNames() {
+ return recorded_delta_histogram_names_;
+ }
+
+ private:
+ std::vector<std::string> recorded_delta_histogram_names_;
+
+ DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder);
+};
+
+class HistogramSnapshotManagerTest : public testing::Test {
+ protected:
+ HistogramSnapshotManagerTest()
+ : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {}
+
+ virtual ~HistogramSnapshotManagerTest() {}
+
+ StatisticsRecorder statistics_recorder_;
+ HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_;
+ HistogramSnapshotManager histogram_snapshot_manager_;
+};
+
+TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) {
+ // kNoFlags filter should record all histograms.
+ UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
+ UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
+
+ histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags,
+ HistogramBase::kNoFlags);
+
+ const std::vector<std::string>& histograms =
+ histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
+ EXPECT_EQ(2U, histograms.size());
+ EXPECT_EQ("UmaHistogram", histograms[0]);
+ EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
+}
+
+TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) {
+ // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag.
+ UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
+ UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
+
+ histogram_snapshot_manager_.PrepareDeltas(
+ HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag);
+
+ const std::vector<std::string>& histograms =
+ histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
+ EXPECT_EQ(2U, histograms.size());
+ EXPECT_EQ("UmaHistogram", histograms[0]);
+ EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
+}
+
+TEST_F(HistogramSnapshotManagerTest,
+ PrepareDeltasUmaStabilityHistogramFlagFilter) {
+ UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
+ UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
+
+ histogram_snapshot_manager_.PrepareDeltas(
+ HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag);
+
+ const std::vector<std::string>& histograms =
+ histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
+ EXPECT_EQ(1U, histograms.size());
+ EXPECT_EQ("UmaStabilityHistogram", histograms[0]);
+}
+
+} // namespace base
diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h
index 5e53f274..7a81826 100644
--- a/base/metrics/statistics_recorder.h
+++ b/base/metrics/statistics_recorder.h
@@ -86,6 +86,7 @@ class BASE_EXPORT StatisticsRecorder {
friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
friend class HistogramBaseTest;
+ friend class HistogramSnapshotManagerTest;
friend class HistogramTest;
friend class SparseHistogramTest;
friend class StatisticsDeltaReaderTest;