Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: components/metrics/drive_metrics_provider_linux.cc

Issue 2489853002: Added function to provide the short board name of the device (Closed)
Patch Set: Fixed the review comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« base/sys_info.h ('K') | « base/sys_info_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 14 matching lines...) Expand all
25 // See http://www.kernel.org/doc/Documentation/devices.txt for more info. 25 // See http://www.kernel.org/doc/Documentation/devices.txt for more info.
26 const int kFirstScsiMajorNumber = 8; 26 const int kFirstScsiMajorNumber = 8;
27 const int kPartitionsPerScsiDevice = 16; 27 const int kPartitionsPerScsiDevice = 16;
28 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational"; 28 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational";
29 29
30 } // namespace 30 } // namespace
31 31
32 // static 32 // static
33 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path, 33 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
34 bool* has_seek_penalty) { 34 bool* has_seek_penalty) {
35 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
Thiemo Nagel 2016/11/23 20:21:19 There's parrot, parrot_ivb and parrot_freon. Whic
Dan Beam 2016/11/23 21:18:37 ¯\_(ツ)_/¯ maybe use StartsWith()?
igorcov 2016/11/25 11:08:59 Done.
36 std::string board = base::SysInfo::GetLsbReleaseBoard(); 36 std::string board = base::SysInfo::GetStrippedReleaseBoard();
37 if (board != "unknown" && board != "parrot") { 37 if (board != "unknown" && board != "parrot") {
38 // All ChromeOS devices have SSDs. Except some parrots. 38 // All ChromeOS devices have SSDs. Except some parrots.
39 *has_seek_penalty = false; 39 *has_seek_penalty = false;
40 return true; 40 return true;
41 } 41 }
42 #endif 42 #endif
43 43
44 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); 44 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
45 if (!file.IsValid()) 45 if (!file.IsValid())
46 return false; 46 return false;
47 47
48 struct stat path_stat; 48 struct stat path_stat;
49 int error = fstat(file.GetPlatformFile(), &path_stat); 49 int error = fstat(file.GetPlatformFile(), &path_stat);
50 if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) { 50 if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) {
51 // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM? 51 // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM?
52 return false; 52 return false;
53 } 53 }
54 54
55 char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice; 55 char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice;
56 std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX); 56 std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX);
57 std::string rotates; 57 std::string rotates;
58 if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates)) 58 if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates))
59 return false; 59 return false;
60 60
61 *has_seek_penalty = rotates.substr(0, 1) == "1"; 61 *has_seek_penalty = rotates.substr(0, 1) == "1";
62 return true; 62 return true;
63 } 63 }
64 64
65 } // namespace metrics 65 } // namespace metrics
OLDNEW
« base/sys_info.h ('K') | « base/sys_info_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698