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

Unified 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: indent 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 side-by-side diff with in-line comments
Download patch
Index: base/sys_info_win.cc
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc
index 9cc0cfa48a3637d48c36978de2c798383e9a194d..a6b364b7e43306984b2757c44c730956d5378480 100644
--- a/base/sys_info_win.cc
+++ b/base/sys_info_win.cc
@@ -5,7 +5,9 @@
#include "base/sys_info.h"
#include <windows.h>
+#include <winioctl.h>
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -24,9 +26,7 @@ int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) {
}
int64 rv = static_cast<int64>(memory_info.*memory_field);
- if (rv < 0)
- rv = kint64max;
- return rv;
+ return rv < 0 ? kint64max : rv;
}
} // namespace
@@ -55,16 +55,50 @@ int64 SysInfo::AmountOfVirtualMemory() {
// static
int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) {
- base::ThreadRestrictions::AssertIOAllowed();
+ ThreadRestrictions::AssertIOAllowed();
ULARGE_INTEGER available, total, free;
- if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) {
+ if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free))
return -1;
- }
+
int64 rv = static_cast<int64>(available.QuadPart);
- if (rv < 0)
- rv = kint64max;
- return rv;
+ return rv < 0 ? kint64max : rv;
+}
+
+bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) {
+ ThreadRestrictions::AssertIOAllowed();
+
+ DCHECK(path.IsAbsolute());
+ DCHECK(has_seek_penalty);
+
+ // TODO(dbeam): Vista, XP support.
+ if (win::GetVersion() < win::VERSION_WIN7)
+ return false;
+
+ std::vector<FilePath::StringType> components;
+ path.GetComponents(&components);
+ File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN);
+ if (!drive.IsValid())
+ return false;
+
+ STORAGE_PROPERTY_QUERY query;
+ query.QueryType = PropertyStandardQuery;
+ query.PropertyId = StorageDeviceSeekPenaltyProperty;
+
+ DEVICE_SEEK_PENALTY_DESCRIPTOR result;
+ DWORD bytes_returned;
+
+ BOOL success = DeviceIoControl(drive.GetPlatformFile(),
+ IOCTL_STORAGE_QUERY_PROPERTY,
+ &query, sizeof(query),
+ &result, sizeof(result),
+ &bytes_returned,
+ NULL);
+ if (success == FALSE || bytes_returned < sizeof(result))
+ return false;
+
+ *has_seek_penalty = result.IncursSeekPenalty != FALSE;
+ return true;
}
// static

Powered by Google App Engine
This is Rietveld 408576698