home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / metrics / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-09-18  |  9.5 KB

  1. Subject:  v20i010:  Tools for generating software metrics, Part03/14
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr>
  7. Posting-number: Volume 20, Issue 10
  8. Archive-name: metrics/part03
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # this is part 3 of a multipart archive
  13. # do not concatenate these parts, unpack them in order with /bin/sh
  14. # file doc/Results1 continued
  15. #
  16. CurArch=3
  17. if test ! -r s2_seq_.tmp
  18. then echo "Please unpack part 1 first!"
  19.      exit 1; fi
  20. ( read Scheck
  21.   if test "$Scheck" != $CurArch
  22.   then echo "Please unpack part $Scheck next!"
  23.        exit 1;
  24.   else exit 0; fi
  25. ) < s2_seq_.tmp || exit 1
  26. echo "x - Continuing file doc/Results1"
  27. sed 's/^X//' << 'SHAR_EOF' >> doc/Results1
  28. Xheavily to the change count.  This is also intuitive.  (I think there
  29. Xare two reasons for this, (1) that code with many special cases requiring
  30. Xreturns/exits is not well thought out ahead of time, but rather, coded
  31. Xas the implementor thought and (2) that changes to code with many returns
  32. Xcan be difficult, and can easily be incorrect.
  33. X
  34. XYou might think at this point that you have a magic formula for predicting
  35. Xerrors.  Unfortunately, although this stuff does a very good job of
  36. Xpredicting problems on the pascal project, the best R-sqared I ever
  37. Xgot for the RSM(*1) data was still less than .4.  Apparently, there are
  38. Xother factors at work.  I believe that one very important factor is the
  39. Xexperience/skill of the original implementor and of those who made changes
  40. Xto the module.  The uids of these people can be obtained from the sccs file.
  41. XYou then need to have some way to associate a skill level with the person
  42. X(note that time may be important here too).  I never completed this final
  43. Xstep.  
  44. X
  45. X
  46. X*1 - RSM == Remote Software Management, a distributed source distribution
  47. Xand control system.  See results2 for more info.
  48. X
  49. XAs always, feel free to contact me with questions or assistance in setting
  50. Xthis stuff up to work on a project you want to analyze.
  51. X
  52. XBrian Renaud
  53. SHAR_EOF
  54. echo "File doc/Results1 is complete"
  55. chmod 0644 doc/Results1 || echo "restore of doc/Results1 fails"
  56. echo "x - extracting doc/Results2 (Text)"
  57. sed 's/^X//' << 'SHAR_EOF' > doc/Results2
  58. XSome additional example metrics.  These are from the RSM and pascal
  59. X(combined) projects.
  60. X
  61. XThis example predicts changes (errors) by using (halstead) volume,
  62. Xcomments, functions (number of functions in file) and returns
  63. X(total returns).  There are 490 files (data points).  The data contains
  64. Xa number of significant outliers.  For every variable, the standard
  65. Xdeviation is greater than the mean.
  66. X
  67. XNote that I included function count rather than mccabe.  This
  68. Xseemed to be a more significant variable.
  69. X
  70. XThe regression equation is:
  71. X
  72. Xchanges    =   0.00164 volume  -  0.1097comments  -  0.2515 functions  
  73. X      + 0.07432 returns  +  3.18609
  74. X
  75. XR-Squared is .5818
  76. X
  77. XNote that, once again we have a counter-intuitive variable.  This time
  78. Xfunctions varies inversely with changes.  (That is, more functions in
  79. Xa file imply fewer changes.)  Strange; I speculate that since file size
  80. Xis explained by the volume variable, many functions in a file means small
  81. Xfunctions.  Small functions typically contain fewer errors.
  82. X
  83. XThe correlation matrix is:
  84. X
  85. Xchanges        1.0000
  86. Xvolume        0.6630    1.0000
  87. Xcomments    0.2152    0.7068    1.0000
  88. Xfunctions    0.2394    0.6311    0.7528    1.0000
  89. Xreturns        0.6879    0.7087    0.1825    0.3079    1.0000
  90. X
  91. X
  92. XThe t test results are:
  93. X
  94. Xvolume        10.5995
  95. Xcomments     5.0503
  96. Xfunctions     1.8426
  97. Xreturns         3.8045
  98. SHAR_EOF
  99. chmod 0644 doc/Results2 || echo "restore of doc/Results2 fails"
  100. echo "x - extracting doc/halstead.doc (Text)"
  101. sed 's/^X//' << 'SHAR_EOF' > doc/halstead.doc
  102. XHalstead provides various indicators of the module's complexity.
  103. XThe module is examined to determine the following
  104. X
  105. Xn1 == number of unique operators
  106. Xn2 == number of unique operands
  107. XN1 == number of total operators
  108. XN2 == number of total operands
  109. X
  110. XThe program writes these output fields:
  111. X
  112. XFile Name
  113. XProgram Length          (N  = N1 + N2)
  114. XProgram Volume          (V  = N log<base2> (n1 + n2))
  115. XProgram Level           (L  = (2/n1) * (n2/N2))
  116. XMental Discriminations  (E^ = V / L)
  117. X
  118. XThe program volume (aka ``Halstead Volume'') is probably most useful
  119. Xand seems to be reasonably well correlated with error counts for modules.
  120. SHAR_EOF
  121. chmod 0644 doc/halstead.doc || echo "restore of doc/halstead.doc fails"
  122. echo "x - extracting doc/kdsi.1L (Text)"
  123. sed 's/^X//' << 'SHAR_EOF' > doc/kdsi.1L
  124. X.TH KDSI "L COSI" 2/2/86
  125. X.\" bdr
  126. X.UC
  127. X.SH NAME
  128. Xkdsi - count number of lines of code in a C program
  129. X.SH SYNOPSIS
  130. X.B kdsi
  131. X.B [ file ]*
  132. X.SH DESCRIPTION
  133. X.I Kdsi
  134. Xcounts the lines of code in a C program.
  135. XIt provides the following information:
  136. X.sp 1
  137. X.nf
  138. X          lines of code
  139. X          blank lines
  140. X          comments lines
  141. X          number of comments
  142. X.fi
  143. X.LP
  144. XIf you specify no files,
  145. X.I kdsi
  146. Xwill read from stdin.
  147. XIf you specify more than one file on the command line,
  148. X.I kdsi
  149. Xwill print the total for each category.
  150. X.SH SEE ALSO
  151. Xwc(1)
  152. SHAR_EOF
  153. chmod 0644 doc/kdsi.1L || echo "restore of doc/kdsi.1L fails"
  154. echo "x - extracting doc/mccabe.doc (Text)"
  155. sed 's/^X//' << 'SHAR_EOF' > doc/mccabe.doc
  156. XMccabe determines function complexity based on Mccabe model
  157. Xof program complexity.
  158. X
  159. XUsage: mccabe [-n] file [file]
  160. X
  161. XThe -n flag (No Header) is useful if you are using this to produce data for
  162. Xother tools
  163. X
  164. XMccabe produces (in order) the following output
  165. X
  166. X    File Name
  167. X    Function Name    (or *** for complexity not in a function, as in yacc)
  168. X    Complexity
  169. X    Count of Return statements
  170. X
  171. XTypically a complexity over 10 is cause for further examination.  The
  172. Xnumber of returns in a function is also important in predicting error
  173. Xcounts for that function, perhaps even more important than the complexity.
  174. SHAR_EOF
  175. chmod 0644 doc/mccabe.doc || echo "restore of doc/mccabe.doc fails"
  176. echo "x - extracting src/control/README (Text)"
  177. sed 's/^X//' << 'SHAR_EOF' > src/control/README
  178. XThis directory contains an example of some tools which glom together the
  179. Xoutput of various metrics tools into some (potentially) usable databases.
  180. XThere are two databases produced, one of which is file-based (containing
  181. Xhalstead, change count and line count information) and one of which is
  182. Xfunction based (containing mccabe and return information).  Obviously,
  183. Xthere can be one or more functions in a file.
  184. X
  185. XI have only a few printouts left indicating the results of the multiple
  186. Xregression models I built.  The results from these are presented later in
  187. Xthis file.  The most (statistically) significant variable for the
  188. Xprediction of errors (SCCS changes) was halstead volume.  Mccabe, returns
  189. Xand comment counts were also significant, at similar statistical levels.
  190. XKdsi and volume were highly correlated.  The only variable I disbelieve is
  191. Xthe values for mccabe.  See my comments in the doc directory.
  192. X
  193. XThe structure of the scripts follows.  They are not easy to read, although
  194. Xif you lay them all out before you, they are not too bad.
  195. X
  196. XThe file pascal_stats is the highest level script.  It actually knows about
  197. Xthe structure of the application's directories.  (But, before trying to use
  198. Xthis file, see the comments about proj_stats below.) It calls gather_stats
  199. Xto pull stuff together for each directory.  The output from gather_stats is
  200. Xjust appended to the appropriate metrics database.
  201. X
  202. XGather_stats actually gets the statistics, for the file specification
  203. Xpassed to it.  Note that I have modified it since it was last used.  I
  204. Xassume that it still compiles.  In addition, some of the commands produce
  205. Xmore and different output than they used to.  I have changed the
  206. Xspecification of the joins to what I think it should be.
  207. X
  208. XI have created a new script proj_stats which employs a different (easier to
  209. Xread) method than that in "pascal_stats" for naming all of the directories
  210. Xand files in a project.  It reads a file for the names of the directories
  211. Xand the patterns which describe files in those directories.  An example
  212. Xfile which should work for the pascal project is in "example_spec".
  213. X
  214. XThe other new scripts are altparse.prs and altkdsi.  Altkdsi just post-
  215. Xprocesses the output of the kdsi command to strip off the totals line.
  216. XAltparse.prs finds the change count from sccs.  It does not count ".1"
  217. Xdeltas, assuming that those are new releases, rather than bug fixes.
  218. SHAR_EOF
  219. chmod 0644 src/control/README || echo "restore of src/control/README fails"
  220. echo "x - extracting src/control/altkdsi (Text)"
  221. sed 's/^X//' << 'SHAR_EOF' > src/control/altkdsi
  222. X: postprocess kdsi to put it in form for gather_stats
  223. X
  224. Xkdsi $* | awk '$5 != "total" {printf("%s\t%s\t%s\n", $5, $1, $4);}'
  225. SHAR_EOF
  226. chmod 0644 src/control/altkdsi || echo "restore of src/control/altkdsi fails"
  227. echo "x - extracting src/control/altparse.prs (Text)"
  228. sed 's/^X//' << 'SHAR_EOF' > src/control/altparse.prs
  229. X: parse output from sccs prs command
  230. X
  231. Xfor file in $*
  232. Xdo
  233. X    prs ${file} | awk '
  234. X    BEGIN {
  235. X        True = 1;
  236. X        False = 0;
  237. X        inMR = False;
  238. X        inComment = False;
  239. X        first = True;
  240. X    }
  241. X
  242. X    $0 == "" {
  243. X        inMR = False;
  244. X        inComment = False;
  245. X        next;
  246. X    }
  247. X
  248. X    $0 ~ /^D [0-9][0-9]*\.[0-9][0-9]*/ {
  249. X        # got delta entry
  250. X        len = length( $2 );
  251. X        if ( substr($2, len - 1) != ".1" )
  252. X            changect++;
  253. X        next;
  254. X    }
  255. X
  256. X    $1 ~ /^MRs:/ {
  257. X        inMR = True;
  258. X        next;
  259. X    }
  260. X
  261. X    $1 ~ /^COMMENT/ {
  262. X        inComment = True;
  263. X        next;
  264. X    }
  265. X
  266. X    inMR == 1 {    # skipping through MR section
  267. X        next;
  268. X    }
  269. X
  270. X    inComment == 1 {    # skipping through comment section
  271. SHAR_EOF
  272. echo "End of part 3"
  273. echo "File src/control/altparse.prs is continued in part 4"
  274. echo "4" > s2_seq_.tmp
  275. exit 0
  276.  
  277.  
  278.