|
|
In most unix systems, and in my case most relevantly in linux, there's
a very useful command-line utility (or, in many cases, a shell built-in
command) called "time". This utility can be used to very accurately
measure how much system-time, user-time and overall time a program takes
during its execution. This is extremely useful for example when comparing
the speed of several versions of a program.
Now, what I would also like to have is a similar utility or built-in
command which tells be the peak memory usage of a program. I want to know,
for example, if an optimization I made in a program really saved a relevant
amount of memory or not. Sounds rather simple, doesn't it?
Well, to my amazement there doesn't seem to be any such utility in
existence for unix or linux in particular.
There are tons of ways of seeing how much a program is *currently*
taking. For example, you can use utilities like "top", "pmap", "vmstat"
and "ps" for this purpose. They all can tell how much memory a program
is taking.
However, those are no good. If a program runs just for a few seconds,
constantly allocating more and more memory, those utilities are completely
useless. Even if you get to run them during the execution of the program,
you only get a completely random result: They show you how much memory
the program is using *at that moment*. They don't show you the overall
peak memory usage of the program. The program may well allocate humongous
amounts of memory more after you took a look at it with any of those
utilities. They don't tell you anything relevant. (Those utilities are
only useful for programs which are running for a long time, and you want
to take a look on how much they are consuming memory currently.)
What I don't understand is why there can't be any such utility.
Given that utilities like "top" & co. can measure the memory usage
of a process, it would sound quite plausible that it would be rather
easy to make a utility similar to "time" which measures the peak memory
usage of a program.
But no. There doesn't seem to be any such program. I'm completely
puzzled about why this is so.
(And before anyone suggests using the gnu version of "time", don't
bother: It doesn't work. It always gives 0 as the amount of memory used,
which is documented to happen when it doesn't support measuring that.)
--
- Warp
Post a reply to this message
|
|