mem-info-0.1.0.0: Print the core memory usage of programs
Copyright(c) 2023 Tim Emiola
LicenseBSD3
MaintainerTim Emiola <adetokunbo@emio.la>
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.MemInfo

Description

Implements printmem, a command that computes the memory usage of some processes

Synopsis

Implement printmem

getChoices :: IO Choices Source #

Parses the command line arguments.

printProcs :: Choices -> IO () Source #

Print a report to stdout displaying the memory usage of the programs specified by Choices

Read MemUsage

readForOnePid :: ProcessID -> IO (Either NotRun (ProcName, MemUsage)) Source #

Load the MemUsage of a program specified by its ProcessID

readMemUsage' :: Ord a => ProcNamer -> Indexer a -> ReportBud -> IO (Either LostPid (Map a MemUsage)) Source #

Loads the MemUsage specified by a ReportBud

Fails if

  • the system does not have the expected /proc filesystem memory records
  • any of the processes specified by ReportBud are missing or inaccessible

data NotRun Source #

Represents errors that prevent a report from being generated

Instances

Instances details
Show NotRun Source # 
Instance details

Defined in System.MemInfo

Eq NotRun Source # 
Instance details

Defined in System.MemInfo

data LostPid Source #

Represents reasons a specified pid may not have memory records.

Instances

Instances details
Show LostPid Source # 
Instance details

Defined in System.MemInfo

Eq LostPid Source # 
Instance details

Defined in System.MemInfo

Stream MemUsage periodically

unfoldMemUsage :: Ord a => ProcNamer -> Indexer a -> ReportBud -> IO (Either [ProcessID] ((Map a MemUsage, [ProcessID]), ReportBud)) Source #

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).

unfoldMemUsageAfter' :: (Ord a, Integral seconds) => ProcNamer -> Indexer a -> seconds -> ReportBud -> IO (Either [ProcessID] ((Map a MemUsage, [ProcessID]), ReportBud)) Source #

Like unfoldMemUsage but computes the MemUsages after a delay

Obtain the process/program name

type ProcNamer = ProcessID -> IO (Either LostPid ProcName) Source #

Functions that obtain a process name given its pid

nameFromExeOnly :: ProcNamer Source #

Obtain the ProcName by examining the path linked by {proc_root}/pid/exe

nameFor :: ProcNamer Source #

Obtain the ProcName by examining the path linked by {proc_root}/pid/exe or its parent's name if that is a better match

nameAsFullCmd :: ProcNamer Source #

Obtain the ProcName as the full cmd path

Index by pid or name

type ProcName = Text Source #

The name of a process or program in the memory report.

type Indexer index = (ProcessID, ProcName, ProcUsage) -> (index, ProcUsage) Source #

Functions that generate the report index

dropId :: Indexer ProcName Source #

Index a ProcUsage using just the program name

ProcUsage's with the same ProcName will be merged when added to a MemUsage

withPid :: Indexer (ProcessID, ProcName) Source #

Index a ProcUsage using the program name and process ID.

Each ProcUsage remains distinct when added to a MemUsage

Print MemUsage

printUsage' :: AsCmdName a => (a, MemUsage) -> Bool -> IO () Source #

Print the program name and memory usage, optionally hiding the swap size

printUsage :: AsCmdName a => (a, MemUsage) -> IO () Source #

Like printUsage', but alway shows the swap size

Convenient re-exports

mkReportBud :: NonEmpty ProcessID -> IO (Maybe ReportBud) Source #

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

class AsCmdName a where Source #

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

Methods

asCmdName :: a -> Text Source #

Instances

Instances details
AsCmdName Text Source # 
Instance details

Defined in System.MemInfo.Print

Methods

asCmdName :: Text -> Text Source #

AsCmdName (ProcessID, Text) Source # 
Instance details

Defined in System.MemInfo.Print