Process(3) User Contributed Perl Documentation Process(3)

# [NAME](#NAME)

```
 Memory::Process - Perl class to determine actual memory usage.
```

# [SYNOPSIS](#SYNOPSIS)

```
 use Memory::Process;
 my $m = Memory::Process->new(%params);
 $m->dump;
 $m->record($message, $pid);
 my @report = $m->report;
 my $report = $m->report;
 $m->reset;
 $m->state;
```

# [METHODS](#METHODS)

## ["new"](#_new_)

```
 my $m = Memory::Process->new(%params);
```

Constructor.

Returns instance of object.

## ["dump"](#_dump_)

```
 $m->dump;
```

Print report to STDERR.

Returns return value of **print()**.

## ["record"](#_record_)

```
 $m->record($message, $pid);
```

Set record. If message not set, use ''.

Returns undef.

## ["report"](#_report_)

```
 my @report = $m->report;
 my $report = $m->report;
```

Get report.

In scalar context returns string with report. In array context returns array of report lines. First line is title.

## ["reset"](#_reset_)

```
 $m->reset;
```

Reset records.

Returns undef.

## ["state"](#_state_)

```
 $m->state;
```

Get internal state.

Each state item consists from:

```
 - timestamp (in seconds since epoch)
 - message (from record())
 - virtual memory size (in kB)
 - resident set size (in kB)
 - shared memory size (in kB)
 - text size (in kB)
 - data and stack size (in kB)
```

Returns reference to array with state items.

# [EXAMPLE1](#EXAMPLE1)

```
 use strict;
 use warnings;
 use Memory::Process;
 # Object.
 my $m = Memory::Process->new;
 # Example process.
 $m->record("Before my big method");
 my $var = ('foo' x 100);
 sleep 1;
 $m->record("After my big method");
 sleep 1;
 $m->record("End");
 # Print report.
 print $m->report."\n";
 # Output like:
 #   time    vsz (  diff)    rss (  diff) shared (  diff)   code (  diff)   data (  diff)
 #      1  19120 (     0)   2464 (     0)   1824 (     0)      8 (     0)   1056 (     0) After my big method
 #      2  19120 (     0)   2464 (     0)   1824 (     0)      8 (     0)   1056 (     0) End
```

# [EXAMPLE2](#EXAMPLE2)

```
 use strict;
 use warnings;
 use Data::Printer;
 use Memory::Process;
 # Object.
 my $m = Memory::Process->new;
 # Example process.
 $m->record("Before my big method");
 my $var = ('foo' x 100);
 sleep 1;
 $m->record("After my big method");
 sleep 1;
 $m->record("End");
 # Print report.
 my $state_ar = $m->state;
 # Dump out.
 p $state_ar;
 # Output like:
 # \ [
 #     [0] [
 #         [0] 1445941214,
 #         [1] "Before my big method",
 #         [2] 33712,
 #         [3] 7956,
 #         [4] 3876,
 #         [5] 8,
 #         [6] 4564
 #     ],
 #     [1] [
 #         [0] 1445941215,
 #         [1] "After my big method",
 #         [2] 33712,
 #         [3] 7956,
 #         [4] 3876,
 #         [5] 8,
 #         [6] 4564
 #     ],
 #     [2] [
 #         [0] 1445941216,
 #         [1] "End",
 #         [2] 33712,
 #         [3] 7956,
 #         [4] 3876,
 #         [5] 8,
 #         [6] 4564
 #     ]
 # ]
```

# [DEPENDENCIES](#DEPENDENCIES)

Memory::Usage, Readonly.

# [SEE ALSO](#SEE_ALSO)

[Memory::Stats](#Memory::Stats)

Memory Usage Consumption of your process

[Memory::Usage](#Memory::Usage)

Tools to determine actual memory usage

# [REPOSITORY](#REPOSITORY)

&lt;https://github.com/michal-josef-spacek/Memory-Process&gt;

# [AUTHOR](#AUTHOR)

Michal Josef Špaček &lt;mailto:skim@cpan.org&gt;

&lt;http://skim.cz/&gt;

# [LICENSE AND COPYRIGHT](#LICENSE_AND_COPYRIGHT)

© 2014-2023 Michal Josef Špaček

BSD 2-Clause License

# [VERSION](#VERSION)

0.06

2026-10-26 perl v5.44.0

---

Document: Memory::Process(3pm) from perl-memory-process 0.06-r12 (Chainguard OS)
Source: https://github.com/michal-josef-spacek/Memory-Process
