A dynamic code complexity analysis and performance prediction method and system
By performing genetic diversity analysis and analogous metabolic analysis of the target code, combining the operation log to adjust complex weights, and building complexity and performance prediction models, the shortcomings in code complexity and performance evaluation in the existing technology are solved, and early risk prediction and quality improvement are achieved.
Patent Information
- Application Number
- CN202510751571.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-06-06
AI Technical Summary
The existing technology is difficult to dynamically reflect the real behavior of the code at runtime, and lacks a comprehensive evaluation of code diversity, module coupling and concurrency problems, resulting in performance problems being exposed later in the development stage or after deployment, which is high in repair costs.
Gene diversity analysis is performed by obtaining the target code, logical genes are determined and diversity parameters are calculated, and analytical metabolic analysis and functional information processing is combined to build a characteristic index network, adjust complex weights based on the operation log, and complexity and performance prediction models are constructed.
It has achieved the early stage quantification of code complexity and predict performance, reduced risks, improved software quality, accurately evaluated gene complexity and dynamic adjustment, overcoming the shortcomings of traditional static indicators.
Smart Images

Figure CN120256276B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code analysis and performance prediction, and in particular to a method and system for dynamic code complexity analysis and performance prediction. Background Art
[0002] As software scale expands and its architecture becomes more complex, code complexity and performance issues become key challenges in development and maintenance. Highly complex code not only increases maintenance costs but can also lead to potential performance bottlenecks and runtime exceptions.
[0003] In existing technologies, code is usually evaluated using traditional static analysis tools, such as cyclomatic complexity, number of lines of code, and Halstead complexity indicators. These tools are difficult to dynamically reflect the actual behavior of the code at runtime, and lack a comprehensive assessment of code diversity, module coupling, and concurrency issues. In addition, performance issues are often exposed in the late stages of development or after deployment, resulting in a sharp increase in repair costs. Therefore, there is an urgent need for a dynamic, multi-dimensional analysis method that can quantify code complexity and predict performance at an early stage, providing a basis for optimization decisions, thereby reducing risks and improving software quality. Summary of the Invention
[0004] The purpose of the present invention is to address the problems existing in the background technology and propose a dynamic code complexity analysis and performance prediction method and system.
[0005] The technical solution of the present invention is a method for dynamic code complexity analysis and performance prediction, comprising the following steps:
[0006] Obtain the target code and perform gene diversity analysis to determine the logical genes contained in each target code, calculate the occurrence frequency of different logical genes, and obtain the gene diversity parameters of the target code;
[0007] Analogous metabolic analysis of the target code was performed to determine gene complexity;
[0008] Obtain the function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed;
[0009] A complexity calculation model of the target code is constructed based on the gene diversity parameters and gene complexity of the target code, and the complexity of the target code is output. A performance prediction model is constructed based on the complexity and feature index network, and the code performance prediction result is output.
[0010] Preferably, the method for performing genetic diversity analysis on the target code comprises:
[0011] Obtaining several code samples, performing syntax parsing on the code samples, determining a sample abstract syntax tree for each code sample, determining several grammatical structures contained in the code sample based on the sample abstract syntax tree, treating each grammatical structure as a logical gene, and combining several logical genes to obtain a code sample logical gene set;
[0012] Perform union operation on the logical gene sets of each code sample to obtain the logical gene library;
[0013] The target code is parsed to determine the ecological abstract syntax tree of the target code, the logical genes included in the ecological abstract syntax tree are marked as selected genes in the logical gene library, and the gene diversity parameters of the target code are calculated.
[0014] Preferably, the method for analogical metabolic analysis of the target code comprises:
[0015] Perform complex characteristic analysis on the target code to determine the dynamic complexity weight of each logic gene, including the basic control flow complexity weight, basic data flow complexity weight, and basic concurrency complexity weight;
[0016] The selected genes in the logical gene library are marked as target genes in turn, and several code samples are traversed according to the target genes to determine the target samples and build an abnormal type library of the target samples.
[0017] Preferably, in the same abnormality type library, the operation abnormalities caused by the target gene are marked as target abnormalities, and the number of target abnormalities is counted to obtain the total number of target abnormalities;
[0018] Obtain the total repair time of the target sample for the abnormal type library, and count the repair time caused by the target abnormality in the abnormal type library and mark it as the target repair time. Combine the basic control flow complexity weight, basic data flow complexity weight, and basic concurrency complexity weight to calculate the adjustment weight of the target gene in the target sample;
[0019] The adjusted weights of the target gene in all target samples are averaged to obtain the dynamic complexity weight of the target gene, and the gene complexity of the target code is calculated based on the dynamic complexity weight of the target gene.
[0020] Preferably, the method of performing analog metabolic analysis on the target code further includes performing adaptive metabolic rate analysis on the target code to determine the energy consumption index of each logical gene.
[0021] Preferably, the method for processing function information includes obtaining the number of input parameter types, the number of output parameter types and the nesting depth, and calculating the interface complexity of the function;
[0022] Perform the target element acquisition operation on the function and establish a call relationship pair. Obtain the number of parameters passed and the number of return value dependencies when executing the call relationship, and use them as the number of passed and returned target elements in the call relationship pair respectively. Calculate the data coupling strength of the target element based on the number of passed and returned parameters.
[0023] Preferably, the method for constructing the target code complexity calculation model includes calculating the ecological gene comprehensive index based on the gene diversity parameter and gene complexity of the target code:
[0024] A complexity calculation model is constructed based on the comprehensive ecological gene index, the preset first complexity threshold and the second complexity threshold, and the complex prediction results are output.
[0025] Preferably, the method for constructing the performance prediction model includes calculating a performance score of the characteristic index network based on the number of input parameter types, the number of output parameter types, and the energy consumption index of the logic gene;
[0026] Building a performance prediction model based on the performance score, the first complexity threshold, and the second complexity threshold, and outputting a performance prediction estimate;
[0027] The performance prediction estimate is compared with the performance threshold. If the performance prediction estimate is not greater than the performance threshold, the target code performance is determined to be good and no prompt is given. If the performance prediction estimate is greater than the performance threshold, the target code performance is determined to be unqualified, a prompt is given, and the optimization is notified.
[0028] The present invention also discloses a dynamic code complexity analysis and performance prediction system, which applies the above-mentioned dynamic code complexity analysis and performance prediction method, specifically comprising:
[0029] The first analysis module is used to obtain the target code and perform gene diversity analysis to determine the logical genes contained in each target code, calculate the occurrence frequency of different logical genes, and obtain the gene diversity parameters of the target code;
[0030] The second analysis module is used to perform analogical metabolic analysis on the target code to determine the gene complexity;
[0031] An information processing module is used to obtain function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed;
[0032] The modeling and calculation module is used to build a complexity calculation model of the target code based on the gene diversity parameters and gene complexity of the target code, and output the complexity of the target code, build a performance prediction model based on the complexity and feature index network, and output the code performance prediction results.
[0033] Compared with the prior art, the above technical solution of the present invention has the following beneficial technical effects:
[0034] (1) Perform ecological digital simulation of the code, generate an abstract syntax tree by parsing the code, construct the logical gene of the syntax structure, identify the logical gene and calculate the diversity parameter, quantify the diversity and repetitiveness of the code modules, and overcome the problem that traditional static indicators such as the number of lines of code are insufficient to describe the structural diversity.
[0035] (2) Based on the statistics of control flow, data flow and concurrent exceptions in the operation log, the complexity weight of the logical gene is dynamically adjusted in combination with the repair time, so as to more accurately evaluate the gene complexity and solve the problem that traditional methods often ignore the actual impact of runtime exceptions on complexity.
[0036] (3) A characteristic indicator network is constructed based on interface complexity and data coupling strength, and a comprehensive model is constructed by integrating gene diversity and complexity to achieve the linkage between complexity classification and performance prediction, thus solving the shortcomings of existing methods that mostly analyze complexity and performance in isolation and lack dynamic correlation. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 This is a method block diagram of embodiment 1 proposed by the present invention. DETAILED DESCRIPTION
[0038] Example 1, as Figure 1 As shown, the present invention proposes a dynamic code complexity analysis and performance prediction method, comprising the following steps:
[0039] Obtain the target code and perform gene diversity analysis to determine the logical genes contained in each target code, calculate the occurrence frequency of different logical genes, and obtain the gene diversity parameters of the target code;
[0040] Methods for genetic diversity analysis of target code include:
[0041] Obtain several code samples, perform syntax parsing on the code samples, determine a sample abstract syntax tree for each code sample, determine several grammatical structures contained in the code sample based on the sample abstract syntax tree, take each grammatical structure as a logical gene, and combine several logical genes to obtain a code sample logical gene set; it should be noted that syntax parsing can be performed using the ANTLR tool in Java, which is a prior art and will not be described in detail here;
[0042] Perform union operation on the logical gene sets of each code sample to obtain the logical gene library;
[0043] The target code is parsed to determine the ecological abstract syntax tree of the target code. The logical genes included in the ecological abstract syntax tree are marked as selected genes in the logical gene library. The gene diversity parameter GD of the target code is calculated. The gene diversity parameter GD is calculated using the following formula:
[0044] ;
[0045] Where Ci is the number of times the selected gene appears in the target code; i is the selected gene number, i is a positive integer, i∈[1,n], n is the total number of selected genes;
[0046] Analogous metabolic analysis of the target code was performed to determine gene complexity;
[0047] Methods for analogical metabolic analysis of target codes include:
[0048] Perform complex characteristic analysis on the target code to determine the dynamic complexity weight of each logic gene, including the basic control flow complexity weight, basic data flow complexity weight, and basic concurrency complexity weight;
[0049] Mark the selected genes in the logical gene library as target genes in turn, traverse several code samples according to the target genes, determine the target samples and build an abnormal type library of the target samples. The method includes:
[0050] If the target gene exists in the code sample, it will be marked as the target sample, otherwise it will not be marked;
[0051] Perform the following operations on the target sample:
[0052] Obtain the target sample's operation log, count the total number of operation exceptions caused by control exceptions, data exceptions, and concurrency exceptions, and build an exception type library for the target sample based on the same exception type;
[0053] In the same abnormality type library, the operation abnormalities caused by the target gene are marked as target abnormalities, and the number of target abnormalities is counted to obtain the total number of target abnormalities;
[0054] Obtain the total repair time of the target sample for the abnormal type library, and count the repair time caused by the target abnormality in the abnormal type library and mark it as the target repair time. Combine the basic control flow complexity weight, basic data flow complexity weight and basic concurrency complexity weight to calculate the adjustment weight of the target gene in the target sample. The method includes:
[0055] The adjusted weight Dw of the target gene in the target sample is determined by the following formula:
[0056] ;
[0057] Where, 、 、 They are the basic flow complexity weight, basic data flow complexity weight and basic concurrency complexity weight respectively; j is the complexity weight number, j=(1, 2, 3); is the total number of target anomalies; is the total number of operational exceptions; Target repair time; is the total repair time;
[0058] The adjusted weights of the target gene in all target samples are averaged to obtain the dynamic complexity weight of the target gene. The gene complexity GC of the target code is calculated based on the dynamic complexity weight of the target gene. The method includes:
[0059] By formula Calculate the genetic complexity GC of the target code; where, is the dynamic complexity weight of the target gene;
[0060] Perform adaptive metabolic rate analysis on the target code to determine the energy consumption index of each logical gene, including:
[0061] Obtain modification data of the target code, determine the number of modifications and the amount of functional changes of the target code based on the modification data, and calculate the energy consumption index based on the number of modifications and the amount of functional changes ;
[0062] Energy consumption index Calculated by the following formula:
[0063] ;
[0064] Where fh is the amount of functional change; kh is the functional impact weight, which is based on the functional evaluation test calibration of the target code; h is the modification number, h is a positive integer, i∈[1,m], m is the total number of modifications;
[0065] Obtain the function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed;
[0066] The method of processing function information includes obtaining the number of input parameter types, the number of output parameter types and the nesting depth, and calculating the interface complexity of the function through the formula Calculate the interface complexity of the function ;
[0067] Where, The number of input parameter types; The number of output parameter types; is the nesting depth; g is the function number, g is a positive integer;
[0068] Perform target element acquisition operations on the function and establish a call relationship pair. The methods include:
[0069] Arrange the functions according to their numbers to obtain a function sequence, and perform mark judgment operations on the elements of the function sequence:
[0070] According to the order of the elements of the function sequence, the sequence elements are marked as target elements and the marked labels are added, and the remaining elements are marked as regular elements. The following operations are performed on the target elements:
[0071] Determine whether there is a regular element such that the target element has a calling relationship with the regular element. If there is a regular element such that the target element has a calling relationship with the regular element, establish a calling relationship pair based on the target element and the regular element. If there is no regular element such that the target element has a calling relationship with the regular element, do not perform any operation, unmark the target element, and mark the next sequence element of the function sequence as the target element.
[0072] Traverse the marked labels of all elements in the function sequence until all sequence elements have marked labels, then stop the mark judgment operation;
[0073] Obtain the number of parameters passed and the number of return value dependencies when executing the call relationship, and use them as the number of passed and returned values of the target element in the call relationship, respectively. Calculate the data coupling strength of the target element based on the number of passed and returned values, and use the formula Calculate the data coupling strength of the target element ;
[0074] Where, is the number of target elements passed; is the number of target elements returned; a is the call relationship pair number, a is a positive integer, a∈[1, r], r is the total number of call relationship pairs;
[0075] A target code complexity calculation model is constructed based on the target code's gene diversity parameters and gene complexity, and the target code complexity is output. A performance prediction model is constructed based on the complexity and feature index network, and the code performance prediction results are output.
[0076] The method for constructing the complexity calculation model of the target code includes calculating the ecological gene comprehensive index according to the gene diversity parameter and gene complexity of the target code, and calculating the ecological gene comprehensive index according to the formula Calculate the ecological gene comprehensive index EC of the target code;
[0077] Where GD is the gene diversity parameter; GC is the gene complexity; and is the weight coefficient;
[0078] A complexity calculation model is constructed based on the comprehensive ecological gene index, the preset first complexity threshold, and the second complexity threshold, and the complexity prediction result is output. The expression of the complexity calculation model is as follows:
[0079] ;
[0080] Where, is the complex prediction result; E1 and E2 are the preset first complexity threshold and second complexity threshold respectively;
[0081] The method for constructing a performance prediction model includes calculating the performance score of the characteristic index network according to the number of input parameter types, the number of output parameter types and the energy consumption index of the logical gene, and using the formula The performance score IA of the characteristic index network is calculated; where, and All are weight coefficients;
[0082] A performance prediction model is constructed based on the performance score, the first complexity threshold, and the second complexity threshold, and the performance prediction estimate is output. The expression of the performance prediction model is as follows:
[0083] ;
[0084] Where, Estimates for performance predictions;
[0085] Estimating performance predictions Compared with the performance threshold, if the performance prediction estimate If the performance prediction value is not greater than the performance threshold, the target code performance is determined to be good and no prompt is given; if the performance prediction value is If the value is greater than the performance threshold, the target code performance is judged to be unqualified, and a prompt is given and the optimization is notified.
[0086] In the second embodiment, a dynamic code complexity analysis and performance prediction system proposed by the present invention is applied to the dynamic code complexity analysis and performance prediction method proposed in the first embodiment, and specifically includes:
[0087] The first analysis module is used to obtain the target code and perform gene diversity analysis to determine the logical genes contained in each target code, calculate the occurrence frequency of different logical genes, and obtain the gene diversity parameters of the target code;
[0088] The second analysis module is used to perform analogical metabolic analysis on the target code to determine the gene complexity;
[0089] An information processing module is used to obtain function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed;
[0090] The modeling and calculation module is used to build a complexity calculation model of the target code based on the gene diversity parameters and gene complexity of the target code, and output the complexity of the target code, build a performance prediction model based on the complexity and feature index network, and output the code performance prediction results.
[0091] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited thereto. Various changes can be made within the scope of knowledge possessed by those skilled in the art without departing from the spirit of the present invention.
Claims
1. A dynamic code complexity analysis and performance prediction method, characterized in that: The following steps are involved: Obtaining several code samples, performing syntax parsing on the code samples, determining a sample abstract syntax tree for each code sample, determining several grammatical structures contained in the code sample based on the sample abstract syntax tree, treating each grammatical structure as a logical gene, and combining several logical genes to obtain a code sample logical gene set; Perform union operation on the logical gene sets of each code sample to obtain the logical gene library; The target code is parsed to determine the ecological abstract syntax tree of the target code. The logical genes included in the ecological abstract syntax tree are marked as selected genes in the logical gene library. The gene diversity parameter GD of the target code is calculated. The gene diversity parameter GD is calculated using the following formula: ; Where Ci is the number of times the selected gene appears in the target code; i is the number of the selected gene, i is a positive integer, i∈[1,n], n is the total number of selected genes; Analogous metabolic analysis of the target code was performed to determine gene complexity; Obtain the function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed; A target code complexity calculation model is constructed based on the target code's gene diversity parameters and gene complexity, and the target code complexity is output. A performance prediction model is constructed based on the complexity and feature index network, and the code performance prediction results are output. Methods for analogical metabolic analysis of target codes include: Perform complex characteristic analysis on the target code to determine the dynamic complexity weight of each logic gene, including the basic control flow complexity weight, basic data flow complexity weight, and basic concurrency complexity weight; Mark the selected genes in the logical gene library as target genes in turn, traverse several code samples according to the target genes, determine the target samples and build an abnormal type library of the target samples; In the same abnormality type library, the operation abnormalities caused by the target gene are marked as target abnormalities, and the number of target abnormalities is counted to obtain the total number of target abnormalities; Obtain the total repair time of the target sample for the abnormal type library, and count the repair time caused by the target abnormality in the abnormal type library and mark it as the target repair time. Combine the basic control flow complexity weight, basic data flow complexity weight, and basic concurrency complexity weight to calculate the adjustment weight of the target gene in the target sample; The adjusted weights of the target gene in all target samples are averaged to obtain the dynamic complexity weight of the target gene, and the gene complexity GC of the target code is calculated based on the dynamic complexity weight of the target gene; By formula Calculate the genetic complexity GC of the target code; where, is the dynamic complexity weight of the target gene.
2. A dynamic code complexity analysis and performance prediction method according to claim 1, characterized in that: The method of performing analogical metabolic analysis on the target code also includes performing adaptive metabolic rate analysis on the target code to determine the energy consumption index of each logical gene; Energy consumption index Calculated by the following formula: ; Where fh is the functional change amount; kh is the functional impact weight, which is based on the functional evaluation test calibration of the target code; h is the modification number of the target code, h is a positive integer, i∈[1,m], and m is the total number of modifications of the target code.
3. A dynamic code complexity analysis and performance prediction method according to claim 2, characterized in that: The method for processing function information includes obtaining the number of input parameter types, the number of output parameter types and the nesting depth, and calculating the interface complexity of the function; Perform the target element acquisition operation on the function and establish a call relationship pair. Obtain the number of parameters passed and the number of return value dependencies when executing the call relationship, and use them as the number of passed and returned target elements in the call relationship pair respectively. Calculate the data coupling strength of the target element based on the number of passed and returned parameters.
4. A dynamic code complexity analysis and performance prediction method according to claim 3, characterized in that: The method for constructing a target code complexity calculation model includes calculating an ecological gene comprehensive index based on the gene diversity parameter and gene complexity of the target code: A complexity calculation model is constructed based on the comprehensive ecological gene index, the preset first complexity threshold and the second complexity threshold, and the complex prediction results are output.
5. A dynamic code complexity analysis and performance prediction method according to claim 4, characterized in that: The method for constructing a performance prediction model includes calculating a performance score of a feature index network based on the number of input parameter types, the number of output parameter types, and an energy consumption index of a logic gene; Building a performance prediction model based on the performance score, the first complexity threshold, and the second complexity threshold, and outputting a performance prediction estimate; Compare the performance prediction estimate with the performance threshold. If the performance prediction estimate is not greater than the performance threshold, the target code is judged to have good performance and no prompt is given. If the performance prediction estimate is greater than the performance threshold, the target code performance is determined to be unqualified, a prompt is given, and the optimization is notified.
6. A dynamic code complexity analysis and performance prediction system, applied to a dynamic code complexity analysis and performance prediction method according to any one of claims 1 to 5, characterized in that: Specifically include: The first analysis module is used to obtain the target code and perform gene diversity analysis to determine the logical genes contained in each target code, calculate the occurrence frequency of different logical genes, and obtain the gene diversity parameters of the target code; The second analysis module is used to perform analogical metabolic analysis on the target code to determine the gene complexity; An information processing module is used to obtain function information of the target code, perform information processing on the function information, determine the interface complexity and data coupling strength of each function, and use them as two characteristic indicators of the function. Based on the characteristic indicators of the function, a characteristic indicator network of the target code is constructed; The modeling and calculation module is used to build a complexity calculation model of the target code based on the gene diversity parameters and gene complexity of the target code, and output the complexity of the target code, build a performance prediction model based on the complexity and feature index network, and output the code performance prediction results.
Citation Information
Patent Citations
Code complexity determination method and device, equipment and storage medium
CN117806704A
AST-based code test analysis and correction method and system
CN118642942A