-
Notifications
You must be signed in to change notification settings - Fork 69
Output memory as KB, MB, GB. Accept memory arguments as KB, MB, GB. #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericjster
wants to merge
1
commit into
pshved:master
Choose a base branch
from
ericjster:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,10 @@ | |
|
|
||
| sub usage{ print STDERR <<usage_ends; | ||
| Usage: | ||
| timeout [-t timelimit] [-m memlimit] [-x hertz] command [arguments ...] | ||
| timeout [-t timelimit] [-m memlimit] [-s memlimit-rss] [-x hertz] command [arguments ...] | ||
|
|
||
| Memory limits may be specified as KB (default), MB, or GB. | ||
| Example: timeout -memlimit 2.5GB -memlimit-rss 7800MB | ||
|
|
||
| usage_ends | ||
| die; | ||
|
|
@@ -61,8 +64,8 @@ GetOptions( | |
| 'detect-hangups!'=>\$kill_stale, | ||
| # allow-hangups is kept for backward compatibility. | ||
| 'allow-hangups!'=>\$kill_stale, | ||
| 'memlimit|m=i'=>\$memlimit, | ||
| 'memlimit-rss|s=i'=>\$memlimit_rss, | ||
| 'memlimit|m=s'=>\$memlimit, | ||
| 'memlimit-rss|s=s'=>\$memlimit_rss, | ||
| 'frequency|x=i'=>\$frequency, | ||
| 'pattern|p=s'=>\$strpat, | ||
| 'output|o=s'=>\$output, | ||
|
|
@@ -76,6 +79,9 @@ GetOptions( | |
|
|
||
| @ARGV or usage; | ||
|
|
||
| $memlimit = parse_memory_arg($memlimit); | ||
| $memlimit_rss = parse_memory_arg($memlimit_rss); | ||
|
|
||
| my $uinfo = get_patterns($strpat); | ||
|
|
||
| my $uwait = int (1_000_000 / $frequency); | ||
|
|
@@ -446,7 +452,7 @@ sub print_uinfo | |
| my $reason = shift; | ||
| # Print generic information to STDERR | ||
| my $ticks = $timeinfo->{ticks_stale} || 0; | ||
| printf STDERR "${id_str}%s CPU %.2f MEM %d MAXMEM %d STALE %d MAXMEM_RSS %d\n", $reason, $timeinfo->{total}, $meminfo, $maxmem, ceil($ticks/$frequency), $maxmem_rss if ($reason ne 'FINISHED') || $info_on_success; | ||
| printf STDERR "${id_str}%s CPU %.2f MEM %d KB %d MB %d GB MAXMEM %d KB %d MB %d GB STALE %d MAXMEM_RSS %d KB %d MB %d GB\n", $reason, $timeinfo->{total}, $meminfo, $meminfo/1024, $meminfo/1024/1024, $maxmem, $maxmem/1024, $maxmem/1024/1024, ceil($ticks/$frequency), $maxmem_rss, $maxmem_rss/1024, $maxmem_rss/1024/1024 if ($reason ne 'FINISHED') || $info_on_success; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not change the output format
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other ppl's software might depend on it, and also I find it a bit superfluous. |
||
|
|
||
| if (defined $output){ | ||
| open(FIL,">>", $output) or die "Can't open output file: $!\n"; | ||
|
|
@@ -516,3 +522,25 @@ sub child_status_to_exit_code | |
| return $child_retv >> 8; | ||
| } | ||
| } | ||
|
|
||
| # Allow memory arguments to specified as bytes, KB, MB, or GB. | ||
| sub parse_memory_arg | ||
| { | ||
| my ($mem) = @_; | ||
| if (defined($mem)) { | ||
| if ($mem =~ /^\d+$/) { | ||
| $mem = int($mem); | ||
| } elsif ($mem =~ /(^\d*\.{0,1}\d*)kb$/i) { | ||
| $mem = int($1); | ||
| } elsif ($mem =~ /(^\d*\.{0,1}\d*)mb$/i) { | ||
| $mem = int($1*1024); | ||
| } elsif ($mem =~ /(^\d*\.{0,1}\d*)gb$/i) { | ||
| $mem = int($1*1024*1024); | ||
| } else { | ||
| print STDERR "Error: Unrecognized memory argument: '$mem'.\n"; | ||
| usage(); | ||
| } | ||
| printf STDERR "mem : %d KB = %.1f MB = %.1f GB\n", $mem, $mem/1024., $mem/1024./1024. if $debug; | ||
| } | ||
| return $mem; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you documented that the default is Kilobytes. These days, however, it's not clear if that means 1000 bytes or 1024 bytes; can you please clarify?