Automatic code static analysis and resource optimization method and system based on Polyspace

By combining Polyspace static analysis, Jenkins automation construction and machine learning model, static analysis and resource optimization of automated code are achieved, solving the problems of low efficiency of traditional on-board software testing, lack of integration and collaboration and poor resource management, and improving the efficiency and quality of software development.

CN119862574APending Publication Date: 2025-04-22BORGWARNER DRIVE SYST (SUZHOU) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411937100.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

Traditional in-vehicle software testing is inefficient, lack of integration and collaboration, and poor resource management, resulting in extended software development cycle, difficult quality assurance and waste of resources.

Method used

By combining Polyspace static analysis, Jenkins automation construction and machine learning models, automated code static analysis and resource optimization are achieved. Jenkins calls Polyspace for static code analysis, and uses machine learning models to predict resource requirements and dynamically adjust resource configuration.

Benefits of technology

It realizes early detection and repair of code problems, optimizes resource allocation, improves software development efficiency and quality, and ensures the stable operation of on-board software in the automotive system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119862574A_ABST
    Figure CN119862574A_ABST
Patent Text Reader

Abstract

The invention relates to an automatic code static analysis and resource optimization method and system based on Polyspace, the method calls the Polyspace and a machine learning model through Jenkins to realize static code analysis and predict resource requirements, and the method comprises the following steps: triggering the Jenkins to call a Polyspace condition, after the Jenkins performs code pulling and compiling, calling the Polyspace to perform static code analysis, and after the Jenkins performs code compiling, calling the Polyspace to perform resource optimization. A static code analysis result is transmitted to Jenkins, and a code analysis report is automatically generated by the Jenkins; resource data and management data are obtained, and based on the resource data, the management data and the code analysis report, Jenkins calls a machine learning model to carry out resource demand prediction; and dynamically adjusting the resource configuration when the Jenkins executes the task based on the resource demand prediction result. Compared with the prior art, by means of the automatic process, the software development efficiency and the code quality are improved, resource allocation in the code analysis process is optimized, and efficient code analysis is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of computer software engineering, code static analysis, continuous integration / continuous deployment (CI / CD), machine learning and resource management, and in particular to an automated code static analysis and resource optimization method and system based on Polyspace. Background Art

[0002] With the rapid development of automobile intelligence and networking, the scale and complexity of vehicle application layer software are increasing. The software installed in the vehicle not only needs to process complex sensor data and execute various control logics, but also needs to interact with other systems in the vehicle and external networks. Therefore, high-quality software is essential to ensure the safety, reliability and performance of the vehicle. However, traditional software testing and resource management methods have the following disadvantages: 1) Low testing efficiency: Manual testing of code is a common method in the traditional software development process, but this method consumes a lot of time and manpower. In the vehicle-mounted underlying and application layer software, the code volume is huge and the logic is complex. Manual testing is difficult to cover all possible execution paths and input conditions. And every time the code is modified, it needs to be fully retested, which prolongs the development cycle. In addition, traditional code analysis tools can often only perform superficial syntax checks or simple logic verifications, and have limited detection capabilities for potential deep-level errors, such as runtime errors, memory leaks, data competition, etc. This makes many software problems discovered only in the late development stage or even in the vehicle operation stage, and the repair cost is extremely high; 2) Lack of integration and collaboration: Code static analysis tools, continuous integration servers, and resource management systems are often independent of each other and lack effective integration. In addition, although Polyspace is powerful, when used alone, it lacks close integration with the entire software development process and cannot achieve automated continuous analysis. For different types of in-vehicle software projects, there is also a lack of targeted integration strategies, resulting in unstable integration effects and the inability to give full play to the advantages of Polyspace static code testing and analysis. If the results of code analysis cannot be fed back to the continuous integration system for processing in a timely manner, and resource allocation cannot be dynamically adjusted according to the situation of code analysis, the entire software development process will be fragmented, information transmission will be poor, and it will be difficult for various links to work together. 3) Poor resource management: In terms of resource allocation, traditional methods are mostly based on experience or simple rules and lack scientific basis. It is impossible to accurately predict the resource requirements of software projects at different development stages and different functional modules, which is prone to waste due to excessive resource allocation, or slow or even failed analysis due to insufficient resource allocation. In addition, during the operation of the project, there is a lack of effective monitoring and dynamic adjustment mechanisms, and resource allocation cannot be optimized in a timely manner according to actual conditions, resulting in waste of hardware resources and increased enterprise costs.

