note this is not for the faint of heart. and do it on another box, not production !
stop mysql and start it under the view of valgrind.
do your thing for a while. for instance run a quick php that uses your routine/query.
maybe capture 20 seconds of data usage at most.
then stop mysql via same stop below.
then examine the log file in the /tmp dir ... examine data by timestamps
service mysql stop
apt-get install valgrind
valgrind --tool=massif --massif-out-file=/tmp/massif.out /etc/init.d/mysql start
#-----------
snapshot=32
#-----------
time=217073
mem_heap_B=1140
mem_heap_extra_B=324
mem_stacks_B=0
heap_tree=empty
#-----------
snapshot=33
#-----------
time=226099
mem_heap_B=1156
mem_heap_extra_B=332
mem_stacks_B=0
heap_tree=detailed
n3: 1156 (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
n5: 944 0x40AA47: ??? (in /bin/dash)
n3: 832 0x41184C: ??? (in /bin/dash)
n1: 704 0x4120F5: ??? (in /bin/dash)
n1: 704 0x4020E4: ??? (in /bin/dash)
n0: 704 0x4E4E76B: (below main) (libc-start.c:226)
n1: 96 0x411EC0: ??? (in /bin/dash)
n1: 96 0x4048E3: ??? (in /bin/dash)
n1: 96 0x403BD5: ??? (in /bin/dash)
n1: 96 0x40A88C: ??? (in /bin/dash)
n1: 96 0x402159: ??? (in /bin/dash)
n0: 96 0x4E4E76B: (below main) (libc-start.c:226)
n1: 32 0x41212F: ??? (in /bin/dash)
n1: 32 0x4020E4: ??? (in /bin/dash)
n0: 32 0x4E4E76B: (below main) (libc-start.c:226)