功能单元最大扇入扇出工具分析

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

文档名称:功能单元最大扇入扇出工具分析作者:日期:1.概念由于度量的目标是C源代码,所以“功能单元的最大扇入扇出”的含义如下:功能单元:c语言的函数。扇入:有多少其他函数调用了A函数。扇出:A函数调用了多少其他函数。2cFlow2.1工具简介度量工具名称cFlow网址操作方式命令行实现语言C适用的操作系统linux可以度量的属性备注可作为Fan-in、Fan-out度量的参考GNU计划,又称革奴计划,是由RichardStallman在1983年9月27日公开发起的。它的目标是创建一套完全自由的操作系统。RichardStallman最早是在net.unix-wizards新闻组上公布该消息,并附带一份《GNU宣言》等解释为何发起该计划的文章,其中一个理由就是要“重现当年软件界合作互助的团结精神”。为保证GNU软件可以自由地“使用、复制、修改和发布”,所有GNU软件都在一份在禁止其他人添加任何限制的情况下授权所有权利给任何人的协议条款,GNU通用公共许可证(GNUGeneralPublicLicense,GPL)。即“反版权”(或称Copyleft)概念。2.2工具优缺点总结cflow程序会输出一个函数调用树,这是一个显示函数调用关系的图表。这对于查看程序结构来了解他是如何操作的以及了解对于一个函数有哪些影响是十分有用的。一些版本的cflow可以同时作用于目标文件与源代码。查看手册页我们可以了解更为详细的操作。GNU官方的一个工具,最大的优点是成熟、可靠。但源代码比较难读懂。GNU的东西,封装性、技巧性比较强。2.3使用例程1.下载源代码2.解压3../configure4.make5.makeinstall6.cflowtes.cmain()intmain()attest-cflow.c:17:printf()do_something_firstly()voiddo_something_firstly()attest-cflow.c:4:malloc()free()do_something_finally()voiddo_something_finally()attest-cflow.c:12:printf()7.输出结果2.4核心代码抽取通过此工具的源代码,可以获取匹配函数定义语句的功能,函数调用关系的功能,从来实现fan-in,fan-out度量。3CandC++CodeCounter3.1工具简介度量工具名称CandC++CodeCounter网址操作方式命令行实现语言C++适用的操作系统Win32、Linux可以度量的属性LOCMVCCOMLOC/COMMVG/COMFan-outFan-inHKSNOMWMCREJ备注开源,有源代码,可分析后在基础上修改3.2工具优缺点总结功能强大,基本能够进行所有的静态度量。支持c语言。缺点:源代码比较复杂,研读需要时间。并不支持函数的扇入扇出。4.3实例1.实例代码:#includestdio.h/*testexample*/intf1(){inta=1,b=2;if(a==1)a=4;else{if(b==2){a=4;}}return1;}intf2(){return1;}intf3(){f1();f2();return1;}main(){inta=10;f1();f2();f3();}2.安装cccc官方网站下载安装文件3.执行度量4.查看结果F3调用了f1,f2,但度量结果,并没有反应出来。4.4分析扇出扇出的分析:Fan-In,Fan-Out(FI,FIc,FIv,FO,FOc,FOv)Traditionally,userelationshipsbetweenmoduleswereidentifiedbycountingfunctioninvocationsoraccesstomoduledatainproceduralcode.CCCCidentifiesrelationshipsonlythroughstructuresapparentinthedefinitionsoftheinterfacesofC++classesorJavaclassesorinterfaces.Thespecificrelationshipswhichcanbedetectedareinheritanceofasupplierclassbyaclient,containmentofaninstanceofasupplierclassinaclient,andtheexistenceofmemberfunctionsoftheclientclasswhichacceptorreturnaninstanceofthesupplier.Whiletheserelationshipsmayseemunrelatedtotheinvocationandmoduledatacounts,theyarelikelytoshowastrongcorelationbecauseofthefactthatinanobjectorientedenvironment,itislikely(butnotinevitable)thatthelow-leveluserelationshipsofinvocationanddirectaccesstodatastructuresrequireanobjectoftheclassofthesuppliermoduletobeavailable.Thisavailabilitycanbethroughinstantiationofaninstanceofthesupplierclasswithinproceduralcode,butwilloftenbeduetotheexistenceofoneofthehigherlevelrelationshipsdescribedabove.ThecountsofFan-InandFan-Outareregardedasameasureofthestructuralqualityofaprogram,withhighvaluesofeither(andparticularlyhighvaluesofbothwithinthesamemodule)indicatingincreasedriskofchangesrequiredinonemodulerequiringchangesacrossothermodules.CCCCchoosestodefinetherelationshipcountsinsuchawaythateachsupplierorclientmoduleiscountedonlyonce,howevermanyseparatewaystherelationshipisdetected.CCCCappliesfilteringtotherelationshipsidentifiedtodistinguishbetweendifferentkindsofuseswhichmaycarrywiththemdifferentlevelsofstructuralrisk.Therearetwofilters:visibilityandconcreteness.Thevisibilityfilterremovesfromconsiderationrelationshipswhichareknowntobeonlyaccessiblefromtheprivateinterfaceofamodule.Relationshipswhicharedefinedinthevisiblepartoftheinterfacecanbeexploitedbyclientsofthecurrentmodule,thusforcingthoseclientsalsotobeclientsofthecurrentmodule'ssupplier.Visiblerelationshipsalsoincreasetherangeofoperationsavailableonanobject,thusincreasingthecognitivecomplexityoftheinterfacefromthepointofviewofaprogrammerrequiredtouseamodule.Theconcretenessfilterremovesfromconsiderationrelationshipswhichdonotcreateadependencyoftheimplementationoftheclientmoduleontheimplementationofthesupplierclass.Dependency-creatingrelationshipsincreaseriskbecausetheymaynotbecyclical,andthusinhibitthecreationofotherrelationships.Theyalsoinhibittheabilityofmodulestobebuiltseparately,requiringrecompilationoftheclientmodulewhenthesupplierchanges.ThetestforthisfilterinC++iswhetheraforwarddeclarationofthesupplierclassisadequatetoallowtheclientmoduledefinitiontobecompiled:containmentandparameterpassingwheretheclientmoduleismodifiedbyareferentialoperatorareallowedinthiscase,containmentorpassingbyvalueorinheritancearealldependency-creating.InJava,relationshipsexceptinheritancearetreatedasnon-dependencycreating.通过上述cccc的原文,可以得知,cccc中的扇入扇出是关于类之间的。4结论计算java语言的圈复杂度工具有很多,例如CherryPick,LachesisAnalysis(eclipse的一个插件)。计算扇入扇出的主要技术点:1.确定函数定义部分2.确定函数调用fanout3.确定被调次数fanin可以通过cFlow和Cccc的源代码,尽量抽取出来。

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功