You are not logged in.
What's the best way to reckon up the memory usage of a program?
I want to know how much memory is used by a program, and how long it toke to run.
Offline
GNU "time" should do the trick; but it would seem Arch doesn't package it.
You can use the 'getrusage' C function (or from within a scripting language like Python, if you prefer). I believe GNU time just wraps getrusage.
EDIT: actually, that looks like it only gets the resident set size...
Offline
GNU "time" should do the trick; but it would seem Arch doesn't package it.
I have time on my system. I think it's part of the shell as it seems that there is no time binary.
Offline
Yep, that's a builtin shell command. There's an actual standalone program called 'time' too. http://directory.fsf.org/GNU/time.html
Sorry, should've put that in the first post...
Offline
No problem. I'll try to do a PKGBUILD for it.
EDIT: There was already a PKGBUILD in AUR. http://aur.archlinux.org/packages.php?d … =1&ID=1010
I've posted a few comments to improve it, though.
Offline
And how to get the memory-spend info?
Offline
I've check the output more closely. I get 0 for the memory usage.
Not all resources are measured by all versions of Unix, so some of the values might be reported as zero.
I don't know if it's a problem with my system or with Linux.
Offline
Yes, I check the man page too.
But I cant really understand the whole meaning since I'm not a English speaker:(
I do it like this:
time -p "mem-usage %Kn" foo
Please correct me.
Thank you.
Offline
First, you need to use the full path or use the gnutime link as I mentioned in the AUR, otherwise you'll use the built-in shell 'time' command which only gives the execution time. In your example, you forgot the -f in front of the string:
/usr/bin/time -p -f"mem-usage %Kn" foo
There's also the %M which is the maximum real memory actually used by the program. I am not too familiar myself with these technical terms. And the fact that I only get 0 don't help.
Offline
Yes, I get 0 too. Strange.
Offline
I run the gnutime in verbose mode, and these are all I get:
Command being timed: "mozilla"
User time (seconds): 2.16
System time (seconds): 0.23
Percent of CPU this job got: 22%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:10.78
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 0
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 16873
Voluntary context switches: 833
Involuntary context switches: 1722
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Anyone can help me?
Offline
Maybe you should just try
man top
and look for memory. Go the easy route...
Offline
Or, if you need to do it from a program, cat /proc/pid/status ... surely there's a better way, though.
Offline
For some reasons, I must run a program and get run infos immediately.
Please, help me.
Offline
That means, I don't know the pid, and usually, the program runs in a very short time.
Offline
I prefer htop to find memory hungry programs.
That means, I don't know the pid, and usually, the program runs in a very short time.
pgrep procressname
will give you the process number. Or you can do
kill -TERM `pgrep proccessname`
to find and terminate in one shot.
Offline
D'oh! Just found this at the very bottom of the man page.
The above struct was taken from 4.3BSD Reno. Not all fields are meaningful under Linux. In linux 2.4 only the fields ru_utime, ru_stime, ru_minflt, and ru_majflt are maintained. Since Linux 2.6, ru_nvcsw and ru_nivcsw are also maintained.
Offline
The Program will be run many times in a short time too. That I can get its pid correctly.
Im waiting for a better solution.
Offline
Have you ever used this function - setrlimit?
http://www.opengroup.org/onlinepubs/007 … limit.html
Offline
Who can tell me the python way?
I'm using python now.
Offline