An Exception Handling Method during Code Generation

Through the machine learning model, the code generation process is monitored in real time, combined with historical data to identify exception patterns, and corrective measures are triggered in stages, solving the accuracy and system stability of abnormal detection during the code generation process, and achieving efficient exception handling.

CN119883870BActive Publication Date: 2025-07-22TAIJI COMPUTER CORPORATION LIMITED
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510379090.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-28
Publication Date
2025-07-22
Estimated Expiration
2045-03-28

AI Technical Summary

Technical Problem

Modern software systems are complex, and abnormalities in the code generation process are difficult to predict and deal with. Traditional methods are inefficient and prone to false alarms or missed reports.

Method used

Through the machine learning model, the code generation process is monitored in real time, combined with historical data to identify abnormal patterns, corrective measures are triggered in stages, including the first abnormality detection and the second abnormality detection, to evaluate the correction effect and continuously improve.

Benefits of technology

It improves the accuracy and system robustness of abnormal detection, reduces false alarms and missed reports, optimizes the exception handling process, and reduces the need for manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883870B_ABST
    Figure CN119883870B_ABST
Patent Text Reader

Abstract

The present invention provides an exception handling method during code generation, belonging to the technical field of anomaly detection. The method includes collecting historical data during the code generation process, analyzing the historical data using machine learning algorithms to identify anomaly patterns, training a machine learning model using the anomaly patterns, deploying the machine learning model into the code generation process, real-time monitoring code parameters and performing a first anomaly detection on the code generation process to obtain a first anomaly detection result, triggering a first corrective measure of the system, recording the environmental dynamics when an anomaly is detected, and performing a second anomaly detection on the code generation process according to the environmental dynamics to obtain a second anomaly detection result, thereby triggering a second corrective measure, judging the execution effects of the first corrective measure and the second corrective measure and making improvements, improving the accuracy of anomaly detection and the robustness of the system, effectively coping with anomaly situations in complex environments, reducing false alarms and missed detections, and optimizing the anomaly handling process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of anomaly detection, and particularly to an anomaly handling method during the code generation process. Background Art

[0002] Modern software systems are becoming increasingly complex, involving a large number of parameters, dependency libraries, and operating environments. As a result, the code generation process has become more complex, making it difficult to predict and handle abnormal situations. Traditional rule-based anomaly detection methods are difficult to cope with complex and changeable anomaly patterns, with low efficiency and prone to false alarms or missed detections.

[0003] Therefore, the present invention provides an anomaly handling method during the code generation process. Summary of the Invention

[0004] An anomaly handling method during the code generation process provided by the present invention monitors the code generation process in real time through a machine learning model, identifies anomaly patterns in combination with historical data, and triggers corrective measures in stages. First, a first anomaly detection is performed and a first corrective measure is triggered. Subsequently, a second anomaly detection is dynamically performed according to the environment and a second corrective measure is triggered. Finally, the execution effects of the corrective measures are evaluated and continuously improved, thereby improving the accuracy of anomaly detection and the robustness of the system, effectively coping with abnormal situations in complex environments, reducing false alarms and missed detections, optimizing the anomaly handling process, and reducing the need for manual intervention.

[0005] The present invention provides an anomaly handling method during the code generation process, including:

[0006] Step 1: Collect historical data during the code generation process, analyze the historical data using machine learning algorithms to identify anomaly patterns, and train a machine learning model using the anomaly patterns.

[0007] Step 2: Deploy the machine learning model into the code generation process, monitor code parameters in real time, perform a first anomaly detection on the code generation process, obtain a first anomaly detection result, and trigger a first corrective measure of the system.

[0008] Step 3: Record the environmental dynamics when an anomaly is detected, perform a second anomaly detection on the code generation process according to the environmental dynamics, obtain a second anomaly detection result, and further trigger a second corrective measure.

[0009] Step 4: Judge the execution effects of the first corrective measure and the second corrective measure and make improvements.

[0010] An anomaly handling method during the code generation process provided by the present invention collects historical data during the code generation process, analyzes the historical data using machine learning algorithms to identify anomaly patterns, and trains a machine learning model using the anomaly patterns, including:

[0011] Clean and transform the historical data to obtain processed data, classify and extract features from the processed data to obtain the key features and classification features in the code generation process;

[0012] Match machine learning algorithms based on the key features and classification features to obtain the first machine learning algorithm and the second machine learning algorithm, and obtain the abnormal pattern;

[0013] Train a machine learning model according to the abnormal pattern.

[0014] An abnormal handling method in the code generation process provided by the present invention matches machine learning algorithms based on key features and classification features to obtain the first machine learning algorithm and the second machine learning algorithm, and performs abnormal pattern recognition, including:

[0015] Use the first machine learning algorithm to encode the classification features, construct a first model by combining the key features and the encoded classification features, call the first prediction method of the first model to detect abnormal points, the prediction result of the abnormal point is -1, and the normal point is 1. Mark the detected abnormal points for the first time and output them as the first abnormal point set;

