@@ -74,6 +74,8 @@ instance Storable MachTaskBasicInfo where
7474
7575foreign import ccall unsafe c_get_process_memory_info2 :: Ptr MachTaskBasicInfo -> CInt -> IO CInt
7676
77+ foreign import ccall unsafe c_get_process_cpu_time_microseconds :: CInt -> IO Word64
78+
7779
7880getMemoryInfo :: ProcessID -> IO MachTaskBasicInfo
7981getMemoryInfo pid =
@@ -84,13 +86,12 @@ getMemoryInfo pid =
8486
8587readResourceStatsInternal :: IO (Maybe ResourceStats )
8688readResourceStatsInternal = getProcessID >>= \ pid -> do
87- cpu <- getMemoryInfo pid
8889 rts <- GhcStats. getRTSStats
8990 mem <- getMemoryInfo pid
91+ cpuTimeMicro <- c_get_process_cpu_time_microseconds (fromIntegral pid)
9092 pure . Just $
9193 Resources
92- { rCentiCpu = timeValToCenti (_user_time cpu)
93- + timeValToCenti (_system_time cpu)
94+ { rCentiCpu = usToCenti cpuTimeMicro
9495 , rCentiGC = nsToCenti $ GhcStats. gc_cpu_ns rts
9596 , rCentiMut = nsToCenti $ GhcStats. mutator_cpu_ns rts
9697 , rGcsMajor = fromIntegral $ GhcStats. major_gcs rts
@@ -109,8 +110,5 @@ readResourceStatsInternal = getProcessID >>= \pid -> do
109110 where
110111 nsToCenti :: GhcStats. RtsTime -> Word64
111112 nsToCenti = fromIntegral . (`div` 10000000 )
112- timeValToCenti :: TIME_VALUE_T -> Word64
113- timeValToCenti tv = usFromTimeValue tv `div` 10000
114-
115- usFromTimeValue :: TIME_VALUE_T -> Word64
116- usFromTimeValue (TIME_VALUE_T s us) = s * 1000000 + us
113+ usToCenti :: Word64 -> Word64
114+ usToCenti = (`div` 10000 )
0 commit comments