Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to profile my rspec tests to find the biggest memory hogs?

We use circleci as part of our deployment process. Circleci runs our 3000 tests and sometimes fails because it hits a 4 GB memory limit. It looks like some of our tests are creating a lot of objects and using up a ton of memory. I just don't know which ones are.

Is there an easy way for me to profile the memory used for a given test? If I knew how to do this, I could easily loop through each test and run it and see how much memory it uses.

like image 562
user1180596 Avatar asked Jan 14 '15 22:01

user1180596


1 Answers

You can use the ruby-prof gem to profile memory usage. But first you might try running rspec with the --profile flag. It will give you the 10 slowest specs which is probably a good place to start looking for specs that are consuming massive amounts of memory.

like image 51
robertjlooby Avatar answered Sep 18 '22 15:09

robertjlooby