JP2016143107A - Source code evaluation system and method - Google Patents

Source code evaluation system and method Download PDF

Info

Publication number
JP2016143107A
JP2016143107A JP2015016323A JP2015016323A JP2016143107A JP 2016143107 A JP2016143107 A JP 2016143107A JP 2015016323 A JP2015016323 A JP 2015016323A JP 2015016323 A JP2015016323 A JP 2015016323A JP 2016143107 A JP2016143107 A JP 2016143107A
Authority
JP
Japan
Prior art keywords
source code
pattern
metrics
refactoring
evaluation system
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
JP2015016323A
Other languages
Japanese (ja)
Other versions
JP6310865B2 (en
Inventor
中川 香織
Kaori Nakagawa
香織 中川
敬志 大島
Takashi Oshima
敬志 大島
大二郎 村田
Daijiro Murata
大二郎 村田
三部 良太
Ryota Sambe
良太 三部
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hitachi Ltd
Original Assignee
Hitachi Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hitachi Ltd filed Critical Hitachi Ltd
Priority to JP2015016323A priority Critical patent/JP6310865B2/en
Publication of JP2016143107A publication Critical patent/JP2016143107A/en
Application granted granted Critical
Publication of JP6310865B2 publication Critical patent/JP6310865B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

PROBLEM TO BE SOLVED: To provide an efficient program analysis method for specifying a source code in which factoring is truly necessary, without extracting a complicated source code in which refactoring is unnecessary.SOLUTION: A program analysis method includes steps of: measuring metrics from a source code/configuration management system/operation log; evaluating whether the source code is applicable to an anti pattern using the metrics measurement result; and calculating and presenting priority of refactoring on each source code using the metrics measurement result.SELECTED DRAWING: Figure 1

Description

本発明は、エンタープライズシステム(業務システム)の評価に関する。その中でも、アプリケーションの保守性向上のためのソースコード評価に関する。   The present invention relates to evaluation of enterprise systems (business systems). Among them, it relates to source code evaluation for improving maintainability of applications.

エンタープライズシステムのアプリケーションは場当たり的な機能追加によって時間経過と共にソースコードが複雑化することがある。複雑化するとシステムに機能追加・修正を行う際作業者は不良を入れ込みやすくなってしまう。この不良を入れ込みやすくなるソースコードの構造を「アンチパターン」という。アンチパターンはプログラミングの文法には問題なくコンパイルは通る。   Enterprise system applications may become complicated over time due to the addition of ad hoc functions. When it becomes complicated, it becomes easy for an operator to introduce defects when adding or correcting functions in the system. The structure of the source code that makes it easy to insert defects is called “anti-pattern”. The anti-pattern compiles without any problem in the programming grammar.

しかし、可読性・保守性が悪化し、作業者がソースコードに書かれている処理フローの理解を間違えたり、機能追加・修正の作業の抜け漏れを誘発するよう構造になっている。アンチパターンはすぐにはシステム障害を引き起こしはしないが、放置すると後のシステム障害の原因になりうる。   However, readability and maintainability deteriorate, and the structure is such that the operator may make a mistake in understanding the processing flow written in the source code, or induce omission of work for adding or correcting functions. Anti-patterns do not cause system failures immediately, but if left unchecked, they can cause system failures later.

アンチパターンには特徴によって知られているものだけでも数十種類存在する。例えば、「1メソッドが長すぎる」アンチパターンや、「引数が多すぎる」アンチパターンなどである。これら特徴に分類したアンチパターンそれぞれを「アンチパターン因子」と呼ぶ。   There are dozens of anti-patterns that are known only for their characteristics. For example, an anti-pattern “one method is too long” or an anti-pattern “too many arguments”. Each anti-pattern classified into these features is called an “anti-pattern factor”.

ソースコードに存在するアンチパターン因子を修正することをリファクタリングという。リファクタリング作業は大量のソースコードを読み、アンチパターン因子を抽出し、アンチパターン因子の特徴に合った方法でリファクタリングを行う。これは多大な工数がかかるだけでなく、リファクタリング作業者に高いスキルが必要である。   Modifying the anti-pattern factor that exists in the source code is called refactoring. In the refactoring work, a large amount of source code is read, anti-pattern factors are extracted, and refactoring is performed according to the characteristics of the anti-pattern factors. This not only takes a lot of man-hours, but also requires high skills for refactoring workers.

そこで、ソースコードに存在するアンチパターン因子の特徴を自動的に抽出し、少ない工数でアンチパターン抽出・リファクタリング作業を行う技術の研究がなされている。例えば特許文献1や2ではサイクロマティック複雑度やコード行数といった、ソースコードの複雑度を定量的に評価するメトリクスを利用し、その計測結果から複雑度の高いモジュールを抽出・提示している。さらにその複雑度の度合いや複雑性に起因するコストによってリファクタリングの優先度を提示する。   Therefore, research on a technique for automatically extracting features of anti-pattern factors existing in source code and performing anti-pattern extraction / refactoring operations with a small number of man-hours has been conducted. For example, Patent Documents 1 and 2 use metrics that quantitatively evaluate source code complexity such as cyclomatic complexity and the number of code lines, and extract and present modules with high complexity from the measurement results. Furthermore, the priority of refactoring is presented according to the degree of complexity and the cost due to the complexity.

WO2008/020468WO2008 / 020468 特開2014-032466JP2014-032466

上記の特許文献においては、複雑化されたソースコードへの対応が困難な場合が多い。ここで、ソースコードが複雑な理由は大きく二つある。一つは処理フローそのものが複雑で、ソースコードの構造が複雑にならざるを得ないもの。もう一つは運用開始当初は単純な構造のソースコードであったが、場当たり的な機能追加を繰り返してきたため複雑な構造になったものがある。前者はリファクタリングの必要はなく、後者はリファクタリングの必要がある。   In the above patent documents, it is often difficult to deal with complicated source code. Here, there are two main reasons why the source code is complicated. One is that the processing flow itself is complicated and the structure of the source code must be complicated. The other was source code with a simple structure at the beginning of operation, but there was a complicated structure due to repeated addition of functions on an ad hoc basis. The former need not be refactored and the latter needs to be refactored.

上記特許文献1,2においてはソースコードの複雑性にのみ着目している。そのため、リファクタリングの必要がある複雑なソースコードだけでなく、リファクタリングが必要ない複雑なソースコードも抽出してしまい、リファクタリング作業の効率を向上できない。   The above Patent Documents 1 and 2 focus only on the complexity of the source code. Therefore, not only complicated source code that needs refactoring but also complicated source code that does not require refactoring is extracted, and the efficiency of the refactoring work cannot be improved.

上記の課題を解決するために、本発明では、リファクタリングの必要があるソースコード、言い換えると複雑な構造のソースコードを抽出するものである。さらに、抽出したソースコードのアンチパターン因子の特徴からリファクタリング手法を提案し、リファクタリングの効果やコストの観点からモジュールごとのリファクタリング優先度を提示するものである。また、システムのログなど複数の資源から複数種類のメトリクス・情報を取得し、それを組み合わせて種々のアンチパターン因子が存在しているか否かを評価することも本発明の一態様である。   In order to solve the above problems, the present invention extracts source code that needs to be refactored, in other words, source code having a complicated structure. Furthermore, a refactoring method is proposed based on the characteristics of the extracted anti-pattern factor of the source code, and the refactoring priority for each module is presented from the viewpoint of the refactoring effect and cost. It is also an aspect of the present invention to acquire a plurality of types of metrics / information from a plurality of resources such as system logs and to evaluate whether various anti-pattern factors exist by combining them.

さらに、本発明の望ましい態様においては、構成管理システムからソースコードの各モジュール(クラス)単位におけるメトリクス取得手段と、ソースコードの各バージョン間の差分を取得し、差分部についてのメトリクス取得手段と、構成管理システムログについてのメトリクス取得手段と、稼動ログについてのメトリクス計測手段と、取得したメトリクス値から各種アンチパターン因子に該当するか否かを評価する手段と、該当したアンチパターン因子の種類からリファクタリング手法を提案する手段と、リファクタリング優先度を算出する手段と、リファクタリング手段・優先度を画面に表示する。   Furthermore, in a desirable aspect of the present invention, metrics acquisition means in each module (class) unit of the source code from the configuration management system, a difference between each version of the source code, and metrics acquisition means for the difference unit, Metric acquisition means for configuration management system log, metrics measurement means for operation log, means for evaluating whether or not it corresponds to various anti-pattern factors from the obtained metric values, and refactoring from the types of applicable anti-pattern factors A means for proposing a method, a means for calculating refactoring priority, and a refactoring means / priority are displayed on the screen.

本発明によれば、大規模ソースコードに存在するアンチパターン因子を効率的により効率的に抽出可能になる。   According to the present invention, an anti-pattern factor existing in a large-scale source code can be extracted more efficiently and efficiently.

本発明の一実施の形態における機能構成図である。It is a functional block diagram in one embodiment of this invention. 本発明の一実施の形態における機能ブロック図である。It is a functional block diagram in one embodiment of the present invention. 本発明の一実施の形態における機能内のセンサ・メトリクス値テーブルの例を示す図である。It is a figure which shows the example of the sensor metric value table in the function in one embodiment of this invention. 本発明の一実施の形態における差分コードメトリクス値テーブルに格納されるデータの一例を示す図である。It is a figure which shows an example of the data stored in the difference code metric value table in one embodiment of this invention. 本発明の一実施の形態におけるソースコードメトリクス値テーブルに格納されるデータの一例を示す図である。It is a figure which shows an example of the data stored in the source code metric value table in one embodiment of this invention. 本発明の一実施の形態におけるアンチパターン評価の処理フローを示す図であるIt is a figure which shows the processing flow of the anti-pattern evaluation in one embodiment of this invention 本発明の一実施の形態で用いるアンチパターン因子1の特徴を示す図である。It is a figure which shows the characteristic of the anti-pattern factor 1 used by one embodiment of this invention. 本発明の一実施の形態で用いるアンチパターン因子1に対応するアンチパターン評価ロジック定義ファイルの一例を示す図である。It is a figure which shows an example of the anti-pattern evaluation logic definition file corresponding to the anti-pattern factor 1 used by one embodiment of this invention. 本発明の一実施の形態で用いるアンチパターン因子1に対応するアンチパターン評価利用メトリクス閾値定義ファイルの一例を示す図である。It is a figure which shows an example of the anti-pattern evaluation utilization metrics threshold value definition file corresponding to the anti-pattern factor 1 used by one embodiment of this invention. 本発明の一実施の形態で用いるアンチパターン因子2の特徴を示す図である。It is a figure which shows the characteristic of the anti-pattern factor 2 used by one embodiment of this invention. 本発明の一実施の形態で用いるアンチパターン因子2に対応するアンチパターン評価ロジック定義ファイルの一例を示す図である。It is a figure which shows an example of the anti-pattern evaluation logic definition file corresponding to the anti-pattern factor 2 used by one embodiment of this invention. 本発明の一実施の形態で用いるアンチパターン因子2に対応するアンチパターン評価利用メトリクス閾値定義ファイルの一例を示す図である。It is a figure which shows an example of the anti-pattern evaluation utilization metrics threshold value definition file corresponding to the anti-pattern factor 2 used by one embodiment of this invention. 本発明の一実施の形態におけるアンチパターン判定テーブルに格納されるデータの一例を示す図である。It is a figure which shows an example of the data stored in the anti-pattern determination table in one embodiment of this invention. 本発明の一実施の形態におけるアンチパターンリファクタリング手順テーブルに格納されるデータの一例を示す図である。It is a figure which shows an example of the data stored in the anti-pattern refactoring procedure table in one embodiment of this invention. 本発明の一実施の形態におけるリファクタリング手法案一覧テーブルに格納されるデータの一例を示す図である。It is a figure which shows an example of the data stored in the refactoring technique plan list table in one embodiment of this invention. 本発明の一実施の形態におけるリファクタリング手法・優先度一覧画面の一例を示す図である。It is a figure which shows an example of the refactoring method and priority list screen in one embodiment of this invention. 本発明の一実施の形態におけるアンチパターン評価ロジック定義ファイルを鑑みた効果的なセンサ実行のロジックを示す図である。It is a figure which shows the logic of the effective sensor execution in view of the anti-pattern evaluation logic definition file in one embodiment of this invention.

以下、本発明の一実施の形態について、図面を用いて説明する。まず、図1に本実施の形態によるソースコード評価システムの機能構成図を示す。計算機1はメモリ10と、HDD11と、CPU12と、表示装置13と、入力装置14とを備える。メモリ10は差分コードメトリクス取得部と、ソースコードメトリクス取得部と、構成管理ログメトリクス取得部と、稼動ログメトリクス取得部と、アンチパターン評価部と、リファクタリング方法提案部と、リファクタリング手法・優先度一覧画面表示部とを備える。これらは、すなわち、HDD11に格納された処理プログラムがメモリ10上に展開されたものであり、CPU12で演算が実行され、各機能が実現される。HDD11はソースコード格納部111と、稼動ログ格納部112と、差分コードメトリクス値テーブル格納部113と、ソースコードメトリクス値テーブル格納部114と、アンチパターン評価ロジック定義ファイル格納部115と、アンチパターン評価利用メトリクス閾値定義ファイル格納部116と、アンチパターン判断テーブル格納部117と、アンチパターンリファクタリング手順テーブル格納部118と、リファクタリング手法一覧テーブル格納部119とを備える。これらは、上述したメモリ10の各部、つまり、プログラムの各機能で用いる各種データがHDD11に保持されていることを示す。   Hereinafter, an embodiment of the present invention will be described with reference to the drawings. First, FIG. 1 shows a functional configuration diagram of a source code evaluation system according to the present embodiment. The computer 1 includes a memory 10, an HDD 11, a CPU 12, a display device 13, and an input device 14. The memory 10 includes a differential code metrics acquisition unit, a source code metrics acquisition unit, a configuration management log metrics acquisition unit, an operation log metrics acquisition unit, an anti-pattern evaluation unit, a refactoring method proposal unit, a refactoring method / priority list. A screen display unit. In other words, the processing program stored in the HDD 11 is expanded on the memory 10, and the CPU 12 performs calculations to realize each function. The HDD 11 includes a source code storage unit 111, an operation log storage unit 112, a differential code metrics value table storage unit 113, a source code metrics value table storage unit 114, an anti-pattern evaluation logic definition file storage unit 115, and an anti-pattern evaluation A usage metrics threshold value definition file storage unit 116, an anti-pattern determination table storage unit 117, an anti-pattern refactoring procedure table storage unit 118, and a refactoring technique list table storage unit 119 are provided. These indicate that each part of the memory 10 described above, that is, various data used for each function of the program is held in the HDD 11.

図2に本発明の実施の形態によるソースコード評価システムの機能ブロック図を示す。つまり、上述したプログラムの各機能の概要を説明する。
ソースコード格納部111は、ソフトウェア構成管理システムである。ソースコードのバージョン管理や変更の記録など行っている。差分コードメトリクス取得部101は、ソースコード格納部111からあるバージョンのソースコードのクラスと1つ前のバージョンのクラスを取得し、差分の有無を算出する。差分がある場合、コード行数やネスト数などのメトリクス計測を行い、その結果を差分コードメトリクス値テーブル格納部113に出力する。また、ソースコードメトリクス取得部102は、ソースコード格納部111から各バージョンの各クラスを取得し、メトリクス計測を行いその結果をソースコードメトリクス値テーブル格納部114へ出力する。構成管理ログメトリクス取得部103はソースコード修正日などの変更履歴に関連する情報取得を行い、その結果をソースコードメトリクス値テーブル格納部114へ出力する。
FIG. 2 shows a functional block diagram of the source code evaluation system according to the embodiment of the present invention. That is, an overview of each function of the above-described program will be described.
The source code storage unit 111 is a software configuration management system. Source code version management and change recording. The difference code metrics acquisition unit 101 acquires a source code class of a certain version and a class of the previous version from the source code storage unit 111, and calculates the presence / absence of a difference. When there is a difference, metrics such as the number of code lines and the number of nesting are measured, and the result is output to the difference code metrics value table storage unit 113. Further, the source code metrics acquisition unit 102 acquires each class of each version from the source code storage unit 111, performs metrics measurement, and outputs the result to the source code metrics value table storage unit 114. The configuration management log metrics acquisition unit 103 acquires information related to the change history such as the source code modification date, and outputs the result to the source code metrics value table storage unit 114.

稼動ログ格納部112は、システム資源の負荷の大きさやシステム障害などのシステムの稼動状況の履歴ログを格納する。稼働ログメトリクス取得部104は稼働ログ格納部112から稼働ログを取得し、障害発生日などの情報を抽出しその結果を出力する。
差分コードメトリクス取得部101と、ソースコードメトリクス取得部102と、構成管理ログメトリクス取得部103と、稼働ログメトリクス取得部104とはシステム資源からアンチパターン評価に必要な情報をとる機能であることから、まとめて「センサ部」と定義する。また各種メトリクス・情報を取得する個々の機能を「センサ」と呼ぶ。
The operation log storage unit 112 stores a history log of system operation status such as the load of system resources and system failures. The operation log metrics acquisition unit 104 acquires an operation log from the operation log storage unit 112, extracts information such as the date of failure, and outputs the result.
The differential code metrics acquisition unit 101, the source code metrics acquisition unit 102, the configuration management log metrics acquisition unit 103, and the operation log metrics acquisition unit 104 are functions that take information necessary for anti-pattern evaluation from system resources. These are collectively defined as “sensor unit”. The individual functions for acquiring various metrics and information are called “sensors”.

図3にセンサとセンサに必要なパラメータ、そしてセンサが出力する値の形式の一例を示す。センサの列には取得するメトリクス・情報の種類が記述されている。パラメータの列にはセンサを実行させる際必要なソースコードの情報の形式が記述されている。値の列はセンサ実行の結果出力される値の形式が記述されている。取得手段の列はセンサが101、102、103、104のうちどこの機能によるものなのかが記述されている。   FIG. 3 shows an example of a sensor, parameters necessary for the sensor, and a format of a value output from the sensor. The type of metrics and information to be acquired is described in the sensor column. The parameter column describes the information format of the source code necessary for executing the sensor. The value column describes the format of the value output as a result of sensor execution. The column of the acquisition means describes which function the sensor 101, 102, 103, 104 is from.

図4に、差分コードメトリクス取得部101で出力され差分コードメトリクス値テーブル格納部113に格納されるテーブルの形式の一例を示す。テーブルはソースコードの各クラスごとに作成される。あるクラスのテーブル内の”バージョン差分”行にはどのバージョンとどのバージョンのクラスの差分をとっているかが示されており、その差分部のメトリクス値が格納されている。   FIG. 4 shows an example of the format of a table output from the differential code metrics acquisition unit 101 and stored in the differential code metrics value table storage unit 113. A table is created for each class of source code. A “version difference” line in a table of a class indicates which version and which version of the class are taken, and the metric value of the difference part is stored.

図5にソースコードメトリクス取得部102と、構成管理ログメトリクス取得部103と、稼働ログメトリクス取得部104とが出力し、ソースコードメトリクス値テーブル格納部114に格納されているテーブルの形式の一例を示す。テーブルはソースコードの各クラスごとに作成される。あるクラスのテーブル内の”バージョン”行にはバージョン番号が示されており、それぞれのバージョンでのメトリクス値が格納されている。
アンチパターン評価部105、は各クラスが各種アンチパターン因子に該当するか否かを評価する機能を備える。
FIG. 5 shows an example of a table format output from the source code metrics acquisition unit 102, the configuration management log metrics acquisition unit 103, and the operation log metrics acquisition unit 104 and stored in the source code metrics value table storage unit 114. Show. A table is created for each class of source code. A version number is indicated in the “version” line in a table of a class, and a metric value in each version is stored.
The anti-pattern evaluation unit 105 has a function of evaluating whether each class corresponds to various anti-pattern factors.

図6に、アンチパターン評価部105における処理フローを示す。ステップ1051から実行される。ステップ1051では、アンチパターン評価ロジック定義ファイル格納部115から評価したいアンチパターン因子に対応するアンチパターン評価ロジック定義ファイルを取得する。ステップ1052では、アンチパターン評価利用メトリクス閾値定義ファイル格納部116から評価したいアンチパターン因子に対応するアンチパターン評価利用メトリクス閾値定義ファイルを取得する。ステップ1053では、ステップ1051で取得したアンチパターン評価ロジック定義ファイルからアンチパターン評価に用いるメトリクス値を把握し、それを差分コードメトリクス値テーブル格納部113と、ソースコードメトリクス値テーブル格納部114から取得する。ステップ1054では、ステップ1051で取得したアンチパターン評価ロジック定義ファイルに記されたロジックに従い、各クラスがアンチパターン因子に該当するか否かを判断する。ステップ1055で、もしあるクラスがアンチパターン因子に該当すると判明したなら、ステップ1056で、アンチパターン判定テーブル格納部117の該当アンチパターン因子の欄に「○」を格納する。ステップ1055で、もしあるクラスがアンチパターン因子に該当しないと判明したなら、ステップ1056で、アンチパターン判定テーブル格納部117の該当アンチパターン因子の欄に「×」を格納する。   FIG. 6 shows a processing flow in the anti-pattern evaluation unit 105. It is executed from step 1051. In step 1051, an anti-pattern evaluation logic definition file corresponding to the anti-pattern factor to be evaluated is acquired from the anti-pattern evaluation logic definition file storage unit 115. In step 1052, the anti-pattern evaluation utilization metrics threshold value definition file corresponding to the anti-pattern factor to be evaluated is acquired from the anti-pattern evaluation utilization metrics threshold value definition storage unit 116. In step 1053, the metric value used for anti-pattern evaluation is grasped from the anti-pattern evaluation logic definition file acquired in step 1051, and it is acquired from the differential code metric value table storage unit 113 and the source code metric value table storage unit 114. . In step 1054, it is determined whether each class corresponds to an anti-pattern factor according to the logic described in the anti-pattern evaluation logic definition file acquired in step 1051. If it is determined in step 1055 that a certain class corresponds to the anti-pattern factor, “◯” is stored in the corresponding anti-pattern factor column of the anti-pattern determination table storage unit 117 in step 1056. If it is determined in step 1055 that a certain class does not correspond to the anti-pattern factor, “x” is stored in the corresponding anti-pattern factor column of the anti-pattern determination table storage unit 117 in step 1056.

次に、評価対象であるアンチパターン因子1に該当するか否かを評価する処理の具体例を図7乃至図9を用いて説明する。
まず、図7にアンチパターン因子1の特徴を示す。アンチパターン因子1は業務共通クラスに個々の業務処理を場当たり的にif文で追加し、巨大になったクラスである。よって処理フローを追うのが複雑になり可読性が悪化しているアンチパターンである。これはコード規模が大きく、新バージョンソースコードは旧バージョンソースコードと比べ新たな差分が加わり、その差分がif文節であり、同じクラスのバージョン間での差分発生回数が多く、結果現状ソースコードのネスト数が大きい、という特徴を有している。
上記からアンチパターン因子1は、「コード行数」が100以上、「コード比較」で差分が存在し、「分岐」で差分がif文節であり、if文節の差分が5回以上あり、現状版ソースコードのネスト数が5以上であれば該当するというロジックとする。
Next, a specific example of processing for evaluating whether or not the anti-pattern factor 1 to be evaluated is applicable will be described with reference to FIGS.
First, FIG. 7 shows the characteristics of anti-pattern factor 1. Anti-pattern factor 1 is a class that has become huge by adding individual business processes to the business common class in an ad hoc manner. Therefore, the anti-pattern is complicated to follow the processing flow and the readability is deteriorated. This is because the code size is large, the new version source code adds a new difference compared to the old version source code, the difference is an if clause, the number of occurrences of differences between versions of the same class is large, the result of the current source code It has the feature that the number of nesting is large.
From the above, anti-pattern factor 1 has “code line count” of 100 or more, “code comparison” has a difference, “branch” has a difference of if clause, if clause has a difference of 5 or more, and current version If the number of nestings in the source code is 5 or more, the logic is that it corresponds.

図8に、上記ロジックを記述言語で示す。図8はアンチパターン評価ロジック定義ファイル格納部115に格納されている。
図8で記述されているロジックは以下の内容である。
FIG. 8 shows the above logic in a description language. FIG. 8 is stored in the anti-pattern evaluation logic definition file storage unit 115.
The logic described in FIG. 8 is as follows.

まず、アンチパターン評価を行うソースコードのクラスを宣言(特定)し、センサ「過去コード」を利用し対象クラスの過去バージョンのコードを宣言する。ここでは、各クラス、コードについて、対象となるもののすべてを特定するようにしてもよい。センサ「コード比較」を利用し1つのクラスの各バージョンの差分をとり、センサ「分岐」を利用し各差分が分岐文であるか否かを判定する。分岐文であれば判定値1、分岐文であれば判定値0と判定され、各差分の分岐文判定値の総和を導出する。その上で分岐文判定値の総和がi以上、かつ、センサ「コード行数」を利用し導出した最新のソースコードのコード行数がj以上、かつ、センサ「ネスト」を利用し導出した最新のソースコードのネスト数がk以上であればアンチパターン因子1に該当する。なお、i、j、kに入る値は、アンチパターン評価利用メトリクス閾値定義ファイル格納部内116で設定される。その内容を、以下で説明する。   First, a source code class for anti-pattern evaluation is declared (specified), and a past version code of the target class is declared using a sensor “past code”. Here, for each class and code, all of the target may be specified. The sensor “code comparison” is used to take the difference between versions of one class, and the sensor “branch” is used to determine whether each difference is a branch sentence. If it is a branch sentence, the judgment value is 1 and if it is a branch sentence, the judgment value is 0, and the sum of the branch sentence judgment values of each difference is derived. On top of that, the sum of branch statement judgment values is i or more, the number of code lines of the latest source code derived using sensor “number of code lines” is more than j, and the latest derived using sensor “nesting” If the source code nesting number is greater than or equal to k, it corresponds to anti-pattern factor 1. It should be noted that the values entering i, j, and k are set in the anti-pattern evaluation utilization metrics threshold value definition file storage unit 116. The contents will be described below.

図9は、上記ロジックで利用されているメトリクス閾値を定義したものである。図9はアンチパターン評価利用メトリクス閾値定義ファイル格納部116に格納されている。図8のロジック記述言語内で設定されたi、j、kのパラメータはそれぞれ分岐文の修正回数、上限行数、上限ネスト数である。アンチパターン因子1であると判定するための閾値はi、j、kそれぞれ5以上、100以上、4以上と設定されている。   FIG. 9 defines metrics thresholds used in the above logic. FIG. 9 is stored in the anti-pattern evaluation utilization metrics threshold value definition file storage unit 116. The i, j, and k parameters set in the logic description language of FIG. 8 are the number of branch statement corrections, the maximum number of rows, and the maximum number of nestings, respectively. The threshold values for determining the anti-pattern factor 1 are set to 5 or more, 100 or more, or 4 or more for i, j, and k, respectively.

さらに、アンチパターン因子2に該当するか否かを評価する処理の具体例を図10乃至図12を用いて説明する。
まず、図10にアンチパターン因子2の特徴を示す。アンチパターン因子2は機能追加の際、同じような処理を複数個所にif文で追加したものである。よって追加部を修正する際、他の同様の処理の箇所にも修正を行う必要があり、修正ミスの可能性があるアンチパターンである。これは、新バージョンソースコードは旧バージョンソースコードと比べ新たな差分が加わり、同じクラスのバージョン間での差分発生が複数回あり、その差分がif文節であり、その差分が他ソースコードとコードクローンである。
Further, a specific example of processing for evaluating whether or not the anti-pattern factor 2 is applicable will be described with reference to FIGS.
First, FIG. 10 shows the characteristics of anti-pattern factor 2. Anti-pattern factor 2 is obtained by adding the same processing to multiple places with if statements when adding functions. Therefore, when the additional portion is corrected, it is necessary to correct other similar processing portions, which is an anti-pattern that may cause a correction error. This is because the new version source code has a new difference compared to the old version source code, there are multiple differences between versions of the same class, the difference is an if clause, and the difference is the code from other source code. It is a clone.

上記からアンチパターン因子2は、「コード比較」で差分が存在し、「分岐」で差分はif文節が存在し、if文節の差分が2回以上あり、その差分がクローンであれば該当するというロジックとする。   From the above, anti-pattern factor 2 is applicable if there is a difference in “code comparison”, if there is an if clause in “branch”, if there is a difference in if clause more than once, and the difference is a clone Use logic.

次に、図11に上記ロジックを記述言語で示す。図11はアンチパターン評価ロジック定義ファイル格納部115に格納されている。
図11で記述されているロジックは以下の内容である。
最初にアンチパターン評価を行うソースコードクラスを宣言し、センサ「過去コード」を利用し対象クラスの過去バージョンのコードを宣言する。ここでは、各クラス、コードについて、対象となるもののすべてを特定するようにしてもよい。
Next, FIG. 11 shows the above logic in a description language. FIG. 11 is stored in the anti-pattern evaluation logic definition file storage unit 115.
The logic described in FIG. 11 is as follows.
First, declare the source code class for anti-pattern evaluation, and declare the past version of the target class using the sensor “past code”. Here, for each class and code, all of the target may be specified.

まず、センサ「コード比較」を利用し1つのクラスの各バージョンの差分をとり、センサ「分岐」を利用し各差分が分岐文であるか否かを判定する。分岐文であれば判定値1、分岐文であれば判定値0と判定され、各差分の分岐文判定値の総和を導出する。さらに、センサ「クローン」を利用し各差分がコードクローンであるかを検査する。その上で、分岐文判定値の総和かm以上、かつ、差分がクローンであればアンチパターン因子2に該当する。なお、mに入る値は、アンチパターン評価利用メトリクス閾値定義ファイル格納部内116で設定される。これらについて、以下で説明する。   First, the difference between each version of one class is obtained using the sensor “code comparison”, and it is determined whether each difference is a branch sentence using the sensor “branch”. If it is a branch sentence, the judgment value is 1 and if it is a branch sentence, the judgment value is 0, and the sum of the branch sentence judgment values of each difference is derived. Further, it is checked whether each difference is a code clone using a sensor “clone”. In addition, if the sum of branch sentence determination values is m or more and the difference is a clone, it corresponds to anti-pattern factor 2. Note that the value entering m is set in the anti-pattern evaluation utilization metrics threshold value definition file storage unit 116. These will be described below.

図12は、上記ロジックで利用されているメトリクス閾値を定義したものである。図12はアンチパターン評価利用メトリクス閾値定義ファイル格納部116に格納されている。図11のロジック記述言語内で設定されたmのパラメータはコード修正回数である。アンチパターン因子1であると判定するための閾値はmが2以上と設定されている。
図13に、アンチパターン評価部105から出力されアンチパターン判定テーブル格納部117に格納されるテーブルの例を示す。各クラスが各種アンチパターン因子に該当していれば「○」、該当していなければ「×」が格納されている。
FIG. 12 defines a metric threshold used in the logic. FIG. 12 is stored in the anti-pattern evaluation utilization metrics threshold definition file storage unit 116. The parameter m set in the logic description language of FIG. 11 is the number of code corrections. The threshold for determining that the anti-pattern factor is 1 is set such that m is 2 or more.
FIG. 13 shows an example of a table output from the anti-pattern evaluation unit 105 and stored in the anti-pattern determination table storage unit 117. “○” is stored if each class corresponds to various anti-pattern factors, and “X” is stored otherwise.

次に、図14に、アンチパターン因子ごとのリファクタリング手順と過去の実績から計算した1Kstepあたりのリファクタリング想定工数のテーブルの例を示す。このテーブルはアンチパターンリファクタリング手順テーブル格納部118に格納されている
ここで、リファクタリング方法提案部106は、アンチパターン判定テーブル格納部117から図13のテーブルと、アンチパターンリファクタリング手順テーブル格納部118から図14のテーブルと、ソースコードメトリクス値テーブル格納部114から各クラスの障害発生回数とを取得し、リファクタリング要素一覧テーブルを作成する。
Next, FIG. 14 shows an example of a table of a refactoring procedure for each anti-pattern factor and a refactoring estimated man-hour per 1 Kstep calculated from past results. This table is stored in the anti-pattern refactoring procedure table storage unit 118. Here, the refactoring method proposing unit 106 includes the anti-pattern determination table storage unit 117 to the table of FIG. 13 and the anti-pattern refactoring procedure table storage unit 118 of FIG. The table 14 and the number of failure occurrences of each class are acquired from the source code metric value table storage unit 114, and a refactoring element list table is created.

次に、図15にリファクタリング方法提案部106で作成され、リファクタリング要素一覧テーブル格納部に格納されたリファクタリング要素一覧テーブルの一例を示す。各クラスが各種アンチパターン因子に該当するか否を示す欄と、各クラスの1年あたりの障害発生回数を示す欄と、クラス各々に該当するアンチパターン因子の種類からどのようなリファクタリング手法をとるべきか提示する欄と、各クラスのリファクタリング想定工数を各クラスのステップ数にあわせて計算し示す欄とがある。
図16に、リファクタリング手法・優先度一覧画面表示部107で表示される内容の一例を示す。画面にはそのプロジェクトの運用予定期間を入力する欄と、そのプロジェクトにおいて1回の障害修正にかかるコストを入力する欄とがあり、さらに、リファクタリング優先度ランキング番号を示す欄と、クラス名を示す欄と、各クラスに存在するアンチパターン因子の種類を示す欄と、各クラスのとるべきリファクタリング手法を提示する欄と、リファクタリング優先度評価値を示す欄とを有するテーブルが表示されている。
リファクタリング優先度評価値は以下の式で導出する。
リファクタリング 優先度評価値=リファクタリング効果−リファクタリング工数
={年平均障害発生回数(回/365日)
×運用予定期間(日)
×1回の障害修正にかかるコスト(人月/回)}
− リファクタリング想定工数(人月)…(数1)
リファクタリング優先度ランキングは、リファクタリング工数に対してリファクタリング効果が大きいクラス、つまりリファクタリング優先度評価値が大きいクラスの優先度が高くなるように順位づけし、表示する。
Next, FIG. 15 shows an example of the refactoring element list table created by the refactoring method proposing unit 106 and stored in the refactoring element list table storage unit. What refactoring method to use based on the type of anti-pattern factor that corresponds to each class, the column that shows whether each class falls under various anti-pattern factors, the column that shows the number of failures per year for each class, and There is a column for indicating whether or not to be calculated, and a column for calculating and indicating the refactoring man-hours of each class according to the number of steps of each class.
FIG. 16 shows an example of contents displayed on the refactoring technique / priority list screen display unit 107. The screen has a field for entering the planned operation period of the project, a field for entering the cost for one fault correction in the project, a field for indicating the refactoring priority ranking number, and a class name. A table having a column, a column indicating the type of anti-pattern factor existing in each class, a column indicating a refactoring technique to be taken by each class, and a column indicating a refactoring priority evaluation value is displayed.
The refactoring priority evaluation value is derived by the following formula.
Refactoring Priority evaluation value = Refactoring effect-Refactoring man-hours
= {Number of annual average failures (times / 365 days)
× Operation period (days)
× Costs required for correcting one failure (person month / time)}
− Estimated man-hours for refactoring (person month)… (Equation 1)
In the refactoring priority ranking, a class having a large refactoring effect with respect to the refactoring man-hour, that is, a class having a large refactoring priority evaluation value is ranked and displayed so as to have a high priority.

図17に101、102、103、104のセンサ部の実行を効率的に行うための処理フローを示す。ステップ1001から実行される。ステップ1001では、アンチパターン評価ロジック定義ファイル格納部115からアンチパターン評価ロジック定義ファイルを読み込み、アンチパターン評価に必要なメトリクスの種類を取得する。ステップ1002ではアンチパターン評価利用メトリクス閾値定義ファイル格納部116からアンチパターン因子評価に必要なメトリクスの閾値の判定条件を取得する。ステップ1003では、取得したメトリクスの中で、102の機能のみでアンチパターンか否かを判断できるメトリクスを列挙する。ステップ1004では、各クラスの上記メトリクス計測を行う。ステップ1005では、ステップ1004で得られたメトリクス値に対して、ステップ1002で得られた閾値の判定条件を利用して閾値判定を行う。   FIG. 17 shows a processing flow for efficiently executing the sensor units 101, 102, 103, and 104. It is executed from step 1001. In step 1001, the anti-pattern evaluation logic definition file is read from the anti-pattern evaluation logic definition file storage unit 115, and the metric type necessary for the anti-pattern evaluation is acquired. In step 1002, the metrics threshold value determination conditions necessary for the anti-pattern factor evaluation are acquired from the anti-pattern evaluation utilization metrics threshold definition file storage unit 116. In step 1003, the metrics that can be determined whether or not the anti-pattern is only the function 102 are listed from the obtained metrics. In step 1004, the metrics of each class are measured. In step 1005, threshold determination is performed on the metric value obtained in step 1004 using the threshold determination condition obtained in step 1002.

ステップ1006で、もし閾値判定の結果、判定条件に合致していれば、ステップ1007でそのクラスは以後メトリクス計測対象であると判定され、アンチパターン評価部105において計測対象となる。一方ステップ1006で、もし閾値判定の結果、判定条件に合致してなければ、ステップ1008でそのクラスは以後メトリクス計測対象外であると判定され、アンチパターン評価部105において計測対象とはならない。
なお、上記のセンサ実行の処理フローを用いることで、アンチパターン評価部105において対象となるクラスの数を絞り込むことができ、効率的である。
In step 1006, if the result of the threshold determination is that the determination condition is met, the class is determined to be a metric measurement target in step 1007 and becomes a measurement target in the anti-pattern evaluation unit 105. On the other hand, if it is determined in step 1006 that the threshold value does not match the determination condition, it is determined in step 1008 that the class is not subject to metrics measurement, and the anti-pattern evaluation unit 105 does not measure it.
In addition, by using the above-described sensor execution process flow, the anti-pattern evaluation unit 105 can narrow down the number of target classes, which is efficient.

以上、本発明の一実施形態によれば、アンチパターン因子の抽出を、少ない工数かつ高精度で抽出することが可能である。またアンチパターン因子抽出・リファクタリングの作業者が熟練者でなくても容易にそれを行うことができる。   As described above, according to an embodiment of the present invention, it is possible to extract an anti-pattern factor with a small number of steps and with high accuracy. Moreover, even if the operator of anti-pattern factor extraction / refactoring is not an expert, it can be performed easily.

1…計算機、10…メモリ、11…HDD、12…CPU、13…表示装置、14…入力装置、101…差分コードメトリクス取得部、102…ソースコードメトリクス取得部、103…構成管理ログメトリクス取得部、104…稼働ログメトリクス取得部、105…アンチパターン評価部、106…リファクタリング方法提案部、107…リファクタリング手法・優先度一覧画面表示部、111…ソースコード格納部、112…稼働ログ格納部、113…差分コードメトリクス値テーブル格納部、114…ソースコードメトリクス値テーブル格納部、115アンチパターン評価ロジック定義ファイル格納部、116…アンチパターン評価利用メトリクス閾値定義ファイル格納部、117…アンチパターン判定テーブル格納部、118…アンチパターンリファクタリング手順テーブル格納部、119…リファクタリング要素一覧テーブル格納部 DESCRIPTION OF SYMBOLS 1 ... Computer, 10 ... Memory, 11 ... HDD, 12 ... CPU, 13 ... Display apparatus, 14 ... Input device, 101 ... Difference code metrics acquisition part, 102 ... Source code metrics acquisition part, 103 ... Configuration management log metrics acquisition part , 104 ... Operation log metrics acquisition unit, 105 ... Anti-pattern evaluation unit, 106 ... Refactoring method proposal unit, 107 ... Refactoring method / priority list screen display unit, 111 ... Source code storage unit, 112 ... Operation log storage unit, 113 ... difference code metrics value table storage unit, 114 ... source code metrics value table storage unit, 115 anti-pattern evaluation logic definition file storage unit, 116 ... anti-pattern evaluation utilization metrics threshold definition file storage unit, 117 ... anti-pattern determination table storage unit , 118 ... Anne Pattern refactoring procedure table storage unit, 119 ... refactoring element list table storage unit

Claims (5)

システムで用いられるプログラムを分析し、当該プログラムのアンチパターンを抽出するソースコード評価システムにおいて、
前記システムのソースコードを含む稼働に関する情報からメトリクスを計測する手段と、
前記計測されたメトリクスを用いて、前記ソースコードがアンチパターンの該当可否をその複雑さ示す指標を用いて評価する手段と、
前記評価された結果について、前記ソースコードのリファクタリングの優先度を算出・提示する手段を有することを特徴とするソースコード評価システム
In a source code evaluation system that analyzes a program used in the system and extracts an anti-pattern of the program,
Means for measuring metrics from information about operation including source code of the system;
Means for evaluating, using the measured metrics, an index indicating the complexity of whether or not the source code is an anti-pattern;
A source code evaluation system comprising means for calculating and presenting a priority of refactoring of the source code for the evaluated result
請求項1に記載のソースコード評価システムにおいて、
前記メトリクスの項目を要素とし、前記アンチパターンを記述する手段をさらに有することを特徴とするソースコード評価システム。
The source code evaluation system according to claim 1,
The source code evaluation system further comprising means for describing the anti-pattern using the metrics item as an element.
請求項1に記載のソースコード評価システムにおいて、
前記ソースコードの各バージョン間の差分を取得し、取得された差分についてのメトリクスを取得する手段と、
取得された前記差分を用いて、前記ソースコードがアンチパターンの該当可否を評価する手段をさらに有することを特徴とするソースコード評価システム。
The source code evaluation system according to claim 1,
Means for obtaining a difference between each version of the source code and obtaining a metric for the obtained difference;
The source code evaluation system further comprising means for evaluating whether or not the source code corresponds to an anti-pattern using the acquired difference.
請求項1に記載のソースコード評価システムにおいて、
リファクタリング実施による障害発生削減効果とリファクタリング実施の際の工数を見積もり、当該見積もり結果からリファクタリング優先度を掲示する手段をさらに有することを特徴とするソースコード評価システム。
The source code evaluation system according to claim 1,
A source code evaluation system further comprising means for estimating an effect of reducing the occurrence of failure by performing refactoring and man-hours for performing refactoring, and posting a refactoring priority from the estimated result.
請求項1に記載のソースコード評価システムにおいて、
前記ソースコードから計測した前記メトリクスに基づいて、特定条件を満たすメトリクスの絞込みを行い、絞り込まれた前記メトリクスに基づいて、他のメトリクスの取得可否を判定する手段をさらに有することを特徴とするソースコード評価システム。
The source code evaluation system according to claim 1,
The source further comprising means for narrowing down metrics satisfying a specific condition based on the metrics measured from the source code, and determining whether or not other metrics can be acquired based on the narrowed metrics. Code evaluation system.
JP2015016323A 2015-01-30 2015-01-30 Source code evaluation system and method Active JP6310865B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2015016323A JP6310865B2 (en) 2015-01-30 2015-01-30 Source code evaluation system and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2015016323A JP6310865B2 (en) 2015-01-30 2015-01-30 Source code evaluation system and method

Publications (2)

Publication Number Publication Date
JP2016143107A true JP2016143107A (en) 2016-08-08
JP6310865B2 JP6310865B2 (en) 2018-04-11

Family

ID=56570461

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2015016323A Active JP6310865B2 (en) 2015-01-30 2015-01-30 Source code evaluation system and method

Country Status (1)

Country Link
JP (1) JP6310865B2 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110618926A (en) * 2018-06-19 2019-12-27 歌乐株式会社 Source code analysis method and source code analysis device
US11392371B2 (en) 2018-11-28 2022-07-19 Fujitsu Limited Identification of a partial code to be refactored within a source code

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2022186541A (en) * 2021-06-04 2022-12-15 株式会社日立製作所 Source code analysis apparatus and source code analysis method

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2009011056A1 (en) * 2007-07-19 2009-01-22 Fujitsu Limited Application improvement supporting program, application improvement supporting method, and application improvement supporting device
JP2009129355A (en) * 2007-11-27 2009-06-11 Hitachi Ltd Component division support device, its method, and program
JP2012230512A (en) * 2011-04-26 2012-11-22 Hitachi Ltd System for displaying correspondence table between change frequency in each function in source code and complexity

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2009011056A1 (en) * 2007-07-19 2009-01-22 Fujitsu Limited Application improvement supporting program, application improvement supporting method, and application improvement supporting device
JP2009129355A (en) * 2007-11-27 2009-06-11 Hitachi Ltd Component division support device, its method, and program
JP2012230512A (en) * 2011-04-26 2012-11-22 Hitachi Ltd System for displaying correspondence table between change frequency in each function in source code and complexity

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
秦野克彦、乃村能成、谷口秀夫、牛島和夫: "ソフトウェアメトリクスを利用したリファクタリングの自動化支援機構", 情報処理学会論文誌, vol. Vol.44,No.6, JPN6012024317, 15 June 2003 (2003-06-15), JP, pages p.1548−1557 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110618926A (en) * 2018-06-19 2019-12-27 歌乐株式会社 Source code analysis method and source code analysis device
US11392371B2 (en) 2018-11-28 2022-07-19 Fujitsu Limited Identification of a partial code to be refactored within a source code

Also Published As

Publication number Publication date
JP6310865B2 (en) 2018-04-11

Similar Documents

Publication Publication Date Title
Aranha et al. An estimation model for test execution effort
US9235494B2 (en) Automated code analyzer
US9621679B2 (en) Operation task managing apparatus and method
US10671061B2 (en) Devices, methods, and systems for a distributed rule based automated fault detection
US11347864B2 (en) Ace: assurance, composed and explained
US10871951B2 (en) Code correction
Kadry A new proposed technique to improve software regression testing cost
JP2017091329A (en) Database analysis device and database analysis method
JP2016167259A (en) Method and apparatus for analyzing availability of system, in particular of safety critical system
Joshi et al. FMEA and alternatives v/s enhanced risk assessment mechanism
Gitzel Data Quality in Time Series Data: An Experience Report.
JP6310865B2 (en) Source code evaluation system and method
US8589898B2 (en) Method and apparatus for analyzing software including a calibrated value
US9798605B2 (en) Supporting global effect analysis
CN111773728A (en) Data table testing method, device, equipment and storage medium
Duarte et al. PSP PAIR: automated personal software process performance analysis and improvement recommendation
US10387532B2 (en) Manufacturing control system, manufacturing control method, and manufacturing control program
Bala et al. Use of the multiple imputation strategy to deal with missing data in the ISBSG repository
JP2009301341A (en) Service system, service system management method, and program
JP5741265B2 (en) Program improvement support system
US9600245B2 (en) Computer-implemented method for generating control unit program code and message management environment relating thereto
US20220245475A1 (en) Automatically evaluating application architecture through architecture-as-code
JP6320269B2 (en) Software test support apparatus and software test support program
WO2016163008A1 (en) Fault diagnostic device and fault diagnostic method
WO2017212552A1 (en) Data processing device, data processing method, and data processing program

Legal Events

Date Code Title Description
RD04 Notification of resignation of power of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7424

Effective date: 20170110

RD04 Notification of resignation of power of attorney

Free format text: JAPANESE INTERMEDIATE CODE: A7424

Effective date: 20170112

A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20170321

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20180112

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20180220

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20180319

R150 Certificate of patent or registration of utility model

Ref document number: 6310865

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150