Skip to content

Commit

Permalink
Merge pull request #16 from adetokunbo/bugfix-valid-test-data-generation
Browse files Browse the repository at this point in the history
Ensure generated siName does not contain newlines
  • Loading branch information
adetokunbo authored Jan 17, 2025
2 parents 5b078f6 + 6632563 commit 00032a0
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/System/MemInfo/Proc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ data StatusInfo = StatusInfo
instance Validity StatusInfo where
validate StatusInfo {siName, siParent} =
let name' = Text.strip siName
nameOk = Text.length name' > 0 && siName == name'
noNewlines = not $ Text.any (== '\n') siName
nameOk = noNewlines && Text.length name' > 0 && siName == name'
in mconcat
[ check nameOk "the process name"
, delve "the process ID" $ toInteger siParent
Expand Down Expand Up @@ -121,7 +122,7 @@ instance Validity ExeInfo where

-- | Combine @'ProcUsage'@, grouping them by the effective program name
amass ::
Ord a =>
(Ord a) =>
Bool ->
[(a, ProcUsage)] ->
Map a MemUsage
Expand Down Expand Up @@ -158,7 +159,7 @@ data MemUsage = MemUsage


incrSubTotals ::
Ord a =>
(Ord a) =>
Bool ->
Map a SubTotal ->
(a, ProcUsage) ->
Expand Down Expand Up @@ -335,19 +336,19 @@ incrSharedHuge ms = maybe ms $ \n -> ms {ssSharedHuge = n + ssSharedHuge ms}
incrSmapStats :: SmapStats -> Text -> SmapStats
incrSmapStats acc l =
if
| Text.isPrefixOf "Private_Hugetlb:" l -> incrPrivateHuge acc $ smapValMb l
| Text.isPrefixOf "Shared_Hugetlb:" l -> incrSharedHuge acc $ smapValMb l
| Text.isPrefixOf "Shared" l -> incrShared acc $ smapValMb l
| Text.isPrefixOf "Private" l -> incrPrivate acc $ smapValMb l
| Text.isPrefixOf "Pss:" l ->
let acc' = acc {ssHasPss = True, ssPssCount = 1 + ssPssCount acc}
in incrPss acc' $ smapValMb l
| Text.isPrefixOf "Swap:" l -> incrSwap acc $ smapValMb l
| Text.isPrefixOf "SwapPss:" l -> incrSwapPss (acc {ssHasSwapPss = True}) $ smapValMb l
| otherwise -> acc


smapValMb :: Read a => Text -> Maybe a
| Text.isPrefixOf "Private_Hugetlb:" l -> incrPrivateHuge acc $ smapValMb l
| Text.isPrefixOf "Shared_Hugetlb:" l -> incrSharedHuge acc $ smapValMb l
| Text.isPrefixOf "Shared" l -> incrShared acc $ smapValMb l
| Text.isPrefixOf "Private" l -> incrPrivate acc $ smapValMb l
| Text.isPrefixOf "Pss:" l ->
let acc' = acc {ssHasPss = True, ssPssCount = 1 + ssPssCount acc}
in incrPss acc' $ smapValMb l
| Text.isPrefixOf "Swap:" l -> incrSwap acc $ smapValMb l
| Text.isPrefixOf "SwapPss:" l -> incrSwapPss (acc {ssHasSwapPss = True}) $ smapValMb l
| otherwise -> acc


smapValMb :: (Read a) => Text -> Maybe a
smapValMb l =
let memWords = Text.words l
readVal (_ : x : _) = readMaybe $ Text.unpack x
Expand Down

0 comments on commit 00032a0

Please sign in to comment.