Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "cros-disks/metrics.h" |
| 6 | |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 7 | #include <base/files/file_path.h> |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 8 | #include <base/logging.h> |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 9 | #include <base/strings/string_util.h> |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 10 | |
Anand K Mistry | 40cff45 | 2019-07-30 10:24:48 +1000 | [diff] [blame] | 11 | namespace cros_disks { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 12 | namespace { |
| 13 | |
| 14 | const char kArchiveTypeMetricName[] = "CrosDisks.ArchiveType"; |
| 15 | const char kDeviceMediaTypeMetricName[] = "CrosDisks.DeviceMediaType"; |
| 16 | const char kFilesystemTypeMetricName[] = "CrosDisks.FilesystemType"; |
| 17 | |
| 18 | } // namespace |
| 19 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 20 | Metrics::ArchiveType Metrics::GetArchiveType( |
| 21 | const std::string& archive_type) const { |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 22 | const auto map_iter = archive_type_map_.find(archive_type); |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 23 | if (map_iter != archive_type_map_.end()) |
| 24 | return map_iter->second; |
| 25 | return kArchiveUnknown; |
| 26 | } |
| 27 | |
| 28 | Metrics::FilesystemType Metrics::GetFilesystemType( |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 29 | const std::string& filesystem_type) const { |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 30 | const auto map_iter = filesystem_type_map_.find(filesystem_type); |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 31 | if (map_iter != filesystem_type_map_.end()) |
| 32 | return map_iter->second; |
| 33 | return kFilesystemOther; |
| 34 | } |
| 35 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 36 | void Metrics::RecordArchiveType(const std::string& archive_type) { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 37 | if (!metrics_library_.SendEnumToUMA(kArchiveTypeMetricName, |
| 38 | GetArchiveType(archive_type), |
| 39 | kArchiveMaxValue)) |
| 40 | LOG(WARNING) << "Failed to send archive type sample to UMA"; |
| 41 | } |
| 42 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 43 | void Metrics::RecordFilesystemType(const std::string& filesystem_type) { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 44 | if (!metrics_library_.SendEnumToUMA(kFilesystemTypeMetricName, |
| 45 | GetFilesystemType(filesystem_type), |
| 46 | kFilesystemMaxValue)) |
| 47 | LOG(WARNING) << "Failed to send filesystem type sample to UMA"; |
| 48 | } |
| 49 | |
| 50 | void Metrics::RecordDeviceMediaType(DeviceMediaType device_media_type) { |
| 51 | if (!metrics_library_.SendEnumToUMA(kDeviceMediaTypeMetricName, |
| 52 | device_media_type, |
Ben Chan | 6d0b272 | 2011-11-18 08:24:14 -0800 | [diff] [blame] | 53 | DEVICE_MEDIA_NUM_VALUES)) |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 54 | LOG(WARNING) << "Failed to send device media type sample to UMA"; |
| 55 | } |
| 56 | |
François Degros | 37f1948 | 2020-07-13 21:17:48 +1000 | [diff] [blame] | 57 | void Metrics::RecordFuseMounterErrorCode(const std::string& mounter_name, |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 58 | const int error_code) { |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 59 | metrics_library_.SendSparseToUMA("CrosDisks.Fuse." + mounter_name, |
| 60 | error_code); |
| 61 | } |
| 62 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 63 | } // namespace cros_disks |