Real-time feedback method in code dyeing and test analysis monitoring
By applying a recursive neural network-based method in code coverage monitoring, the problems of inefficiency, insufficient real-time and difficulty in achieving comprehensive coverage in the existing technology are solved, and efficient, real-time monitoring and comprehensive coverage of code coverage are achieved, which significantly improves the level of software quality assurance.
Patent Information
- Application Number
- CN202411642181.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-02-28
Smart Images

Figure CN119537230A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer data processing, and is a real-time feedback method in code coloring and test analysis monitoring, which is specifically applied to real-time monitoring of codes of recursive neural networks. Background Art
[0002] In the context of the rapid development of today's software industry, ensuring software quality has become the key to corporate competitiveness. Code coverage is the core indicator for evaluating the integrity of software testing. It reveals the extent to which test cases touch the program source code. At present, the code coverage monitoring methods commonly used in the industry include statement coverage, branch coverage, path coverage, etc. Although these methods play an important role in software testing, they still face the following limitations: First, the current code coverage monitoring methods often rely on manually written test cases, which is not only inefficient, but also easily affected by human factors, resulting in deviations in test results. Second, traditional methods lack the ability to monitor code coverage in real time, which may lead to problems that cannot be discovered and corrected in time during the software development process, increasing the risk of software defects. Finally, in the face of complex software projects, traditional code coverage monitoring methods often find it difficult to achieve comprehensive coverage effects, and thus cannot ensure the overall improvement of software quality.
[0003] In recent years, breakthroughs in deep learning technology have provided new ideas for solving these problems. In particular, recursive neural networks (RNNs), as a deep learning model that specializes in processing sequence data, have the unique ability to identify and remember long-distance dependencies in sequence data. Introducing recursive neural network technology into the field of code coverage monitoring is expected to overcome the shortcomings of traditional methods, achieve more efficient and accurate code coverage evaluation, and provide technical support for real-time monitoring and comprehensive coverage. Summary of the invention
[0004] A monitoring method for code coloring and test analysis based on recurrent neural network (RNN) and a real-time feedback method thereof are intended to solve the problems of low efficiency, insufficient real-time performance, and difficulty in comprehensive coverage in the existing technology in code coverage monitoring, thereby improving the level of software quality assurance. First, the traditional code coverage monitoring method mainly relies on manually writing test cases, which is not only time-consuming and labor-intensive, but also difficult to achieve ideal coverage when facing complex software systems. The present invention uses the powerful sequence learning ability of recurrent neural networks to predict code coverage and improve the efficiency of code coverage monitoring. Secondly, the existing technology often cannot achieve real-time monitoring of code coverage, resulting in potential problems and defects that cannot be discovered and repaired in time during the software development process. The present invention realizes real-time monitoring of code coverage through the application of recurrent neural networks, which helps developers to understand the software quality status in time and take corresponding measures. Thirdly, for complex projects, it is difficult for traditional code coverage monitoring methods to achieve comprehensive coverage. In addition, the real-time feedback method of the present invention is another core innovation. The method is implemented in the following ways: 1. By building and training an LSTM model, developers can use machine learning technology to predict code coverage. Identifying potential coverage deficiencies before actual testing enables developers to optimize test cases and ensure that the code is fully tested under different conditions. This foresight helps reduce software defects and improve product stability and user satisfaction.
[0005] Second, in the code preprocessing and feature extraction stage, in-depth lexical and grammatical analysis provides high-quality input data for the LSTM model. This data captures the details and structural information of code changes, enhancing the prediction accuracy of the model. High-quality feature input means that the model can more accurately understand the complexity of the code, thereby improving the reliability of the prediction.
[0006] 3. Model training and optimization By combining optimization algorithms and specific model architectures, we ensure that the LSTM model can efficiently learn the temporal dependencies in the code submission sequence. A high-performance model can accurately predict code coverage in practical applications, help development teams effectively allocate testing resources and time, and improve development efficiency.
[0007] 4. Code coverage positioning and path tracing Use tools (such as JaCoCo) to analyze and identify untested code paths. This analysis guides the supplementation and optimization of test cases to improve the comprehensiveness and effectiveness of testing. Comprehensive test coverage ensures the stability of the software in different scenarios and reduces the risk of major problems after release.
[0008] 5. Data collection and processing Probes generate coverage data and convert it into a format suitable for analysis and modeling, providing a high-quality data foundation for model training and analysis. Data cleaning, merging and analysis ensure its integrity and accuracy, supporting subsequent model training and performance optimization.
[0009] 6. Real-time monitoring and feedback mechanism provides developers with instant information about code coverage. This real-time feedback helps to quickly identify and solve problems, improve development efficiency and code quality. Developers can promptly understand the impact of code changes on coverage and make corresponding adjustments to avoid the accumulation of problems.
[0010] Finally, by generating detailed coverage reports, the development team gets a comprehensive analysis of code coverage. This not only helps identify long-standing problems, but also provides data support for quality control and code optimization. The detailed information in the report helps the team develop more effective improvement strategies and improve the overall quality of the software.
[0011] The purpose of the present invention is to use the application of recursive neural networks in the field of code coloring and test analysis monitoring to achieve the following effects: This systematic process significantly improves the code coverage and quality in the software development process through the combination of machine learning, code analysis and real-time feedback, and supports more efficient and reliable software delivery. Improve the automation and efficiency of code coverage monitoring; achieve real-time monitoring of code coverage and reduce software development risks; improve the comprehensiveness and accuracy of code coverage for complex projects; promote the interaction between developers and the testing process through real-time feedback methods to jointly improve software quality.
[0012] The present invention solves the deficiencies of the prior art and provides the following technical solutions: Step 1: Construction and training of recurrent neural network The input layer uses the tanh and sigmoid activation functions of the LSTM model, and the output layer uses the Softmax activation function to output the probability distribution, which is used for coverage prediction to annotate the input and output dimensions of each LSTM layer; the training data set automatically captures the submission history of open source projects in a specific language through the GitHub API; during the data collection process, data cleaning is required to retain only code changes; the data set is divided using the train_test_split function in the Python sklearn library; TensorBoard or a custom logger is used to record the accuracy and loss values of the training and validation sets at the end of each epoch; Matplotlib is used to generate loss curves and accuracy curves, and provide chart displays; Step 2: Code preprocessing and feature extraction First, ANTLR is used to parse the code and generate an abstract syntax tree (AST) to extract function definitions and key node information of control structures. The Word2Vec model is used to train identifiers and keywords in the code. Python code snippet def add(a, b): return a + b; Through lexical analysis, this code is decomposed into basic lexical units: ['def', 'add', '(', 'a', ',', 'b', ')', ':', 'return', 'a','+', 'b']; Using ANTLR for syntax analysis, the generated AST contains nodes such as FunctionDef, arguments, and Return. The Word2Vec model is used to convert identifiers and keywords into feature vectors; Step 3: Model training and optimization We represent the code submission sequence as X = [x_1, x_2, ..., x_T] where each x_1, x_2, ..., x_T is a feature vector; these feature vectors are preprocessed in step 2; Step 4: Code coverage location and path tracing First, we configure the output format of JaCoCo and choose to generate coverage reports in XML or HTML format for subsequent analysis and presentation; insert probes at each function entry, loop, and conditional branch; insert probes through JaCoCo configuration files and command line tools; add the JaCoCo plug-in to the configuration file of the build tool Maven or Gradle, and specify the rules for probe insertion and the format of the output report; Record the number of calls and parameters of each function by inserting probes in the code, and use the API provided by JaCoCo or parse the coverage report it generates; extract the execution information of each function by parsing the report in XML format, including reading the XML file, parsing the node information, and storing the data in a hash table or database; Step 5: Data collection and processing During software testing, coverage data is usually generated by probes; these probes are embedded in the code and record information about the execution path. The coverage data is converted into JSON format. Data cleaning, removing redundant or incomplete data entries, and merging coverage data from multiple files or multiple test runs; Step 6: Real-time monitoring and feedback Real-time feedback is achieved by using Python's websockets library. WebSocket is a full-duplex communication protocol that allows real-time data exchange between the server and the client, and pushes the code coverage results to the developer's integrated development environment IDE in real time. The server will calculate the coverage after the code is submitted, and send the latest coverage data to the client through the WebSocket connection. After receiving the data, the client will immediately update the interface in the IDE to display the current coverage situation. Step 7: Customize report generation and optimization Use Python's ReportLab library to generate coverage reports in PDF format, extract key information from coverage data, and utilize ReportLab's API to format and layout report content.
[0013] The beneficial effects of the present invention are to focus on the monitoring model of code coloring and test analysis based on recursive neural networks, as well as its core real-time feedback method, aiming to improve the code quality in the software development process through intelligent means. Specifically, the main technical contents of the present invention are as follows: First, a recursive neural network model specifically for code coverage monitoring was built. This model uses deep learning algorithms, especially the long short-term memory network (LSTM), to capture the temporal dependencies in the code submission sequence, thereby accurately predicting the code coverage.
[0014] Secondly, code preprocessing methods were invented, including lexical analysis and vectorization. These methods can extract key features from the code, such as the number of code lines, newly added / deleted code lines, variable names, function names, etc., and convert these features into numerical vectors to provide high-quality input data for recurrent neural networks.
[0015] Third, we invented a method to monitor code coverage in real time. When the code is submitted, the trained recursive neural network model is run in real time to predict the coverage of the current submission and compare it with the data obtained by the probe to ensure the immediacy and accuracy of monitoring.
[0016] Finally, the present invention also proposes a real-time feedback mechanism to improve code quality. The mechanism can generate a report containing coverage statistics and detailed information of uncovered code based on the prediction results, and feed back the report and improvement suggestions to the developers. In this way, the development team can understand the code coverage situation in a timely manner, and optimize the code structure and write more effective test cases based on the feedback results.
[0017] In summary, the present invention realizes accurate monitoring and instant reporting of code coverage through the deep learning ability and real-time feedback mechanism of recursive neural networks, providing software development teams with an efficient, reliable and easy-to-operate quality assurance system. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0019] This solution innovatively integrates the deep learning capabilities of RNN, especially the sequence processing advantages of long short-term memory network LSTM, to achieve accurate monitoring and instant reporting of code coverage. This technology not only greatly improves the quality control level in the software development process, but also ensures that the development team can obtain feedback in real time and respond quickly to code changes, thereby improving software quality and development efficiency. The following are the specific technical implementation steps: Step 1: Construction and training of recurrent neural network Regarding the choice of activation function, LSTM usually uses tanh and sigmoid activation functions instead of ReLU, because the structure of LSTM itself determines the use of its activation function. The output layer uses the Softmax activation function to output probability distribution for coverage prediction. In order to better understand the network structure, a detailed architecture diagram can be provided, marking the input and output dimensions of each LSTM layer. For example, the dimension of the input layer is (batch_size, sequence_length, feature_dimension), the dimension of the first layer of LSTM is (batch_size, sequence_length, 256), and so on, until the fully connected layer (batch_size, num_classes).
[0020] In terms of training data sets, data can be automatically captured by writing scripts using the GitHub API to capture the submission history of open source projects in specific languages (such as Python and Java). During the data collection process, data cleaning is required to filter out invalid submissions (such as empty submissions, document changes) and only retain code changes. The goal is to collect at least 50,000 valid submissions to ensure data diversity and thus enhance the generalization ability of the model. The data set can be divided using the train_test_split function in Python's sklearn library, with 80% for training, 10% for validation, and 10% for testing.
[0021] In terms of recording performance indicators, you can use TensorBoard or a custom logger to record the accuracy and loss values of the training and validation sets at the end of each epoch. These records include training loss, validation loss, training accuracy, and validation accuracy. In order to show the results more intuitively, you can use Matplotlib to generate loss curves and accuracy curves and provide charts. For example, the loss curve and accuracy curve can show the changing trends of loss and accuracy during training and validation, respectively, to help identify the optimal epoch.
[0022] Through these detailed steps and methods, the construction and training process of recursive neural networks will be clearer and more operational, which not only improves the feasibility of implementation, but also enhances the understanding and mastery of technical details.
[0023] Step 2: Code preprocessing and feature extraction In this stage, we perform comprehensive lexical analysis and grammatical analysis on the code submission. First, in terms of feature extraction tools and methods, we use ANTLR (Another Tool for Language Recognition) to parse the code and generate an abstract syntax tree (AST). ANTLR is a powerful syntax analysis tool that can parse the code into a structured tree representation, which allows us to extract key node information such as function definitions and control structures. This information is crucial for understanding the structure and logic of the code.
[0024] In order to further extract semantic information from the code, we used the Word2Vec model to train the identifiers and keywords in the code. Word2Vec is a word embedding technology for natural language processing. By converting words into vectors, the semantic relationship between words can be captured. In our implementation, the dimension of the word embedding vector is set to 100. This choice balances the computational complexity and representation ability in the experiment. The specific tool implementation includes code examples for generating AST using ANTLR, as well as the training parameter settings and training process of the Word2Vec model.
[0025] In the data example section, we provide a simple Python code snippet def add(a, b):return a + b. Through lexical analysis, this code is decomposed into basic lexical units: ['def', 'add', '(','a', ',', 'b', ')', ':', 'return', 'a', '+', 'b']. Next, ANTLR is used for syntax analysis. The generated AST contains nodes such as FunctionDef, arguments, Return, etc., which clearly show the structure of the code. Finally, through the Word2Vec model, we convert these identifiers and keywords into feature vectors, such as [0.25, 0.13, ..., 0.47], which are used for subsequent model training.
[0026] To verify the effect of feature extraction, we conducted experiments. The experimental results show that on a code dataset containing 10,000 submissions, the model using the above feature extraction method has a 15% increase in coverage prediction accuracy and a 20% reduction in loss. These results show that through careful feature extraction, we have significantly improved the performance of the model.
[0027] In terms of experimental settings, we recorded in detail the hardware environment, software versions, and running time used in the experiment. For example, the experiment was conducted on a computer equipped with an NVIDIA GTX 1080 Ti GPU, using Python version 3.8 and TensorFlow version 2.4. The experimental running time was about 2 hours, depending on the size of the dataset and the complexity of the model.
[0028] This step not only improves the accuracy of the model, but also lays a solid foundation for subsequent model training.
[0029] Experimental results: Experiments were conducted on a real dataset containing thousands of code submissions. The model using lexical and grammatical analysis features improved the accuracy of coverage prediction by about 15% and reduced the loss by 20%. This shows that more detailed feature extraction significantly improves model performance.
[0030] Through these steps, we can effectively capture the syntax and semantic information of the code, provide richer input features for the subsequent LSTM network, and thus achieve more accurate coverage prediction. This method not only performs well in experiments, but also demonstrates its superiority in practical applications.
[0031] Step 3: Model training and optimization. In the process of model training and optimization, we need to combine the model's architectural characteristics and the selection of optimization algorithms to ensure that the LSTM model can efficiently learn and predict when processing code submission sequences. The following is a detailed description after integration: We represent the code submission sequence as ( X = [x_1, x_2, ..., x_T] where each x_t is a feature vector). After preprocessing in step 2, these feature vectors can effectively capture the details of the code changes, including the structure, syntax, and semantic information of the code.
[0032] import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense # Assume that feature extraction has been completed and the processed feature vector sequence has been obtained # X = [x_1, x_2, ..., x_T] where each x_t is a eigenvector # y is the corresponding label sequence, each label represents a submitted coverage category # Define LSTM model model = Sequential() model.add(LSTM(units=256,input_shape=(sequence_length,feature_dimension), return_sequences=False)) model.add(Dense(num_classes, activation='softmax')) # Compile the model, specify the optimizer, loss function and evaluation index model.compile(optimizer='adam', loss='categorical_crossentropy',metrics=['accuracy']) # Train the model history = model.fit(X, y, epochs=10, batch_size=32, validation_split=0.1) # Evaluate the model test_loss, test_accuracy = model.evaluate(X_test, y_test) # Print evaluation results print(f"Test Loss: {test_loss}, Test Accuracy: {test_accuracy}") This code covers the implementation of the entire process from building an LSTM model to training and evaluation, and uses the LSTM network for learning and prediction, which can effectively capture the details of code changes and predict the trend of code coverage.
[0033] Step 4: Code coverage location and path tracing. JaCoCo is a code coverage analysis tool for Java that records program execution paths by inserting probes into compiled bytecodes. First, we need to configure the output format of JaCoCo. You can choose to generate coverage reports in XML or HTML format for subsequent analysis and presentation. The location where the probe is inserted is very critical. To ensure the comprehensiveness of the coverage path, we insert probes at each function entry, loop, and conditional branch. The selection of these locations is based on the best practices of coverage analysis, which can capture the key paths and branches of program execution. Through JaCoCo's configuration files and command line tools, we can easily insert probes. You can add a JaCoCo plugin to the configuration file of a build tool (such as Maven or Gradle) and specify the rules for probe insertion and the format of the output report. A simple configuration example is to add a JaCoCo plugin to Maven's pom.xml and configure its execution goals and report output path.
[0034] Path tracing is the core of code coverage analysis. In the specific implementation, we can record the number of calls and parameters of each function through the probes inserted in the code. For example, during the execution of the function add, the probe will record the number of times the function is called and the parameters passed, generating a data format similar to {'add': 10, 'subtract': 5}. This recording method can not only show the frequency of function calls, but also reveal the execution path and logic flow of the code.
[0035] To implement path tracing, we can use the API provided by JaCoCo or parse the coverage report it generates. By parsing the report in XML format, we can extract the execution information of each function and format it into a data structure that is easy to analyze. The specific code implementation may include reading the XML file, parsing the node information, and storing the data in a hash table or database for subsequent statistics and analysis.
[0036] The advantage of this method is that it not only provides comprehensive coverage data, but also helps developers identify untested code paths, thereby guiding the supplementation and optimization of test cases. Through this sophisticated path tracing and coverage analysis, the development team can better understand the test coverage of the software and improve code quality and reliability.
[0037] Step 5: Data collection and processing. In the process of software testing and quality assurance, coverage data is usually generated by probes. These probes are embedded in the code and record information about the execution path. The generated coverage data needs to be effectively collected and stored for subsequent analysis. In our example, the coverage data is converted into JSON format. This format was chosen because JSON is well structured and readable, which is convenient for integration with other data sources (prediction results of LSTM models).
[0038] Coverage data in JSON format usually contains the following information: Filename: The name of the code file.
[0039] Line number: The line number of the code being executed.
[0040] Execution count: The number of times each line of code is executed.
[0041] Timestamp: records the time when the data is generated.
[0042] The Json format is as follows: { "file_name": "example.py", "coverage": [ {"line": 10, "execution_count": 5}, {"line": 20, "execution_count": 3} ], "timestamp": "2023-10-05T14:48:00Z" } Data processing is the process of converting raw coverage data into a data set that can be used for analysis and model training. The specific steps include: Data cleaning. Remove redundant or incomplete data entries. For example, filter out those lines that have no execution times; Data merging. Merge coverage data from multiple files or multiple test runs to form a complete coverage graph; Data analysis: Calculate statistical information such as coverage percentage, identify unexecuted code blocks, and provide a basis for the next step of predictive modeling.
[0043] Step 6: Real-time monitoring and feedback. The real-time feedback mechanism can be implemented by using Python's websockets library. WebSocket is a full-duplex communication protocol that allows real-time data exchange between the server and the client. We can use this feature to push the code coverage results to the developer's integrated development environment (IDE) in real time. In the specific implementation process, the server will calculate the coverage after the code is submitted, and send the latest coverage data to the client through the WebSocket connection. After receiving the data, the client can instantly update the interface in the IDE to display the current coverage situation.
[0044] In order to make the feedback information more intuitive, we need to design a user-friendly feedback interface. The interface design diagram can include a coverage trend chart, a list of uncovered code, and detailed information for each uncovered code (such as code path and line number). This design not only helps developers quickly understand the coverage situation, but also provides specific directions for improvement. For example, a real-time report example may show: the current submission coverage is 85%, the uncovered code includes the subtract function, and provides the file path and specific line number of the function.
[0045] Step 7: Customize report generation and optimization. In addition to real-time feedback, generating detailed coverage reports is also an effective analysis method. We can use Python's ReportLab library to generate coverage reports in PDF format. ReportLab is a powerful tool that can create complex documents and charts, and is suitable for generating coverage reports that contain rich information. In the implementation process, we can write scripts to extract key information from the coverage data and use ReportLab's API to format and layout the report content.
[0046] The content of the report needs to be comprehensive and detailed. Statistics of overall coverage, trend charts of coverage over time, detailed lists of uncovered code, etc. In addition, charts such as pie charts or bar charts can be added to the report to visualize the distribution of coverage data. By providing a sample report screenshot, we can visually demonstrate the layout and content of the report, thereby helping the development team better understand and use the data.
[0047] In short, through real-time monitoring and feedback mechanisms and the generation of customized reports, developers can obtain instant and detailed information about code coverage, which not only helps to quickly identify and solve problems, but also provides strong support for long-term quality control and code optimization.
[0048] Through the close coordination of the above seven steps, our technical solution can achieve accurate monitoring and real-time reporting of code coverage, providing software development teams with an efficient, reliable and easy-to-operate quality assurance system.
[0049] After an in-depth discussion of the application of recurrent neural networks (RNNs) in code coloring and test analysis monitoring and its real-time feedback methods, we came to the following detailed technical summary: This solution innovatively combines the deep learning capabilities of RNNs, especially the sequence processing advantages of long short-term memory networks (LSTMs), to achieve accurate monitoring and instant reporting of code coloring and test analysis. This technology not only greatly improves the level of quality control in the software development process, but also ensures that the development team can obtain feedback in real time and respond quickly to code changes, thereby improving software quality and development efficiency. The following is the optimized technical implementation process: Requirements analysis and design: Determine the monitoring objectives, clarify the code base, programming language, code coloring indicators, test analysis indicators, etc. that need to be monitored. The focus of the analysis is to clarify the monitoring scope and objectives. We need to identify which modules and functions in the project are critical and which code paths require special attention. Based on these analyses, we design a monitoring plan, plan the architecture of the recursive neural network, and how to extract data from the code base and implement real-time feedback processes. The design phase also includes selecting a suitable LSTM network architecture, because LSTM performs well in processing sequence data and is very suitable for processing time series data of code submissions.
[0050] Data collection and preprocessing: We use GitHub API to extract the code submission history of the project. By writing scripts, we automatically filter out valid code changes and remove invalid submissions such as document changes or empty submissions. To ensure the diversity of the data, our goal is to collect at least 50,000 valid submissions. Then, we use ANTLR to perform lexical and grammatical analysis to extract code features, such as function definitions, control structures and other key node information. In order to convert these features into a format acceptable to the model, we use Word2Vec technology to convert code features into vector representations. This step of verification uses visualization methods, such as t-SNE dimensionality reduction diagrams, to check the discrimination of different functional modules and ensure the effectiveness of feature extraction.
[0051] In the data preprocessing stage, after lexical and grammatical analysis by ANTLR, the extracted code features need to be converted into numerical vectors. The Word2Vec model is used here, and its core is to calculate word embedding as a vector representation. Assuming we have a vocabulary (V), each word (w) is mapped to a (d)-dimensional vector space, the specific calculation is: text{vector}(w) = text{Word2Vec}(w) vector(w)=Word2Vec(w) In implementation, Word2Vec learns word embeddings by optimizing the following objective function: J(theta) = -sum_{w in V} log p(w|text{context}(w)) J(θ)=−w∈V∑ logp(w∣context(w)) Where (text{context}(w)) is the context window of word (w). The optimized word vector is used to construct the input data matrix for the LSTM model.
[0052] Build a recursive neural network model: When building a recursive neural network model, we choose LSTM as the basic architecture. The dimension of the input layer is determined according to the characteristics of the dataset. For example, (batch_size, sequence_length, feature_dimension) can be set to (32, 50, 100). The design of the model includes multiple LSTM layers and a Softmax output layer to generate probability distributions to predict code coverage. Cross entropy is selected as the loss function, and the Adam optimizer is used for parameter update. After the model architecture design is completed, the network structure diagram is drawn and the input and output dimensions of each layer are marked to ensure the rationality and operability of the design.
[0053] The core of the LSTM model lies in its gating mechanism, which controls the flow of information and state updates through formula calculations. Specifically, the calculation of each LSTM unit at time step (t) is as follows: The code to implement the above mathematical formula is as follows: import tensorflow as tf # Define LSTM layer lstm_cell = tf.keras.layers.LSTMCell units=256) # Initialize state Initialize the hidden state (hidden_state) and cell state (cell_state) to 0.
[0054] # The two states are the internal states maintained by the LSTM unit while processing the sequence.
[0055] hidden_state = tf.zeros(shape=[batch_size, 256]) cell_state = tf.zeros(shape=[batch_size, 256]) # Iterate over each time step of the sequence for t in range(sequence_length): # Get the feature vector of the current time step x_t = input_sequence[:, t, :] # LSTM unit update # Calculate the output of the forget gate. The forget gate determines which information should be discarded from the cell state. f_t = tf.sigmoid(tf.matmul([hidden_state, x_t], lstm_cell.kernel_f) +lstm_cell.bias_f) # Calculate the output of the input gate. The input gate determines what new information should be stored in the cell state. i_t = tf.sigmoid(tf.matmul([hidden_state, x_t], lstm_cell.kernel_i) +lstm_cell.bias_i) # Compute the output of candidate memory, which is new information that may be added to the cell state C_tilde = tf.tanh(tf.matmul([hidden_state, x_t], lstm_cell.kernel_C)+ lstm_cell.bias_C) # Update the unit state. The forget gate controls the retention of old information, and the input gate controls the addition of new information.
[0056] C_t = f_t * cell_state + i_t * C_tilde # Calculate the output of the output gate. The output gate determines the output of the current time step.
[0057] o_t = tf.sigmoid(tf.matmul([hidden_state, x_t], lstm_cell.kernel_o) +lstm_cell.bias_o) # Calculate the hidden state, which is the output of the LSTM unit and will be passed to the next time step hidden_state = o_t * tf.tanh(C_t) # Update cell status cell_state = C_t This code implements the forward propagation process of the LSTM unit on a given sequence, updates the hidden state and unit state time-step by time step, and finally outputs the hidden state sequence of the entire sequence. This enables LSTM to selectively remember or forget information, thereby effectively capturing long-term dependencies.
[0058] Model training: We divide the preprocessed dataset into training set, validation set, and test set, usually in a ratio of 80%, 10%, and 10%. During the training process, the training loss and accuracy of each epoch are recorded through TensorBoard to monitor the convergence of the model. The validation set is used to evaluate the performance of the model and help adjust the network structure and parameters to achieve the best results. The training effect is displayed by visualizing the loss curve and accuracy curve to help identify the optimal training epoch.
[0059] Code coloring analysis: Record execution paths by inserting probes into the code base. Using tools such as JaCoCo, probes are inserted into key locations such as function entry, loops, and conditional branches to ensure comprehensive coverage recording. During the analysis, the data recorded by the probes is compared with the prediction results of the LSTM model to verify the accuracy of coloring code recognition. The generated coverage report shows the uncolored code areas and provides specific improvement suggestions.
[0060] Test analysis and monitoring: Test analysis and monitoring runs the LSTM model in real time to predict the coverage of the latest code submission. Real-time feedback is achieved through the WebSocket protocol to ensure that developers can obtain coverage change information in a timely manner. The coverage status is updated instantly in the IDE, and detailed information about uncovered code, such as specific line numbers and paths, is displayed. This real-time performance ensures that problems can be quickly identified and resolved, improving development efficiency.
[0061] Custom report generation and optimization: Generate custom reports based on user-specified parameters, such as submission time, version, etc. The reports not only contain the stained code statistics and test analysis results, but also show the changing trends of the stained codes and the untested code areas. The reports and improvement suggestions are fed back to developers, and feedback from the development team is collected to optimize the monitoring system and reports.
[0062] Glossary: RNN is the abbreviation of Recurrent Neural Network. Its Chinese name is recursive neural network. It is a neural network model used to process sequence data. Unlike traditional neural networks, RNN has the ability to process sequence data and can capture the dependencies between data.
[0063] LSTM is the abbreviation of Long Short-Term Memory, and its Chinese name is Long Short-Term Memory Network. It is a special recurrent neural network (RNN) proposed by Hochreiter and Schmidhuber in 1997 to solve the gradient vanishing or gradient exploding problems encountered by traditional RNN when processing long sequence data.
Claims
1. A real-time feedback method for code coloring and test analysis monitoring, characterized in that The steps include: Step 1: Construction and training of recurrent neural network The input layer uses the tanh and sigmoid activation functions of the LSTM model, and the output layer uses the Softmax activation function to output the probability distribution, which is used for coverage prediction to mark the input and output dimensions of each LSTM layer; The training dataset automatically crawls the submission history of open source projects in a specific language through GitHub API; during the data collection process, data cleaning is required to retain only code changes; the dataset is divided using the train_test_split function in Python's sklearn library; TensorBoard or a custom logger is used to record the accuracy and loss values of the training and validation sets at the end of each epoch; Matplotlib is used to generate loss curves and accuracy curves, and provide chart presentations; Step 2: Code preprocessing and feature extraction First, ANTLR is used to parse the code and generate an abstract syntax tree (AST) to extract function definitions and key node information of control structures. The Word2Vec model is used to train identifiers and keywords in the code. Python code snippet def add(a, b): return a + b; Through lexical analysis, this code is decomposed into basic lexical units: ['def', 'add', '(', 'a', ',', 'b', ')', ':', 'return', 'a', '+','b']; Using ANTLR for syntax analysis, the generated AST contains nodes such as FunctionDef, arguments, and Return. The Word2Vec model is used to convert identifiers and keywords into feature vectors; Step 3: Model training and optimization We represent the code submission sequence as X = [x_1, x_2, ..., x_T] where each x_1, x_2, ..., x_T is a feature vector; These feature vectors are preprocessed in step 2; Step 4: Code coverage location and path tracing First, we configure the output format of JaCoCo and choose to generate coverage reports in XML or HTML format for subsequent analysis and presentation; insert probes at each function entry, loop, and conditional branch; Insert probes through JaCoCo configuration files and command line tools; add JaCoCo plugins to the configuration files of build tools Maven or Gradle, and specify the rules for probe insertion and the format of output reports; Record the number of calls and parameters of each function by inserting probes in the code, and use the API provided by JaCoCo or parse the coverage report it generates; extract the execution information of each function by parsing the report in XML format, including reading the XML file, parsing the node information, and storing the data in a hash table or database; Step 5: Data collection and processing During software testing, coverage data is usually generated by probes; these probes are embedded in the code and record information about the execution path. The coverage data is converted into JSON format. Data cleaning, removing redundant or incomplete data entries, and merging coverage data from multiple files or multiple test runs; Step 6: Real-time monitoring and feedback Real-time feedback is achieved by using Python's websockets library. WebSocket is a full-duplex communication protocol that allows real-time data exchange between the server and the client, pushing the code coverage results to the developer's integrated development environment IDE in real time; The server will calculate the coverage after the code is submitted, and send the latest coverage data to the client through the WebSocket connection. After receiving the data, the client will immediately update the interface in the IDE to display the current coverage situation; Step 7: Customize report generation and optimization Use Python's ReportLab library to generate coverage reports in PDF format, extract key information from coverage data, and utilize ReportLab's API to format and layout report content.
Citation Information
Cited By
C + + code coverage rate visual detection method
CN120234241A