[0003] Therefore, providing a method that can integrate and solve the problems of low testing efficiency, lack of integration and coordination, and poor resource management existing in traditional vehicle software testing and resource management methods is a technical problem that needs to be solved. Summary of the invention

[0004] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and to provide an automated code static analysis and resource optimization method and system based on Polyspace. By combining the accuracy of Polyspace static analysis, the automated construction capability of Jenkins and the resource allocation of machine learning models, early discovery and repair of code problems can be achieved, resource allocation can be optimized, software development efficiency and software quality can be improved, and the stable operation of vehicle-mounted software in the automobile system can be guaranteed.

[0005] The purpose of the present invention can be achieved by the following technical solutions:

[0006] According to a first aspect of the present invention, there is provided a Polyspace-based automated code static analysis and resource optimization method, wherein the method implements static code analysis and predicts resource requirements by calling Polyspace and a machine learning model through Jenkins, including:

[0007] Triggering Jenkins to call Polyspace conditions, after Jenkins pulls and compiles the code, calls the Polyspace to perform static code analysis, and transmits the results of the static code analysis to Jenkins, and the Jenkins automatically generates a code analysis report; the code analysis report includes: code error distribution, complexity analysis and security vulnerabilities;

[0008] Obtain resource data and management data. Based on the resource data, management data and code analysis report, Jenkins calls the machine learning model to predict resource demand; the resource data includes actual CPU usage and actual memory usage, and the management data includes code change records;

[0009] Dynamically adjust the resource configuration when Jenkins executes tasks based on resource demand prediction results. The tasks include code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection, and calling machine learning models.

[0010] As a preferred technical solution, the conditions for calling Polyspace include: source code changes, meeting the scheduled time for calling Polyspace, or meeting the number of code submissions.

[0011] As a preferred technical solution, the method for code analysis includes control flow analysis and data flow analysis. The Bug Finder module in the Polyspace detects potential errors in code execution based on the control flow analysis results and the data flow analysis results; the Code Prover module in the Polyspace detects code execution errors based on the control flow analysis results and the data flow analysis results; the potential errors include null pointer references, memory leaks and data contention, and the execution errors include overflow, division by zero and array out of bounds.

[0012] As a preferred technical solution, the control flow analysis and data flow analysis method is:

[0013] The control flow determines all execution paths of the code execution based on all logical paths of the acquired code, wherein the execution paths include branches, loops and function calls;

[0014] The data flow determines the value range of the variable based on the flow of the variable in the code execution path and the definition, use and transfer of all variables in the code.

[0015] As a preferred technical solution, the method for predicting resource demand is:

[0016] Processing the resource data, management data and code analysis report, and performing feature conversion on the results of the data processing to obtain input features;

[0017] The input features are processed using a machine learning model to obtain a resource demand prediction result.

[0018] As a preferred technical solution, the data processing includes:

[0019] Data cleaning: Check whether the data in the code analysis report is reasonable and complete based on the resource monitoring log and code change record, and remove or mark unreasonable and incomplete data;

[0020] Feature extraction: Preliminary extraction of numerical features based on the code analysis report after data cleaning;

[0021] Feature standardization: based on the numerical features, the resource data are paired, and the correlation coefficient between the features and the resource data is calculated using a correlation analysis method, and features with high correlation coefficient values ​​are selected for feature standardization;

[0022] Feature optimization: Visualize the features after feature standardization to obtain input features.

[0023] As a preferred technical solution, the visualization processing includes drawing a correlation matrix diagram and a feature distribution histogram.

