Bug 1128472 - Part 3. Vendor string on windows. r=aklotz
authorMilan Sreckovic <msreckovic@mozilla.com>
Thu, 03 Sep 2015 13:10:00 +0200
changeset 294111 6d67e5c0e73b8f8e5c55d357e2b3012a417f62fc
parent 294110 912d328e8ac0e94dc97584900856bf19446bd94e
child 294112 057ec1b930fd0090a0075a98e175478ca42bd1ce
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1128472
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1128472 - Part 3. Vendor string on windows. r=aklotz
toolkit/components/telemetry/docs/environment.rst
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
xpcom/base/nsSystemInfo.cpp
--- a/toolkit/components/telemetry/docs/environment.rst
+++ b/toolkit/components/telemetry/docs/environment.rst
@@ -75,17 +75,17 @@ Structure::
       },
       system: {
         memoryMB: <number>,
         virtualMaxMB: <number>, // windows-only
         isWow64: <bool>, // windows-only
         cpu: {
             count: <number>,  // desktop only, e.g. 8, or null on failure - logical cpus
             cores: <number>, // desktop only, e.g., 4, or null on failure - physical cores
-            vendor: <string>, // e.g. "GenuineIntel", or null on failure, only on mac & linux
+            vendor: <string>, // desktop only, e.g. "GenuineIntel", or null on failure
             family: <string>, // desktop only, null on failure
             model: <string>, // desktop only, null on failure
             stepping: <string>, // desktop only, null on failure
             l2cacheKB: <number>, // L2 cache size in KB, only on windows & mac
             l3cacheKB: <number>, // desktop only, L3 cache size in KB
             speedMHz: <number>, // desktop only, cpu clock speed in MHz
             extensions: [
               <string>,
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -363,20 +363,17 @@ function checkSystemSection(data) {
   for (let f of EXPECTED_FIELDS) {
     Assert.ok(f in data.system, f + " must be available.");
   }
 
   Assert.ok(Number.isFinite(data.system.memoryMB), "MemoryMB must be a number.");
 
   if (gIsWindows || gIsMac || gIsLinux) {
     let EXTRA_CPU_FIELDS = ["cores", "model", "family", "stepping",
-			    "l2cacheKB", "l3cacheKB", "speedMHz"];
-    if (gIsMac || gIsLinux) {
-      EXTRA_CPU_FIELDS.push("vendor");
-    }
+			    "l2cacheKB", "l3cacheKB", "speedMHz", "vendor"];
 
     for (let f of EXTRA_CPU_FIELDS) {
       // Note this is testing TelemetryEnvironment.js only, not that the
       // values are valid - null is the fallback.
       Assert.ok(f in data.system.cpu, f + " must be available under cpu.");
     }
 
     if (gIsWindows) {
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -391,23 +391,38 @@ nsSystemInfo::Init()
 
   // CPU speed
   HKEY key;
   static const WCHAR keyName[] =
     L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
 
   if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName , 0, KEY_QUERY_VALUE, &key)
       == ERROR_SUCCESS) {
-    DWORD data, len;
+    DWORD data, len, vtype;
     len = sizeof(data);
 
     if (RegQueryValueEx(key, L"~Mhz", 0, 0, reinterpret_cast<LPBYTE>(&data),
                         &len) == ERROR_SUCCESS) {
       cpuSpeed = static_cast<int>(data);
     }
+
+    // Limit to 64 double byte characters, should be plenty, but create
+    // a buffer one larger as the result may not be null terminated. If
+    // it is more than 64, we will not get the value.
+    wchar_t cpuVendorStr[64+1];
+    len = sizeof(cpuVendorStr)-2;
+    if (RegQueryValueExW(key, L"VendorIdentifier",
+                         0, &vtype,
+                         reinterpret_cast<LPBYTE>(cpuVendorStr),
+                         &len) == ERROR_SUCCESS &&
+        vtype == REG_SZ && len % 2 == 0 && len > 1) {
+      cpuVendorStr[len/2] = 0; // In case it isn't null terminated
+      CopyUTF16toUTF8(nsDependentString(cpuVendorStr), cpuVendor);
+    }
+
     RegCloseKey(key);
   }
 
   // Other CPU attributes:
   SYSTEM_INFO si;
   GetNativeSystemInfo(&si);
   logicalCPUs = si.dwNumberOfProcessors;
   GetProcessorInformation(&physicalCPUs, &cacheSizeL2, &cacheSizeL3);