Forums

Utility or not of cobra compiler generating code metrics.

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Re: Utility or not of cobra compiler generating code metrics

Postby hopscc » Fri Aug 13, 2010 7:00 am

Added ticket:245 for metrics code enhancement and provided a patch
supporting the metrics calc and framework - I went with a Table format emitted as a new last phase.

This code/patch includes the code/patch for the new multival options value mentioned previously as the new metrics options uses it
Currently there are two subOptions - loc ( Lines of Code) and mcc (MccabeComplexityCalc),
both can take an optional overriding threshold value to print the methodname when exceeded
default is loc=100 and mcc=25.

examples
Code: Select all
#enable all metrics using default thresholds
-metrics

# enable mcc metrics only with default threshold
-metrics:mcc

# enable loc metrics only with default threshold
-metrics:loc

# enable (only) loc and mcc metrics calculations with default thresholds
-metrics:mcc,loc

# print loc and mcc metrics for all methods using explicit thresholds
# 2 is good for loc as it elides methods containing only a 'pass' and base call only initializers/methods
-metrics:loc=2, mcc=10

#enable loc and mcc metrics, loc with default threshold, mcc complexity>20
-metrics:loc,mcc=20

#Display metrics for methods that have more than 50 lines of code or a complexity calc >10
-metrics:loc=50,mcc=10

#display method names (and complexity count) for methods with complexity >20
-metrics:mcc=20

#display method names (and numLines) for methods  with more than 75 codelines
-metrics:loc=75


Additional metrics ( that work on the AST at least) can be relatively easily added by adding the calculation into the desired
visited node Types in MetricsGenerator and enabled by adding a new subOption to the metrics Option in CommandLine.cobra.

Metrics output lines are currently emitted in MetricsGenerator in gen(method as AbstractMethod) which works well for the existing ones which are
all metrics for methods. Any Future ones might vary or change this depending on the code metric and what it covers...

I also added a new option -p/-parse[/-syntax similar in intent to the duo
-compile(-c) and -run(-r) giving an increasing processing triumvirant - parse/compile/run
(I'm not sure that parse is the right name (translate/convert ??) but it should suffice for the moment)

Specifying -parse suppresses backend processing (Code generation and native code compilation) - it does only the front end phases - tokenising,parsing, binding, etc.
(i.e parse-only)
This saves some overhead if you want things like metrics (or even a code syntax check) without a compilation run.
Code: Select all
cobra -parse -metrics  *.cobra

cobra -parse file.cobra
cobra -syntax -files:fileList.txt


Now I shall rest.
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Utility or not of cobra compiler generating code metrics

Postby Charles » Mon Oct 18, 2010 2:12 am

I'll take a look at this some time after the release.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Previous

Return to Discussion

Who is online

Users browsing this forum: No registered users and 79 guests

cron