[0024] As a preferred technical solution, the training method of the machine learning model is a distributed training method, including:

[0025] Constructing a machine learning model training data set and processing the data in the data set, wherein the machine learning model training data set includes historical resource data, management data, and code analysis reports;

[0026] Randomly shuffle the machine learning model training data set after data preprocessing, and divide it into training set, validation set and test set according to the preset ratio;

[0027] Divide the data in the training set into multiple parts and assign each part to different computing nodes;

[0028] Each computing node is trained based on the corresponding training set data;

[0029] The model performance is evaluated using the validation set and test set, and the machine learning model with the best performance is selected.

[0030] As a preferred technical solution, the method further includes: obtaining resource data and code analysis reports for dynamically adjusting Jenkins to execute calling tasks, analyzing them, and generating corresponding operations based on the analysis results, wherein the analysis results and corresponding operations include:

[0031] If the analysis result is that the CPU usage continues to exceed the set threshold, the memory usage reaches the set value, or the Polyspace code analysis has a serious error and / or the Polyspace code analysis time exceeds the preset time, the corresponding operation generated is to issue an alarm signal;

[0032] If the resource demand prediction result predicted by the machine learning model deviates from the actual situation by more than a threshold, the corresponding operation generated is to retrain the machine learning model based on the deviation.

[0033] According to a second aspect of the present invention, there is provided an automated code static analysis and resource optimization system based on Polyspace, the system being used to implement the above method, comprising:

[0034] Code static analysis module: This module uses Polyspace to perform static analysis on the code obtained from the automatic build and report generation module, and outputs the code static analysis results;

[0035] Automatic build and report generation module: This module includes the Jenkins server and its related plug-ins and project management tools. The Jenkins server and its related plug-ins are used for code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection and calling machine learning models. The project management tool is used to record code changes and perform task allocation.

[0036] Resource Demand Prediction Module: This module uses machine learning models to predict resource demand based on the code analysis reports, resource data, and management data generated or recorded by the automatic build and report generation module;

[0037] Resource allocation optimization module: This module uses the server's resource management tool to dynamically adjust the resource configuration when Jenkins executes the calling task based on the resource demand prediction results generated by the resource demand prediction module.

[0038] Compared with the prior art, the present invention integrates a Jenkins server, a Polyspace static code analysis tool, and a machine learning model, sets the conditions for the Jenkins server to call the Polyspace static code analysis tool for code analysis, realizes the automation of code analysis and resource optimization during code analysis, and optimizes the resource allocation of the code analysis process while improving software development efficiency and code quality, thereby ensuring efficient code analysis. The method provided by the present invention does not require manual intervention, reduces development and operation and maintenance costs, and in practical applications can effectively help vehicle application layer software developers quickly discover and fix code problems, reasonably allocate resources, and ensure the security, reliability, and performance of software, thereby providing strong technical support for the development of automotive intelligence and having broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 is a flow chart of the method of the present invention;

[0040] Figure 2 This is the architecture diagram of the vehicle application layer software automatic code static analysis and resource optimization of the present invention;

[0041] Figure 3 The following is a flow chart of the PolySpace code static analysis task of the present invention;

[0042] Figure 4 The resource allocation and monitoring optimization flow chart of the present invention;

[0043] Figure 5 It is the Jenkins task flow of the present invention;

[0044] Figure 6 This is a diagram of the machine learning model architecture of the present invention. DETAILED DESCRIPTION

[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0046] The present invention provides a method for automatic code static analysis and resource optimization of vehicle application layer software to solve the problems of low code testing efficiency, difficulty in ensuring software quality and unreasonable resource allocation. By combining Polyspace static analysis, Jenkins automatic construction and machine learning model prediction, efficient testing, quality assurance and resource optimization of vehicle application layer software are achieved. Figure 1 The process shown is implemented Figure 2 The functions of the automatic code static analysis and resource optimization architecture of the in-vehicle application layer software are shown.

