<p>I hope not everyone is using Rational Purify.</p>

<p>So what do you do when you want to measure:</p>

<ul>
<li>time taken by a function</li>
<li>peak memory usage </li>
<li>code coverage</li>
</ul>

<p>At the moment, we do it manually [using log statements with timestamps and another script to parse the log and output to excel. phew...)</p>

<p>What would you recommend? Pointing to tools or any techniques would be appreciated!</p>

<p>EDIT: Sorry, I didn't specify the environment first, <em>Its plain C on a proprietary mobile</em> platform</p>

[{'answer_id': 56675, 'author': 'Steve Duitsman', 'author_id': 4575, 'author_profile': 'https://Stackoverflow.com/users/4575', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://nprof.sourceforge.net/Site/Description.html" rel="nofollow noreferrer">nProf</a> - Free, does that for .NET.  </p>\n\n<p>Gets the job done, at least enough to see the 80/20. (20% of the code, taking 80% of the time)</p>\n'}, {'answer_id': 56679, 'author': 'Luther Baker', 'author_id': 4910, 'author_profile': 'https://Stackoverflow.com/users/4910', 'pm_score': 0, 'selected': False, 'text': '<p>Windows (.NET and Native Exes): <a href="http://www.automatedqa.com/products/aqtime/" rel="nofollow noreferrer">AQTime</a> is a great tool for the money. Standalone or as a Visual Studio plugin.</p>\n\n<p>Java: I\'m a fan of <a href="http://www.ej-technologies.com/products/jprofiler/overview.html" rel="nofollow noreferrer">JProfiler</a>. Again, can run standalone or as an Eclipse (or various other IDEs) plugin.</p>\n\n<p>I believe both have trial versions.</p>\n'}, {'answer_id': 56713, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 2, 'selected': False, 'text': '<p>For complex applications I am a great fan of Intel\'s <a href="http://www.intel.com/cd/software/products/asmo-na/eng/239144.htm" rel="nofollow noreferrer">Vtune</a>.  It is a slightly different mindset to a traditional profiler that instruments the code. It works by sampling the processor to see where instruction pointer is 1,000 times a second.  It has the huge advantage of not requiring any changes to your binaries, which as often as not would change the timing of what you are trying to measure.</p>\n\n<p>Unfortunately it is no good for .net or java since there isn\'t a way for the Vtune to map instruction pointer to symbol like there is with traditional code. </p>\n\n<p>It also allows you to measure all sorts of other processor/hardware centric metrics, like clocks per instruction, cache hits/misses, TLB hits/misses, etc which let you identify why certain sections of code may be taking longer to run than you would expect just by inspecting the code. </p>\n'}, {'answer_id': 56755, 'author': 'Andy Brice', 'author_id': 455552, 'author_profile': 'https://Stackoverflow.com/users/455552', 'pm_score': 3, 'selected': True, 'text': '<p>You probably want different tools for performance profiling and code coverage.</p>\n\n<p>For profiling I prefer Shark on MacOSX. It is free from Apple and very good. If your app is vanilla C you should be able to use it, if you can get hold of a Mac.</p>\n\n<p>For profiling on Windows you can use LTProf. Cheap, but not great:\n<a href="http://successfulsoftware.net/2007/12/18/optimising-your-application/" rel="nofollow noreferrer">http://successfulsoftware.net/2007/12/18/optimising-your-application/</a></p>\n\n<p>(I think Microsoft are really shooting themself in the foot by not providing a decent profiler with the cheaper versions of Visual Studio.)</p>\n\n<p>For coverage I prefer Coverage Validator on Windows:\n<a href="http://successfulsoftware.net/2008/03/10/coverage-validator/" rel="nofollow noreferrer">http://successfulsoftware.net/2008/03/10/coverage-validator/</a>\nIt updates the coverage in real time.</p>\n'}, {'answer_id': 56876, 'author': 'Will Dean', 'author_id': 987, 'author_profile': 'https://Stackoverflow.com/users/987', 'pm_score': 2, 'selected': False, 'text': "<p>If you're doing an 'on the metal' embedded 'C' system (I'm not quite sure what 'mobile' implied in your posting), then you usually have some kind of timer ISR, in which it's fairly easy to sample the code address at which the interrupt occurred (by digging back in the stack or looking at link registers or whatever).  Then it's trivial to build a histogram of addresses at some combination of granularity/range-of-interest.</p>\n\n<p>It's usually then not too hard to concoct some combination of code/script/Excel sheets which merges your histogram counts with addresses from your linker symbol/list file to give you profile information.</p>\n\n<p>If you're very RAM limited, it can be a bit of a pain to collect enough data for this to be both simple and useful, but you would need to tell us a more about your platform.</p>\n"}, {'answer_id': 58342, 'author': 'Chris Mayer', 'author_id': 4121, 'author_profile': 'https://Stackoverflow.com/users/4121', 'pm_score': 0, 'selected': False, 'text': '<p>The <a href="http://code.google.com/p/google-perftools/" rel="nofollow noreferrer">Google Perftools</a> are extremely useful in this regard.</p>\n'}, {'answer_id': 58382, 'author': 'Ana Betts', 'author_id': 5728, 'author_profile': 'https://Stackoverflow.com/users/5728', 'pm_score': -1, 'selected': False, 'text': "<p>How are any tools going to work if your platform is a proprietary OS? I think you're doing the best you can right now</p>\n"}, {'answer_id': 75893, 'author': 'EvilTeach', 'author_id': 7734, 'author_profile': 'https://Stackoverflow.com/users/7734', 'pm_score': 0, 'selected': False, 'text': '<p>I use <a href="http://en.wikipedia.org/wiki/DevPartner" rel="nofollow noreferrer">devpartner</a> with MSVC 6 and XP</p>\n'}, {'answer_id': 263789, 'author': 'Mike Dunlavey', 'author_id': 23771, 'author_profile': 'https://Stackoverflow.com/users/23771', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve done this a lot. If you have an IDE, or an ICE, <a href="https://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024">there is a technique</a> that takes some manual effort, but works without fail.</p>\n\n<p>Warning: modern programmers hate this, and I\'m going to get downvoted. They love their tools. But it really works, and you don\'t always have the nice tools.</p>\n\n<p>I assume in your case the code is something like DSP or video that runs on a timer and has to be fast. Suppose what you run on each timer tick is subroutine A. Write some test code to run subroutine A in a simple loop, say 1000 times, or long enough to make you wait at least several seconds.</p>\n\n<p>While it\'s running, randomly halt it with a pause key and sample the call stack (not just the program counter) and record it. (That\'s the manual part.) Do this some number of times, like 10. Once is not enough.</p>\n\n<p>Now look for commonalities between the stack samples. Look for any instruction or call instruction that appears on at least 2 samples. There will be many of these, but some of them will be in code that you could optimize.</p>\n\n<p>Do so, and you will get a nice speedup, guaranteed. The 1000 iterations will take less time.</p>\n\n<p>The reason you don\'t need a lot of samples is you\'re not looking for small things. Like if you see a particular call instruction on 5 out of 10 samples, it is responsible for roughly 50% of the total execution time. More samples would tell you more precisely what the percentage is, if you really want to know. If you\'re like me, all you want to know is where it is, so you can fix it, and move on to the next one.</p>\n\n<p>Do this until you can\'t find anything more to optimize, and you will be at or near your top speed.</p>\n'}]
['https://Stackoverflow.com/questions/56672', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/123/']