[0016] Based on the key features and classification features, use the second machine learning algorithm to set the number of neighbors and the abnormal point ratio, construct a second model, call the second prediction method of the second model to detect abnormal points, and mark the detected abnormal points for the second time and output them as the second abnormal point set;

[0017] Compare the first abnormal point set with the second abnormal point set, and finally mark the intersection of the first abnormal point set and the second abnormal point set to obtain the final abnormal point set;

[0018] Statistically analyze the feature distribution of the final abnormal point set to obtain the abnormal pattern.

[0019] An abnormal handling method in the code generation process provided by the present invention deploys the machine learning model into the code generation process, monitors the code parameters in real time and performs the first abnormal detection on the code generation process to obtain the first abnormal detection result and trigger the first corrective measure of the system, including:

[0020] Integrate the trained machine learning model into the code generation tool for real-time call, collect the code parameters in the code generation process in real time, and the machine learning model sets the first threshold for the code parameters;

[0021] Perform the first abnormal detection based on the first threshold to obtain the first abnormal detection result and implement the first corrective measure.

[0022] An exception handling method during code generation provided by the present invention, wherein a machine learning model sets a first threshold for the code parameters, includes:

[0023] , where represents the first threshold; represents the weight coefficient of the sliding window; t represents time; T represents the time length of the sliding window; represents time the signal value at; represents time the mean value at; represents the exponentially weighted average; k represents the adjustment coefficient; represents the exponentially weighted moving variance.

[0024] An exception handling method during code generation provided by the present invention, records the environmental dynamics when an exception is detected, and performs a second exception detection on the code generation process according to the environmental dynamics to obtain a second exception detection result, and then triggers a second corrective measure, includes:

[0025] Based on the first exception detection result, record the environmental variables, external dependencies, and user behaviors when the exception is detected, and generate a second exception detection;

[0026] According to the second exception detection, determine the second exception detection result in the code generation process and trigger a second corrective measure.

[0027] An exception handling method during code generation provided by the present invention, based on the first exception detection result, records the environmental variables, external dependencies, and user behaviors when the exception is detected, and generates a second exception detection, includes:

[0028] Analyze the correlation between the environmental variables and the first exception detection result, and generate an environmental detection based on the correlation;

[0029] Monitor the running status of the external dependency service, perform index analysis on the performance indicators of the external dependency service, and determine the propagation path of the exception from the external dependency service to the code generation process based on the index analysis, and generate an external dependency detection;

[0030] Analyze the input data and operation sequence submitted by the user, determine the user characteristics, establish a user profile according to the user characteristics, and comprehensively generate a user detection based on the input data, operation sequence, and user profile;

[0031] Combine the environmental detection, external dependency detection, and user detection to generate a second exception detection.

[0032] An exception handling method during code generation provided by the present invention judges the execution effects of a first corrective measure and a second corrective measure and makes improvements, including:

[0033] Quantitatively evaluate the first corrective measure and the second corrective measure to obtain a first effect, and qualitatively evaluate the first corrective measure and the second corrective measure to obtain a second effect;

[0034] Obtain the execution effect by synthesizing the first effect and the second effect, and improve the first corrective measure and the second corrective measure according to the execution effect.

[0035] Compared with the prior art, the beneficial effects of the present application are as follows: By using a machine learning model to monitor the code generation process in real time, identifying abnormal patterns in combination with historical data, and triggering corrective measures in stages. First, perform a first anomaly detection and trigger a first corrective measure, then perform a second anomaly detection according to the environment dynamics and trigger a second corrective measure, and finally evaluate the corrective effect and continuously improve, so as to improve the accuracy of anomaly detection and the system robustness, effectively cope with abnormal situations in complex environments, reduce false alarms and missed alarms, optimize the anomaly handling process, and reduce the need for manual intervention.

[0036] Other features and advantages of the present invention will be described in the following specification, and part of them will become obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention can be realized and obtained by the structures specifically pointed out in the written specification and the drawings.

[0037] The technical solution of the present invention will be further described in detail below through the drawings and embodiments. Description of the Drawings

[0038] The drawings are used to provide a further understanding of the present invention, and constitute a part of the specification. They are used together with the embodiments of the present invention to explain the present invention, and do not constitute a limitation to the present invention. In the drawings:

[0039] Figure 1 It is a flowchart of an exception handling method during code generation provided by an embodiment of the present invention. Detailed Embodiments

[0040] The following describes the preferred embodiments of the present invention with reference to the drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0041] Embodiment 1:

[0042] An embodiment of the present invention provides an exception handling method during code generation, as Figure 1 shown, including:

[0043] Step 1: Collect historical data during the code generation process, analyze the historical data using machine learning algorithms to identify abnormal patterns, and use the abnormal patterns to train a machine learning model;

[0044] Step 2: Deploy the machine learning model into the code generation process, monitor code parameters in real time and perform the first anomaly detection on the code generation process to obtain the first anomaly detection result, and trigger the first corrective measure of the system;