[0047] Detailed, automated static analysis of vehicle application layer software code and assembly of resource optimization architecture include:

[0048] A1. Install Polyspace and Jenkins, and prepare the machine learning environment.

[0049] A11. Install Polyspace according to the server's operating system type and hardware configuration. Perform a preliminary test after the installation is complete. Enter simple test commands through the command line to verify whether Polyspace can start and run basic functions normally, and configure the Polyspace environment variables so that it can be called through the command line in any directory on the server.

[0050] A12. Choose a Jenkins installation method that is compatible with the server operating system. When installing necessary plug-ins, such as the Git plug-in for code version management and the email plug-in for sending reports, first check the compatibility of the plug-ins. After setting up the Jenkins CI / CD server, perform basic system configuration, such as setting the working directory and build cache space, to optimize server performance. When configuring the working directory, select a disk partition with sufficient storage space and fast read and write speed to avoid the execution of build tasks affected by insufficient disk space or read and write bottlenecks. Create a task in Jenkins specifically for performing Polyspace analysis through Pipeline, then fill in the code repository information in the source code management section and set the build trigger. According to project requirements, the trigger condition can be set to the source code change in the code repository, the scheduled time for calling Polyspace, or the number of code submissions. Define the build phase in detail in the Pipeline script, including code pulling, compilation, calling Polyspace for Run Bug Finder and Code Prover static analysis, and other steps.

[0051] A13. Select the appropriate machine learning library to install according to project requirements.

[0052] The assembly environment of this architecture is Python, and the corresponding GPU driver and CUDA toolkit (for NVIDIA GPU) need to be installed according to the hardware configuration of the server (whether there is a GPU). At the same time, in order to improve the training efficiency of the model, the GPU memory usage ratio is set to ensure that the model training can obtain sufficient GPU resources when running multiple tasks. In addition, the Python environment is optimized, and the acceleration library (numba) is installed to increase the data processing speed, realizing the allocation and optimization of server resources.

[0053] Specifically, the method provided by the present invention comprises the following steps:

[0054] S1. Code static analysis:

[0055] S11. Using the source code of the vehicle navigation system software as input, the source code includes codes of functional modules such as map display, route planning, and real-time traffic information acquisition.

[0056] S12, determine whether the condition for Jenkins to call Polyspace can be triggered. If so, after Jenkins pulls and compiles the source code of the vehicle navigation system software, Polyspace is called to perform static code analysis. The steps are as follows: Figure 3 As shown, including:

[0057] S121. Polyspace extracts the source code of the in-vehicle navigation system software processed by Jenkins from the code repository of the server and parses it, parsing the syntactic elements such as class definitions and function calls into AST nodes and edges.

[0058] Among them, Jenkins processing includes: code pulling and compilation. In the code pulling stage, the Git plug-in is used to obtain the latest source code from the code repository to the Jenkins workspace, and the data flow is from the code repository to the Jenkins local environment; in the compilation stage, the corresponding compilation commands are executed according to the programming language and project structure of the vehicle navigation system software (assuming that the project already has a suitable Makefile, if the source code is in C language, the make command can be used for compilation). In the present invention, the make command is used to build the project, the input data is the pulled code, and the output data is the executable file or intermediate file after construction. The data in the compilation stage is processed in the Jenkins local environment.

[0059] S122, traverse the AST to identify the conditional judgment, loop, function call and other statements in the code, build a control flow chart, and determine all possible execution paths, including branches, loops and function calls, in the process of control flow analysis and data flow analysis, and determine the value range of each variable under different execution paths in combination with the definition, use and transfer of all variables in the code. For example, the value range of the variable that obtains traffic congestion data from real-time traffic information is determined according to the different levels of traffic congestion. That is, after receiving the data, the data flow analyzes the transfer and changes of the data between various variables and functions, and then determines the value range of each variable. Then, based on the analysis results, simulate the variable value range and the behavior of the program in different states in the abstract domain to determine whether the input code is wrong.

