Technical debt real-time early warning method and device, electronic equipment and storage medium
By building and updating the software system dependency graph and comparing code quality in real time, the problem of untimely identification of technical debts in software development is solved, rapid assessment and early warning is achieved, resource consumption and complexity are reduced, and technical debt management efficiency is improved.
Patent Information
- Application Number
- CN202411041259.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-08
AI Technical Summary
It is difficult for existing technology to identify and warn of technical debts in a timely manner during software development, resulting in an increase in debt accumulation and repair costs, and the existing real-time monitoring methods consume a lot of resources and are complex.
By obtaining the source code of the software program, building a system dependency graph, calculating code quality, and updating the dependency graph when the code changes, comparing quality changes in real time to issue a technical debt warning, reducing resource consumption and complexity.
It realizes rapid assessment of technical debts when code changes, prompt repairs are made, reducing resource consumption and complexity of the analysis process, and improving the efficiency and effectiveness of software technical debt management.
Smart Images

Figure CN118916072A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software maintenance technology, and in particular to a real-time warning method, device, electronic device and storage medium for technical debt. Background Art
[0002] Software technical debt refers to the potential problems or hidden dangers left behind by some quick or temporary solutions taken for short-term benefits or rapid delivery during the software development process. Similar to financial debt, software technical debt needs to be "repaid" in the future, otherwise it may have a negative impact on the quality and maintainability of the software.
[0003] In the daily development of software, technical debt may accumulate silently and thus be difficult to identify. The assessment of software technical debt can be roughly divided into two types from the time point before the end of software evolution: the first is the conventional method, which is to identify and quantify technical debt after the software evolution technology. This method has low initial investment and does not require continuous resource investment. It is only evaluated at a specific time point, but it has a certain lag and may have missed the best time to fix the software technical debt problem, resulting in the accumulation and deterioration of technical debt, which may require more time and resources to fix errors and failures, increasing the cost of debt repair. The second is real-time monitoring and early warning of code changes during the software evolution process; this method can remind developers to repair in time, prevent a large amount of debt from accumulating, and avoid the need for large-scale repairs in the later stage, but the large-scale code base and complex dependencies may make the analysis process very time-consuming, requiring a lot of resources, and increasing development costs. Summary of the invention
[0004] The embodiments of the present application provide a real-time warning method, device, electronic device and storage medium for technical debt, which are characterized by real-time and convenience, can detect and remind to repair problems at an early stage, reduce the resource consumption and complexity of the analysis process, and improve the efficiency and effectiveness of software technical debt management.
[0005] The present application provides a real-time warning method for technical debt, the method comprising:
[0006] Get the source code of the software;
[0007] constructing a first system dependency graph of the software;
[0008] Calculating a first quality of the software based on the program source code and the first system dependency graph;
[0009] Based on the code changes of the software, construct a second system dependency graph of the software;
[0010] Calculating a second quality of the software based on the program source code and the second system dependency graph;
[0011] The first quality and the second quality are compared to obtain a comparison result, and a technical debt warning result is obtained according to whether the comparison result meets a preset requirement.
[0012] In the real-time early warning method for technical debts described in this embodiment, the step of constructing the first system dependency graph of the software includes:
[0013] Extracting the path of each code in the source program of the software, and correspondingly generating a node with the path as an attribute;
[0014] Obtain the program source code, construct a first abstract syntax tree for each file source code therein, and extract a first dependency relationship based on the first abstract syntax tree;
[0015] Extracting all first statements associated with the first dependency and attributes of the first statements;
[0016] Traversing the attributes of nodes in the software, and locating a first node having the same attributes as any of the first statements;
[0017] A dependency edge between the first nodes is constructed, and the attributes of the first statements are used as attributes of the dependency edge.
[0018] In the real-time early warning method for technical debts described in this embodiment, the calculating the first quality of the software based on the program source code and the first system dependency graph includes:
[0019] Obtaining the number of code lines, the number of variables, the number of comment lines, and the number of decision points in the program source code;
[0020] Obtaining the cyclomatic complexity of the first system dependency graph;
[0021] A first quality of the software is calculated based on the number of code lines, the number of variables, the number of comment lines, the cyclomatic complexity, and the number of decision points.
[0022] In the real-time warning method for technical debts described in this embodiment, constructing the second system dependency graph of the software based on the code change of the software includes:
[0023] Recording changes to the software code, classifying them according to the change type, and obtaining different types of code change sets;
[0024] Periodically extract all said code change sets;
[0025] Based on the type of each of the code change sets, the first system dependency graph is updated to obtain a second system dependency graph.
[0026] In the technical debt real-time early warning method described in this embodiment, updating the first system dependency graph based on the type of each code change set includes:
[0027] If the type of the code change set is a deletion code, extracting paths of all deletion codes in the code change set;
[0028] Traverse the paths of the nodes in the first system dependency graph, determine whether the path of each node is the same as the path of the deletion code, and if so, calculate the forward slices of all variables in the current node, delete all dependency edges traversed by the forward slice, and delete the current node.
[0029] In the technical debt real-time early warning method described in this embodiment, updating the first system dependency graph based on the type of each code change set includes:
[0030] If the type of the code change set is newly added code, extracting the paths of all newly added codes in the code change set in the source program, and correspondingly generating a node with the path as an attribute in the first system dependency graph;
[0031] Construct a second abstract syntax tree based on the newly added code, and extract a second dependency relationship based on the second abstract syntax tree;
[0032] Extracting all second statements associated with the second dependency and attributes of the second statements;
[0033] Traversing the attributes of the nodes in the first system dependency graph, and locating a second node having the same attributes as any of the second statements;
[0034] Construct a dependency edge between the node corresponding to the newly added code and the second node.
[0035] In the technical debt real-time early warning method described in this embodiment, the comparing the first quality and the second quality to obtain a comparison result, and obtaining a technical debt early warning result according to whether the comparison result meets a preset requirement, includes:
[0036] The second quality is compared with the first quality to determine whether the comparison result exceeds a preset warning threshold, and if so, a technical debt warning is issued.
[0037] The present application also provides a real-time warning device for technical debts, including:
[0038] An acquisition unit, used for acquiring program source code of the software;
[0039] A first construction unit, used for constructing a first system dependency graph of the software;
[0040] A first calculation unit, configured to calculate a first quality of the software based on the program source code and the first system dependency graph;
[0041] A second construction unit, configured to construct a second system dependency graph of the software based on a code change of the software;
[0042] A second calculation unit, configured to calculate a second quality of the software based on the program source code and the second system dependency graph;
[0043] The early warning unit is used to compare the first quality and the second quality, obtain a comparison result, and obtain a technical debt early warning result according to whether the comparison result meets a preset requirement.
[0044] An embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor executes the real-time warning method for technical debt described in any of the above embodiments by calling the computer program stored in the memory.
[0045] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a computer, the computer executes the real-time warning method for technical debt as described in any of the above embodiments.
[0046] Beneficial effects:
[0047] The real-time warning method for technical debt in the embodiment of the present application can quickly obtain the impact of the changed code on the system dependency graph when the code is changed, thereby obtaining the technical debt assessment result of the software and making a real-time warning, overcoming the technical problems of untimely discovery of software technical debt and low real-time warning performance in the prior art, reducing the resource consumption and complexity of the analysis process, and improving the efficiency and effectiveness of software technical debt management. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can obtain other drawings based on these drawings without creative work.
[0049] Figure 1 A flowchart of a real-time warning method for technical debt provided in an embodiment of the present application.
[0050] Figure 2A schematic diagram of the structure of a real-time warning device for technical debt provided in an embodiment of the present application.
[0051] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0053] In the embodiment of the present application, the process of implementing the real-time warning of technical debt can be applied to electronic devices, which can be computers, mobile phones or other devices with processing capabilities.
[0054] In software development, technical debt may accumulate quietly and be difficult to identify. The assessment of technical debt can be divided into two methods before the end of software evolution: one is to identify and quantify technical debt after the software evolution. This method has a certain lag and may miss the best time to repair, resulting in debt accumulation and deterioration, and increasing repair costs. The second is real-time monitoring. For large-scale code bases and complex dependencies, the analysis process of this method is time-consuming and resource-intensive. Based on this, in an embodiment of the present application, a real-time early warning method is proposed from the perspective of software technical debt. When the code is changed, the impact of the changed code on the system dependency graph is quickly obtained, thereby obtaining the technical debt assessment results of the software and performing real-time early warning, thereby overcoming the technical problems of untimely discovery of software technical debt and low performance in real-time early warning in the prior art, reducing resource consumption and complexity of the analysis process, and improving the efficiency and effectiveness of software technical debt management.
[0055] See also Figure 1 , Figure 1 A flowchart of a method for real-time early warning of technical debt provided in an embodiment of the present application. The method for real-time early warning of technical debt may include the following steps:
[0056] S100: Obtaining the program source code of the software.
[0057] The latest source code of the program can be obtained by pulling it from a version control system or exporting it from a development environment.
[0058] S200: Constructing a first system dependency graph of the software.
[0059] Based on the obtained program source code, a first system dependency graph is constructed for describing the dependency relationship between the modules. In an embodiment of the present invention, in order to further accurately describe the dependency relationship, the method may further include the following steps:
[0060] S201: Extract the path of each code in the software in the source program, and correspondingly generate a node with the path as an attribute.
[0061] The path of each code can be recorded as path, which includes the file path, line number and function or method of the corresponding code. Path is used as the attribute of the node created for each code, so that the corresponding code line can be quickly located according to the path attribute.
[0062] S202: Obtain the program source code, construct a first abstract syntax tree for each file source code therein, and extract a first dependency relationship based on the first abstract syntax tree.
[0063] The first dependency relationship may be one or more. In the embodiments of the present invention, data dependency and control dependency are used as examples. Data dependency mainly refers to the dependency between two codes, where the definition or modification of a variable in one statement can affect the use of the variable in another code; control dependency mainly refers to the dependency between two codes, where the definition or modification of a variable in one statement can determine whether another code is executed. In other embodiments of the present invention, other dependency relationships may also be used, such as environmental dependency and external dependency.
[0064] S203: Extract all first statements associated with the first dependency relationships and attributes of the first statements.
[0065] Based on the data dependency and control dependency extracted in step S202, the statements and their attributes associated with the two dependencies are extracted respectively. The attributes of the two statements are recorded as path i and path j .
[0066] S204: Traverse the attributes of the nodes in the software, and locate the first node having the same attributes as any of the first statements.
[0067] Among them, all nodes in the software are visited to search for the attribute value of path i or path j Node.
[0068] S205: Construct dependency edges between the first nodes, and use the attributes of the first statements as attributes of the dependency edges.
[0069] Construct the above two attributes respectively as path i and path j The dependency edge between the nodes is recorded as <path i ,path j >.
[0070] Thus, a first system dependency graph is obtained.
[0071] S300: Calculating a first quality of the software based on the program source code and the first system dependency graph.
[0072] In an embodiment of the present invention, the first quality of the corresponding software is calculated by obtaining the number of code lines, the number of variables, the number of comment lines, and the cyclomatic complexity in the program source code and the first system dependency graph. Among them, the number of code lines refers to the total number of all non-blank lines and non-comment lines in the program source code file of the software; cyclomatic complexity is an indicator of software complexity, which is used to reflect the number of independent paths in the code; the number of decision points is the total number of codes containing control structures such as if, else if, switch, case, for, while, dowhile, etc.; the number of variables is the total number of local variables, global variables, function parameters and return values; the number of comment lines refers to the number of lines in the source code file used to explain, describe or record the code. The calculation formula for the first quality of the software is as follows:
[0073] Q = 171-5.2log 10 LOC-0.23*CC-16.2*log 10 (D / V)+50*log 10 (C / LOC)
[0074] Where Q is the first quality of the software, LOC is the number of lines of code, CC is the cyclomatic complexity, D is the number of decision points, V is the number of variables, and C is the number of comment lines.
[0075] Among the parameters in this formula, the number of code lines, the number of decision points, the number of variables, the number of comment lines and the number of decision points can all be obtained directly, while the cyclomatic complexity needs to be obtained through further calculation. Conventional calculation methods include calculating the cyclomatic complexity based on the system dependency graph or based on the number of decision points.
[0076] In the embodiment of the present invention, the calculation of cyclomatic complexity based on the system dependency graph is taken as an example. Another calculation method based on the number of decision points also has a clear calculation formula, which is not limited or specifically described here. Those skilled in the art can choose and use it at their own will. The formula for calculating cyclomatic complexity based on the system dependency graph is as follows:
[0077] CC=E-N+2P
[0078] Where CC is the cyclomatic complexity, E is the total number of dependency edges in the system dependency graph, N is the total number of nodes in the system dependency graph, and P is the number of connected components of the system dependency graph (usually 1).
[0079] For example, when the values of E, N, and P are 80, 40, and 1 respectively, substituting them into the above formula, the cyclomatic complexity value is 42.
[0080] It can be further seen that when the values of LOC, D, V and C are 5000, 80, 200 and 100 respectively, combined with the value of CC obtained above, Q can be calculated accordingly:
[0081] Q=171-5.2*log 10 5000-0.23*42-16.2*log 10 (80 / 200)+50*log 10 (100 / 5000) = 63.60
[0082] From the above, it can be seen that the value of the first quality Q of the software is 63.60, which is the measurement value of the quality of the software before the update.
[0083] S400: Constructing a second system dependency graph of the software based on the code change of the software.
[0084] In an embodiment of the present invention, the method may further include the following steps:
[0085] S401: Record the changes of the software code, classify them according to the change type, and obtain different types of code change sets.
[0086] Among them, code changes can be recorded by the development platform plug-in, and the types of code changes can include code addition, code change, code modification, code refactoring, and code merging, etc. In order to take into account both construction efficiency and effect, in the embodiment of the present invention, code changes are mainly classified into two types: code addition and code change.
[0087] S402: Periodically extract all the code change sets, and based on the type of each of the code change sets, update the first system dependency graph to obtain a second system dependency graph.
[0088] A time t is set, such as 10 minutes, which may be determined according to actual needs. At each interval t, a recorded code change set is extracted from the development platform plug-in. Based on the type of the code change set, the first system dependency graph is updated accordingly. The specific operations are as follows:
[0089] If the type of the code change set is a deletion code, extracting paths of all deletion codes in the code change set;
[0090] Traverse the paths of the nodes in the first system dependency graph, determine whether the path of each node is the same as the path of the deletion code, and if so, calculate the forward slices of all variables in the current node, delete all dependency edges traversed by the forward slice, and delete the current node.
[0091] For example, when the path of the deleted code is ma in\DAO.java12, all nodes in the first system dependency graph are accessed to determine whether the path of each node is ma in\DAO.java12. If so, the dependency edges traversed by the forward slice of the node are calculated, and then the node is deleted.
[0092] If the type of the code change set is newly added code, extracting the paths of all newly added codes in the code change set in the source program, and correspondingly generating a node with the path as an attribute in the first system dependency graph;
[0093] Construct a second abstract syntax tree based on the newly added code, and extract a second dependency relationship based on the second abstract syntax tree;
[0094] Extracting all second statements associated with the second dependency and attributes of the second statements;
[0095] Traversing the attributes of the nodes in the first system dependency graph, and locating a second node having the same attributes as any of the second statements;
[0096] Construct a dependency edge between the node corresponding to the newly added code and the second node.
[0097] For example, the newly added code is inta=b+3, and its path in the source program is main\DAO.java12. Accordingly, a node with the attribute main\DAO.java12 is generated in the first system dependency graph.
[0098] Among them, the second dependency relationship can be data dependency, control dependency, interaction dependency and external dependency, etc. In the embodiment of the present invention, data dependency and control dependency are used as examples. Specifically, based on the constructed second abstract syntax tree, the data dependency and control dependency of the newly added code inta=b+3 are analyzed. When the newly added code has a dependency relationship with the 10th line of code in the same file, the location of the code is recorded, that is, main\DAO.java10, and the nodes in the first system dependency graph are traversed to find the node with the attribute of main\DAO.java10, and the dependency edge <main\DAO.java12, main\DAO.java10> between the newly added code and the node is constructed.
[0099] In the above two update operations, incremental update technology is used, so that the dependency graph can be updated quickly, improving the real-time feedback. In addition to the above-mentioned deletion code and addition code, in other embodiments of the present invention, the code change set may also include other types, such as modification code. Code modification usually involves a combination of deletion and addition operations. In an embodiment of the present invention, when the code change type is code modification, it can be regarded as a combination of deletion code and addition code. Therefore, when updating the first system dependency graph, the update operations of the two can be referred to. The specific operations are as follows:
[0100] Traversing the path of the node in the first system dependency graph, determining whether the path of the node is the same as the path of the modified code, and if so, deleting the current node, calculating the forward slices of all variables in the current node, and deleting the dependency edges traversed by the forward slices;
[0101] Get the corresponding modified code at the end of the traversal;
[0102] Building a second abstract syntax tree based on the modified code, and extracting a second dependency relationship based on the second abstract syntax tree;
[0103] Extracting all second statements associated with the second dependency and attributes of the second statements;
[0104] Traversing the attributes of the nodes in the first system dependency graph, and locating a second node having the same attributes as any of the second statements;
[0105] A dependency edge is constructed between the node corresponding to the modified code and the second node.
[0106] From the above content, it can be seen that when the code change type is code modification, the update operation of the first system dependency graph is similar to when the code change type is code addition and code deletion. Similarly, most types of code changes can be regarded as a combination or extension of code addition and code change. Therefore, when updating the first system dependency graph, those skilled in the art can refer to these two types accordingly, and no further description is given here.
[0107] S500: Calculating a second quality of the software based on the program source code and the second system dependency graph.
[0108] In this step, based on obtaining the system dependency graph of the updated software, the calculation of the second quality may specifically refer to the detailed steps and calculation formula in S300, which will not be described in detail here.
[0109] S600: Compare the first quality and the second quality to obtain a comparison result, and obtain a technical debt warning result according to whether the comparison result meets a preset requirement.
[0110] For example, in S500 , the second quality Q′ of the software is calculated to be 60.02, and Q′ is compared with Q obtained in S300 to obtain a comparison result, which is used to represent the technical debt of the software.
[0111] The comparison result may be a difference, a ratio, or a result in other forms that can reflect the difference between the first quality and the second quality. Taking the difference as an example, the comparison result DT may be expressed by the following formula:
[0112] DT=Q'-Q
[0113] Substituting the Q' and Q obtained in the above S300 and S500, it can be seen that the current technical debt DT of the software is -3.58.
[0114] When comparing the comparison result with the preset requirement, the preset requirement may be one or more preset thresholds. When there is one threshold, a technical debt warning may be issued when the threshold is exceeded; when there are multiple thresholds, technical debt warnings representing different levels may be issued. Specifically, a low technical debt warning threshold LowThreshold and a high technical debt warning threshold LowThreshold are set. When DT≥0, no technical debt warning is required; when LowThreshold≤DT<0, a low-level technical debt warning is issued; when HighThreshold≤DT<LowThreshold, an intermediate-level technical debt warning is issued; when DT<HighThreshold, a high-level technical debt warning is issued.
[0115] For example, the value of LowThreshold is -2, and the value of DT<HighThreshold is -10. When DT=-3.58, HighThreshold<DT<LowThreshold, a medium-level technical debt warning is issued.
[0116] In specific implementation, the present application is not limited by the execution order of the various steps described. If no conflict occurs, some steps can be performed in other orders or simultaneously.
[0117] From the above, it can be seen that the real-time warning method for technical debt provided in the embodiment of the present application can quickly obtain the impact of the changed code on the system dependency graph, thereby obtaining the technical debt assessment results of the software and making real-time warnings, overcoming the technical problems of untimely discovery of software technical debt and low performance in real-time warnings in the prior art, reducing resource consumption and complexity of the analysis process, and improving the efficiency and effectiveness of software technical debt management.
[0118] In order to facilitate better implementation of the technical debt real-time warning method provided in the embodiment of the present application, a technical debt real-time warning device is also provided in one embodiment. The meanings of the terms are the same as those in the above technical debt real-time warning method, and the specific implementation details can refer to the description in the method embodiment.
[0119] See also Figure 2 , Figure 2 This is a schematic diagram of the structure of the real-time warning device for technical debt provided in an embodiment of the present application. The real-time warning device for technical debt can be integrated in a computer device. The real-time warning device for technical debt 30 may include an acquisition unit 301, a first construction unit 302, a first calculation unit 303, a second construction unit 304, a second calculation unit 305 and a warning unit 306, as follows:
[0120] The acquisition unit 301 is used to acquire the program source code of the software;
[0121] A first construction unit 302, used to construct a first system dependency graph of the software;
[0122] A first calculation unit 303, configured to calculate a first quality of the software based on the program source code and the first system dependency graph;
[0123] A second construction unit 304 is used to construct a second system dependency graph of the software based on the code change of the software;
[0124] A second calculation unit 305, configured to calculate a second quality of the software based on the program source code and the second system dependency graph;
[0125] The early warning unit 306 is used to compare the first quality and the second quality, obtain a comparison result, and obtain a technical debt early warning result according to whether the comparison result meets a preset requirement.
[0126] In one embodiment, the first construction unit 302 includes:
[0127] A node generation unit, used for extracting the path of each code in the software in the source program, and correspondingly generating a node with the path as an attribute;
[0128] A dependency extraction unit, configured to obtain the program source code, construct a first abstract syntax tree for each file source code therein, and extract a first dependency based on the first abstract syntax tree;
[0129] A first attribute extraction unit, used to extract all first statements associated with the first dependency relationships and attributes of the first statements;
[0130] A first node locating unit, used for traversing the attributes of nodes in the software, and locating a first node having the same attributes as any of the first statements;
[0131] The first dependency edge construction unit is used to construct the dependency edge between the first nodes, and use the attributes of the first statements as the attributes of the dependency edge.
[0132] In one embodiment, the first calculation unit 303 includes:
[0133] A program source code acquisition unit, used to acquire the number of code lines, the number of variables, the number of comment lines and the number of decision points in the program source code;
[0134] A first system dependency graph acquisition unit, configured to acquire the cyclomatic complexity in the first system dependency graph;
[0135] A first quality calculation unit is used to calculate a first quality of the software based on the number of code lines, the number of variables, the number of comment lines, the cyclomatic complexity and the number of decision points.
[0136] In one embodiment, the second construction unit 304 includes:
[0137] A code change recording unit, used to record the changes of the software code, classify the changes according to the change type, and obtain different types of code change sets;
[0138] a code change set extraction unit, used for periodically extracting all the code change sets;
[0139] The second system dependency graph updating unit is used to update the first system dependency graph based on the type of each of the code change sets to obtain a second system dependency graph.
[0140] In one embodiment, the second system dependency graph updating unit includes:
[0141] a deletion code set judging unit, configured to extract paths of all deletion codes in the code change set if the type of the code change set is a deletion code;
[0142] A node judgment unit is used to traverse the paths of the nodes in the first system dependency graph, determine whether the path of each node is the same as the path of the deletion code, and if so, calculate the forward slice of all variables in the current node, delete all dependency edges traversed by the forward slice, and delete the current node.
[0143] In one embodiment, the second system dependency graph updating unit includes:
[0144] a new code set judgment unit, configured to extract the paths of all the new codes in the code change set in the source program if the type of the code change set is new codes, and to generate a node with the path as an attribute in the first system dependency graph;
[0145] A second dependency extraction unit, configured to construct a second abstract syntax tree based on the newly added code, and extract a second dependency based on the second abstract syntax tree;
[0146] A second attribute extraction unit, used for extracting all second statements associated with the second dependency relations and attributes of the second statements;
[0147] A second node locating unit, configured to traverse the attributes of the nodes in the first system dependency graph and locate a second node having the same attributes as any of the second statements;
[0148] The second dependency edge construction unit is used to construct a dependency edge between the node corresponding to the newly added code and the second node.
[0149] In one embodiment, the warning unit 306 includes:
[0150] The warning issuing unit is used to compare the second quality with the first quality, determine whether the comparison result exceeds a preset warning threshold, and if so, issue a technical debt warning.
[0151] As can be seen from the above, an embodiment of the present application provides a real-time warning device for technical debt, which obtains the program source code of the software through an acquisition unit 301; constructs the first system dependency graph of the software through a first construction unit 302; calculates the first quality of the software based on the program source code and the first system dependency graph through a first calculation unit 303; constructs the second system dependency graph of the software based on the code change of the software through a second construction unit 304; calculates the second quality of the software based on the program source code and the second system dependency graph through a second calculation unit 305; compares the first quality and the second quality through a warning unit 306 to obtain a comparison result, and obtains a technical debt warning result based on whether the comparison result meets the preset requirements.
[0152] Accordingly, the present application also provides an electronic device, see Figure 3 , Figure 3 The electronic device 1200 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, and the electronic device can be used to implement the real-time warning method for technical debt in the above embodiment. The electronic device 1200 can be an electronic device such as a computer.
[0153] like Figure 3 As shown, the electronic device 1200 may include an RF (Radio Frequency) circuit 110, a memory 120 including one or more (only one is shown in the figure) computer-readable storage media, an input unit 130, a display unit 140, a sensor 150, an audio circuit 160, a transmission module 170, a processor 180 including one or more (only one is shown in the figure) processing cores, and a power supply 190. Those skilled in the art will understand that Figure 3 The structure of the electronic device 1200 shown in the figure does not constitute a limitation on the electronic device 1200, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0154] The RF circuit 110 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices. The RF circuit 110 may include various existing circuit elements for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption / decryption chip, a user identity module (SIM) card, a memory, etc. The RF circuit 110 can communicate with various networks such as the Internet, an intranet, a wireless network, or communicate with other devices through a wireless network.
[0155] The memory 120 can be used to store software programs and modules, such as the program instructions / modules corresponding to the real-time warning method for technical debt in the above-mentioned embodiment. The processor 180 can improve the recognition efficiency of human body motion posture by running the software programs and modules stored in the memory 120, thereby executing various functional applications and data processing. The memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 120 may further include a memory remotely arranged relative to the processor 180, and these remote memories may be connected to the electronic device 1200 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0156] The input unit 130 can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. Specifically, the input unit 130 may include a touch-sensitive surface 131 and other input devices 132. The touch-sensitive surface 131, also known as a touch display screen or a touch pad, can collect user touch operations on or near it (such as operations performed by users using fingers, styluses, or any other suitable objects or accessories on or near the touch-sensitive surface 131), and drive corresponding connection devices according to a pre-set program. Optionally, the touch-sensitive surface 131 may include a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into touch point coordinates, and then sends it to the processor 180, and can receive and execute commands sent by the processor 180. In addition, the touch-sensitive surface 131 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface 131, the input unit 130 may further include other input devices 132. Specifically, other input devices 132 may include but are not limited to one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc.
[0157] The display unit 140 may be used to display information input by the user or information provided to the user and various graphical user interfaces of the electronic device 1200, which may be composed of graphics, text, icons, videos and any combination thereof. The display unit 140 may include a display panel 141. Optionally, the display panel 141 may be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like. Further, the touch-sensitive surface 131 may cover the display panel 141. When the touch-sensitive surface 131 detects a touch operation on or near it, it is transmitted to the processor 180 to determine the type of touch event. Subsequently, the processor 180 provides a corresponding visual output on the display panel 141 according to the type of touch event. Although in Figure 3 In the embodiment, the touch-sensitive surface 131 and the display panel 141 are implemented as two independent components to realize the input and output functions. However, in some embodiments, the touch-sensitive surface 131 and the display panel 141 can be integrated to realize the input and output functions.
[0158] The electronic device 1200 may also include at least one sensor 150, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 141 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 141 and / or the backlight when the electronic device 1200 is moved to the ear. As a type of motion sensor, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when stationary, which can be used for applications that identify the posture of the electronic device (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc. that can also be configured in the electronic device 1200, they will not be repeated here.
[0159] The audio circuit 160, the speaker 161, and the microphone 162 can provide an audio interface between the user and the electronic device 1200. The audio circuit 160 can transmit the received audio data to the speaker 161 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 162 converts the collected sound signal into an electrical signal, which is received by the audio circuit 160 and converted into audio data, and then the audio data is output to the processor 180 for processing, and then sent to another terminal through the RF circuit 110, or the audio data is output to the memory 120 for further processing. The audio circuit 160 may also include an earplug jack to provide communication between an external headset and the electronic device 1200.
[0160] The electronic device 1200 can help users send and receive emails, browse web pages, and access streaming media through the transmission module 170 (such as a Wi-Fi module), which provides users with wireless broadband Internet access. Figure 3 The transmission module 170 is shown, but it is understandable that it is not an essential component of the electronic device 1200 and can be omitted as needed without changing the essence of the invention.
[0161] The processor 180 is the control center of the electronic device 1200. It uses various interfaces and lines to connect various parts of the entire electronic device 1200. By running or executing software programs and / or modules stored in the memory 120, and calling data stored in the memory 120, it executes various functions of the electronic device 1200 and processes data, thereby monitoring the human body as a whole. Optionally, the processor 180 may include one or more processing cores; in some embodiments, the processor 180 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 180.
[0162] The electronic device 1200 also includes a power supply 190 (such as a battery) for supplying power to various components. In some embodiments, the power supply can be logically connected to the processor 180 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 190 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0163] Although not shown, the electronic device 1200 may also include a camera (such as a front camera, a rear camera), a Bluetooth module, etc., which will not be described in detail here.
[0164] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0165] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0166] To this end, an embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program runs on a computer, the computer executes the real-time warning method for technical debt described in any of the above embodiments.
[0167] It should be noted that, for the real-time warning method for technical debt described in this application, ordinary testers in this field can understand that all or part of the process of implementing the real-time warning method for technical debt described in the embodiment of this application can be completed by controlling the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, such as stored in the memory of an electronic device, and executed by at least one processor in the electronic device, and the execution process may include the process of the embodiment of the real-time warning method for technical debt. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), etc.
[0168] The above is a detailed introduction to the real-time warning method, device, electronic device and storage medium for technical debt provided in the embodiments of the present application. This article uses specific examples to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and scope of application. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A real-time early warning method for technical debt, characterized in that: The method comprises: Get the source code of the software; constructing a first system dependency graph of the software; Calculating a first quality of the software based on the program source code and the first system dependency graph; Based on the code changes of the software, construct a second system dependency graph of the software; Calculating a second quality of the software based on the program source code and the second system dependency graph; The first quality and the second quality are compared to obtain a comparison result, and a technical debt warning result is obtained according to whether the comparison result meets a preset requirement.
2. The real-time early warning method for technical debt according to claim 1, characterized in that: The step of constructing the first system dependency graph of the software includes: Extracting the path of each code in the source program of the software, and correspondingly generating a node with the path as an attribute; Obtain the program source code, construct a first abstract syntax tree for each file source code therein, and extract a first dependency relationship based on the first abstract syntax tree; Extracting all first statements associated with the first dependency and attributes of the first statements; Traversing the attributes of nodes in the software, and locating a first node having the same attributes as any of the first statements; A dependency edge between the first nodes is constructed, and the attributes of the first statements are used as attributes of the dependency edge.
3. The real-time early warning method for technical debt according to claim 1, characterized in that: The calculating the first quality of the software based on the program source code and the first system dependency graph includes: Obtaining the number of code lines, the number of variables, the number of comment lines, and the number of decision points in the program source code; Obtaining the cyclomatic complexity of the first system dependency graph; A first quality of the software is calculated based on the number of code lines, the number of variables, the number of comment lines, the cyclomatic complexity, and the number of decision points.
4. The real-time early warning method for technical debt according to claim 2, characterized in that: The constructing a second system dependency graph of the software based on the code change of the software includes: Recording changes to the software code, classifying them according to the change type, and obtaining different types of code change sets; Periodically extract all said code change sets; Based on the type of each of the code change sets, the first system dependency graph is updated to obtain a second system dependency graph.
5. The real-time early warning method for technical debt according to claim 4, characterized in that: The updating of the first system dependency graph based on the type of each of the code change sets includes: If the type of the code change set is a deletion code, extracting paths of all deletion codes in the code change set; Traverse the paths of the nodes in the first system dependency graph, determine whether the path of each node is the same as the path of the deletion code, and if so, calculate the forward slices of all variables in the current node, delete all dependency edges traversed by the forward slice, and delete the current node.
6. The real-time early warning method for technical debt according to claim 4, characterized in that: The updating of the first system dependency graph based on the type of each of the code change sets includes: If the type of the code change set is newly added code, extracting the paths of all newly added codes in the code change set in the source program, and correspondingly generating a node with the path as an attribute in the first system dependency graph; Construct a second abstract syntax tree based on the newly added code, and extract a second dependency relationship based on the second abstract syntax tree; Extracting all second statements associated with the second dependency and attributes of the second statements; Traversing the attributes of the nodes in the first system dependency graph, and locating a second node having the same attributes as any of the second statements; Construct a dependency edge between the node corresponding to the newly added code and the second node.
7. The real-time early warning method for technical debt according to claim 1, characterized in that: The comparing the first quality and the second quality to obtain a comparison result, and obtaining a technical debt warning result according to whether the comparison result meets a preset requirement, includes: The second quality is compared with the first quality to determine whether the comparison result exceeds a preset warning threshold, and if so, a technical debt warning is issued.
8. A real-time early warning device for technical debt, characterized in that: include: An acquisition unit, used for acquiring program source code of the software; A first construction unit, used for constructing a first system dependency graph of the software; A first calculation unit, configured to calculate a first quality of the software based on the program source code and the first system dependency graph; A second construction unit, configured to construct a second system dependency graph of the software based on a code change of the software; A second calculation unit, configured to calculate a second quality of the software based on the program source code and the second system dependency graph; The early warning unit is used to compare the first quality and the second quality, obtain a comparison result, and obtain a technical debt early warning result according to whether the comparison result meets a preset requirement.
9. An electronic device, characterized in that: It comprises a processor and a memory, wherein a computer program is stored in the memory, and the processor is used to execute the real-time early warning method for technical debts according to any one of claims 1 to 7 by calling the computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program runs on a computer, the computer is enabled to execute the real-time early warning method for technical debts according to any one of claims 1 to 7.
