Loading metrics/constants.h 0 → 100644 +28 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef METRICS_CONSTANTS_H_ #define METRICS_CONSTANTS_H_ namespace metrics { static const char kMetricsDirectory[] = "/data/misc/metrics/"; static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; } // namespace metrics #endif // METRICS_CONSTANTS_H_ metrics/metrics_daemon_main.cc +3 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include <chromeos/flag_helper.h> #include <chromeos/syslog_logging.h> #include "constants.h" #include "metrics_daemon.h" const char kScalingMaxFreqPath[] = Loading @@ -34,10 +35,10 @@ int main(int argc, char** argv) { "Interval at which metrics_daemon sends the metrics. (needs " "-uploader)"); DEFINE_string(server, "https://clients4.google.com/uma/v2", metrics::kMetricsServer, "Server to upload the metrics to. (needs -uploader)"); DEFINE_string(metrics_file, "/var/lib/metrics/uma-events", metrics::kMetricsEventsFilePath, "File to use as a proxy for uploading the metrics"); DEFINE_string(config_root, "/", "Root of the configuration files (testing only)"); Loading metrics/metrics_daemon_test.cc +0 −2 Original line number Diff line number Diff line Loading @@ -44,8 +44,6 @@ static const uint64_t kFakeWriteSectors[] = {3000, 4000}; static const char kFakeVmStatsName[] = "fake-vm-stats"; static const char kFakeScalingMaxFreqPath[] = "fake-scaling-max-freq"; static const char kFakeCpuinfoMaxFreqPath[] = "fake-cpuinfo-max-freq"; static const char kMetricsServer[] = "https://clients4.google.com/uma/v2"; static const char kMetricsFilePath[] = "/var/lib/metrics/uma-events"; class MetricsDaemonTest : public testing::Test { protected: Loading metrics/metrics_library.cc +8 −10 Original line number Diff line number Diff line Loading @@ -13,12 +13,10 @@ #include <cstdio> #include <cstring> #include "constants.h" #include "serialization/metric_sample.h" #include "serialization/serialization_utils.h" static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; static const char kCrosEventHistogramName[] = "Platform.CrOSEvent"; static const int kCrosEventHistogramMax = 100; Loading Loading @@ -46,7 +44,7 @@ static const char *kCrosEventNames[] = { time_t MetricsLibrary::cached_enabled_time_ = 0; bool MetricsLibrary::cached_enabled_ = false; MetricsLibrary::MetricsLibrary() : consent_file_(kConsentFile) {} MetricsLibrary::MetricsLibrary() : consent_file_(metrics::kConsentFilePath) {} MetricsLibrary::~MetricsLibrary() {} // We take buffer and buffer_size as parameters in order to simplify testing Loading Loading @@ -127,7 +125,7 @@ bool MetricsLibrary::AreMetricsEnabled() { } void MetricsLibrary::Init() { uma_events_file_ = kUMAEventsPath; uma_events_file_ = metrics::kMetricsEventsFilePath; } bool MetricsLibrary::SendToAutotest(const std::string& name, int value) { Loading @@ -150,30 +148,30 @@ bool MetricsLibrary::SendToUMA(const std::string& name, return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::HistogramSample(name, sample, min, max, nbuckets) .get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample, int max) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::LinearHistogramSample(name, sample, max).get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::SparseHistogramSample(name, sample).get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendUserActionToUMA(const std::string& action) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::UserActionSample(action).get(), kUMAEventsPath); *metrics::MetricSample::UserActionSample(action).get(), metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); *metrics::MetricSample::CrashSample(crash_kind).get(), metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { Loading metrics/persistent_integer.cc +2 −7 Original line number Diff line number Diff line Loading @@ -9,14 +9,9 @@ #include <base/logging.h> #include <base/posix/eintr_wrapper.h> #include "constants.h" #include "metrics/metrics_library.h" namespace { // The directory for the persistent storage. const char kBackingFilesDirectory[] = "/var/lib/metrics/"; } namespace chromeos_metrics { Loading @@ -31,7 +26,7 @@ PersistentInteger::PersistentInteger(const std::string& name) : if (testing_) { backing_file_name_ = name_; } else { backing_file_name_ = kBackingFilesDirectory + name_; backing_file_name_ = metrics::kMetricsDirectory + name_; } } Loading Loading
metrics/constants.h 0 → 100644 +28 −0 Original line number Diff line number Diff line // // Copyright (C) 2015 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef METRICS_CONSTANTS_H_ #define METRICS_CONSTANTS_H_ namespace metrics { static const char kMetricsDirectory[] = "/data/misc/metrics/"; static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events"; static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID"; static const char kMetricsServer[] = "http://clients4.google.com/uma/v2"; static const char kConsentFilePath[] = "/data/misc/metrics/enabled"; } // namespace metrics #endif // METRICS_CONSTANTS_H_
metrics/metrics_daemon_main.cc +3 −2 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include <chromeos/flag_helper.h> #include <chromeos/syslog_logging.h> #include "constants.h" #include "metrics_daemon.h" const char kScalingMaxFreqPath[] = Loading @@ -34,10 +35,10 @@ int main(int argc, char** argv) { "Interval at which metrics_daemon sends the metrics. (needs " "-uploader)"); DEFINE_string(server, "https://clients4.google.com/uma/v2", metrics::kMetricsServer, "Server to upload the metrics to. (needs -uploader)"); DEFINE_string(metrics_file, "/var/lib/metrics/uma-events", metrics::kMetricsEventsFilePath, "File to use as a proxy for uploading the metrics"); DEFINE_string(config_root, "/", "Root of the configuration files (testing only)"); Loading
metrics/metrics_daemon_test.cc +0 −2 Original line number Diff line number Diff line Loading @@ -44,8 +44,6 @@ static const uint64_t kFakeWriteSectors[] = {3000, 4000}; static const char kFakeVmStatsName[] = "fake-vm-stats"; static const char kFakeScalingMaxFreqPath[] = "fake-scaling-max-freq"; static const char kFakeCpuinfoMaxFreqPath[] = "fake-cpuinfo-max-freq"; static const char kMetricsServer[] = "https://clients4.google.com/uma/v2"; static const char kMetricsFilePath[] = "/var/lib/metrics/uma-events"; class MetricsDaemonTest : public testing::Test { protected: Loading
metrics/metrics_library.cc +8 −10 Original line number Diff line number Diff line Loading @@ -13,12 +13,10 @@ #include <cstdio> #include <cstring> #include "constants.h" #include "serialization/metric_sample.h" #include "serialization/serialization_utils.h" static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events"; static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; static const char kCrosEventHistogramName[] = "Platform.CrOSEvent"; static const int kCrosEventHistogramMax = 100; Loading Loading @@ -46,7 +44,7 @@ static const char *kCrosEventNames[] = { time_t MetricsLibrary::cached_enabled_time_ = 0; bool MetricsLibrary::cached_enabled_ = false; MetricsLibrary::MetricsLibrary() : consent_file_(kConsentFile) {} MetricsLibrary::MetricsLibrary() : consent_file_(metrics::kConsentFilePath) {} MetricsLibrary::~MetricsLibrary() {} // We take buffer and buffer_size as parameters in order to simplify testing Loading Loading @@ -127,7 +125,7 @@ bool MetricsLibrary::AreMetricsEnabled() { } void MetricsLibrary::Init() { uma_events_file_ = kUMAEventsPath; uma_events_file_ = metrics::kMetricsEventsFilePath; } bool MetricsLibrary::SendToAutotest(const std::string& name, int value) { Loading @@ -150,30 +148,30 @@ bool MetricsLibrary::SendToUMA(const std::string& name, return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::HistogramSample(name, sample, min, max, nbuckets) .get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample, int max) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::LinearHistogramSample(name, sample, max).get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::SparseHistogramSample(name, sample).get(), kUMAEventsPath); metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendUserActionToUMA(const std::string& action) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::UserActionSample(action).get(), kUMAEventsPath); *metrics::MetricSample::UserActionSample(action).get(), metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { return metrics::SerializationUtils::WriteMetricToFile( *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath); *metrics::MetricSample::CrashSample(crash_kind).get(), metrics::kMetricsEventsFilePath); } bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { Loading
metrics/persistent_integer.cc +2 −7 Original line number Diff line number Diff line Loading @@ -9,14 +9,9 @@ #include <base/logging.h> #include <base/posix/eintr_wrapper.h> #include "constants.h" #include "metrics/metrics_library.h" namespace { // The directory for the persistent storage. const char kBackingFilesDirectory[] = "/var/lib/metrics/"; } namespace chromeos_metrics { Loading @@ -31,7 +26,7 @@ PersistentInteger::PersistentInteger(const std::string& name) : if (testing_) { backing_file_name_ = name_; } else { backing_file_name_ = kBackingFilesDirectory + name_; backing_file_name_ = metrics::kMetricsDirectory + name_; } } Loading