[0060] S123. Use the Bug Finder module and the Code Prover module to detect potential runtime errors including null pointer reference, memory leak and data competition, and runtime errors including overflow, division by zero and array out of bounds, output the analysis results, point out the potential error location, type and code quality related information in the code, and store the analysis results in path / to / polyspace / results / polyspace_results.xml.

[0061] S13. The results of static code analysis are transmitted to Jenkins, which automatically generates a code analysis report, including: code error distribution, complexity analysis and security vulnerabilities. In this stage, Jenkins reads the Polyspace analysis results, encrypts the analysis results using a Python encryption script, and the relevant data flows from the local file to the memory for encryption processing. The encrypted result file is collected in Jenkins' Archive Artifacts, and the data flows from the memory to the storage area of ​​Jenkins. If the collection fails, according to the result collection error handling mechanism set in the Jenkins task configuration, when the "Archive Artifacts" function fails to collect the result file, use Jenkins' retry function to set a reasonable number of retries (such as 3 times). An appropriate time interval (such as 1 minute) can be set between each retry, and data flows between the local file system and Jenkins storage.

[0062] In step S1, the following processing is performed on possible error situations such as code pulling failure and Polyspace analysis error, including retrying according to the preset retry strategy, recording the cause of failure, recording the error information in detail and notifying relevant personnel, and taking preliminary repair measures according to the error type.

[0063] S2. Resource demand forecast:

[0064] S21. Obtain resource data and management data from the server, specifically resource usage logs and task allocation information related to the running of the vehicle navigation system software code. The present invention uses an XML parsing library to read logs stored in JSON format, which records information such as CPU usage, memory usage, disk I / O operation times and data volume, and network bandwidth usage at various time points during the actual running of the software; and uses CSV to read management data such as function processing code change records, where the collected code change records include data that can reflect the frequency and magnitude of code changes for each change, such as the number of code lines, change time intervals, and other features. From the code analysis report, obtain relevant information such as code complexity (quantified by calculating indicators such as cyclomatic complexity), function call relationships, code nesting depth, and other features.

[0065] S22. Data processing:

[0066] S221, read the data obtained from different sources in step S21 into the memory, traverse the data in the memory to perform data cleaning, that is, check each record to determine whether there are missing values ​​in the key data fields, and choose to correct or replace the abnormal values ​​in the resource usage log with reasonable values ​​or directly delete the data record, and remove or mark it. Record relevant error information, and establish a data backup mechanism to regularly back up the collected data to prevent data loss or damage.

[0067] S222. Preliminary extraction of numerical features of the data after data cleaning, focusing on features such as code complexity and code nesting depth, function call frequency, and code change frequency.

[0068] S223. Pair the numerical features with the corresponding resource data, and use the correlation analysis method to calculate the correlation coefficient between the features and the resource data. Set the correlation threshold to 0.3-0.5, select the features with high correlation coefficient values ​​that meet the threshold range, and use the Z-score standardization method to standardize the features, so that the numerical features of different magnitudes are scaled to a similar range to remove the dimension effect.

[0069] S224. Use Python's seaborn and matplotlib libraries to draw a correlation matrix diagram and a feature distribution histogram of the features after feature standardization to obtain input features.

[0070] S23. Use the machine learning model to process input features to obtain resource demand prediction results.

[0071] S231. The input features processed in step S22 are organized into project feature data and sent to the machine learning model API service in JSON format using an HTTP request.

[0072] S232. The machine learning model API service receives the call request from Jenkins and performs resource demand prediction.

[0073] S3, dynamically adjust the resource configuration when Jenkins executes tasks. The process of this step is as follows Figure 4 As shown:

[0074] S31. Based on the resource demand prediction results, the server's resource management tool Linux cgroups dynamically adjusts the resource configuration when Jenkins executes tasks (including code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection, and calling machine learning models). For example, if it is predicted that a certain code module analysis requires higher CPU resources, the resource management tool automatically allocates more CPU cores or increases the CPU frequency when executing the Polyspace code static analysis task of the module; for tasks with large memory requirements, the memory allocation is adjusted accordingly.

