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

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: DONT_ASSERT_ANYTHING 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.h » ('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(path.IsAbsolute());
72 DCHECK(has_seek_penalty);
73
74 // TODO(dbeam): Vista, XP support.
75 if (win::GetVersion() < win::VERSION_WIN7)
76 return false;
77
78 std::vector<FilePath::StringType> components;
79 path.GetComponents(&components);
80
81 File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN);
82 if (!drive.IsValid())
83 return false;
84
85 STORAGE_PROPERTY_QUERY query;
86 query.QueryType = PropertyStandardQuery;
87 query.PropertyId = StorageDeviceSeekPenaltyProperty;
88
89 DEVICE_SEEK_PENALTY_DESCRIPTOR result;
90 DWORD bytes_returned;
91
92 BOOL success = DeviceIoControl(drive.GetPlatformFile(),
93 IOCTL_STORAGE_QUERY_PROPERTY,
94 &query, sizeof(query),
95 &result, sizeof(result),
96 &bytes_returned,
97 NULL);
98 if (success == FALSE || bytes_returned < sizeof(result))
99 return false;
100
101 *has_seek_penalty = result.IncursSeekPenalty != FALSE;
102 return true;
68 } 103 }
69 104
70 // static 105 // static
71 std::string SysInfo::OperatingSystemName() { 106 std::string SysInfo::OperatingSystemName() {
72 return "Windows NT"; 107 return "Windows NT";
73 } 108 }
74 109
75 // static 110 // static
76 std::string SysInfo::OperatingSystemVersion() { 111 std::string SysInfo::OperatingSystemVersion() {
77 win::OSInfo* os_info = win::OSInfo::GetInstance(); 112 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, 156 void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
122 int32* minor_version, 157 int32* minor_version,
123 int32* bugfix_version) { 158 int32* bugfix_version) {
124 win::OSInfo* os_info = win::OSInfo::GetInstance(); 159 win::OSInfo* os_info = win::OSInfo::GetInstance();
125 *major_version = os_info->version_number().major; 160 *major_version = os_info->version_number().major;
126 *minor_version = os_info->version_number().minor; 161 *minor_version = os_info->version_number().minor;
127 *bugfix_version = 0; 162 *bugfix_version = 0;
128 } 163 }
129 164
130 } // namespace base 165 } // namespace base
OLDNEW
« no previous file with comments | « base/sys_info_unittest.cc ('k') | chrome/browser/metrics/chrome_metrics_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698