workflow.html 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. <!DOCTYPE html>
  2. <!--
  3. Metrix++, Copyright 2009-2013, Metrix++ Project
  4. Link: http://metrixplusplus.sourceforge.net
  5. This file is part of Metrix++ Tool.
  6. Metrix++ is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, version 3 of the License.
  9. Metrix++ is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <meta charset="utf-8">
  19. <title>Metrix++ Project</title>
  20. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  21. <meta name="description" content="">
  22. <meta name="author" content="">
  23. <!-- Le styles -->
  24. <!--
  25. <link href="../../style.css" rel="stylesheet">
  26. -->
  27. <link href="assets/css/bootstrap.css" rel="stylesheet">
  28. <link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
  29. <link href="assets/css/docs.css" rel="stylesheet">
  30. <link href="assets/js/google-code-prettify/prettify.css" rel="stylesheet">
  31. <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
  32. <!--[if lt IE 9]>
  33. <script src="assets/js/html5shiv.js"></script>
  34. <![endif]-->
  35. <!-- Le fav and touch icons -->
  36. <link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
  37. <link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
  38. <link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
  39. <link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
  40. <link rel="shortcut icon" href="assets/ico/favicon.png">
  41. <!--
  42. <script type="text/javascript">
  43. var _gaq = _gaq || [];
  44. _gaq.push(['_setAccount', 'UA-146052-10']);
  45. _gaq.push(['_trackPageview']);
  46. (function() {
  47. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  48. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  49. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  50. })();
  51. </script>
  52. -->
  53. </head>
  54. <body data-spy="scroll" data-target=".bs-docs-sidebar">
  55. <!-- Navbar
  56. ================================================== -->
  57. <div class="navbar navbar-link navbar-fixed-top">
  58. <div class="navbar-inner">
  59. <div class="container">
  60. <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
  61. <span class="icon-bar"></span>
  62. <span class="icon-bar"></span>
  63. <span class="icon-bar"></span>
  64. </button>
  65. <a class="brand" href="./index.html">Metrix++</a>
  66. <div class="nav-collapse collapse">
  67. <ul class="nav">
  68. <li class="">
  69. <a href="./index.html">Home</a>
  70. </li>
  71. <li class="">
  72. <a href="./workflow.html">Workflow</a>
  73. </li>
  74. <li class="">
  75. <a href="./extend.html">Create plugin</a>
  76. </li>
  77. </ul>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <!-- Subhead
  83. ================================================== -->
  84. <header class="jumbotron" id="overview">
  85. <div class="container">
  86. <div class="row">
  87. <div class="span3">
  88. </div>
  89. <div class="span9">
  90. <h5 class="text-right">Management of source code quality is possible.</h5>
  91. <p class="text-right">
  92. <a href="https://sourceforge.net/projects/metrixplusplus/files/latest/download"
  93. ><button type="button"class="btn btn-danger">Download</button></a>
  94. <!--
  95. <button type="button"class="btn btn-warning">Donate</button>
  96. -->
  97. </p>
  98. </div>
  99. </div>
  100. </div>
  101. </header>
  102. <div class="container"><div class="row">
  103. <!-- Docs nav
  104. ================================================== -->
  105. <div class="span3 bs-docs-sidebar">
  106. <ul class="nav nav-list bs-docs-sidenav">
  107. <li><a href="#workflow_collect_section"><i class="icon-chevron-right"></i> Workflow: Collect data</a></li>
  108. <li><a href="#workflow_view_section"><i class="icon-chevron-right"></i> Workflow: View data</a></li>
  109. <li><a href="#workflow_view_summary_section"><i class="icon-hand-right"></i> &middot; summary &amp; distributions</a></li>
  110. <li><a href="#workflow_view_details_section"><i class="icon-hand-right"></i> &middot; details per file/region</a></li>
  111. <li><a href="#workflow_limit_section"><i class="icon-chevron-right"></i> Workflow: Apply thresholds</a></li>
  112. <li><a href="#workflow_limit_hotspots_section"><i class="icon-hand-right"></i> &middot; hotspots</a></li>
  113. <li><a href="#workflow_limit_control_section"><i class="icon-hand-right"></i> &middot; controlling trends</a></li>
  114. <li><a href="#workflow_other_section"><i class="icon-chevron-right"></i> Workflow: Other applications</a></li>
  115. </ul>
  116. </div>
  117. <!-- Sections
  118. ================================================== -->
  119. <div class="span9">
  120. <div class="page-header">
  121. <h1>Workflow</h1>
  122. </div>
  123. <p>The workflow and application usecases are demonstrated using source code from the
  124. <a href="http://www.boost.org/doc/libs/1_54_0/doc/html/interprocess.html">boost/interprocess library</a>.
  125. Boost versions 1.52 and 1.54 are used and refered below as the 'previous' version and the 'current' version accordingly.</p>
  126. <section id="workflow_collect_section">
  127. <h2>Collect data</h2>
  128. <p>The first step is to collect the data.
  129. The 'collect' tool has got multiple options to enable various metrics plugins.
  130. Let's collect the number of lines of code and cyclomatic complexity metrics
  131. for the previous (1.52.0 version) boost interprocess library. Assuming that 2 versions of boost library
  132. are unpacked in the current working directory:</p>
  133. <pre>
  134. &gt; cd boost_1_52_0
  135. &gt; python "/path/to/metrix++.py" collect --std.code.lines.code --std.code.complexity.cyclomatic -- boost/interprocess
  136. &gt; cd ../ # return back to working directory
  137. </pre>
  138. <p>The list of arguments after '--' enumerates the paths to read the source files.
  139. As a result of execution of this command, a file metrixpp.db will be written in the current working directory.
  140. It can be redefined using the --db-file option.</p>
  141. <p>Metrix++ can compare code bases which reduces processing scope to the modified or new code.
  142. So, let's collect the same data for the current (1.54.0 version) boost interprocess library.</p>
  143. <pre>
  144. &gt; cd boost_1_54_0
  145. &gt; python "/path/to/metrix++.py" collect --std.code.lines.code --std.code.complexity.cyclomatic -- boost/interprocess --db-file-prev=../boost_1_52_0/metrixpp.db
  146. &gt; cd ../ # return back to working directory
  147. </pre>
  148. <p>The option --db-file-prev points to the file with the data collected in the previous step.
  149. So, eventually it executed iterative collection. It can speed up the exectuion significantly,
  150. depending on amount of changes between two version.</p>
  151. <p>Check other options of the collect tool by executing:</p>
  152. <pre>
  153. &gt; python "/path/to/metrix++.py" collect --help
  154. </pre>
  155. </section>
  156. <section id="workflow_view_section">
  157. <h2>View data</h2>
  158. </section>
  159. <section id="workflow_view_summary_section">
  160. <h3>Summary metrics and distribution tables/graphs</h3>
  161. <p>It is time to look at the data files collected (step above). The command:</p>
  162. <pre>
  163. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db
  164. </pre>
  165. <p>prints summary metrics, like minimum/maximum, and distribution/frequency tables:</p>
  166. <pre>
  167. :: info: Overall metrics for 'std.code.complexity:cyclomatic' metric
  168. Average : 0.652902698283
  169. Minimum : 0
  170. Maximum : 37
  171. Total : 1597.0
  172. Distribution : 2446 regions in total (including 0 suppressed)
  173. Metric value : Ratio : R-sum : Number of regions
  174. 0 : 0.771 : 0.771 : 1886 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  175. 1 : 0.110 : 0.881 : 268 |||||||||||
  176. 2 : 0.044 : 0.925 : 108 ||||
  177. 3 : 0.025 : 0.949 : 60 ||
  178. 4 : 0.016 : 0.966 : 40 ||
  179. 5 : 0.007 : 0.973 : 18 |
  180. 6 : 0.006 : 0.979 : 14 |
  181. 7 : 0.004 : 0.983 : 10
  182. 8 : 0.003 : 0.986 : 8
  183. 9 : 0.002 : 0.988 : 4
  184. 10 : 0.004 : 0.991 : 9
  185. 11 : 0.002 : 0.993 : 4
  186. 12 : 0.001 : 0.994 : 3
  187. 13 : 0.001 : 0.995 : 2
  188. 14 : 0.001 : 0.996 : 2
  189. 15-16 : 0.001 : 0.997 : 3
  190. 17-18 : 0.001 : 0.998 : 3
  191. 20 : 0.000 : 0.999 : 1
  192. 23-25 : 0.001 : 1.000 : 2
  193. 37 : 0.000 : 1.000 : 1
  194. :: info: Overall metrics for 'std.code.lines:code' metric
  195. Average : 6.64356984479
  196. Minimum : 0
  197. Maximum : 201
  198. Total : 23970.0
  199. Distribution : 3608 regions in total (including 0 suppressed)
  200. Metric value : Ratio : R-sum : Number of regions
  201. 0-1 : 0.088 : 0.088 : 319 |||||||||
  202. 2 : 0.320 : 0.409 : 1155 ||||||||||||||||||||||||||||||||
  203. 3 : 0.108 : 0.517 : 390 |||||||||||
  204. 4 : 0.081 : 0.598 : 294 ||||||||
  205. 5 : 0.080 : 0.678 : 290 ||||||||
  206. 6 : 0.061 : 0.739 : 220 ||||||
  207. 7 : 0.049 : 0.788 : 176 |||||
  208. 8 : 0.030 : 0.818 : 109 |||
  209. 9 : 0.025 : 0.843 : 89 ||
  210. 10-11 : 0.032 : 0.876 : 117 |||
  211. 12-13 : 0.020 : 0.895 : 71 ||
  212. 14 : 0.012 : 0.907 : 43 |
  213. 15-16 : 0.017 : 0.924 : 61 ||
  214. 17-19 : 0.015 : 0.939 : 55 ||
  215. 20-22 : 0.013 : 0.952 : 46 |
  216. 23-26 : 0.011 : 0.963 : 40 |
  217. 27-30 : 0.009 : 0.972 : 33 |
  218. 31-39 : 0.009 : 0.981 : 33 |
  219. 40-65 : 0.009 : 0.991 : 34 |
  220. 66-201 : 0.009 : 1.000 : 33 |
  221. :: info: Directory content:
  222. Directory : .
  223. </pre>
  224. <p>The same command with --db-file-prev option enables comparision and change trends are shown in [] brackets:</p>
  225. <pre>
  226. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db
  227. </pre>
  228. <pre>
  229. :: info: Overall metrics for 'std.code.complexity:cyclomatic' metric
  230. Average : 0.652902698283 [+0.00362138411453]
  231. Minimum : 0 [+0]
  232. Maximum : 37 [+1]
  233. Total : 1597.0 [+16.0]
  234. Distribution : 2446 [+11] regions in total (including 0 [+0] suppressed)
  235. Metric value : Ratio : R-sum : Number of regions
  236. 0 : 0.771 : 0.771 : 1886 [+5 ] |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  237. 1 : 0.110 : 0.881 : 268 [+4 ] |||||||||||
  238. 2 : 0.044 : 0.925 : 108 [+0 ] ||||
  239. 3 : 0.025 : 0.949 : 60 [+2 ] ||
  240. 4 : 0.016 : 0.966 : 40 [-1 ] ||
  241. 5 : 0.007 : 0.973 : 18 [-1 ] |
  242. 6 : 0.006 : 0.979 : 14 [+1 ] |
  243. 7 : 0.004 : 0.983 : 10 [+1 ]
  244. 8 : 0.003 : 0.986 : 8 [+1 ]
  245. 9 : 0.002 : 0.988 : 4 [+0 ]
  246. 10 : 0.004 : 0.991 : 9 [-2 ]
  247. 11 : 0.002 : 0.993 : 4 [+1 ]
  248. 12 : 0.001 : 0.994 : 3 [+0 ]
  249. 13 : 0.001 : 0.995 : 2 [+0 ]
  250. 14 : 0.001 : 0.996 : 2 [+0 ]
  251. 15-16 : 0.001 : 0.997 : 3 [-1 ]
  252. 17-18 : 0.001 : 0.998 : 3 [+1 ]
  253. 20 : 0.000 : 0.999 : 1 [+0 ]
  254. 23-25 : 0.001 : 1.000 : 2 [+0 ]
  255. 36-37 : 0.000 : 1.000 : 1 [+0 ]
  256. :: info: Overall metrics for 'std.code.lines:code' metric
  257. Average : 6.64356984479 [+0.012181964309]
  258. Minimum : 0 [+0]
  259. Maximum : 201 [+4]
  260. Total : 23970.0 [+223.0]
  261. Distribution : 3608 [+27] regions in total (including 0 [+0] suppressed)
  262. Metric value : Ratio : R-sum : Number of regions
  263. 0-1 : 0.088 : 0.088 : 319 [+3 ] |||||||||
  264. 2 : 0.320 : 0.409 : 1155 [+9 ] ||||||||||||||||||||||||||||||||
  265. 3 : 0.108 : 0.517 : 390 [-3 ] |||||||||||
  266. 4 : 0.081 : 0.598 : 294 [+7 ] ||||||||
  267. 5 : 0.080 : 0.678 : 290 [+7 ] ||||||||
  268. 6 : 0.061 : 0.739 : 220 [-1 ] ||||||
  269. 7 : 0.049 : 0.788 : 176 [-2 ] |||||
  270. 8 : 0.030 : 0.818 : 109 [-1 ] |||
  271. 9 : 0.025 : 0.843 : 89 [+4 ] ||
  272. 10-11 : 0.032 : 0.876 : 117 [+9 ] |||
  273. 12-13 : 0.020 : 0.895 : 71 [-9 ] ||
  274. 14 : 0.012 : 0.907 : 43 [+0 ] |
  275. 15-16 : 0.017 : 0.924 : 61 [+0 ] ||
  276. 17-19 : 0.015 : 0.939 : 55 [+6 ] ||
  277. 20-22 : 0.013 : 0.952 : 46 [-3 ] |
  278. 23-26 : 0.011 : 0.963 : 40 [+2 ] |
  279. 27-30 : 0.009 : 0.972 : 33 [-3 ] |
  280. 31-39 : 0.009 : 0.981 : 33 [+0 ] |
  281. 40-65 : 0.009 : 0.991 : 34 [+1 ] |
  282. 66-201 : 0.009 : 1.000 : 33 [+1 ] |
  283. :: info: Directory content:
  284. Directory : .
  285. </pre>
  286. <h4>Reducing analysis scope</h4>
  287. <p>There are two ways to reduce the analysis scope for the view tool. The first is to enumerate paths of interest.
  288. For example, the following command reduces scope to the 'allocators' sub-directory within the processed code.</p>
  289. <pre>
  290. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db -- ./boost/interprocess/allocators
  291. </pre>
  292. <p>The second is to specify the --scope-mode option, which instructs the tool to process only modified and/or new files/regions.
  293. For example, to view the summary metrics for all modified and new regions:</p>
  294. <pre>
  295. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db --scope-mode=touched
  296. </pre>
  297. <pre>
  298. :: info: Overall metrics for 'std.code.complexity:cyclomatic' metric
  299. Average : 1.84924623116 [-0.0230941943761]
  300. Minimum : 0 [+0]
  301. Maximum : 37 [+1]
  302. Total : 368.0 [+16.0]
  303. Distribution : 199 [+11] regions in total (including 0 [+0] suppressed)
  304. Metric value : Ratio : R-sum : Number of regions
  305. 0 : 0.608 : 0.608 : 121 [+5 ] |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  306. 1 : 0.131 : 0.739 : 26 [+4 ] |||||||||||||
  307. 2 : 0.070 : 0.809 : 14 [+0 ] |||||||
  308. 3 : 0.060 : 0.869 : 12 [+2 ] ||||||
  309. 4 : 0.015 : 0.884 : 3 [-1 ] ||
  310. 5 : 0.015 : 0.899 : 3 [-1 ] ||
  311. 6 : 0.005 : 0.905 : 1 [+1 ] |
  312. 7 : 0.015 : 0.920 : 3 [+1 ] ||
  313. 8 : 0.015 : 0.935 : 3 [+1 ] ||
  314. 9 : 0.010 : 0.945 : 2 [+0 ] |
  315. 10 : 0.010 : 0.955 : 2 [-2 ] |
  316. 11 : 0.005 : 0.960 : 1 [+1 ] |
  317. 12 : 0.005 : 0.965 : 1 [+0 ] |
  318. 13 : 0.005 : 0.970 : 1 [+0 ] |
  319. 16 : 0.005 : 0.975 : 1 [-1 ] |
  320. 17 : 0.005 : 0.980 : 1 [+0 ] |
  321. 18 : 0.010 : 0.990 : 2 [+1 ] |
  322. 20 : 0.005 : 0.995 : 1 [+0 ] |
  323. 36-37 : 0.005 : 1.000 : 1 [+0 ] |
  324. :: info: Overall metrics for 'std.code.lines:code' metric
  325. Average : 15.9645390071 [-0.815853149771]
  326. Minimum : 0 [+0]
  327. Maximum : 201 [+6]
  328. Total : 4502.0 [+223.0]
  329. Distribution : 282 [+27] regions in total (including 0 [+0] suppressed)
  330. Metric value : Ratio : R-sum : Number of regions
  331. 0-1 : 0.053 : 0.053 : 15 [+3 ] |||||
  332. 2 : 0.124 : 0.177 : 35 [+9 ] ||||||||||||
  333. 3 : 0.053 : 0.230 : 15 [-3 ] |||||
  334. 4 : 0.060 : 0.291 : 17 [+7 ] ||||||
  335. 5 : 0.089 : 0.379 : 25 [+7 ] |||||||||
  336. 6 : 0.060 : 0.440 : 17 [-1 ] ||||||
  337. 7 : 0.050 : 0.489 : 14 [-2 ] |||||
  338. 8-9 : 0.074 : 0.564 : 21 [+3 ] |||||||
  339. 10 : 0.035 : 0.599 : 10 [+5 ] ||||
  340. 11 : 0.082 : 0.681 : 23 [+4 ] ||||||||
  341. 12-13 : 0.043 : 0.723 : 12 [-9 ] ||||
  342. 14-15 : 0.039 : 0.762 : 11 [-1 ] ||||
  343. 16-18 : 0.028 : 0.791 : 8 [+4 ] |||
  344. 19-22 : 0.039 : 0.830 : 11 [+0 ] ||||
  345. 23-26 : 0.039 : 0.869 : 11 [+2 ] ||||
  346. 27-32 : 0.028 : 0.897 : 8 [-3 ] |||
  347. 38-50 : 0.025 : 0.922 : 7 [+0 ] ||
  348. 51-69 : 0.025 : 0.947 : 7 [+1 ] ||
  349. 71-100 : 0.032 : 0.979 : 9 [+2 ] |||
  350. 101-201 : 0.021 : 1.000 : 6 [-1 ] ||
  351. :: info: Directory content:
  352. Directory : .
  353. </pre>
  354. </section>
  355. <section id="workflow_view_details_section">
  356. <h3>Detailed metrics per file/region</h3>
  357. <p>The same view tool can print detailed metrics per file and per every region in the specified file.
  358. In order to get detailed metrics, enumerate files of interest after '--'. For example:</p>
  359. <pre>
  360. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db -- ./boost/interprocess/detail/managed_open_or_create_impl.hpp
  361. </pre>
  362. <p>produces output similar to this (truncated to make the page shorter):</p>
  363. <pre>
  364. ./interprocess/detail/managed_open_or_create_impl.hpp:302: info: Metrics per 'priv_open_or_create' region
  365. Region name : priv_open_or_create
  366. Region type : function
  367. Offsets : 8314-14526
  368. Line numbers : 301-467
  369. Modified : True
  370. std.code.complexity:cyclomatic: 37 [+1]
  371. std.code.lines:code: 148 [+4]
  372. </pre>
  373. </section>
  374. <section>
  375. <h3>More about the viewer</h3>
  376. <p>The 'view' command has got an option to alter the output format. It is possible to get the same data
  377. in xml or python dictionary formats. This can be particularly useful for integration of the tool with
  378. other applications. For example, an editor may re-collect and show context based metrics when a file is saved.</p>
  379. <pre>
  380. &gt; python "/path/to/metrix++.py" view --db-file=boost_1_54_0/metrixpp.db --format=xml
  381. </pre>
  382. <p>Check other options of the view tool by executing:</p>
  383. <pre>
  384. &gt; python "/path/to/metrix++.py" view --help
  385. </pre>
  386. </section>
  387. <section id="workflow_limit_section">
  388. <h2>Apply thresholds</h2>
  389. <p>The viewer shows (above) that there are functions with quite large cyclomatic complexities.
  390. Growth of this metric can be considered as negative trend. The Metrix++ 'limit' tool offers the capability
  391. to manage control over trends by applying limits to metric values.
  392. Exceeded limits could be raised as alarms by quality management and control.</p>
  393. </section>
  394. <section id="workflow_limit_hotspots_section">
  395. <h3>Hotspots</h3>
  396. <p>The hotspots mode of the limit tool helps to identify top files/regions exceeding a metric threshold.
  397. Let's identify the top 3 functions in the boost interprocess library, which exceed a limit of 15 points of
  398. cyclomatic complexity:</p>
  399. <pre>
  400. &gt; python "/path/to/metrix++.py" limit --db-file=boost_1_54_0/metrixpp.db --max-limit=std.code.complexity:cyclomatic:15 --hotspots=3
  401. </pre>
  402. <pre>
  403. ./interprocess/detail/managed_open_or_create_impl.hpp:302: warning: Metric 'std.code.complexity:cyclomatic' for region 'priv_open_or_create' exceeds the limit.
  404. Metric name : std.code.complexity:cyclomatic
  405. Region name : priv_open_or_create
  406. Metric value : 37
  407. Modified : None
  408. Change trend : None
  409. Limit : 15.0
  410. Suppressed : False
  411. ./interprocess/streams/vectorstream.hpp:284: warning: Metric 'std.code.complexity:cyclomatic' for region 'seekoff' exceeds the limit.
  412. Metric name : std.code.complexity:cyclomatic
  413. Region name : seekoff
  414. Metric value : 25
  415. Modified : None
  416. Change trend : None
  417. Limit : 15.0
  418. Suppressed : False
  419. ./interprocess/streams/bufferstream.hpp:174: warning: Metric 'std.code.complexity:cyclomatic' for region 'seekoff' exceeds the limit.
  420. Metric name : std.code.complexity:cyclomatic
  421. Region name : seekoff
  422. Metric value : 23
  423. Modified : None
  424. Change trend : None
  425. Limit : 15.0
  426. Suppressed : False
  427. </pre>
  428. </section>
  429. <section id="workflow_limit_control_section">
  430. <h3>Controlling trends</h3>
  431. <p>The exit code of the 'limit' tool is equal to the number of warnings printed. This supports use of the tool
  432. as a static analysis tool during the software build process. In this case, a non-zero exit code means
  433. that there are violations to the agreed standards and it may fail the build. The same command
  434. without --hotspots option will print all regions/files exceeding the specified limit:</p>
  435. <pre>
  436. &gt; python "/path/to/metrix++.py" limit --db-file=boost_1_54_0/metrixpp.db --max-limit=std.code.complexity:cyclomatic:15
  437. </pre>
  438. <h4>Modes to exclude old code from the considiration</h4>
  439. <p>However, it is likely there are many warnings printed in this mode, especially if very old or legacy code is profiled
  440. against new metrics and coding rules. Although all warnings can be removed
  441. by re-factoring as a big task force activity, it is where many tools are rejected,
  442. because it is difficult to justify the initial cost of applying and integrating them.
  443. The Metrix++ 'limit' tool has got an option --warn-mode, which helps to overcome this problem.</p>
  444. <p>--warn-mode=touched encourages re-factoring only for new and modified regions. It enables
  445. continuous refactoring. It does not matter how late the rule is applied or the
  446. coding standard is modified. It is possible to do it anytime with zero initial investment.
  447. For example, applying it to the boost interprocess library for a changes between 1.52 and 1.54 versions
  448. results in only 6 warnings:</p>
  449. <pre>
  450. &gt; python "/path/to/metrix++.py" limit --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db --max-limit=std.code.complexity:cyclomatic:15 --warn-mode=touched
  451. </pre>
  452. <pre>
  453. ./interprocess/detail/managed_open_or_create_impl.hpp:302: warning: Metric 'std.code.complexity:cyclomatic' for region 'priv_open_or_create' exceeds the limit.
  454. Metric name : std.code.complexity:cyclomatic
  455. Region name : priv_open_or_create
  456. Metric value : 37
  457. Modified : True
  458. Change trend : +1
  459. Limit : 15.0
  460. Suppressed : False
  461. ./interprocess/ipc/message_queue.hpp:375: warning: Metric 'std.code.complexity:cyclomatic' for region 'insert_at' exceeds the limit.
  462. Metric name : std.code.complexity:cyclomatic
  463. Region name : insert_at
  464. Metric value : 16
  465. Modified : True
  466. Change trend : 0
  467. Limit : 15.0
  468. Suppressed : False
  469. ./interprocess/mapped_region.hpp:575: warning: Metric 'std.code.complexity:cyclomatic' for region 'mapped_region' exceeds the limit.
  470. Metric name : std.code.complexity:cyclomatic
  471. Region name : mapped_region
  472. Metric value : 18
  473. Modified : True
  474. Change trend : +2
  475. Limit : 15.0
  476. Suppressed : False
  477. ./interprocess/mem_algo/detail/mem_algo_common.hpp:452: warning: Metric 'std.code.complexity:cyclomatic' for region 'priv_allocate_many' exceeds the limit.
  478. Metric name : std.code.complexity:cyclomatic
  479. Region name : priv_allocate_many
  480. Metric value : 20
  481. Modified : True
  482. Change trend : 0
  483. Limit : 15.0
  484. Suppressed : False
  485. ./interprocess/mem_algo/rbtree_best_fit.hpp:787: warning: Metric 'std.code.complexity:cyclomatic' for region 'priv_expand_both_sides' exceeds the limit.
  486. Metric name : std.code.complexity:cyclomatic
  487. Region name : priv_expand_both_sides
  488. Metric value : 17
  489. Modified : True
  490. Change trend : 0
  491. Limit : 15.0
  492. Suppressed : False
  493. ./interprocess/sync/windows/named_sync.hpp:98: warning: Metric 'std.code.complexity:cyclomatic' for region 'open_or_create' exceeds the limit.
  494. Metric name : std.code.complexity:cyclomatic
  495. Region name : open_or_create
  496. Metric value : 18
  497. Modified : True
  498. Change trend : 0
  499. Limit : 15.0
  500. Suppressed : False
  501. </pre>
  502. <p>If it is challenging or of little benefit to refactor everything touched,
  503. --warn-mode=trends simplifies the control over modified regions and only makes sure
  504. that there are no regressions in modified code. In other words, a warning is printed about a modified region/file
  505. only if a metric exceeds the specified limit and the value of the metric has got a negative trend due to the modification.
  506. It is possible to apply it anytime with zero initial investment and almost zero on-going investment around old code.
  507. For example, applying it to the boost interprocess library for a changes between 1.52 and 1.54 versions
  508. results in only 2 warnings:</p>
  509. <pre>
  510. &gt; python "/path/to/metrix++.py" limit --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db --max-limit=std.code.complexity:cyclomatic:15 --warn-mode=trend
  511. </pre>
  512. <pre>
  513. ./interprocess/detail/managed_open_or_create_impl.hpp:302: warning: Metric 'std.code.complexity:cyclomatic' for region 'priv_open_or_create' exceeds the limit.
  514. Metric name : std.code.complexity:cyclomatic
  515. Region name : priv_open_or_create
  516. Metric value : 37
  517. Modified : True
  518. Change trend : +1
  519. Limit : 15.0
  520. Suppressed : False
  521. ./interprocess/mapped_region.hpp:575: warning: Metric 'std.code.complexity:cyclomatic' for region 'mapped_region' exceeds the limit.
  522. Metric name : std.code.complexity:cyclomatic
  523. Region name : mapped_region
  524. Metric value : 18
  525. Modified : True
  526. Change trend : +2
  527. Limit : 15.0
  528. Suppressed : False
  529. </pre>
  530. <p>--warn-mode=new ignores existing code and ensures that warnings are only about new code.
  531. For example, applying it to the boost interprocess library for a changes between 1.52 and 1.54 versions
  532. results in 0 warnings, so it shows that the new code is totally compliant with the standard required in the example.</p>
  533. <pre>
  534. &gt; python "/path/to/metrix++.py" limit --db-file=boost_1_54_0/metrixpp.db --db-file-prev=boost_1_52_0/metrixpp.db --max-limit=std.code.complexity:cyclomatic:15 --warn-mode=new
  535. </pre>
  536. <h4>Suppressions</h4>
  537. <p>It is possible to suppress warnings. Suppressions are collected from comments in code
  538. and used by the 'limit' tool to filter out suppressed warnings.
  539. It supports fine grained control over false-positive warnings, if there are any.</p>
  540. <p>In order to suppress a warning:</p>
  541. <ul>
  542. <li>per region metrics: put the metrix++ instruction in the comments before the region, for example:</li>
  543. <pre class="prettyprint linenums">
  544. // This function returns string typed
  545. // representation of a name of a color,
  546. // requested by color's id
  547. // metrix++: suppress std.code.complexity:cyclomatic
  548. std::string getColorName(int color_id)
  549. {
  550. switch (color_id)
  551. {
  552. case COLOR_RED:
  553. return std::string("red")
  554. case COLOR_GREEN:
  555. return std::string("green")
  556. case COLOR_BLUE:
  557. return std::string("blue")
  558. /* and so on */
  559. }
  560. }
  561. </pre>
  562. <li>per file metrics: put the metrix++ instruction in the comments at the beginning of a file, for example:</li>
  563. <pre class="prettyprint linenums">
  564. //
  565. // This file does processing of colors and brushes
  566. // Copyright is my company, 2013
  567. //
  568. // However, it is too long and big file, and there is no time
  569. // to split it into multiple file, so shut up the metrix++ warnings:
  570. // metrix++: suppress std.general:size
  571. //
  572. std::string getColorName(int color_id)
  573. {
  574. ...
  575. ...
  576. </pre>
  577. <li>activate collection of suppressions:</li>
  578. <pre>
  579. &gt; python "/path/to/metrix++.py" collect --std.suppress
  580. </pre>
  581. <li>run the 'limit' tool WITHOUT --disable-suppressions option:</li>
  582. <pre>
  583. &gt; python "/path/to/metrix++.py" limit ...
  584. </pre>
  585. </ul>
  586. <h5>Important notice:</h5>
  587. <ul><li>The --std.suppress option enables collection of 2 metrics as well: 'std.suppress:count' and
  588. 'std.suppress.file:count'. The first is number of suppressions per region.
  589. The second is the same but applies to file-scope metrics.
  590. It supports management of the number of suppressions.
  591. Usually there are no false-positives to suppress with the <strong>right</strong> metric,
  592. but there could be exceptions in specific cases. Managing suppressions is about managing exceptions.
  593. If there are many exceptional cases, maybe something is wrong with a metric or the application of a metric.
  594. Two code examples about colors above do not demonstrate the technically exceptional case,
  595. they likely demonstrate a case of a process exception, like "there is no time to do it properly now", or
  596. a case of the wrong application of a metric, like "shut up the useless tool". So, be careful.
  597. The 'view' tool shows the number of suppressions and its change trends on a per metric basis.</li></ul>
  598. </section>
  599. <section id="workflow_other_section">
  600. <h2>Other applications</h2>
  601. <h3>Checking data file properties</h3>
  602. <p>The Metrix++ 'info' tool is helpful to check the properties of a data file, like the settings used to write it,
  603. collected metrics and files processed. For example:</p>
  604. <pre>
  605. &gt; python "/path/to/metrix++.py" info --db-file=boost_1_54_0/metrixpp.db
  606. </pre>
  607. <pre>
  608. boost_1_54_0/metrixpp.db:: info: Created using plugins and settings:
  609. version : 1.0
  610. std.code.complexity:version: 1.1
  611. std.code.cpp:version: 1.1
  612. std.code.cpp:files: *.c,*.cc,*.cpp,*.cxx,*.h,*.hh,*.hpp,*.hxx
  613. std.code.cs:version: 1.0
  614. std.code.cs:files: *.cs
  615. std.code.java:version: 1.1
  616. std.code.java:files: *.java
  617. std.code.lines:version: 1.1
  618. test_workflow.db:: info: Collected metrics:
  619. std.code.complexity:cyclomatic:
  620. std.code.lines:code:
  621. :: info: Processed files and checksums:
  622. ./interprocess/allocators/detail/node_pool.hpp: 0xb099a7c3
  623. ./interprocess/allocators/detail/node_tools.hpp: 0xaaf5044d
  624. ./interprocess/anonymous_shared_memory.hpp: 0x2bf06cb0
  625. ./interprocess/containers/allocation_type.hpp: 0x8e95cda0
  626. ./interprocess/containers/containers_fwd.hpp: 0xa4d0d9f7
  627. ./interprocess/containers/deque.hpp: 0x6dbb77af
  628. ./interprocess/containers/flat_map.hpp: 0x6750338c
  629. ...
  630. </pre>
  631. <h3>Exporting results</h3>
  632. <p>The Metrix++ 'export' tool exports data files to csv formated files. For example:</p>
  633. <pre>
  634. &gt; python "/path/to/metrix++.py" export --db-file=boost_1_54_0/metrixpp.db > boost_1_54_0/metrixpp.csv
  635. </pre>
  636. <pre>
  637. file,region,type,modified,line start,line end,std.code.complexity:cyclomatic,std.code.lines:code
  638. ./interprocess/allocators/detail/node_pool.hpp,__global__,global,,1,110,,0
  639. ./interprocess/allocators/detail/node_pool.hpp,boost,namespace,,33,105,,2
  640. ./interprocess/allocators/detail/node_pool.hpp,interprocess,namespace,,34,104,,2
  641. ./interprocess/allocators/detail/node_pool.hpp,ipcdetail,namespace,,35,103,,4
  642. ./interprocess/allocators/detail/node_pool.hpp,SegmentManager,class,,39,72,,16
  643. ...
  644. </pre>
  645. <p>Files with csv format can be opened by applications, like Microsoft Office Excel, with advanced analysis capabilities.
  646. For example, to draw this distribution graph:</p>
  647. <p align="center"><img src="assets/img/piechart.png"/></p>
  648. <p>It is not recommended to use the export tool to implement custom post-analysis Metrix++ extensions.
  649. The main reason is that granted backward compatibility support for csv columns is not granted.
  650. Another main reason is that
  651. exporting is relatively slow process. It is recommended to use Metrix++ extensions API instead.</p>
  652. </section>
  653. </div> <!-- end for sections -->
  654. </div></div> <!-- end for row and container -->
  655. <!-- Footer
  656. ================================================== -->
  657. <footer class="footer">
  658. <div class="container">
  659. <div class="row">
  660. <div class="span3">
  661. <p><a href="http://sourceforge.net/projects/metrixplusplus/"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=275605&amp;type=3"
  662. alt="Get Metrix++ at SourceForge.net. Fast, secure and Free Open Source software downloads" border="0"></a></p>
  663. <p>&middot;</p>
  664. <p>&middot; &middot;<script type="text/javascript" src="http://www.ohloh.net/p/485947/widgets/project_users_logo.js"></script></p>
  665. <p><a href="http://freecode.com/projects/metrix"><img src="assets/img/fm_logo.png" width="130"></a></p>
  666. <p>&middot;</p>
  667. <p><a href="http://www.softpedia.com/progClean/Metrix-Clean-241097.html"><img src="assets/img/softpedia_free_award_f.gif" width="147" /></a></p>
  668. </div>
  669. <div class="span9">
  670. <p>Copyright <strong>&copy;</strong> 2009 - 2013, <a href="mailto:avkonst@users.sourceforge.net"><span class="normalImportance">Metrix++</span> Project</a></p>
  671. <p>Code licensed under <a href="http://www.gnu.org/licenses/gpl.txt" target="_blank">GPL 3.0</a>, documentation under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
  672. <ul class="footer-links">
  673. <li><a href="https://sourceforge.net/p/metrixplusplus/tickets/new/">Ask question</a></li>
  674. <li class="muted">&middot;</li>
  675. <li><a href="https://sourceforge.net/p/metrixplusplus/tickets/new/">Report defect</a></li>
  676. <li class="muted">&middot;</li>
  677. <li><a href="https://sourceforge.net/p/metrixplusplus/tickets/new/">Feature request</a></li>
  678. <li class="muted">&middot;</li>
  679. <li><a href="https://sourceforge.net/p/metrixplusplus/tickets/search/?q=%21status%3Awont-fix+%26%26+%21status%3Aclosed">Open issues</a></li>
  680. <li class="muted">&middot;</li>
  681. <li><a href="https://sourceforge.net/p/metrixplusplus/wiki/ChangeLog/">Changelog</a></li>
  682. </ul>
  683. </div>
  684. </div>
  685. </div>
  686. </footer>
  687. <!-- Le javascript
  688. ================================================== -->
  689. <!-- Placed at the end of the document so the pages load faster -->
  690. <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
  691. <script src="assets/js/jquery.js"></script>
  692. <script src="assets/js/bootstrap-transition.js"></script>
  693. <script src="assets/js/bootstrap-alert.js"></script>
  694. <script src="assets/js/bootstrap-modal.js"></script>
  695. <script src="assets/js/bootstrap-dropdown.js"></script>
  696. <script src="assets/js/bootstrap-scrollspy.js"></script>
  697. <script src="assets/js/bootstrap-tab.js"></script>
  698. <script src="assets/js/bootstrap-tooltip.js"></script>
  699. <script src="assets/js/bootstrap-popover.js"></script>
  700. <script src="assets/js/bootstrap-button.js"></script>
  701. <script src="assets/js/bootstrap-collapse.js"></script>
  702. <script src="assets/js/bootstrap-carousel.js"></script>
  703. <script src="assets/js/bootstrap-typeahead.js"></script>
  704. <script src="assets/js/bootstrap-affix.js"></script>
  705. <script>
  706. !function ($) {
  707. $(function(){
  708. // carousel demo
  709. $('#myCarousel').carousel()
  710. })
  711. }(window.jQuery)
  712. </script>
  713. <script src="assets/js/holder/holder.js"></script>
  714. <script src="assets/js/google-code-prettify/prettify.js"></script>
  715. <script src="assets/js/application.js"></script>
  716. <script>
  717. </script>
  718. <!-- Analytics
  719. ================================================== -->
  720. <!--
  721. <script>
  722. var _gauges = _gauges || [];
  723. (function() {
  724. var t = document.createElement('script');
  725. t.type = 'text/javascript';
  726. t.async = true;
  727. t.id = 'gauges-tracker';
  728. t.setAttribute('data-site-id', '4f0dc9fef5a1f55508000013');
  729. t.src = '//secure.gaug.es/track.js';
  730. var s = document.getElementsByTagName('script')[0];
  731. s.parentNode.insertBefore(t, s);
  732. })();
  733. </script>
  734. -->
  735. </body>
  736. </html>