[0075] S32. Use a combination of Prometheus and Grafana to monitor data. Prometheus is responsible for collecting server resource usage data (including CPU usage, memory usage, network traffic, disk I / O, etc.) and Polyspace analysis result data (such as the number of code errors, analysis time, code coverage, etc.). The collected data can be stored in a database or log file for subsequent analysis. At the same time, a comprehensive logging system is established to record each step of Jenkins task execution, the Polyspace analysis process, and changes in resource allocation. The log contains key information such as timestamps, operation steps, input and output data, error messages, etc. Use log analysis tools (ELK stack) to analyze and index logs in real time, which is convenient for quick query and troubleshooting.

[0076] S33, obtain the monitoring data and log data of step S32, and analyze them in detail, generate corresponding operations based on the analysis results to optimize the machine learning model and Polyspace, if the analysis results are that the CPU usage rate continues to exceed the set threshold (such as 80%), the memory usage rate reaches the set value (such as 90%), or the Polyspace code analysis is seriously wrong and / or the Polyspace code analysis time exceeds the preset time, etc., send an alarm signal and notify the developer and administrator; if the resource demand prediction result predicted by the machine learning model deviates from the actual situation by more than the threshold, retrain the machine learning model based on the deviation, including adding new relevant features, deleting unimportant features, adjusting the number of layers and learning rate of the neural network, etc. At the same time, based on the monitoring data and log analysis results, regularly generate a system operation report, which contains basic project information, code quality assessment indicators, resource usage, analysis results summary, etc. By configuring the email plug-in, the report is sent to relevant personnel in a timely manner. Configure the storage plug-in in Jenkins according to project requirements, select the appropriate storage method to store the results, use data encryption technology to protect sensitive information, set access control, compress the stored data, and regularly clean and archive it, and establish a data backup and recovery mechanism. Through continuous monitoring and optimization, a feedback closed-loop mechanism is formed, the effects of optimization are continuously tracked and evaluated, and the optimization strategy is adjusted again according to actual conditions to maintain efficient and stable analysis and prediction, and continuously improve the quality and development efficiency of the in-vehicle application layer software.

[0077] The present invention realizes the whole process automation series connection by utilizing Jenkins plug-ins and extension functions, such as using parameterized build plug-ins to pass specific parameters to be passed and used in the process, configuring distributed build functions to distribute different tasks to multiple slave nodes for parallel execution to improve efficiency. The detailed Jenkins process is as follows Figure 5 As shown in the figure, Polyspace and machine learning are called through Jenkins, and code analysis and resource optimization are implemented at the same time. The architecture of the machine learning model is as follows Figure 6 As shown in the figure, the training method of the model is distributed training, including:

[0078] B1. Build a machine learning model training data set and process the data in the data set. The machine learning model training data set includes historical resource data, management data, and code analysis reports.

[0079] B2. Randomly shuffle the machine learning model training data set after data preprocessing and divide it into training set, validation set and test set according to 7:2:1.

[0080] B3. Divide the data in the training set into multiple parts and assign each part to different computing nodes.

[0081] B4. Each computing node is trained based on the corresponding training set data.

[0082] B5. Use the validation set and test set to evaluate model performance and select the machine learning model with the best performance.

[0083] During the training process, a regularization method (L1 regularization or L2 regularization) is used to prevent overfitting of the model. After the training is completed, the present invention uses a variety of evaluation indicators such as accuracy, recall rate, F1 value, etc. to comprehensively evaluate the model to evaluate and verify the model.

[0084] The present invention also provides an automated code static analysis and resource optimization system based on Polyspace, which is used to implement the above method, including:

[0085] Code static analysis module: This module uses Polyspace to perform static analysis on the code obtained from the automatic build and report generation module, and outputs the code static analysis results.

