bash - How to get memory usage high water mark on OSX -


i'd able test guesses memory complexity of various command line utilities.

taking simple example

grep pattern file 

i'd see how memory usage varies size of pattern , size of file.

for time complexity, i'd make guess, run

time grep pattern file 

on various sized inputs see if guess seems borne out in reality, don't know how memory.

one possibility wrapper script initiates job , samples memory usage periodically, seems inelegant , unlikely give real high watermark.

i've seen time -v suggested, don't have flag available on machine (running bash on osx) , don't know find version supports it.

i've seen on linux information available through proc filesystem, again, it's not available me in context.

i'm wondering if dtrace might appropriate tool, again concerned simple sample-based figure might not true high watermark?

does know of tool or approach appropriate on osx?

edit

i removed 2 mentions of disk usage, asides , perhaps distracted main thrust of question.

your question interesting because, without application source code, need make few assumptions constitutes memory use. if use procfs, results misleading: both resident set size , total virtual address space over-estimates since include extraneous data such program text.

particularly small commands, easier track individual allocations, although there need sure include possible sources. in addition malloc() etc., process can extend heap brk() or obtain anonymous memory using mmap().

here's dtrace script traces malloc(); can extend include other allocating functions. note isn't suitable multi-threaded programs uses non-atomic variables.

bash-3.2# cat hwm.d /* find maximum outstanding allocation provided malloc() */ size_t total, high;  pid$target::malloc:entry {     self->size = arg0; }  pid$target::malloc:return /arg1/ {     total += self->size;     allocation[arg1] = self->size;     high = (total > high) ? total : high; }  pid$target::free:entry /allocation[arg0]/ {     total -= allocation[arg0];     allocation[arg0] = 0; }  end {     printf("high water mark %d bytes.\n", high); } bash-3.2# dtrace -x evaltime=exec -qs hwm.d -c 'grep maximum hwm.d' /* find maximum outstanding allocation provided malloc() */ high water mark 62485 bytes.  bash-3.2# 

a more comprehensive discussion of memory allocators contained in this article brendan gregg. provides better answer own question. in particular, includes link script called memleak.d; modify include time stamps allocations & deallocations, can sort output time. then, perhaps using accompanying script example, use perl track current outstanding total allocation , high water mark. such dtrace/perl combination would suitable tracing multi-threaded processes.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -