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

Side by Side Diff: base/sys_info_win.cc

Issue 999623002: metrics/base: log whether drives have seek penalties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: slightly after rush hour Created 5 years, 9 months 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
« no previous file with comments | « base/sys_info_unittest.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <winioctl.h>
8 9
10 #include "base/files/file.h"
9 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
13 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
14 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
15 17
16 namespace { 18 namespace {
17 19
18 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { 20 int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) {
19 MEMORYSTATUSEX memory_info; 21 MEMORYSTATUSEX memory_info;
20 memory_info.dwLength = sizeof(memory_info); 22 memory_info.dwLength = sizeof(memory_info);
21 if (!GlobalMemoryStatusEx(&memory_info)) { 23 if (!GlobalMemoryStatusEx(&memory_info)) {
22 NOTREACHED(); 24 NOTREACHED();
23 return 0; 25 return 0;
24 } 26 }
25 27
26 int64 rv = static_cast<int64>(memory_info.*memory_field); 28 int64 rv = static_cast<int64>(memory_info.*memory_field);
27 if (rv < 0) 29 return rv < 0 ? kint64max : rv;
28 rv = kint64max;
29 return rv;
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace base { 34 namespace base {
35 35
36 // static 36 // static
37 int SysInfo::NumberOfProcessors() { 37 int SysInfo::NumberOfProcessors() {
38 return win::OSInfo::GetInstance()->processors(); 38 return win::OSInfo::GetInstance()->processors();
39 } 39 }
40 40
41 // static 41 // static
42 int64 SysInfo::AmountOfPhysicalMemory() { 42 int64 SysInfo::AmountOfPhysicalMemory() {
43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys); 43 return AmountOfMemory(&MEMORYSTATUSEX::ullTotalPhys);
44 } 44 }
45 45
46 // static 46 // static
47 int64 SysInfo::AmountOfAvailablePhysicalMemory() { 47 int64 SysInfo::AmountOfAvailablePhysicalMemory() {
48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys); 48 return AmountOfMemory(&MEMORYSTATUSEX::ullAvailPhys);
49 } 49 }
50 50
51 // static 51 // static
52 int64 SysInfo::AmountOfVirtualMemory() { 52 int64 SysInfo::AmountOfVirtualMemory() {
53 return 0; 53 return 0;
54 } 54 }
55 55
56 // static 56 // static
57 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { 57 int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
58 base::ThreadRestrictions::AssertIOAllowed(); 58 ThreadRestrictions::AssertIOAllowed();
59 59
60 ULARGE_INTEGER available, total, free; 60 ULARGE_INTEGER available, total, free;
61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { 61 if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free))
62 return -1; 62 return -1;
63 } 63
64 int64 rv = static_cast<int64>(available.QuadPart); 64 int64 rv = static_cast<int64>(available.QuadPart);
65 if (rv < 0) 65 return rv < 0 ? kint64max : rv;
66 rv = kint64max; 66 }
67 return rv; 67
68 bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) {
69 ThreadRestrictions::AssertIOAllowed();
70
71 DCHECK(has_seek_penalty);
72
73 // TODO(dbeam): Vista, XP support.
74 if (!path.IsAbsolute() || win::GetVersion() < win::VERSION_WIN7)
rvargas (doing something else) 2015/03/13 21:03:09 I have not heard why allowing callers to use relat
Dan Beam 2015/03/13 21:15:51 Done. (changed to DCHECK)
75 return false;
76
77 std::vector<FilePath::StringType> components;
78 native_path.GetComponents(&components);
79 File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN);
rvargas (doing something else) 2015/03/13 21:03:09 Still requires if (!drive.IsValid())...
Dan Beam 2015/03/13 21:15:51 Done.
80
81 STORAGE_PROPERTY_QUERY query;
82 query.QueryType = PropertyStandardQuery;
83 query.PropertyId = StorageDeviceSeekPenaltyProperty;
84
85 DEVICE_SEEK_PENALTY_DESCRIPTOR result;
86
87 success = DeviceIoControl(drive.GetPlatformFile(),
88 IOCTL_STORAGE_QUERY_PROPERTY,
89 &query, sizeof(query),
90 &result, sizeof(result),
91 &bytes_returned,
rvargas (doing something else) 2015/03/13 21:03:09 not defined?
Dan Beam 2015/03/13 21:15:51 whoops, Done.
92 NULL);
93 if (success == FALSE || bytes_returned < sizeof(result))
94 return false;
95
96 *has_seek_penalty = result.IncursSeekPenalty == TRUE;
rvargas (doing something else) 2015/03/13 21:03:09 Comparing against TRUE is not a good idea (in gene
Dan Beam 2015/03/13 21:15:51 Done.
97 return true;
68 } 98 }
69 99
70 // static 100 // static
71 std::string SysInfo::OperatingSystemName() { 101 std::string SysInfo::OperatingSystemName() {
72 return "Windows NT"; 102 return "Windows NT";
73 } 103 }
74 104
75 // static 105 // static
76 std::string SysInfo::OperatingSystemVersion() { 106 std::string SysInfo::OperatingSystemVersion() {
77 win::OSInfo* os_info = win::OSInfo::GetInstance(); 107 win::OSInfo* os_info = win::OSInfo::GetInstance();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, 151 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
122 int32* minor_version, 152 int32* minor_version,
123 int32* bugfix_version) { 153 int32* bugfix_version) {
124 win::OSInfo* os_info = win::OSInfo::GetInstance(); 154 win::OSInfo* os_info = win::OSInfo::GetInstance();
125 *major_version = os_info->version_number().major; 155 *major_version = os_info->version_number().major;
126 *minor_version = os_info->version_number().minor; 156 *minor_version = os_info->version_number().minor;
127 *bugfix_version = 0; 157 *bugfix_version = 0;
128 } 158 }
129 159
130 } // namespace base 160 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_unittest.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698