Fix time conversion in SystemNative_GetCpuUtilization (dotnet/corefx#35017)
authorFilip Navara <filip.navara@gmail.com>
Fri, 1 Feb 2019 12:52:54 +0000 (13:52 +0100)
committerStephen Toub <stoub@microsoft.com>
Fri, 1 Feb 2019 12:52:54 +0000 (07:52 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/0d41c895ff6e3094e1e8105a9bb6b4cf3d985bd7

src/libraries/Native/Unix/System.Native/pal_time.c

index 33f168f..ce802e1 100644 (file)
@@ -19,8 +19,9 @@
 
 enum
 {
-    SecondsToMicroSeconds = 1000000,  // 10^6
-    SecondsToNanoSeconds = 1000000000 // 10^9
+    SecondsToMicroSeconds = 1000000,   // 10^6
+    SecondsToNanoSeconds = 1000000000, // 10^9
+    MicroSecondsToNanoSeconds = 1000   // 10^3
 };
 
 int32_t SystemNative_UTimensat(const char* path, TimeSpec* times)
@@ -184,8 +185,12 @@ int32_t SystemNative_GetCpuUtilization(ProcessCpuInformation* previousCpuInfo)
     }
     else
     {
-        kernelTime = ((uint64_t)(resUsage.ru_stime.tv_sec) * SecondsToNanoSeconds) + (uint64_t)(resUsage.ru_stime.tv_usec);
-        userTime = ((uint64_t)(resUsage.ru_utime.tv_sec) * SecondsToNanoSeconds) + (uint64_t)(resUsage.ru_utime.tv_usec);
+        kernelTime =
+            ((uint64_t)(resUsage.ru_stime.tv_sec) * SecondsToNanoSeconds) + 
+            ((uint64_t)(resUsage.ru_stime.tv_usec) * MicroSecondsToNanoSeconds);
+        userTime =
+            ((uint64_t)(resUsage.ru_utime.tv_sec) * SecondsToNanoSeconds) +
+            ((uint64_t)(resUsage.ru_utime.tv_usec) * MicroSecondsToNanoSeconds);
     }
 
     uint64_t timestamp;