[0086] Automatic build and report generation module: This module includes the Jenkins server and its related plug-ins and project management tools. The Jenkins server and its related plug-ins are used for code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection and calling machine learning models. The project management tool is used to record code changes and perform task assignments.

[0087] Resource demand prediction module: This module uses machine learning models to predict resource demand based on the code analysis reports, resource data, and management data generated or recorded by the automatic build and report generation modules. The trained model is deployed as a service that can be called by Jenkins, the API service is written using the Flas framework, and the service is deployed to the server through Docker containerization technology, so that Jenkins can call the model to predict resource demand during operation.

[0088] Resource allocation optimization module: This module uses the server's resource management tool to dynamically adjust the resource configuration when Jenkins executes the calling task based on the resource demand prediction results generated by the resource demand prediction module.

[0089] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above modules can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0090] Specifically, when using the above-mentioned Polyspace automated code static analysis and resource optimization system for code analysis and resource optimization, the usage process is as follows: In the Jenkins interface, click the "New Task" button and enter the task name. For complex in-vehicle software projects, it is recommended to use Pipeline projects to better define and manage complex build processes. On the task configuration page, fill in the project description information to facilitate team members to understand the purpose and objectives of the task. At the same time, you can set the priority and execution node of the task, and arrange the execution order of the task reasonably according to the urgency of the project and the usage of server resources. For example, for critical in-vehicle safety system software projects, a higher priority can be set to ensure that it can obtain server resources for analysis first. When creating a task, you can also configure the permission management of the task, specify which users or user groups have the permission to view, edit and execute the task, and ensure the security and management standardization of the project. Use the "stage" keyword in the Pipeline script to define different stages.

[0091] In the "Build" stage, set the code pulling step, connect to the code repository by configuring the Git plug-in, and use the "checkout scm" command to pull the latest code. In the process of pulling the code, you can add code verification steps, such as checking whether the code format complies with the specifications, whether there are conflicts, etc. In the "Analysis" stage, write a shell script to call Polyspace, for example, set the environment variable "POLYSPACE_HOME" to point to the Polyspace installation directory, and then execute 6 "$POLYSPACE_HOME / bin / polyspace-b<project path>" command for analysis. In order to improve the accuracy and efficiency of the analysis, analysis parameters such as analysis level (detailed level, fast level, etc.) and target architecture are set according to the characteristics of the project. During the configuration process, pay attention to the correctness and completeness of the parameters to avoid analysis failure due to parameter errors. At the same time, the present invention sets an error handling mechanism in this step. When an error occurs in the Polyspace analysis, it can automatically record the error information and take measures such as retrying the analysis or notifying the administrator to handle it.

[0092] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A Polyspace-based automated code static analysis and resource optimization method, characterized in that: The method uses Jenkins to call Polyspace and machine learning models to implement static code analysis and predict resource requirements, including: Triggering Jenkins to call Polyspace conditions, after Jenkins pulls and compiles the code, calls the Polyspace to perform static code analysis, and transmits the results of the static code analysis to Jenkins, and the Jenkins automatically generates a code analysis report; the code analysis report includes: code error distribution, complexity analysis and security vulnerabilities; Obtain resource data and management data. Based on the resource data, management data and code analysis report, Jenkins calls the machine learning model to predict resource demand; the resource data includes actual CPU usage and actual memory usage, and the management data includes code change records; Dynamically adjust the resource configuration when Jenkins executes tasks based on resource demand prediction results. The tasks include code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection, and calling machine learning models.

2. The Polyspace-based automated code static analysis and resource optimization method according to claim 1, characterized in that: The conditions for calling Polyspace include: source code changes, meeting the scheduled time for calling Polyspace, or meeting the number of code submissions.

3. The Polyspace-based automated code static analysis and resource optimization method according to claim 1, characterized in that: The method for performing code analysis includes control flow analysis and data flow analysis. The Bug Finder module in the Polyspace detects potential errors in code execution based on the control flow analysis results and the data flow analysis results; the Code Prover module in the Polyspace detects code execution errors based on the control flow analysis results and the data flow analysis results; the potential errors include null pointer references, memory leaks, and data contention, and the execution errors include overflow, division by zero, and array out-of-bounds.

4. The Polyspace-based automated code static analysis and resource optimization method according to claim 3, characterized in that: The control flow analysis and data flow analysis methods are: The control flow determines all execution paths of the code execution based on all logical paths of the acquired code, wherein the execution paths include branches, loops and function calls; The data flow determines the value range of the variable based on the flow of the variable in the code execution path and the definition, use and transfer of all variables in the code.

5. The Polyspace-based automated code static analysis and resource optimization method according to claim 1, characterized in that: The method for predicting resource demand is as follows: Processing the resource data, management data and code analysis report, and performing feature conversion on the results of the data processing to obtain input features; The input features are processed using a machine learning model to obtain a resource demand prediction result.

6. The Polyspace-based automated code static analysis and resource optimization method according to claim 5, characterized in that: The data processing includes: Data cleaning: Check whether the data in the code analysis report is reasonable and complete based on the resource monitoring log and code change record, and remove or mark unreasonable and incomplete data; Feature extraction: Preliminary extraction of numerical features based on the code analysis report after data cleaning; Feature standardization: based on the numerical features, the resource data are paired, and the correlation coefficient between the features and the resource data is calculated using a correlation analysis method, and features with high correlation coefficient values ​​are selected for feature standardization; Feature optimization: Visualize the features after feature standardization to obtain input features.

7. The Polyspace-based automated code static analysis and resource optimization method according to claim 6, characterized in that: The visualization process includes drawing a correlation matrix diagram and a feature distribution histogram.

8. The Polyspace-based automated code static analysis and resource optimization method according to claim 1, characterized in that: The training method of the machine learning model is a distributed training method, including: Constructing a machine learning model training data set and processing the data in the data set, wherein the machine learning model training data set includes historical resource data, management data, and code analysis reports; Randomly shuffle the machine learning model training data set after data preprocessing, and divide it into training set, validation set and test set according to the preset ratio; Divide the data in the training set into multiple parts and assign each part to different computing nodes; Each computing node is trained based on the corresponding training set data; The model performance is evaluated using the validation set and test set, and the machine learning model with the best performance is selected.

9. The Polyspace-based automated code static analysis and resource optimization method according to claim 1, characterized in that: The method further includes: obtaining resource data and code analysis reports for dynamically adjusting Jenkins to execute calling tasks, analyzing the data and code analysis reports, and generating corresponding operations based on the analysis results, wherein the analysis results and the corresponding operations include: If the analysis result is that the CPU usage continues to exceed the set threshold, the memory usage reaches the set value, or the Polyspace code analysis has a serious error and / or the Polyspace code analysis time exceeds the preset time, the corresponding operation generated is to issue an alarm signal; If the resource demand prediction result predicted by the machine learning model deviates from the actual situation by more than a threshold, the corresponding operation generated is to retrain the machine learning model based on the deviation.

10. An automated code static analysis and resource optimization system based on Polyspace, characterized in that: The system is used to implement the methods described in claims 1 to 9, including: Code static analysis module: This module uses Polyspace to perform static analysis on the code obtained from the automatic build and report generation module, and outputs the code static analysis results; Automatic build and report generation module: This module includes the Jenkins server and its related plug-ins and project management tools. The Jenkins server and its related plug-ins are used for code pulling, code compilation, calling Polyspace for code static analysis, static code analysis result collection and calling machine learning models. The project management tool is used to record code changes and perform task allocation. Resource Demand Prediction Module: This module uses machine learning models to predict resource demand based on the code analysis reports, resource data, and management data generated or recorded by the automatic build and report generation module; Resource allocation optimization module: This module uses the server's resource management tool to dynamically adjust the resource configuration when Jenkins executes the calling task based on the resource demand prediction results generated by the resource demand prediction module.

Citation Information

Cited By

  • Load optimization method of automobile controller and related equipment

    CN121386728A