[0045] Step 3: Record the environmental dynamics when an anomaly is detected, and perform the second anomaly detection on the code generation process according to the environmental dynamics to obtain the second anomaly detection result, and then trigger the second corrective measure;

[0046] Step 4: Judge the execution effects of the first corrective measure and the second corrective measure and make improvements.

[0047] In this embodiment, the historical data is various data records accumulated during the code generation process, used to train a machine learning model to identify abnormal patterns, containing sufficient information to characterize the state and performance of the code generation process, as well as various factors that may cause anomalies, including the metric data of the code generation process, code parameters, input data, environmental variables, etc.

[0048] In this embodiment, the machine learning algorithms include the first machine learning algorithm and the second machine learning algorithm.

[0049] In this embodiment, by cleaning, transforming, classifying, and feature extracting the historical data, the key features and classification features in the code generation process are extracted. Based on these features, machine learning algorithms (the first and second algorithms) are matched to identify abnormal patterns and train a machine learning model.

[0050] In this embodiment, the abnormal pattern is a pattern that is significantly deviated from the normal situation. For example, the combination of high code complexity, large code size, and high memory usage results in too long code generation time, and for specific types of input data, errors frequently occur during the code generation process.

[0051] In this embodiment, the machine learning model is a trained model that can detect anomalies. The input is the key features and classification features (cleaned, transformed, and possibly subjected to feature engineering), and the output is for anomaly detection: a probability score indicating the likelihood that an instance is an anomaly. Then a threshold is set to classify the instance as an anomaly or non - anomaly. For classification / regression: a class label (abnormal type) or a predicted code generation time. For example, an isolation forest model may output a score of 0.95 for a data point, indicating that it is very likely to be an anomaly. A random forest model may classify it as an "memory problem" anomaly.

[0052] In this embodiment, code parameters are the input values and settings used by a code generation tool to generate code. For example, in a Python-to-C++ code generation script, the parameters may include: code specifications, high-level specifications of the code to be generated (e.g., JSON objects), optimization levels, integers representing the code optimization level, target platforms, strings indicating the target platforms (e.g., "x86_64", "ARM").

[0053] In this embodiment, the first anomaly detection result is the output of the first-step anomaly detection, indicating whether the code generation process is running normally or an anomaly has been detected. For example, the output may be a boolean value (True indicates an anomaly, False indicates normal) or a probability score representing the likelihood of an anomaly.

[0054] In this embodiment, the first corrective action is the measure taken by the system to address the detected anomaly. For example, if an anomaly is detected (code generation time exceeds the threshold), the first corrective action may be: Retry: Rerun the code generation process with the same parameters; Warning: Issue a warning to the user, providing information about the detected anomaly; Fallback strategy: Generate a simplified version of the code (possibly reducing the optimization level) to avoid excessive generation time; Logging: Record detailed information about the anomaly for future analysis.

[0055] In this embodiment, the second anomaly detection result is the result of the second anomaly detection, indicating the potential root cause of the initially long code generation time. For example, insufficient memory (low available memory) is the main cause, slow database response time (high database response time) is the bottleneck, and the user provided extremely complex input (high input data complexity).

[0056] In this embodiment, the second corrective action is the measure taken to address the root cause identified by the second anomaly detection. For example, if insufficient memory is the cause: The system may recommend increasing the available memory or optimizing the code generation process to reduce memory usage.

[0057] In this embodiment, the environmental dynamics include environmental variables, external dependencies, and user behavior.

[0058] In this embodiment, the two types of corrective actions are comprehensively evaluated by quantitatively and qualitatively assessing their effectiveness. Quantitative evaluation measures efficiency using specific metrics (such as repair time, success rate, etc.), and qualitative evaluation considers the complexity, maintainability, etc. of the measures. The final comprehensive evaluation result is used to guide improvement measures, forming a closed-loop continuous optimization mechanism.

[0059] The working principle and beneficial effects of the above technical solution are as follows: By using a machine learning model to monitor the code generation process in real time, combining historical data to identify abnormal patterns, and triggering corrective measures in stages. First, perform the first anomaly detection and trigger the first corrective measure. Subsequently, perform the second anomaly detection according to the environment dynamics and trigger the second corrective measure. Finally, evaluate the corrective effect and continuously improve, so as to improve the accuracy of anomaly detection and the robustness of the system, effectively handle abnormal situations in complex environments, reduce false alarms and missed detections, optimize the anomaly handling process, and reduce the need for manual intervention.

[0060] Embodiment 2:

[0061] An embodiment of the present invention provides an anomaly handling method during code generation, which collects historical data during the code generation process, uses machine learning algorithms to analyze the historical data, identifies abnormal patterns, and trains a machine learning model using the abnormal patterns, including:

[0062] Clean and transform the historical data to obtain processed data, classify and extract features from the processed data to obtain key features and classification features during the code generation process;

[0063] Match machine learning algorithms based on key features and classification features to obtain a first machine learning algorithm and a second machine learning algorithm, and obtain abnormal patterns;

[0064] Train a machine learning model according to the abnormal patterns.

[0065] In this embodiment, data cleaning and transformation, cleaning, clean errors and inconsistencies in the original data. For example: handle missing values, replace missing code generation times with the average value, or delete entries containing missing data (if the amount of missing data is small), remove outliers, identify and remove extremely high or low code generation times (which may be errors), for example, using box plots or Z-score methods; data type conversion, ensure that all data is in the correct format (for example, convert a string representing time to a numerical value).

[0066] In this embodiment, transformation is to change the representation of data to make it more suitable for machine learning. For example: normalization / standardization, scale the code generation time to a standard range (for example, 0 - 1 or mean of 0 and standard deviation of 1), prevent features with large numerical values from dominating in the model, feature engineering, create new features based on existing features. For example, the change rate of the code generation time can be calculated, process the data, the data after cleaning and transformation, prepare for analysis, which may be a CSV file, a Pandas DataFrame or a similar data structure.

[0067] In this embodiment, the key features are those highly correlated with the code generation time. For example: code size (number of lines of code, number of functions), code complexity (cyclomatic complexity, nesting level), number of external library calls, CPU usage during code generation, memory usage during code generation.

[0068] In this embodiment, the classification features are those used to classify data points (e.g., "normal" or "abnormal"). For example: code generation time, classifying the main features as normal or abnormal according to a threshold, error flag, a binary feature indicating whether an error occurred during the code generation process. A data point may be as follows: [1000, 5, 20, 60%, 50%, 0], representing [code size (LOC), complexity, number of external calls, CPU usage, memory usage, error flag] respectively.

[0069] In this embodiment, the first machine learning algorithm is an algorithm for anomaly detection. For example: Isolation Forest, which is good at detecting outliers in high-dimensional data, One-Class Support Vector Machine, which effectively performs one-class classification (identifying anomalies in a set mainly composed of normal data).

[0070] In this embodiment, the second machine learning algorithm is a classification or regression algorithm used to further understand the reasons after preliminary anomaly detection. For example: Random Forest, which is used to classify anomalies into different types (e.g., memory problems, long compilation time), Linear Regression, which is used to predict the code generation time based on features to identify factors causing long generation time.

[0071] In this embodiment, the classification features are encoded by the first machine learning algorithm and the first model is constructed to detect anomaly points and output the first set of anomaly points; at the same time, the second machine learning algorithm is used to construct the second model to detect anomaly points and output the second set of anomaly points. The two sets of anomaly points are compared and their intersection is taken as the final set of anomaly points, and the feature distribution is statistically analyzed to identify the anomaly pattern.

[0072] The working principle and beneficial effects of the above technical solution are: by cleaning, transforming, classifying and feature extracting historical data, the key features and classification features in the code generation process are extracted. Based on these features, machine learning algorithms (the first and second algorithms) are matched to identify the anomaly pattern and train the machine learning model, thereby realizing accurate detection and prediction of anomalies in the code generation process and improving the efficiency and accuracy of anomaly detection.

[0073] Embodiment 3:

[0074] An embodiment of the present invention provides an anomaly handling method during code generation, which matches machine learning algorithms based on key features and classification features, obtains the first machine learning algorithm and the second machine learning algorithm, and performs anomaly pattern recognition, including:

[0075] Encode the categorical features using the first machine learning algorithm, construct a first model by combining the key features and the encoded categorical features, call the first prediction method of the first model to detect outliers, with the prediction result of an outlier being -1 and that of a normal point being 1. Mark the detected outliers for the first time, and output them as the first outlier set.

[0076] Based on the key features and categorical features, use the second machine learning algorithm to set the number of neighbors and the outlier ratio, construct a second model, call the second prediction method of the second model to detect outliers, and mark the detected outliers for the second time, outputting them as the second outlier set.

[0077] Compare the first outlier set with the second outlier set, and finally mark the intersection of the first outlier set and the second outlier set to obtain the final outlier set.

[0078] Perform statistics on the feature distribution of the final outlier set to further obtain the outlier pattern.

[0079] In this embodiment, the process of encoding the categorical features using the first machine learning algorithm is to convert the categorical features (e.g., "error flag" - 0 means no error, 1 means error) into a numerical representation that can be understood by the machine learning algorithm. Common encoding techniques include: one-hot encoding, which creates a new binary feature for each category (e.g., "error flag" becomes two features: "error_0" and "error_1"), and label encoding, which assigns a unique integer to each category (e.g., 0 means no error, 1 means error). For example, if we have a "programming language" feature with categories "Python", "Java", and "C++", one-hot encoding will create three new features: "language_Python", "language_Java", and "language_C++", with the value of each feature being 1 or 0 depending on the language used.

[0080] In this embodiment, the first model is constructed using the first machine learning algorithm. The isolation forest model can be used for outlier detection. It receives numerical features (code generation time, code size, complexity, encoded categorical features) as input. The first prediction method is that the model predicts whether each data point is an outlier (-1) or a normal point (1). The first marking is that the data points predicted as outliers (-1) are marked as potential outliers. The first outlier set is the set of potential outliers marked by the first model. For example, the isolation forest model may mark a data point with an extremely long code generation time as an outlier (-1), even if other features seem normal.

[0081] In this embodiment, a second model is constructed and a second prediction method is invoked. The number of neighbors is a parameter for algorithms such as the Local Outlier Factor, which determines how many neighbors to consider when evaluating the outlier score of a data point. The outlier ratio is an estimate of the expected percentage of outliers.

[0082] In this embodiment, the second model can be the LOF model, which uses the same input features as the first model but focuses on local density to identify outliers. The number of neighbors and the outlier ratio are parameters that affect the sensitivity of the model. The second prediction method is that the LOF model calculates the outlier score for each data point. Points exceeding the threshold (based on the "outlier ratio") are marked as outliers. The second marking is that the outliers identified by the LOF model are marked, and the second outlier set is the set of outliers identified by the second model. For example, LOF may identify a cluster of data points with an unusually long code generation time and high complexity as outliers, even if some of these points are not marked as outliers by the Isolation Forest.

[0083] In this embodiment, the intersection of the first outlier set and the second outlier set represents the outliers identified by both models, which increases the confidence in outlier detection. The final outlier set is the set of points marked as outliers by both models. For example, only the data points marked as outliers by both the Isolation Forest and LOF are included in the final outlier set.

[0084] In this embodiment, the feature distribution statistics analyze the distribution of key features in the final outlier set, including calculating summary statistics (mean, median, standard deviation, etc.) of each feature in the outlier set; the outlier pattern is the characteristic of the feature distribution in the final outlier set that reveals the outlier pattern. For example, the analysis may find that the characteristics of outliers are unusually high code complexity, unusually large code size, and frequent calls to specific external libraries.

[0085] The working principle and beneficial effects of the above technical solution are: encoding categorical features through the first machine learning algorithm and constructing the first model to detect outliers and output the first outlier set; at the same time, using the second machine learning algorithm to construct the second model to detect outliers and output the second outlier set, comparing the two outlier sets, and taking their intersection as the final outlier set, and statistically analyzing the feature distribution to identify the outlier pattern, so as to adapt to complex and changing outlier situations.

[0086] Embodiment 4:

[0087] An embodiment of the present invention provides an outlier handling method during code generation. Deploy the machine learning model into the code generation process, monitor code parameters in real time, and perform the first outlier detection on the code generation process to obtain the first outlier detection result and trigger the first corrective measure of the system, including:

[0088] Integrate the trained machine learning model into the code generation tool for real-time invocation, collect the code parameters during the code generation process in real time, and the machine learning model sets a first threshold for the code parameters;

[0089] Perform a first anomaly detection based on the first threshold, obtain a first anomaly detection result, and implement a first corrective measure.

[0090] In this embodiment, the code generation tool is a software application for generating code. For example: compilers (such as GCC or Clang), code generators for specific frameworks (e.g., code generators for game engines).

[0091] In this embodiment, integration means embedding the trained machine learning model into the code generation tool so that it can be accessed and used during the code generation process. This usually involves creating an API or interface that allows the code generation tool to communicate with the machine learning model. For example, one might write a Python function that takes code generation parameters as input, calls the trained machine learning model (e.g., a pre-trained scikit-learn model loaded from a file), and returns the prediction result. This function will be integrated into the code generation script.

[0092] In this embodiment, the first threshold is dynamically determined by the machine learning model based on the input code parameters, representing the boundary between the normal range and the abnormal range of the code generation time. The threshold is not a fixed value but varies dynamically according to the context of the code generation parameters. For example, if the code specification is very complex and the optimization level is high, the model may set a higher threshold for the code generation time because these factors tend to increase the generation time.

[0093] The working principle and beneficial effects of the above technical solution are: Integrate the trained machine learning model into the code generation tool, collect code parameters in real time and set the first threshold. Perform anomaly detection based on the first threshold, obtain the detection result and trigger the first corrective measure, so as to realize the real-time monitoring and anomaly handling of the code generation process, reduce the impact of anomalies on the code generation process, improve the system response speed, correct anomalies in a timely manner, and enhance the robustness and reliability of the code generation tool.

[0094] Embodiment 5:

[0095] The embodiment of the present invention provides an anomaly handling method during code generation. The machine learning model sets a first threshold for the code parameters, including:

[0096] , where represents the first threshold; represents the weight coefficient of the sliding window; t represents time; T represents the time length of the sliding window; The signal value at a specific time ; The mean value at a specific time ; Indicates the exponentially weighted moving average; k represents the adjustment coefficient; Indicates the exponentially weighted moving variance.

[0097] The working principle and beneficial effects of the above technical solution are as follows: The sliding window method and the exponentially weighted moving average method are used to dynamically adjust the first threshold. The sliding window method calculates the mean value and variance of the signal value, and the exponentially weighted moving average method pays more attention to recent data. By adjusting the weight coefficient k, the sensitivity and stability of the threshold are balanced, enabling the system to respond to anomalies in a timely manner and avoid false alarms, thereby improving the sensitivity and accuracy of anomaly detection.

[0098] Embodiment 6:

[0099] The embodiment of the present invention provides an anomaly handling method during code generation, which records the environmental dynamics when an anomaly is detected, performs a second anomaly detection on the code generation process based on the environmental dynamics, obtains a second anomaly detection result, and then triggers a second corrective measure, including:

[0100] Based on the first anomaly detection result, record the environmental variables, external dependencies, and user behavior when the anomaly is detected, and generate a second anomaly detection;

[0101] Determine the second anomaly detection result in the code generation process according to the second anomaly detection, and trigger a second corrective measure.

[0102] In this embodiment, environmental variables are system-specific settings that affect the code generation process. For example, the number of CPU cores, the number of available CPU cores for the code generation process. A small number may lead to a long generation time, available memory, the amount of available memory. Insufficient memory may cause slowdown or crashes, operating system version, the operating system version. Older or unstable operating system versions may have performance issues.

[0103] In this embodiment, external dependencies are the status and performance of external services or resources on which the code generation process depends. For example, database response time, the average response time of database queries used in the code generation process. Slow database queries can significantly affect overall performance, network latency, if the code generation process accesses external APIs or resources, it is the network latency. High latency increases the generation time, file system IOPS, the number of input / output operations per second (IOPS) of the file system. Slow I / O may cause bottlenecks.

[0104] In this embodiment, user behavior refers to operations that a user may perform to affect the code generation process. For example, the size of the input data, which is the size of the input data provided by the user for code generation. A larger input may increase the generation time, and the complexity of the input data, which is a measure of the complexity of the user input data (e.g., the number of elements in a data structure or the nesting level of a configuration file). More complex inputs may lead to longer generation times, and the user experience level, which is an indicator representing the user's proficiency with the code generation tool. Inexperienced users may create inputs that result in unexpected outcomes or longer processing times.

[0105] The working principle and beneficial effects of the above technical solution are as follows: After the first anomaly detection discovers a problem, it records the system environment at that time (environmental variables, external dependencies, user behavior, etc.) as input features for the second anomaly detection. The second anomaly detection model uses these features to identify the root cause of the anomaly and trigger a more accurate second corrective measure, more precisely locating the cause of the anomaly, improving the efficiency of anomaly handling, reducing the false alarm rate, and enhancing the stability and reliability of the system.

[0106] Embodiment 7:

[0107] An embodiment of the present invention provides an anomaly handling method during code generation. Based on the results of the first anomaly detection, it records the environmental variables, external dependency situations, and user behavior when an anomaly is detected, and generates a second anomaly detection, including:

[0108] Analyze the correlation between the environmental variables and the results of the first anomaly detection, and generate an environmental detection based on the correlation;

[0109] Monitor the running status of the external dependency service, perform index analysis on the performance metrics of the external dependency service, and determine the propagation path of the anomaly from the external dependency service to the code generation process based on the index analysis, and generate an external dependency detection;

[0110] Analyze the input data and operation sequence submitted by the user, determine user characteristics, establish a user profile based on the user characteristics, and generate a user detection by integrating the input data, operation sequence, and user profile;

[0111] Generate a second anomaly detection by combining the environmental detection, external dependency detection, and user detection.

[0112] In this embodiment, the correlation is to find the statistical correlation between the environmental variables and the results of the first anomaly detection (e.g., those tasks with overly long running times). Methods such as correlation analysis and regression analysis can be used. For example, assume that the analysis finds that when the available memory of the system is below a certain threshold, the probability of overly long code generation time increases significantly, indicating an association between insufficient available memory and overly long code generation time.

[0113] In this embodiment, based on this association relationship, an environment detection program is designed to continuously monitor the available memory. If the available memory is lower than the preset threshold, an alarm will be issued to indicate that there may be a performance problem.

[0114] In this embodiment, the running status of the external dependent services is monitored, and the performance metrics of the external dependent services are analyzed. Based on the metric analysis, the propagation path of anomalies from the external dependent services to the code generation process is determined, and external dependency detection is generated: The running status is to continuously monitor the running status of the external services (such as databases, network services, caches, etc.) on which the code generation process depends, including checking the availability, connection status, etc. of the services. For example, the code generation process depends on a database. The external dependency detection module will monitor the connection status and query response time of the database.

[0115] In this embodiment, the performance metrics are to collect the key performance metrics of the external dependent services, such as the average query response time of the database, the average latency of the network service, the hit rate of the cache, etc.

[0116] In this embodiment, the metric analysis is to analyze these performance metrics and find the association with the overly long code generation time. For example, it can be analyzed whether the database query response time significantly increases in tasks with overly long code generation time.

[0117] In this embodiment, the propagation path is to try to determine how the anomalies propagate from the external dependent services to the code generation process. For example, if it is found that the increase in the database query response time is highly correlated with the overly long code generation time, then it can be inferred that the database performance problem is the cause of the overly long code generation time.

[0118] In this embodiment, based on the metric analysis and the analysis of the propagation path, an external dependency detection program is designed. This program will continuously monitor the key performance metrics of the external dependent services and issue an alarm when the metrics exceed the preset threshold.

[0119] In this embodiment, the input data and operation sequence submitted by the user are analyzed to determine the user characteristics. Based on the user characteristics, a user profile is established. Combining the input data, operation sequence, and user profile, user detection is generated: The input data and operation sequence submitted by the user (the input data and operation sequence submitted by the user): Record the input data (such as code specifications, parameters, etc.) in the code generation request submitted by the user and the operation sequence performed by the user. For example, record the size and complexity of the code specifications submitted by the user, and the code generation options selected by the user.

[0120] In this embodiment, user features are extracted from the data and operation sequences submitted by the user. For example, the user often submits large and complex code specifications, or the user often selects options with a high optimization level.

[0121] In this embodiment, a user profile is established based on user features. For example, users can be divided into different profiles such as novice users, advanced users, and high-demand users.

[0122] In this embodiment, user detection is to design a user detection program to identify user behavior patterns that may cause excessive code generation time according to the user profile. For example, if it is found that tasks submitted by high-demand users often have excessive code generation time, the program can issue an alarm.

[0123] The working principle and beneficial effects of the above technical solution are: by analyzing the association between the first anomaly detection result and environmental variables, external dependencies, and user behavior, three types of auxiliary detections are constructed: environmental detection, external dependency detection, and user detection. The auxiliary detections identify potential anomaly factors from different dimensions respectively, and the second anomaly detection is generated by integrating the results of the three types of detections, which can more accurately locate the root cause of the problem, thereby triggering more effective second corrective measures, reducing false alarms and missed detections, more effectively identifying the cause of anomalies, and improving the system stability and self-healing ability.

[0124] Embodiment 8:

[0125] An embodiment of the present invention provides an anomaly handling method during code generation, which judges and improves the execution effects of the first corrective measure and the second corrective measure, including:

[0126] Quantitatively evaluate the first corrective measure and the second corrective measure to obtain the first effect, and qualitatively evaluate the first corrective measure and the second corrective measure to obtain the second effect;

[0127] Integrate the first effect and the second effect to obtain the execution effect, and improve the first corrective measure and the second corrective measure according to the execution effect.

[0128] In this embodiment, quantitative evaluation is to measure the effect of the corrective measure using numerical indicators. For example, the first corrective measure is to re-run, and the corresponding quantitative evaluation includes the average repair time after re-running, that is, how long it takes on average to successfully generate code after re-running (the lower the value, the better), and the success rate, that is, what proportion of problems are solved by re-running; the second corrective measure is database optimization, and the corresponding quantitative evaluation includes the average code generation time, that is, what is the average code generation time after database optimization, and the database query response time, that is, whether the optimization reduces the average response time of database queries.

[0129] In this embodiment, the first effect is the result of quantitative evaluation. For example, the re-run mechanism reduces the average repair time by 15%, but the success rate is only 70%. Database optimization reduces the average code generation time by 30% and the database query response time by 40%.

[0130] In this embodiment, qualitative evaluation assesses various aspects of corrective measures that are difficult to quantify. For example, the first corrective measure is re-run, and the corresponding qualitative evaluations include simplicity, whether the re-run mechanism is easy to implement and understand, robustness, whether the re-run is always effective when the problem is caused by a transient issue, or whether it fails repeatedly in some cases, resource consumption, whether the re-run consumes too many system resources; when the second corrective measure is database optimization, the corresponding qualitative evaluations include maintainability, whether the database optimization changes are easy to maintain and update, scope of impact, whether the database optimization has any unexpected impact on other parts of the system, and implementation difficulty, whether it is difficult to implement the database optimization.

[0131] In this embodiment, the second effect is the result of qualitative evaluation. For example, the re-run mechanism is easy to implement but not robust enough; it fails in some cases. Database optimization is relatively complex to implement but improves system stability.

[0132] In this embodiment, the execution effect is a summary of the quantitative and qualitative results, comprehensively evaluating the effectiveness of each corrective measure. For example, although the re-run mechanism provides a quick but unreliable solution, database optimization provides a more sustainable solution and brings significant performance improvements, despite the increased initial implementation complexity.

[0133] In this embodiment, improvement is to modify the corrective measures based on the execution effect. For example, improve the retry mechanism by implementing a more complex retry logic (such as exponential backoff) to more effectively handle transient errors and reduce resource consumption, improve database optimization by further optimizing database queries to obtain greater performance improvements or address any unexpected consequences found in the qualitative evaluation. This may include adjusting database settings or using more efficient query patterns, developing new corrective measures if both methods are not satisfactory, then completely developing new corrective measures.

