Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Getting code coverage information programmatically

Subject: Getting code coverage information programmatically

From: Richard Nicholson

Date: 13 Aug, 2007 16:00:38

Message: 1 of 2

Hi,

I wondered if it's possible to get code coverage
statistics programmatically using the profiler.

For example, if I run the code
profile on;
msgbox('Some string');
profile viewer;

Then the viewer tells me how many lines of code are in the
msgbox function (209) and how many of these my function
call has hit (91). I'd like to get this information in
code rather than through the viewer, but I only seem to be
able to get information about which lines of code have
been executed and nothing about the remaining lines.
(Using the profile('info') call and then looking in the
FunctionTable.ExecutedLines bit of the structure).

Does anybody know if what I'm trying to do is currently
possible?

Thanks,

Rich N

Subject: Getting code coverage information programmatically

From: Ned Gulley

Date: 13 Aug, 2007 20:43:03

Message: 2 of 2

"Richard Nicholson" wrote:
> I wondered if it's possible to get code coverage
> statistics programmatically using the profiler.

Hi Richard:

Getting the correct coverage statistics can be quite
complicated if you use subfunctions, nested functions, and
anonymous functions, but for simple situations, you can do
this (in R2007a).

>> profile on
>> imagesc(magic(5)) % Your code here...
>> profile off
>> runnableLineIndex = callstats('file_lines','magic')

runnableLineIndex =
 13 16 17 18 19 20 23 24 25 26 27 30 31 32 33 34 35
 36 37 38 39 40 41 42

These are the line numbers that can potentially be run for
each function ("magic" in this case). As you indicated, the
profiler info structure tells you which ones actually DID run.

This particular hook into callstats is undocumented and may
change in the future, so use at your own risk.

-Ned.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
callstats Paulo Pegado 8 May, 2008 14:57:18
profiler Ned Gulley 13 Aug, 2007 16:45:09
undocumented Ned Gulley 13 Aug, 2007 16:45:09
code coverage Richard Nicholson 13 Aug, 2007 12:05:34
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics