Commit 0986e1e1 authored by Gabriel Marin's avatar Gabriel Marin Committed by Commit Bot

Export a count of profile sessions with zero samples.

These are indicative of unsupported perf record commands.

BUG=b:169068625

Change-Id: Id04dd286cd77ab0ee6d04f9e3e3ff3986802c878
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424710Reviewed-by: default avatarGabriel Marin <gmx@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Commit-Queue: Gabriel Marin <gmx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809780}
parent 656c23b4
...@@ -282,6 +282,11 @@ void MetricCollector::SaveSerializedPerfProto( ...@@ -282,6 +282,11 @@ void MetricCollector::SaveSerializedPerfProto(
AddToUmaHistogram(CollectionAttemptStatus::PROTOBUF_NOT_PARSED); AddToUmaHistogram(CollectionAttemptStatus::PROTOBUF_NOT_PARSED);
return; return;
} }
// Don't save the profile if there are no samples.
if (perf_data_proto.stats().num_sample_events() == 0) {
AddToUmaHistogram(CollectionAttemptStatus::SESSION_HAS_ZERO_SAMPLES);
return;
}
RemoveUnknownFieldsFromMessagesWithStrings(&perf_data_proto); RemoveUnknownFieldsFromMessagesWithStrings(&perf_data_proto);
sampled_profile->mutable_perf_data()->Swap(&perf_data_proto); sampled_profile->mutable_perf_data()->Swap(&perf_data_proto);
......
...@@ -88,6 +88,7 @@ class MetricCollector { ...@@ -88,6 +88,7 @@ class MetricCollector {
ALREADY_COLLECTING, ALREADY_COLLECTING,
UNABLE_TO_COLLECT, UNABLE_TO_COLLECT,
DATA_COLLECTION_FAILED, DATA_COLLECTION_FAILED,
SESSION_HAS_ZERO_SAMPLES,
NUM_OUTCOMES NUM_OUTCOMES
}; };
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -78,9 +79,9 @@ class TestMetricCollector : public MetricCollector { ...@@ -78,9 +79,9 @@ class TestMetricCollector : public MetricCollector {
public: public:
TestMetricCollector() : TestMetricCollector(CollectionParams()) {} TestMetricCollector() : TestMetricCollector(CollectionParams()) {}
explicit TestMetricCollector(const CollectionParams& collection_params) explicit TestMetricCollector(const CollectionParams& collection_params)
: MetricCollector("UMA.CWP.TestData", collection_params) {} : MetricCollector("Test", collection_params) {}
const char* ToolName() const override { return "test"; } const char* ToolName() const override { return "Test"; }
base::WeakPtr<MetricCollector> GetWeakPtr() override { base::WeakPtr<MetricCollector> GetWeakPtr() override {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
...@@ -93,6 +94,7 @@ class TestMetricCollector : public MetricCollector { ...@@ -93,6 +94,7 @@ class TestMetricCollector : public MetricCollector {
} }
using MetricCollector::collection_params; using MetricCollector::collection_params;
using MetricCollector::CollectionAttemptStatus;
using MetricCollector::CurrentTimerDelay; using MetricCollector::CurrentTimerDelay;
using MetricCollector::Init; using MetricCollector::Init;
using MetricCollector::IsRunning; using MetricCollector::IsRunning;
...@@ -179,22 +181,50 @@ TEST_F(MetricCollectorTest, CheckSetup) { ...@@ -179,22 +181,50 @@ TEST_F(MetricCollectorTest, CheckSetup) {
TEST_F(MetricCollectorTest, EmptyProtosAreNotSaved) { TEST_F(MetricCollectorTest, EmptyProtosAreNotSaved) {
auto sampled_profile = std::make_unique<SampledProfile>(); auto sampled_profile = std::make_unique<SampledProfile>();
sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION);
base::HistogramTester histogram_tester;
metric_collector_->SaveSerializedPerfProto(std::move(sampled_profile), metric_collector_->SaveSerializedPerfProto(std::move(sampled_profile),
std::string()); std::string());
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
EXPECT_TRUE(cached_profile_data_.empty()); EXPECT_TRUE(cached_profile_data_.empty());
histogram_tester.ExpectUniqueSample(
"ChromeOS.CWP.CollectTest",
TestMetricCollector::CollectionAttemptStatus::ILLEGAL_DATA_RETURNED, 1);
}
TEST_F(MetricCollectorTest, ProtosWithNoSamplesAreNotSaved) {
auto sampled_profile = std::make_unique<SampledProfile>();
sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION);
base::HistogramTester histogram_tester;
PerfDataProto proto = GetExamplePerfDataProto();
PerfDataProto_PerfEventStats* stats = proto.mutable_stats();
stats->set_num_sample_events(0);
metric_collector_->SaveSerializedPerfProto(std::move(sampled_profile),
proto.SerializeAsString());
task_environment_.RunUntilIdle();
EXPECT_TRUE(cached_profile_data_.empty());
histogram_tester.ExpectUniqueSample(
"ChromeOS.CWP.CollectTest",
TestMetricCollector::CollectionAttemptStatus::SESSION_HAS_ZERO_SAMPLES,
1);
} }
TEST_F(MetricCollectorTest, PerfDataProto) { TEST_F(MetricCollectorTest, PerfDataProto) {
auto sampled_profile = std::make_unique<SampledProfile>(); auto sampled_profile = std::make_unique<SampledProfile>();
sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION); sampled_profile->set_trigger_event(SampledProfile::PERIODIC_COLLECTION);
base::HistogramTester histogram_tester;
metric_collector_->SaveSerializedPerfProto( metric_collector_->SaveSerializedPerfProto(
std::move(sampled_profile), perf_data_proto_.SerializeAsString()); std::move(sampled_profile), perf_data_proto_.SerializeAsString());
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
ASSERT_EQ(1U, cached_profile_data_.size()); ASSERT_EQ(1U, cached_profile_data_.size());
histogram_tester.ExpectUniqueSample(
"ChromeOS.CWP.CollectTest",
TestMetricCollector::CollectionAttemptStatus::SUCCESS, 1);
const SampledProfile& profile = cached_profile_data_[0]; const SampledProfile& profile = cached_profile_data_[0];
EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event()); EXPECT_EQ(SampledProfile::PERIODIC_COLLECTION, profile.trigger_event());
......
...@@ -9568,6 +9568,9 @@ histogram as enum --> ...@@ -9568,6 +9568,9 @@ histogram as enum -->
<int value="8" label="Data collection failure"> <int value="8" label="Data collection failure">
Failure while collecting data. Failure while collecting data.
</int> </int>
<int value="9" label="Session has zero samples">
The profile session has zero samples.
</int>
</enum> </enum>
<enum name="ChromeOSRecoveryReason"> <enum name="ChromeOSRecoveryReason">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment