OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/metrics/drive_metrics_provider.h" | 5 #include "components/metrics/drive_metrics_provider.h" |
6 | 6 |
7 #include <linux/kdev_t.h> // For MAJOR()/MINOR(). | 7 #include <linux/kdev_t.h> // For MAJOR()/MINOR(). |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file.h" | 11 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/strings/string_util.h" | |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 | 17 |
17 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
19 #endif | 20 #endif |
20 | 21 |
21 namespace metrics { | 22 namespace metrics { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // See http://www.kernel.org/doc/Documentation/devices.txt for more info. | 26 // See http://www.kernel.org/doc/Documentation/devices.txt for more info. |
26 const int kFirstScsiMajorNumber = 8; | 27 const int kFirstScsiMajorNumber = 8; |
27 const int kPartitionsPerScsiDevice = 16; | 28 const int kPartitionsPerScsiDevice = 16; |
28 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational"; | 29 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational"; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 // static | 33 // static |
33 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, | 34 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, |
34 bool* has_seek_penalty) { | 35 bool* has_seek_penalty) { |
35 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
36 std::string board = base::SysInfo::GetLsbReleaseBoard(); | 37 std::string board = base::SysInfo::GetStrippedReleaseBoard(); |
37 if (board != "unknown" && board != "parrot") { | 38 if (board != "unknown" && |
39 !base::StartsWith(board, "parrot", base::CompareCase::SENSITIVE)) { | |
Nico
2016/11/28 15:52:17
why do you need the StartsWith() call if you're no
igorcov
2016/11/28 15:58:02
There are more types of "parrot", specifically: pa
Alexei Svitkine (slow)
2016/11/28 16:03:28
This logic in the code should have a comment about
igorcov
2016/11/28 16:37:08
Done.
| |
38 // All ChromeOS devices have SSDs. Except some parrots. | 40 // All ChromeOS devices have SSDs. Except some parrots. |
39 *has_seek_penalty = false; | 41 *has_seek_penalty = false; |
40 return true; | 42 return true; |
41 } | 43 } |
42 #endif | 44 #endif |
43 | 45 |
44 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 46 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
45 if (!file.IsValid()) | 47 if (!file.IsValid()) |
46 return false; | 48 return false; |
47 | 49 |
48 struct stat path_stat; | 50 struct stat path_stat; |
49 int error = fstat(file.GetPlatformFile(), &path_stat); | 51 int error = fstat(file.GetPlatformFile(), &path_stat); |
50 if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) { | 52 if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) { |
51 // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM? | 53 // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM? |
52 return false; | 54 return false; |
53 } | 55 } |
54 | 56 |
55 char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice; | 57 char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice; |
56 std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX); | 58 std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX); |
57 std::string rotates; | 59 std::string rotates; |
58 if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates)) | 60 if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates)) |
59 return false; | 61 return false; |
60 | 62 |
61 *has_seek_penalty = rotates.substr(0, 1) == "1"; | 63 *has_seek_penalty = rotates.substr(0, 1) == "1"; |
62 return true; | 64 return true; |
63 } | 65 } |
64 | 66 |
65 } // namespace metrics | 67 } // namespace metrics |
OLD | NEW |