Code quality evaluation method and system, computer equipment and readable storage medium
By collecting and preprocessing the runtime data of the application software, determining abnormal functions and performing code evaluation, the problem that the existing technology cannot evaluate the actual use and optimization requirements of online code is solved, and a comprehensive evaluation and optimization suggestions for code quality are achieved.
Patent Information
- Application Number
- CN202411864365.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-08
AI Technical Summary
Static or dynamic code analysis cannot confirm whether online code is in actual use, cannot evaluate whether the code is worthy of optimization under existing business volume, APM tools cannot provide specific code coverage and quality assessment, and cannot give direct coding suggestions.
By collecting runtime data when users use the application software, including interface call data, online error data and code coverage, preprocessing is performed to determine the abnormal function, evaluate the code of the abnormal function according to the preset encoding rules, and push the evaluation results to the terminal.
It realizes the evaluation of the actual usage and optimization requirements of online code, provides specific code coverage and quality assessment, and provides direct coding suggestions to help developers repair and optimize code in a timely manner.
Smart Images

Figure CN119782114A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of code quality assessment, and in particular to a code quality assessment method, a code quality assessment system, a computer device and a readable storage medium. Background Art
[0002] Code quality analysis is a key step in code quality assessment and a key link in software development. Code quality analysis aims to ensure the reliability, maintainability and security of the code. Existing technologies mainly include static code analysis and dynamic code analysis.
[0003] Static code analysis refers to the use of static code analysis tools (such as PMD, SonarQube) to analyze source code to detect syntax errors, coding standards, and potential security vulnerabilities. Static analysis is performed during the code writing phase, which can identify problems in the early stages of development and reduce subsequent debugging costs. However, static analysis can only capture explicit errors and specification issues in the code during the development phase, and cannot detect runtime exceptions and actual performance bottlenecks, nor can it identify whether the online code is still in actual use or its optimization needs.
[0004] Dynamic code analysis refers to code analysis performed while the program is running, such as monitoring memory usage, performance bottlenecks, and concurrency issues while the program is running. It evaluates the actual behavior of the code through runtime data, thereby catching runtime problems that static analysis cannot identify. Although dynamic analysis can monitor runtime memory usage, performance bottlenecks, and concurrency issues, it still relies on specific inputs in the test environment and cannot reflect problems in real user usage scenarios.
[0005] Whether it is static or dynamic code analysis, it is impossible to confirm whether the online code is still in actual use, and whether the code is worth further optimization under the current business volume. Especially now that agile development is popular, both code and personnel are updated very quickly.
[0006] In order to obtain the program runtime indicators, a relatively close solution is the Application Performance Monitor (APM) tool. The APM tool is used to monitor the performance of the application in the production environment and capture data such as response time, resource usage, and abnormal situations. It is similar to dynamic code analysis and focuses on the actual performance data at runtime. The APM tool is mainly used for performance monitoring in the production environment. Although it can capture runtime performance data, it is not directly related to the code quality detection rules, and cannot provide specific code coverage and code quality evaluation, let alone give direct coding suggestions. Summary of the invention
[0007] The technical problems to be solved by the present invention are: neither static nor dynamic code analysis can confirm whether the online code is still in actual use, and whether the code is worth further optimization under the current business volume; and APM tools cannot provide specific code coverage and code quality assessment, let alone give direct coding suggestions.
[0008] In view of the above-mentioned deficiencies of the prior art, the following solutions are provided:
[0009] In a first aspect, the present invention provides a code quality assessment method, the method comprising: when a user uses the application software, collecting runtime data of each function in the application software. Preprocessing the runtime data of each function in the application software and obtaining the preprocessed data. Determining abnormal functions in each function of the application software based on the preprocessed data. Evaluating the code corresponding to the abnormal functions in each function of the application software according to preset coding rules to obtain an evaluation result. And, pushing the evaluation result to a terminal used for coding. The runtime data of each function in the application software includes at least one of the interface call data, online error data and code coverage of each function in the application software.
[0010] Optionally, when the user uses the application software, runtime data of each function in the application software is collected, including: an agent program written using dynamic weaving technology collects runtime data of each function in the application software when the user uses the application software.
[0011] Optionally, the preprocessing method includes: deduplicating the runtime data of each function in the application software to remove erroneous data in the runtime data, performing peak shaving and valley filling processing on the runtime data, and performing at least one of the following processing methods for unifying the format of the runtime data.
[0012] Optionally, the preprocessed data includes data after preprocessing at least one of the interface call data, online error data and code coverage of each function in the application software. Determine the abnormal functions in each function of the application software based on the preprocessed data, including: compare the preprocessed data with at least one of the thresholds of the interface call data, the threshold of the online error data and the code coverage threshold. And, determine that the function corresponding to the interface call data below the threshold of the interface call data in the preprocessed data is an abnormal function, and / or determine that the function corresponding to the online error data above the threshold of the online error data in the preprocessed data is an abnormal function, and / or determine that the function corresponding to the code coverage below the code coverage threshold in the preprocessed data is an abnormal function.
[0013] Optionally, the preset coding rules are obtained based on a static code rule set and expert experience.
[0014] Optionally, the evaluation result includes an evaluation level of the code corresponding to the abnormal function in each function of the application software, and the evaluation levels include the first level, the second level, the third level, the fourth level and the fifth level. The first level is used to indicate that the code has a format problem or a problem of low usage. The second level is used to indicate that the code has a design problem. The third level is used to indicate that the code has a potential problem, the fourth level is used to indicate that the code has an obvious compilation error or runtime error, and the fifth level is used to indicate that the code has a serious security vulnerability or performance problem.
[0015] Optionally, the code quality assessment method further includes: in response to the assessment result including at least one of the first level, the second level and the third level, sending a first prompt message to the terminal used for encoding. And, in response to the assessment result including the fourth level and / or the fifth level, sending a first alarm message to the terminal used for encoding. The first prompt message is used to indicate that the code corresponding to at least one of the first level, the second level and the third level needs to be maintained. The first alarm message is used to indicate that the code corresponding to the fourth level and / or the fifth level needs to be repaired immediately.
[0016] Optionally, the evaluation result includes data corresponding to abnormal functions in various functions of the application software in the preprocessed data.
[0017] Optionally, the code quality assessment method further includes: sending first verification information to the terminal used for encoding. The first verification information includes the assessment result and data corresponding to abnormal functions in various functions of the application software in the preprocessed data, so that the developer or system administrator can verify the assessment result.
[0018] In a second aspect, the present invention provides a code quality assessment system, including a runtime data collection module, a preprocessing module, an abnormal function determination module, an assessment result acquisition module and an assessment result push module. Among them, the runtime data collection module is configured to: collect runtime data of each function in the application software when the user uses the application software. The runtime data of each function in the application software includes at least one of the interface call data, online error data and code coverage of each function in the application software. The preprocessing module is configured to: preprocess the runtime data of each function in the application software and obtain the preprocessed data. The abnormal function determination module is configured to: determine the abnormal functions in each function of the application software according to the preprocessed data. The assessment result acquisition module is configured to: evaluate the code corresponding to the abnormal functions in each function of the application software according to the preset coding rules to obtain the assessment results. The assessment result push module is configured to: push the assessment results to the terminal used for encoding.
[0019] In a third aspect, the present invention provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program stored in the memory, the processor executes the above-mentioned code quality assessment method.
[0020] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the processor executes the above-mentioned code quality assessment method.
[0021] The code quality assessment method, system, computer device and readable storage medium provided by the present invention propose a solution for code quality management by combining user input and program runtime information (e.g., program operation indicators, abnormal error information). The solution combines user input and program information, sets specific code detection rules and levels, checks indicator data such as code coverage, so as to more comprehensively reflect the running status of the code in the real environment, evaluate the code quality, and thus optimize the coding process in a wider range of usage scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A flowchart of a code quality assessment method in an embodiment of the present invention;
[0023] Figure 2 A flowchart of another code quality assessment method in an embodiment of the present invention;
[0024] Figure 3 A flowchart of another code quality assessment method in an embodiment of the present invention;
[0025] Figure 4 A structural diagram of a code quality assessment system in an embodiment of the present invention;
[0026] Figure 5 A structural diagram of another code quality assessment system in an embodiment of the present invention;
[0027] Figure 6 A structural diagram of another code quality assessment system in an embodiment of the present invention;
[0028] Figure 7 The figure is a structural diagram of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the technical solution of the present invention, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0030] It should be understood that the specific embodiments and drawings described herein are only used to explain the present invention rather than to limit the present invention.
[0031] It can be understood that, in the absence of conflict, the various embodiments of the present invention and the various features in the embodiments can be combined with each other.
[0032] It can be understood that, for the convenience of description, the drawings of the present invention only show the parts related to the present invention, while the parts irrelevant to the present invention are not shown in the drawings.
[0033] It can be understood that each unit and module involved in the embodiments of the present invention may correspond to only one physical structure, or may be composed of multiple physical structures, or multiple units and modules may be integrated into one physical structure.
[0034] It can be understood that, without conflict, the functions and steps marked in the flowcharts and block diagrams of the present invention may occur in an order different from that marked in the drawings.
[0035] It is understood that the flowcharts and block diagrams of the present invention illustrate the possible architectures, functions, and operations of the systems, devices, equipment, and methods according to the various embodiments of the present invention. Each box in the flowchart or block diagram may represent a unit, module, program segment, or code, which contains executable instructions for implementing the specified functions. Moreover, each box or combination of boxes in the block diagram and flowchart may be implemented by a hardware-based system that implements the specified functions, or may be implemented by a combination of hardware and computer instructions.
[0036] It can be understood that the units and modules involved in the embodiments of the present invention can be implemented by software or hardware. For example, the units and modules can be located in a processor.
[0037] An embodiment of the present invention provides a code quality assessment method, such as Figure 1 As shown, the code quality assessment method includes steps 101 to 105.
[0038] Step 101: When a user uses an application software, runtime data of each function in the application software is collected.
[0039] In step 101, the runtime data of each function in the application software includes at least one of interface call data, online error data and code coverage of each function in the application software.
[0040] In some embodiments, the implementation method of step 101 includes: using an agent program written using dynamic weaving technology to collect runtime data of various functions in the application software when the user uses the application software.
[0041] It can be understood that dynamic weaving technology refers to a technology that does not require changing the source code or compiled files of the application software, and directly uses an agent program to add data collection related functions when the application software is running. Compared with the method of collecting data through logs, the method of using an agent program to collect data can collect data in real time. Compared with the method of changing the source code or compiled files of the application software to collect data, the method of using an agent program to collect data is less invasive to the source code or compiled files, and will not cause damage to the source code or compiled files.
[0042] Exemplarily, the application software is mainly an application that supports dynamic weaving technology, such as an application written in Java, Kotlin, C# and other languages. The application software itself generally does not need to be modified. Through configuration or command line, the dynamic weaving program to be used is specified to realize real-time runtime data collection.
[0043] Step 102: pre-process the runtime data of each function in the application software and obtain the pre-processed data.
[0044] In some embodiments, the method used for preprocessing in step 102 includes: deduplicating the runtime data of each function in the application software to remove erroneous data in the runtime data, performing peak shaving and valley filling processing on the runtime data, and performing at least one of the following processing methods for unifying the format of the runtime data.
[0045] It can be understood that in the peak-to-valley processing method, the peak-to-valley value refers to the difference in time. For example, some functions will be used more in certain time periods, which is the peak of data production, while the access volume will be relatively small in other time periods, which is the valley. Peak-to-valley filling can be understood as the arrangement of the data flow shape.
[0046] Exemplarily, step 102 can be implemented using storage-related middleware. For example, storage-related middleware can refer to the open source log management and data analysis platform ElasticStack. ElasticStack is a powerful open source log management and data analysis platform, which consists of components such as Elasticsearch, Logstash, Kibana, Beats, etc. ElasticStack can obtain data in any format from any source, search, analyze and visualize, and is widely used in log management, monitoring, security and other fields. Elasticsearch is a JSON-based distributed search and analysis engine that supports real-time search and analysis of large-scale data. It has high scalability and high availability and can process PB-level data. Logstash is a server-side data processing pipeline that can collect data from multiple sources, convert it and send it to the repository. Logstash supports various input and output methods and can process unstructured data. Kibana is an extensible user interface for visual analysis of data in Elasticsearch. Kibana provides a wealth of charts and graphical tools to help users understand and analyze data. Beats is a lightweight data collector, including Filebeat, Metricbeat and other types, which is used to collect data from servers and applications and send it to Logstash or Elasticsearch.
[0047] Exemplarily, after the agent program written using dynamic weaving technology collects the runtime data of each function in the application software when the user uses the application software, the agent program written using dynamic weaving technology can push the collected runtime data of each function in the application software when the user uses the application software to ElasticStack, so that ElasticStack pre-processes and saves the collected runtime data of each function in the application software when the user uses the application software.
[0048] Exemplarily, the process of ElasticStack preprocessing and saving the runtime data of each function in the application software collected when the user uses the application software can be: forwarding the runtime data of each function in the application software collected when the user uses the application software to Logstash through various Beats software in ElasticStack, or directly passing the runtime data of each function in the application software collected when the user uses the application software to Logstash by an agent program written using dynamic weaving technology, and then Logstash preprocesses the data (such as format unification, removal of erroneous data, etc.). The preprocessed data will finally be sent to ElasticSearch, and the document-type storage structure will be used to store different APM data as an independent document for subsequent index query.
[0049] Step 103: Determine abnormal functions among the functions of the application software according to the preprocessed data.
[0050] In some embodiments, in step 103, the preprocessed data includes data after preprocessing at least one of interface call data of each function in the application software, online error data, and code coverage.
[0051] The implementation of step 103 includes: comparing the pre-processed data with at least one of a threshold of interface call data, a threshold of online error data, and a code coverage threshold.
[0052] In this case, the function corresponding to the interface call data in the preprocessed data that is lower than the threshold of the interface call data is determined to be an abnormal function, and / or, the function corresponding to the online error data in the preprocessed data that is higher than the threshold of the online error data is determined to be an abnormal function, and / or, the function corresponding to the code coverage in the preprocessed data that is lower than the code coverage threshold is determined to be an abnormal function.
[0053] It can be understood that interface call data refers to the number of times a function is called, which is used to indicate the frequency of use of a function. For example, if the interface call data of function A in the application software is 0 within a preset time period, it means that the frequency of use of function A is low. Online error data refers to the number of online errors of a function and the specific information of the error, which is used to indicate the smoothness of use of a function. For example, if the number of online errors of function B in the application software is 0 within a preset time period, it means that the use of function B is relatively smooth. Code coverage refers to the ratio between the part of the code that is actually run or executed when executing a certain section of code and the total part of the code of the section of code, which is used to indicate whether the code has been fully checked. The lower the code coverage, the worse the code quality.
[0054] It can be understood that the threshold of interface call data, the threshold of online error data, and the threshold of code coverage can be set separately according to each function of the application software (for example, the threshold of interface call data of function A and function B can be the same or different), or the same threshold of interface call data, threshold of online error data, and threshold of code coverage can be used for each function of the application software (for example, the threshold of interface call data of function A and function B is the same).
[0055] Exemplarily, the threshold of the interface call data can be set to a lower value (1 or 2) to detect some functions with extremely low usage frequency. For example, the threshold of the online error data can be set based on experience. For example, under normal circumstances, the average number of online errors reported by each function of the application software within a day is 2, so the threshold of the online error data can be set to 2. When the online error data (number of times) of function B is higher than 2, function B is considered to be an abnormal function.
[0056] Step 104: Evaluate the codes corresponding to the abnormal functions in the functions of the application software according to the preset coding rules to obtain evaluation results.
[0057] In some embodiments, the preset encoding rules are obtained based on a static code rule set and expert experience.
[0058] It is understandable that developers and system administrators can query and discuss relevant coding information and rules (such as static code rule sets) based on specific indicators on the code rule evaluation system to obtain a coding method that both developers and system administrators agree should be followed, namely the coding rules in step 104.
[0059] In some embodiments, the evaluation result includes an evaluation level of the code corresponding to the abnormal function in each function of the application software, and the evaluation levels include the first level, the second level, the third level, the fourth level and the fifth level. The first level is used to indicate that the code has a format problem or a problem of low usage. The second level is used to indicate that the code has a design problem. The third level is used to indicate that the code has a potential problem, the fourth level is used to indicate that the code has an obvious compilation error or runtime error, and the fifth level is used to indicate that the code has a serious security vulnerability or performance problem.
[0060] Exemplarily, step 104 may be performed by a code management rule system. For example, the code rule evaluation system may pull preprocessed data from storage-related middleware, and organize the preprocessed data according to the type of the preprocessed data (for example, whether the data belongs to interface call data, online error data, or code coverage) and time period, and bind the organized data to the code of the abnormal function in each function of the application, and give the corresponding evaluation level of the code of the abnormal function in each function of the application.
[0061] For example, the first level is "hint", which is a low-priority suggestion for the code, usually used to improve the quality or style consistency of the code. The second level is "smell", which means that there is not necessarily an error in the code, but it indicates that the code may have potential design problems or poor readability, which may cause future maintenance difficulties. The third level is "warning", which refers to potential risks in the code that may cause problems. Developers are advised to check and fix them, but they will not necessarily cause the program to crash. The fourth level is "error", which means that there are clear compilation or runtime errors in the code, which must be fixed to ensure the normal operation of the program. The fifth level is "serious exception", which means that the code has serious security vulnerabilities or performance issues, which may cause the system to crash or be attacked and need to be fixed immediately.
[0062] Step 105: Push the evaluation result to the terminal used for encoding.
[0063] It is understandable that when the first prompt information or the first warning information is pushed to the terminal used for encoding, the evaluation result can also be pushed to the terminal used for encoding, so that the developer or system administrator can understand why the first prompt information or the first warning information is issued.
[0064] In some embodiments, Figure 2 As shown, the code quality assessment method further includes step 201 and step 202.
[0065] Step 201: In response to the evaluation result including at least one of the first level, the second level and the third level, first prompt information is sent to a terminal for encoding.
[0066] In step 201, the first prompt information is used to indicate that the code corresponding to at least one of the first level, the second level and the third level needs to be maintained.
[0067] Exemplarily, the terminal for coding includes an integrated development environment (IDE) used by developers.
[0068] It is understandable that whether the evaluation result is level 1, level 2, or level 3 does not affect the operation of the code, so the developer or system administrator can make adjustments as appropriate.
[0069] Step 202: In response to the evaluation result including the fourth level and / or the fifth level, sending first warning information to the terminal used for encoding.
[0070] In step 202, the first warning information is used to indicate that the codes corresponding to the fourth level and / or the fifth level need to be repaired immediately.
[0071] Understandably, code with an assessment result of level 4 or level 5 will affect the normal operation of the code and requires immediate repair by developers or system administrators, otherwise the code will not run and the corresponding functions may not work.
[0072] It is understandable that the developer or system administrator may not adjust the code when the terminal used for encoding receives the first prompt information, but the developer or system administrator must adjust the corresponding code when the terminal used for encoding receives the first alarm information.
[0073] In some embodiments, the evaluation result includes data corresponding to abnormal functions in various functions of the application software in the pre-processed data.
[0074] It can be understood that when the evaluation results include data corresponding to abnormal functions in various functions of the application software in the pre-processed data, after pushing the evaluation results to the terminal used for encoding, the developer or system administrator can further understand the specific circumstances of the abnormal functions in various functions of the application software, which helps the developer or system administrator to make a judgment.
[0075] It is understandable that coding rules generally represent coding methods that should be followed and are recognized by both developers and system administrators, and the runtime data of each function of the application software collected in step 101 is often affected by the dependent environment, that is, the evaluation result obtained according to step 104 may fluctuate due to the load of the system at that time.
[0076] In this case, if Figure 3 As shown, the code quality assessment system further includes step 106 .
[0077] Step 106: Send first verification information to the terminal used for encoding.
[0078] In step 106, the first verification information includes the evaluation result and the data corresponding to the abnormal functions in each function of the application software in the preprocessed data, so that the developer or system administrator can verify the evaluation result. In other words, through step 105, the developer or system administrator can participate in the process of giving the evaluation result. That is, after the code evaluation system gives the evaluation result, it can be manually confirmed whether the evaluation result is reasonable, and if it is unreasonable, the evaluation result can be manually adjusted.
[0079] The embodiment of the present invention provides a code quality assessment method, which detects code quality through abnormal information during user use, sets coding rules, and checks indicators such as code coverage to more comprehensively reflect the quality status of the code in a real use environment. By combining user behavior with code analysis, the present invention can provide targeted code problems and optimization directions, and improve code quality in a wider range of scenarios.
[0080] A code quality assessment method provided by an embodiment of the present invention is described below with a specific example.
[0081] In this example, the code quality assessment method includes steps S101 to S104.
[0082] S101, an agent program written using dynamic weaving technology collects runtime data of the user on the application software.
[0083] Dynamic weaving technology refers to adding data collection related functions when running using an independent agent program without changing the source code and compiled files. The application software in S101 is mainly applications that support dynamic weaving technology, such as applications written in Java, Kotlin, C# and other languages. The application itself generally does not need to be modified. Through configuration or command line, the dynamic weaving program to be used is specified to achieve transparent runtime data collection. Runtime data includes interface call status, online error information, code coverage, etc.
[0084] S102, the agent program collects, organizes and saves the collected runtime data using storage-related middleware.
[0085] For example, you can use Logstash in ElasticStack to organize data and smooth out peaks and valleys, and use ElasticSearch for data storage and query. The storage-related middleware here is generally middleware with functions such as data collection, organization, and storage. Peak and valley values refer to the fact that due to time differences, some functions will be used more in certain time periods, which is the peak of data production, while the number of visits will be relatively small in other time periods, which is the valley. Shaving peaks and valleys can be understood as the organization of the shape of the data flow.
[0086] Take ElasticStack as an example to illustrate the process from collection to storage:
[0087] The agent forwards the collected data to Logstash through various Beats software in ElasticStack, or the agent directly passes the collected data to Logstash, and then performs preliminary data preprocessing in Logstash (format unification, removal of erroneous data, etc.). For example, if you want to extract error messages from an error stack separately, you can directly process them in the Logstash middleware to extract relevant information and save it as a separate field.
[0088] Data storage: The processed data will eventually be sent to ElasticSearch, using a document-based storage structure so that different APM data can be stored as a separate document for subsequent index queries.
[0089] S103, after the code rule evaluation system organizes the coverage information, exception information and other runtime data, the organized runtime data is displayed.
[0090] The code rule evaluation system pulls runtime data from storage-related middleware, organizes the runtime data by type (such as code coverage, online error, etc.) and time period, and binds the organized runtime data to the code.
[0091] Developers and system administrators can query and discuss relevant coding information and rules based on specific indicators on the code rule evaluation system.
[0092] This link will also directly push some statistical information that is not used as coding rules to the software and hardware terminals used for coding (for example, the integrated development environment (IDE) used by developers), such as the frequency of use of a certain section of code in the recent period, for developers' reference.
[0093] S104: Push the corresponding code encoding rules to the encoding software and hardware terminals according to the sorted runtime data.
[0094] The confirmation of coding rules generally refers to the coding methods that should be followed and are recognized by the community. The data collected during runtime is often affected by the dependent environment and will fluctuate according to the load of the system at that time. Therefore, the code rule evaluation system requires the administrator to confirm and push a rule in a code system rule set, and may re-establish the execution level of the rule before passing the specific coding rule to the terminal.
[0095] It should be noted that the data pushed to the terminal IDE mainly includes statistical data collected during runtime and code detection rules and execution levels based on various data and confirmed by the administrator. The pushed code detection rules are mainly rules in various static code detection sets.
[0096] Currently, the code execution levels mainly include the following 5 levels:
[0097] Tip: Low priority suggestions, usually used to improve code quality or style consistency.
[0098] Smells: Not necessarily errors, but indicate that the code may have potential design problems or poor readability, which may lead to future maintenance difficulties.
[0099] Warning: Potential risks in the code that may cause problems. Developers are advised to check and fix them, but they will not necessarily cause the program to crash.
[0100] Error: A clear compile or run-time error that must be fixed to ensure the correct operation of the program.
[0101] Serious anomalies: Serious security vulnerabilities or performance issues that may cause system crashes or attacks and require immediate repair.
[0102] This example mainly describes the process of how the number of runtime function usages, exception error information, and coverage information (code coverage range run by user actions) are collected by the dynamic weaving agent and ultimately affect the coding rules.
[0103] This example uses functions a, b, c, and d of application software A as an example to illustrate the process of the code quality pipeline method as follows:
[0104] 110. Application software A launches functions a, b, c, and d.
[0105] 111. The dynamic weaving agent collects data on users' use of functions a, b, c, and d for a period of time and uploads it to the storage-related middleware, which is finally stored after data cleaning.
[0106] 112. The code rule evaluation system collects statistics on the usage frequency, abnormal error information, and coverage information of functions a, b, c, and d.
[0107] 113. After the code rule evaluation system collects statistical information, it extracts some relevant rules in combination with the existing static code rule set and recommends them to the administrator. The administrator selects the corresponding rules and adjusts the execution level of the rules and pushes them to the terminal used for coding. In addition, some non-syntactical exceptions, such as the situations encountered by functions a, b, and c below, can be pushed as related functional exceptions of the code block, while function d without any problems can be processed without additional code block rules.
[0108] Function a: There is no usage. You can consult with the product manager and other related colleagues to see whether the function can be taken offline and the redundant code can be cleaned up. If it is confirmed that it can be cleaned up, you can send a "prompt" level rule (such as the first prompt message) to the corresponding code block and push it to the development colleagues for cleanup.
[0109] Function b: If you find that some code has never been executed (for example, if else can only be executed correctly, not incorrectly), you can send the corresponding rules of the "smell" level (such as the first prompt information) to the corresponding code block, so that the development colleagues can confirm the logic.
[0110] Function c: If unrecognized exception information is continuously thrown during runtime, the exception stack can be collected, and the "serious exception" level rules (such as the first warning information) can be assigned to the corresponding code block, indicating that it needs to be repaired immediately.
[0111] An embodiment of the present invention provides a code quality assessment system, such as Figure 4 As shown, the code quality assessment system 400 includes a runtime data collection module 401 , a preprocessing module 402 , an abnormal function determination module 403 , an assessment result acquisition module 404 and an assessment result push module 405 .
[0112] The runtime data collection module 401 is configured to collect runtime data of each function in the application software when the user uses the application software, wherein the runtime data of each function in the application software includes at least one of interface call data, online error data and code coverage of each function in the application software.
[0113] In some embodiments, the runtime data collection module 401 is an agent program written using dynamic weaving technology, and the agent program written using dynamic weaving technology is configured to collect runtime data of various functions in the application software when the user uses the application software.
[0114] The preprocessing module 402 is configured to preprocess the runtime data of each function in the application software and obtain the preprocessed data.
[0115] In some embodiments, the preprocessing module 402 is configured to: perform deduplication processing on the runtime data of each function in the application software to remove erroneous data in the runtime data, perform peak shaving and valley filling processing on the runtime data, and perform at least one of format unification processing on the runtime data.
[0116] The abnormal function determination module 403 is configured to determine an abnormal function among various functions of the application software according to the preprocessed data.
[0117] In some embodiments, the preprocessed data includes data after preprocessing at least one of the interface call data, online error data, and code coverage of each function in the application software. The abnormal function determination module 403 is configured to compare the preprocessed data with at least one of the thresholds of the interface call data, the threshold of the number of online error reports, and the code coverage threshold. And, determine that the function corresponding to the interface call data below the threshold of the interface call data in the preprocessed data is an abnormal function, and / or determine that the function corresponding to the online error data above the threshold of the online error data in the preprocessed data is an abnormal function, and / or determine that the function corresponding to the code coverage below the code coverage threshold in the preprocessed data is an abnormal function.
[0118] The evaluation result acquisition module 404 is configured to evaluate the codes corresponding to the abnormal functions in the functions of the application software according to preset coding rules to obtain evaluation results.
[0119] In some embodiments, the coding rules are derived from a static code rule set and expert experience.
[0120] In some embodiments, the evaluation result includes data corresponding to abnormal functions among the functions of the application software in the preprocessed data.
[0121] In some embodiments, the evaluation result includes an evaluation level of the code data corresponding to the abnormal functions in each function of the application software, and the evaluation levels include the first level, the second level, the third level, the fourth level and the fifth level. The first level is used to indicate that the code has format problems or low usage problems. The second level is used to indicate that the code has design problems. The third level is used to indicate that the code has potential problems, the fourth level is used to indicate that the code has obvious compilation errors or runtime errors, and the fifth level is used to indicate that the code has serious security vulnerabilities or performance problems.
[0122] The evaluation result pushing module 405 is configured to push the evaluation result to the terminal used for encoding.
[0123] In some embodiments, Figure 5 As shown, the evaluation result pushing module 405 includes a first prompt information pushing unit 4051 and a first warning information pushing unit 4052 .
[0124] The first prompt information push unit 4051 is configured to send first prompt information to the terminal for encoding in response to the evaluation result including at least one of the first level, the second level and the third level, wherein the first prompt information is used to indicate that the code data corresponding to at least one of the first level, the second level and the third level needs to be maintained.
[0125] The first warning information push unit 4052 is configured to send a first warning information to the terminal for encoding in response to the evaluation result including the fourth level and / or the fifth level, wherein the first warning information is used to indicate that the code data corresponding to the fourth level and / or the fifth level needs to be repaired immediately.
[0126] In some embodiments, Figure 6 As shown, the code quality assessment system 400 further includes a first verification information sending module 406. The first verification information sending module 406 is configured to send first verification information to the terminal for encoding. The first verification information includes the assessment result and data corresponding to abnormal functions in various functions of the application software in the preprocessed data, so that the developer or system administrator can check the assessment result.
[0127] The specific scheme and beneficial effects of a code quality assessment system provided by an embodiment of the present invention can refer to the relevant description of a code quality assessment method provided by an embodiment of the present invention, which will not be repeated here.
[0128] An embodiment of the present invention provides a computer device, such as Figure 7 As shown, the computer device 700 includes a memory 701 and a processor 702. The memory 701 stores a computer program. When the processor 702 runs the computer program stored in the memory 701, the processor 702 executes the above-mentioned code quality assessment method.
[0129] The specific scheme and beneficial effects of a computer device provided by an embodiment of the present invention can be referred to the relevant description of a code quality assessment method provided by an embodiment of the present invention, which will not be repeated here.
[0130] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the processor executes the above-mentioned code quality assessment method.
[0131] The specific scheme and beneficial effects of a computer-readable storage medium provided by an embodiment of the present invention can be referred to the relevant description of a code quality assessment method provided by an embodiment of the present invention, which will not be repeated here.
[0132] It is to be understood that the above embodiments are merely exemplary embodiments used to illustrate the principles of the present invention, but the present invention is not limited thereto. For those of ordinary skill in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A code quality assessment method, characterized in that: include: When a user uses an application software, collecting runtime data of each function in the application software; The runtime data of each function in the application software includes at least one of interface call data, online error data and code coverage of each function in the application software; Preprocessing the runtime data of each function in the application software and obtaining the preprocessed data; Determining abnormal functions among the functions of the application software according to the preprocessed data; Evaluate the code corresponding to the abnormal function in each function of the application software according to the preset coding rule to obtain an evaluation result; as well as The evaluation result is pushed to a terminal used for encoding.
2. The code quality assessment method according to claim 1, characterized in that: When the user uses the application software, the runtime data of each function in the application software is collected, including: The agent program written by using the dynamic weaving technology collects the runtime data of each function in the application software when the user uses the application software.
3. The code quality assessment method according to claim 1, characterized in that: The preprocessing method includes: deduplication processing of the runtime data of each function in the application software to remove erroneous data in the runtime data, peak shaving and valley filling processing of the runtime data, and at least one of the following processing methods of formatting the runtime data.
4. The code quality assessment method according to claim 1, characterized in that: The preprocessed data includes data obtained by preprocessing at least one of interface call data, online error data, and code coverage of each function in the application software; and determining abnormal functions among the functions of the application software according to the preprocessed data includes: Comparing the preprocessed data with at least one of a threshold of interface call data, a threshold of online error data, and a code coverage threshold; and Determine that a function corresponding to the interface call data in the preprocessed data that is lower than a threshold of the interface call data is an abnormal function, and / or determine that a function corresponding to the online error data in the preprocessed data that is higher than a threshold of the online error data is an abnormal function, and / or determine that a function corresponding to the code coverage in the preprocessed data that is lower than the code coverage threshold is an abnormal function.
5. The code quality assessment method according to claim 1, characterized in that: The preset coding rules are obtained based on a static code rule set and expert experience.
6. The code quality assessment method according to claim 1, characterized in that: The evaluation result includes an evaluation level of the code corresponding to the abnormal function in each function of the application software, and the evaluation levels include a first level, a second level, a third level, a fourth level and a fifth level; the first level is used to indicate that the code has a format problem or a problem of low usage; the second level is used to indicate that the code has a design problem; the third level is used to indicate that the code has a potential problem; the fourth level is used to indicate that the code has an obvious compilation error or runtime error; the fifth level is used to indicate that the code has a serious security vulnerability or performance problem.
7. The code quality assessment method according to claim 6, characterized in that: Also includes: In response to the evaluation result including at least one of the first level, the second level, and the third level, sending first prompt information to the terminal for encoding; The first prompt information is used to indicate that the code corresponding to at least one of the first level, the second level and the third level needs to be maintained; as well as In response to the evaluation result including the fourth level and / or the fifth level, sending first warning information to the terminal for encoding; The first warning information is used to indicate that the codes corresponding to the fourth level and / or the fifth level need to be repaired immediately.
8. The code quality assessment method according to claim 6, characterized in that: The evaluation result includes data corresponding to abnormal functions among the functions of the application software in the preprocessed data.
9. The code quality assessment method according to claim 1, characterized in that: Also includes: Sending first verification information to the terminal for encoding; The first verification information includes the evaluation result and data corresponding to abnormal functions in various functions of the application software in the pre-processed data, so that a developer or a system administrator can verify the evaluation result.
10. A code quality assessment system, characterized in that: include: A runtime data collection module, which is configured to: collect runtime data of each function in the application software when the user uses the application software; the runtime data of each function in the application software includes at least one of interface call data, online error data and code coverage of each function in the application software; A preprocessing module, which is configured to: preprocess the runtime data of each function in the application software and obtain the preprocessed data; an abnormal function determination module, configured to: determine an abnormal function among the functions of the application software according to the preprocessed data; An evaluation result acquisition module is configured to: evaluate the code corresponding to the abnormal function in each function of the application software according to a preset coding rule to obtain an evaluation result; and An evaluation result pushing module is configured to push the evaluation result to a terminal used for encoding.
11. A computer device, characterized in that: The method comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor runs the computer program stored in the memory, the processor executes the code quality assessment method according to any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the processor performs the code quality assessment method according to any one of claims 1 to 9.