Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What command shows the memory usage of a program, i am looking for a command that is simple to use and has similar syntax to the time command. I am trying to find the memory usage of a md5 hashing program that is written in C and takes 7 seconds to hash "hello world" .

I am using the android operating system with busybox installed.

share|improve this question

2 Answers 2

Ironically, time might have answer for you but this should be not shell-built-in time but standalone one:

$ /usr/bin/time -v uname
Linux
        Command being timed: "uname"
        User time (seconds): 0.00
        System time (seconds): 0.00
        Percent of CPU this job got: 2%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.12
        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): 896
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 1
        Minor (reclaiming a frame) page faults: 304
        Voluntary context switches: 3
        Involuntary context switches: 3
        Swaps: 0
        File system inputs: 56
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

It counts MAX RSS though, not VSS, so would it be useful for you or not depends on your very task heavily.

share|improve this answer
    
+1, good to know this. But beware, this is a GNU-specific feature. Does Android include GNU time(1)? –  Warren Young Sep 13 '13 at 6:07
    
Shell builtin? Neither the bash nor zsh manpages here mention this. Are you confusing it with times? –  Warren Young Sep 13 '13 at 6:07
    
@WarrenYoung, for SH in zsh bash dash; do $SH -c 'echo $0; type time'; done — zsh time is a reserved word — bash time is a shell keyword — dash time is /usr/bin/time –  poige Sep 14 '13 at 3:28
    
@WarrenYoung, and nope, Android doesn't have it by default, but since /usr/bin/time is built heavily on top of system calls wait3 or wait4 (I don't remember exactly), it can be easily put into action there as well. –  poige Sep 14 '13 at 3:53

You can use valgrind for this:

$ valgrind myprogram arg1 arg2

Its output will have a lot of irrelevant stuff, but its heap summary does what you want:

==91383== HEAP SUMMARY:
==91383==     in use at exit: 157,643 bytes in 364 blocks
==91383==   total heap usage: 2,999 allocs, 2,635 frees, 306,450 bytes allocated
share|improve this answer
    
I do not have valgrind but it looks like there is a port for android, i will try and install it. –  kyle k Sep 12 '13 at 19:25
1  
@kylek: If you're doing any native CPU software development on Android, you want to have it anyway. –  Warren Young Sep 12 '13 at 19:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.