blob: 6b95c379c9196b92cdfb4593f17f5dda916e6f4e [file] [log] [blame]
Ben Chanbe2b4a72011-11-08 13:42:23 -08001// 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 Degrosaec21fb2020-03-06 15:23:43 +11007#include <base/files/file_path.h>
Ben Chanbe2b4a72011-11-08 13:42:23 -08008#include <base/logging.h>
François Degrosaec21fb2020-03-06 15:23:43 +11009#include <base/strings/string_util.h>
Ben Chanbe2b4a72011-11-08 13:42:23 -080010
Anand K Mistry40cff452019-07-30 10:24:48 +100011namespace cros_disks {
Ben Chanbe2b4a72011-11-08 13:42:23 -080012namespace {
13
14const char kArchiveTypeMetricName[] = "CrosDisks.ArchiveType";
15const char kDeviceMediaTypeMetricName[] = "CrosDisks.DeviceMediaType";
16const char kFilesystemTypeMetricName[] = "CrosDisks.FilesystemType";
17
18} // namespace
19
Ben Chan213c6d92019-04-10 16:21:52 -070020Metrics::ArchiveType Metrics::GetArchiveType(
21 const std::string& archive_type) const {
François Degros13d86e62020-07-12 13:09:13 +100022 const auto map_iter = archive_type_map_.find(archive_type);
Ben Chanbe2b4a72011-11-08 13:42:23 -080023 if (map_iter != archive_type_map_.end())
24 return map_iter->second;
25 return kArchiveUnknown;
26}
27
28Metrics::FilesystemType Metrics::GetFilesystemType(
Ben Chan213c6d92019-04-10 16:21:52 -070029 const std::string& filesystem_type) const {
François Degros13d86e62020-07-12 13:09:13 +100030 const auto map_iter = filesystem_type_map_.find(filesystem_type);
Ben Chanbe2b4a72011-11-08 13:42:23 -080031 if (map_iter != filesystem_type_map_.end())
32 return map_iter->second;
33 return kFilesystemOther;
34}
35
Ben Chan213c6d92019-04-10 16:21:52 -070036void Metrics::RecordArchiveType(const std::string& archive_type) {
Ben Chanbe2b4a72011-11-08 13:42:23 -080037 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 Chan213c6d92019-04-10 16:21:52 -070043void Metrics::RecordFilesystemType(const std::string& filesystem_type) {
Ben Chanbe2b4a72011-11-08 13:42:23 -080044 if (!metrics_library_.SendEnumToUMA(kFilesystemTypeMetricName,
45 GetFilesystemType(filesystem_type),
46 kFilesystemMaxValue))
47 LOG(WARNING) << "Failed to send filesystem type sample to UMA";
48}
49
50void Metrics::RecordDeviceMediaType(DeviceMediaType device_media_type) {
51 if (!metrics_library_.SendEnumToUMA(kDeviceMediaTypeMetricName,
52 device_media_type,
Ben Chan6d0b2722011-11-18 08:24:14 -080053 DEVICE_MEDIA_NUM_VALUES))
Ben Chanbe2b4a72011-11-08 13:42:23 -080054 LOG(WARNING) << "Failed to send device media type sample to UMA";
55}
56
François Degros37f19482020-07-13 21:17:48 +100057void Metrics::RecordFuseMounterErrorCode(const std::string& mounter_name,
François Degrosaec21fb2020-03-06 15:23:43 +110058 const int error_code) {
François Degrosaec21fb2020-03-06 15:23:43 +110059 metrics_library_.SendSparseToUMA("CrosDisks.Fuse." + mounter_name,
60 error_code);
61}
62
Ben Chanbe2b4a72011-11-08 13:42:23 -080063} // namespace cros_disks