Commit 4f33015a authored by Will Harris's avatar Will Harris Committed by Commit Bot

Add Windows.PatchLevelKernel32 histogram.

Reports the PatchLevel of the current running Windows OS as
reported by a call to VerQueryValue() on kernel32.dll.

Also, add comments for missing functions in windows_version.h
and add Kernel32VersionNumber function on OSInfo for
determining Kernel32 version.

BUG=1130738

Change-Id: I70c652e6524e15382a511cfc12311d5ffffedb1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444452Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Will Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813824}
parent 9a035093
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/check_op.h" #include "base/check_op.h"
#include "base/file_version_info_win.h" #include "base/file_version_info_win.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/logging.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -199,6 +200,16 @@ Version OSInfo::Kernel32Version() const { ...@@ -199,6 +200,16 @@ Version OSInfo::Kernel32Version() const {
return kernel32_version; return kernel32_version;
} }
OSInfo::VersionNumber OSInfo::Kernel32VersionNumber() const {
DCHECK(Kernel32BaseVersion().components().size() == 4);
static const VersionNumber version = {
.major = Kernel32BaseVersion().components()[0],
.minor = Kernel32BaseVersion().components()[1],
.build = Kernel32BaseVersion().components()[2],
.patch = Kernel32BaseVersion().components()[3]};
return version;
}
// Retrieve a version from kernel32. This is useful because when running in // Retrieve a version from kernel32. This is useful because when running in
// compatibility mode for a down-level version of the OS, the file version of // compatibility mode for a down-level version of the OS, the file version of
// kernel32 will still be the "real" version. // kernel32 will still be the "real" version.
......
...@@ -120,20 +120,42 @@ class BASE_EXPORT OSInfo { ...@@ -120,20 +120,42 @@ class BASE_EXPORT OSInfo {
// process. This doesn't touch member state, so you can bypass the singleton. // process. This doesn't touch member state, so you can bypass the singleton.
static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
// Returns the OS Version as returned from a call to GetVersionEx().
const Version& version() const { return version_; } const Version& version() const { return version_; }
// Returns detailed version info containing major, minor, build and patch.
const VersionNumber& version_number() const { return version_number_; }
// The Kernel32* set of functions return the OS version as determined by a
// call to VerQueryValue() on kernel32.dll. This avoids any running App Compat
// shims from manipulating the version reported.
Version Kernel32Version() const; Version Kernel32Version() const;
VersionNumber Kernel32VersionNumber() const;
base::Version Kernel32BaseVersion() const; base::Version Kernel32BaseVersion() const;
// The next two functions return arrays of values, [major, minor(, build)].
const VersionNumber& version_number() const { return version_number_; } // Functions to determine Version Type (e.g. Enterprise/Home) and Service Pack
// value. See above for definitions of these values.
const VersionType& version_type() const { return version_type_; } const VersionType& version_type() const { return version_type_; }
const ServicePack& service_pack() const { return service_pack_; } const ServicePack& service_pack() const { return service_pack_; }
const std::string& service_pack_str() const { return service_pack_str_; } const std::string& service_pack_str() const { return service_pack_str_; }
// Returns the number of processors on the system.
const int& processors() const { return processors_; } const int& processors() const { return processors_; }
// Returns the allocation granularity. See
// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info.
const size_t& allocation_granularity() const { const size_t& allocation_granularity() const {
return allocation_granularity_; return allocation_granularity_;
} }
// Returns the WOW64 status of the running process. See above for definitions
// of the values.
const WOW64Status& wow64_status() const { return wow64_status_; } const WOW64Status& wow64_status() const { return wow64_status_; }
// Processor name as read from registry.
std::string processor_model_name(); std::string processor_model_name();
// Returns the "ReleaseId" (Windows 10 release number) from the registry.
const std::string& release_id() const { return release_id_; } const std::string& release_id() const { return release_id_; }
private: private:
......
...@@ -166,6 +166,14 @@ void RecordStartupMetrics() { ...@@ -166,6 +166,14 @@ void RecordStartupMetrics() {
DCHECK(patch_level) << "Windows version too high!"; DCHECK(patch_level) << "Windows version too high!";
base::UmaHistogramSparse("Windows.PatchLevel", patch_level); base::UmaHistogramSparse("Windows.PatchLevel", patch_level);
int kernel32_patch = os_info.Kernel32VersionNumber().patch;
int kernel32_build = os_info.Kernel32VersionNumber().build;
int kernel32_patch_level = 0;
if (kernel32_patch < 65536 && kernel32_build < 65536)
kernel32_patch_level = MAKELONG(kernel32_patch, kernel32_build);
DCHECK(kernel32_patch_level) << "Windows kernel32.dll version too high!";
base::UmaHistogramSparse("Windows.PatchLevelKernel32", kernel32_patch_level);
base::UmaHistogramBoolean("Windows.HasHighResolutionTimeTicks", base::UmaHistogramBoolean("Windows.HasHighResolutionTimeTicks",
base::TimeTicks::IsHighResolution()); base::TimeTicks::IsHighResolution());
......
...@@ -154,7 +154,7 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -154,7 +154,7 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<owner>wfh@chromium.org</owner> <owner>wfh@chromium.org</owner>
<owner>brucedawson@chromium.org</owner> <owner>brucedawson@chromium.org</owner>
<summary> <summary>
The Windows version (base::win::Version) as reported by VeryQueryValue() on The Windows version (base::win::Version) as reported by VerQueryValue() on
kernel32.dll. This is queried shortly after startup. kernel32.dll. This is queried shortly after startup.
</summary> </summary>
</histogram> </histogram>
...@@ -222,11 +222,28 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -222,11 +222,28 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<owner>brucedawson@chromium.org</owner> <owner>brucedawson@chromium.org</owner>
<summary> <summary>
A 32-bit value formed from combining the minor and patch level of the A 32-bit value formed from combining the minor and patch level of the
currently running Windows operating system. E.g. &quot;Windows 10 OS Version currently running Windows operating system as reported by GetVersionEx().
1809 (Build 17763.503)&quot; would be 17763 (0x4563), combined with 503 E.g. &quot;Windows 10 OS Version 1809 (Build 17763.503)&quot; would be 17763
(0x1F7) = 0x456301F7. If either minor or patch level exceeds the value that (0x4563), combined with 503 (0x1F7) = 0x456301F7. If either minor or patch
can fit in a 16-bit unsigned integer, then this histogram will report 0. level exceeds the value that can fit in a 16-bit unsigned integer, then this
Reported once, shortly after browser startup. histogram will report 0. Reported once, shortly after browser startup.
</summary>
</histogram>
<histogram name="Windows.PatchLevelKernel32" enum="WindowsPatchLevel"
expires_after="never">
<!-- expires-never: Needed to measure Windows ecosystem. -->
<owner>wfh@chromium.org</owner>
<owner>brucedawson@chromium.org</owner>
<summary>
A 32-bit value formed from combining the minor and patch level of the
currently running Windows operating system as reported by VerQueryValue() of
kernel32.dll. E.g. &quot;Windows 10 OS Version 1809 (Build 17763.503)&quot;
would be 17763 (0x4563), combined with 503 (0x1F7) = 0x456301F7. If either
minor or patch level exceeds the value that can fit in a 16-bit unsigned
integer, then this histogram will report 0. Reported once, shortly after
browser startup.
</summary> </summary>
</histogram> </histogram>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment