I usually dump a simple script for this type of work.
Take a look at the kernel documentation for the proc file system ("linux proc.txt").
The first line of /proc/stat (section 1.8 in proc.txt) will give you aggregate statistics on processor usage (i.e. user, good, system, simple, ...). For each process, the /proc/$PID/stat file (table 1-4 in the proc.txt file) will provide you with both processor usage statistics and memory usage statistics (see Rss).
If you share a little Google, you will find a lot of detailed information about these files and pointers to libraries / applications / code snippets to help you get / get the values you need. With that in mind, I will focus on high-level strategies.
For processor statistics, use your favorite scripting language to create an executable file that accepts a set of process identifiers for monitoring. With a fixed interval (for example: 1 second), a poll / calculation of the total results for each process and the system as a whole. During each polling interval, write all the results in one line to the standard output.
For memory statistics, write a similar script, but just write down the memory usage for each process. Memory is a bit simpler as we directly get instantaneous values.
Run these scripts throughout the test, passing in a set of process IDs that you want to track and redirect your output to the log file.
./logcpu $(pidof foo) $(pidof bar) > cpustats ./logmem $(pidof foo) $(pidof bar) > memstats
Import the contents of these files into a spreadsheet (for some applications it is as simple as copying / pasting). For the CPU, you are behind instantaneous values, but have cumulative values, so you need to do a little work with spreadsheets to get these values (it's just the delta 't (x + 1) - t (x)'). Of course, you could write your cpu logger, but you will spend a little more time on the script.
Finally, use the table to create a nice plot.