[0134] The working principle and beneficial effects of the above technical solution are as follows: By quantitatively and qualitatively evaluating the effects of the first and second corrective measures, a comprehensive evaluation of these two types of measures is conducted. Quantitative evaluation measures efficiency using specific metrics (such as repair time, success rate, etc.), while qualitative evaluation considers the complexity, maintainability, etc. of the measures. The final comprehensive evaluation result is used to guide improvement measures, forming a closed-loop continuous optimization mechanism, improving the efficiency and accuracy of exception handling, reducing system failure rates, and enhancing system stability and reliability.

[0135] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the present invention in each embodiment.

Claims

1. An exception handling method during code generation, characterized in that Including: Step 1: Collect historical data during the code generation process, analyze the historical data using machine learning algorithms to identify abnormal patterns, and train a machine learning model using the abnormal patterns; Step 2: Deploy the machine learning model into the code generation process, monitor code parameters in real time and perform the first anomaly detection on the code generation process to obtain the first anomaly detection result and trigger the first corrective measure of the system; Step 3: Record the environmental dynamics when an anomaly is detected, and perform the second anomaly detection on the code generation process based on the environmental dynamics to obtain the second anomaly detection result, and then trigger the second corrective measure; Step 4: Judge the execution effects of the first corrective measure and the second corrective measure and make improvements; Among them, Step 2 includes: Integrate the trained machine learning model into the code generation tool for real-time invocation, collect code parameters in the code generation process in real time, and the machine learning model sets a first threshold for the code parameters; Perform the first anomaly detection based on the first threshold to obtain the first anomaly detection result and implement the first corrective measure; Among them, Step 3 includes: Based on the first anomaly detection result, record the environmental variables, external dependencies, and user behaviors when an anomaly is detected to generate the second anomaly detection; Determine the second anomaly detection result in the code generation process according to the second anomaly detection and trigger the second corrective measure; Among them, the machine learning model sets a first threshold for the code parameters, including: , where represents the first threshold; represents the weight coefficient of the sliding window; t represents time; T represents the time length of the sliding window; represents time the signal value at; represents time the mean value at; represents the exponentially weighted average; k represents the adjustment coefficient; represents the exponentially weighted moving variance.

2. The exception handling method during code generation according to claim 1, characterized in that, Collect historical data during the code generation process, analyze the historical data using machine learning algorithms to identify abnormal patterns, and train a machine learning model using the abnormal patterns, including: Clean and transform the historical data to obtain processed data, classify and extract features from the processed data to obtain key features and classification features in the code generation process; Match machine learning algorithms based on the key features and classification features to obtain the first machine learning algorithm and the second machine learning algorithm, and obtain abnormal patterns; Train a machine learning model according to the abnormal patterns.

3. The exception handling method during code generation according to claim 2, characterized in that, Match machine learning algorithms based on the key features and classification features to obtain the first machine learning algorithm and the second machine learning algorithm, and perform abnormal pattern recognition, including: Use the first machine learning algorithm to encode the classification features, construct a first model by combining the key features and the encoded classification features, call the first prediction method of the first model to detect abnormal points, the prediction result of the abnormal point is -1, and the normal point is 1. Mark the detected abnormal points for the first time and output them as the first abnormal point set; Based on the key features and classification features, use the second machine learning algorithm to set the number of neighbors and the abnormal point ratio, construct a second model, call the second prediction method of the second model to detect abnormal points, and mark the detected abnormal points for the second time and output them as the second abnormal point set; Compare the first abnormal point set with the second abnormal point set, and finally mark the intersection of the first abnormal point set and the second abnormal point set to obtain the final abnormal point set; Statistically analyze the feature distribution of the final abnormal point set to obtain abnormal patterns.

4. The exception handling method during code generation according to claim 1, wherein Record the environmental variables, external dependencies, and user behaviors when an anomaly is detected based on the first anomaly detection result, and generate a second anomaly detection, including: Analyze the correlation between the environmental variables and the first anomaly detection result, and generate an environmental detection based on the correlation; Monitor the running status of the external dependent services, perform metric analysis on the performance metrics of the external dependent services, determine the propagation path of the anomaly from the external dependent services to the code generation process based on the metric analysis, and generate an external dependency detection; Analyze the input data and operation sequences submitted by the user, determine the user characteristics, establish a user profile based on the user characteristics, and generate a user detection by integrating the input data, operation sequences, and user profile; Generate a second anomaly detection by combining the environmental detection, external dependency detection, and user detection.

5. The exception handling method during code generation according to claim 1, characterized in that Judge the execution effects of the first corrective measure and the second corrective measure and make improvements, including: Conduct a quantitative evaluation of the first corrective measure and the second corrective measure to obtain a first effect, and conduct a qualitative evaluation of the first corrective measure and the second corrective measure to obtain a second effect; Obtain the execution effect by integrating the first effect and the second effect, and improve the first corrective measure and the second corrective measure according to the execution effect.

Citation Information

Patent Citations

  • Computer software protection system and method based on cloud computing

    CN117892316A

  • Iron tower state monitoring method based on time sequence

    CN118690226A