-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Print the core memory usage of programs -- -- A utility to accurately report the core memory usage of programs. -- -- This is a clone of -- [ps_mem](https:/github.compixelbps_memblobmasterREADME.md), -- which is written in python -- -- The package provides: -- -- -- -- See the README for further details @package mem-info @version 0.1.0.0 -- | This module defines the command line flags used to control the -- behavior of the printmem command module System.MemInfo.Choices -- | Represents the user-specified choices extracted from the command line data Choices Choices :: !Bool -> !Bool -> !Bool -> !Bool -> !Maybe Natural -> !Maybe (NonEmpty ProcessID) -> Choices [choiceSplitArgs] :: Choices -> !Bool [choiceOnlyTotal] :: Choices -> !Bool [choiceByPid] :: Choices -> !Bool [choiceShowSwap] :: Choices -> !Bool [choiceWatchSecs] :: Choices -> !Maybe Natural [choicePidsToShow] :: Choices -> !Maybe (NonEmpty ProcessID) -- | Specifies a command line that when parsed will provide Choices cmdInfo :: ParserInfo Choices -- | Parses the command line arguments. getChoices :: IO Choices instance GHC.Show.Show System.MemInfo.Choices.Choices instance GHC.Classes.Eq System.MemInfo.Choices.Choices -- | This module provides data types that -- -- -- -- along with functions that use these types. module System.MemInfo.SysInfo -- | Gathers the inputs needed to generate a memory usage report data ReportBud ReportBud :: !NonEmpty ProcessID -> !KernelVersion -> !Bool -> !Bool -> !Bool -> Maybe RamFlaw -> Maybe SwapFlaw -> ReportBud [rbPids] :: ReportBud -> !NonEmpty ProcessID [rbKernel] :: ReportBud -> !KernelVersion [rbHasPss] :: ReportBud -> !Bool [rbHasSwapPss] :: ReportBud -> !Bool [rbHasSmaps] :: ReportBud -> !Bool [rbRamFlaws] :: ReportBud -> Maybe RamFlaw [rbSwapFlaws] :: ReportBud -> Maybe SwapFlaw -- | Construct a ReportBud from some ProcessIDs -- -- Generates values for the other fields by inspecting the system -- -- The result is Nothing only when the KernelVersion -- cannot be determined mkReportBud :: NonEmpty ProcessID -> IO (Maybe ReportBud) -- | Describes inaccuracies in the RAM calculation data RamFlaw -- | no shared mem is reported NoSharedMem :: RamFlaw -- | some shared mem not reported SomeSharedMem :: RamFlaw -- | accurate only considering each process in isolation ExactForIsolatedMem :: RamFlaw -- | Describes inaccuracies in the swap measurement data SwapFlaw -- | not available NoSwap :: SwapFlaw -- | accurate only considering each process in isolation ExactForIsolatedSwap :: SwapFlaw -- | Examine the target system for RamFlaws and -- SwapFlaws, and update bud reflect the -- findings. checkForFlaws :: ReportBud -> IO ReportBud -- | Provide Text that explains the RamFlaw fmtRamFlaws :: RamFlaw -> Text -- | Provide Text that explains the SwapFlaw fmtSwapFlaws :: SwapFlaw -> Text -- | Represents a version of Linux kernel type KernelVersion = (Natural, Natural, Natural) -- | Parses Text into a KernelVersion parseKernelVersion :: Text -> Maybe KernelVersion -- | Determines the version of the Linux kernel on the current system. readKernelVersion :: IO (Maybe KernelVersion) -- | On linux kernels before smaps became available, there was no reliable -- way to determine how much of a processes memory was shared -- -- http://lkml.org/lkml/2005/7/6/250 fickleSharing :: KernelVersion -> Bool instance GHC.Classes.Ord System.MemInfo.SysInfo.RamFlaw instance GHC.Show.Show System.MemInfo.SysInfo.RamFlaw instance GHC.Classes.Eq System.MemInfo.SysInfo.RamFlaw instance GHC.Classes.Ord System.MemInfo.SysInfo.SwapFlaw instance GHC.Show.Show System.MemInfo.SysInfo.SwapFlaw instance GHC.Classes.Eq System.MemInfo.SysInfo.SwapFlaw instance GHC.Show.Show System.MemInfo.SysInfo.ReportBud instance GHC.Classes.Eq System.MemInfo.SysInfo.ReportBud -- | This module provides types that model data from files in the Linux -- proc filesystem that track memory usage, combinators for parsing -- the files contents, and for grouping the results. module System.MemInfo.Proc -- | Represents the measured memory usage of a program data MemUsage MemUsage :: !Int -> !Int -> !Int -> !Int -> MemUsage -- | the total shared memory in use [muShared] :: MemUsage -> !Int -- | the total private memory in use [muPrivate] :: MemUsage -> !Int -- | the number of processes running as the program [muCount] :: MemUsage -> !Int -- | the total swap memory in use [muSwap] :: MemUsage -> !Int -- | Combine ProcUsage, grouping them by the effective -- program name amass :: Ord a => Bool -> [(a, ProcUsage)] -> Map a MemUsage -- | Represents the memory metrics for a single process data ProcUsage ProcUsage :: !Int -> !Int -> !Int -> !Int -> !Int -> ProcUsage [puPrivate] :: ProcUsage -> !Int [puShared] :: ProcUsage -> !Int [puSharedHuge] :: ProcUsage -> !Int [puSwap] :: ProcUsage -> !Int [puMemId] :: ProcUsage -> !Int -- | Parse ProcUsage from the contents of -- /proc/<pid>/smap parseFromSmap :: Text -> ProcUsage -- | Parse ProcUsage from the contents of -- /proc/<pid>/statm parseFromStatm :: KernelVersion -> Text -> Maybe ProcUsage -- | Represents the information about a process obtained from -- /proc/<pid>/exe data ExeInfo ExeInfo :: !Text -> !Text -> !Bool -> ExeInfo -- | the path that the link /proc/<pid>/exe resolves to [eiTarget] :: ExeInfo -> !Text -- | a sanitized form of eiTarget; it removes the (deleted) suffix [eiOriginal] :: ExeInfo -> !Text -- | does eiTarget end with (deleted)? [eiDeleted] :: ExeInfo -> !Bool -- | Parses the target of /proc/<pid>/exe into a -- ExeInfo parseExeInfo :: Text -> ExeInfo -- | Parses the content of /proc/<pid>/status into a -- StatusInfo parseStatusInfo :: Text -> Either BadStatus StatusInfo -- | Represents the information about a process obtained from -- procpid/status data StatusInfo StatusInfo :: !Text -> !ProcessID -> StatusInfo [siName] :: StatusInfo -> !Text [siParent] :: StatusInfo -> !ProcessID -- | Indicates why parseStatusInfo failed data BadStatus NoCmd :: BadStatus NoParent :: BadStatus instance GHC.Generics.Generic System.MemInfo.Proc.StatusInfo instance GHC.Show.Show System.MemInfo.Proc.StatusInfo instance GHC.Classes.Eq System.MemInfo.Proc.StatusInfo instance GHC.Show.Show System.MemInfo.Proc.BadStatus instance GHC.Classes.Eq System.MemInfo.Proc.BadStatus instance GHC.Generics.Generic System.MemInfo.Proc.ExeInfo instance GHC.Show.Show System.MemInfo.Proc.ExeInfo instance GHC.Classes.Eq System.MemInfo.Proc.ExeInfo instance GHC.Show.Show System.MemInfo.Proc.MemUsage instance GHC.Classes.Eq System.MemInfo.Proc.MemUsage instance GHC.Show.Show System.MemInfo.Proc.SubTotal instance GHC.Classes.Eq System.MemInfo.Proc.SubTotal instance GHC.Show.Show System.MemInfo.Proc.ProcUsage instance GHC.Classes.Eq System.MemInfo.Proc.ProcUsage instance GHC.Show.Show System.MemInfo.Proc.SmapStats instance GHC.Classes.Eq System.MemInfo.Proc.SmapStats instance Data.Validity.Validity System.MemInfo.Proc.ExeInfo instance Data.Validity.Validity System.MemInfo.Proc.StatusInfo -- | This module provides functions that format the output of the -- printmem command module System.MemInfo.Print -- | Identifies a type as a label to use to index programs in the report -- output -- -- The label is also used to group related processes under a single -- program class AsCmdName a asCmdName :: AsCmdName a => a -> Text -- | Generates the text of the printed header of the memory report fmtAsHeader :: Bool -> Text -- | Generates the text showing the overall memory in the memory report fmtOverall :: Bool -> (Int, Int) -> Text -- | Generates the text of a row displaying the metrics for a single -- command in the memory report fmtMemUsage :: AsCmdName a => Bool -> a -> MemUsage -> Text instance GHC.Enum.Bounded System.MemInfo.Print.Power instance GHC.Enum.Enum System.MemInfo.Print.Power instance GHC.Classes.Ord System.MemInfo.Print.Power instance GHC.Show.Show System.MemInfo.Print.Power instance GHC.Classes.Eq System.MemInfo.Print.Power instance System.MemInfo.Print.AsCmdName Data.Text.Internal.Text instance System.MemInfo.Print.AsCmdName (System.Posix.Types.ProcessID, Data.Text.Internal.Text) -- | Implements printmem, a command that computes the memory usage -- of some processes module System.MemInfo -- | Parses the command line arguments. getChoices :: IO Choices -- | Print a report to stdout displaying the memory usage of the -- programs specified by Choices printProcs :: Choices -> IO () -- | Load the MemUsage of a program specified by its -- ProcessID readForOnePid :: ProcessID -> IO (Either NotRun (ProcName, MemUsage)) -- | Loads the MemUsage specified by a -- ReportBud -- -- Fails if -- -- readMemUsage' :: Ord a => ProcNamer -> Indexer a -> ReportBud -> IO (Either LostPid (Map a MemUsage)) -- | Like readMemUsage' but uses the default -- ProcNamer and Indexer readMemUsage :: ReportBud -> IO (Either LostPid (Map ProcName MemUsage)) -- | Represents errors that prevent a report from being generated data NotRun PidLost :: LostPid -> NotRun MissingPids :: NonEmpty ProcessID -> NotRun NeedsRoot :: NotRun OddKernel :: NotRun NoRecords :: NotRun -- | Represents reasons a specified pid may not have memory -- records. data LostPid NoExeFile :: ProcessID -> LostPid NoStatusCmd :: ProcessID -> LostPid NoStatusParent :: ProcessID -> LostPid NoCmdLine :: ProcessID -> LostPid BadStatm :: ProcessID -> LostPid NoProc :: ProcessID -> LostPid -- | Unfold MemUsages specified by a -- ReportBud -- -- The ProcessID of stopped processes are reported, both as part -- of intermediate invocations (via the [ProcessID] in the -- Right), and in the final one (as the value of the -- Left). unfoldMemUsage :: Ord a => ProcNamer -> Indexer a -> ReportBud -> IO (Either [ProcessID] ((Map a MemUsage, [ProcessID]), ReportBud)) -- | Like unfoldMemUsage but computes the -- MemUsages after a delay unfoldMemUsageAfter' :: (Ord a, Integral seconds) => ProcNamer -> Indexer a -> seconds -> ReportBud -> IO (Either [ProcessID] ((Map a MemUsage, [ProcessID]), ReportBud)) -- | Like unfoldMemUsageAfter', but uses the default -- ProcName and Indexer unfoldMemUsageAfter :: Integral seconds => seconds -> ReportBud -> IO (Either [ProcessID] ((Map Text MemUsage, [ProcessID]), ReportBud)) -- | Functions that obtain a process name given its pid type ProcNamer = ProcessID -> IO (Either LostPid ProcName) -- | Obtain the ProcName by examining the path linked by -- {proc_root}/pid/exe nameFromExeOnly :: ProcNamer -- | Obtain the ProcName by examining the path linked by -- {proc_root}/pid/exe or its parent's name if that is a better -- match nameFor :: ProcNamer -- | Obtain the ProcName as the full cmd path nameAsFullCmd :: ProcNamer -- | The name of a process or program in the memory report. type ProcName = Text -- | Functions that generate the report index type Indexer index = (ProcessID, ProcName, ProcUsage) -> (index, ProcUsage) -- | Index a ProcUsage using just the program name -- -- ProcUsage's with the same ProcName will be merged -- when added to a MemUsage dropId :: Indexer ProcName -- | Index a ProcUsage using the program name and process -- ID. -- -- Each ProcUsage remains distinct when added to a -- MemUsage withPid :: Indexer (ProcessID, ProcName) -- | Print the program name and memory usage, optionally hiding the swap -- size printUsage' :: AsCmdName a => (a, MemUsage) -> Bool -> IO () -- | Like printUsage', but alway shows the swap size printUsage :: AsCmdName a => (a, MemUsage) -> IO () -- | Construct a ReportBud from some ProcessIDs -- -- Generates values for the other fields by inspecting the system -- -- The result is Nothing only when the KernelVersion -- cannot be determined mkReportBud :: NonEmpty ProcessID -> IO (Maybe ReportBud) type ProcessID = CPid -- | Identifies a type as a label to use to index programs in the report -- output -- -- The label is also used to group related processes under a single -- program class AsCmdName a asCmdName :: AsCmdName a => a -> Text instance GHC.Show.Show System.MemInfo.LostPid instance GHC.Classes.Eq System.MemInfo.LostPid instance GHC.Show.Show System.MemInfo.NotRun instance GHC.Classes.Eq System.MemInfo.NotRun