Code file intelligent analysis method, device, electronic device and storage medium
By dynamically allocating tasks with high complexity of code files to processing equipment with excellent performance, and grouping and allocation of tasks when the equipment is fully loaded, the problem of low processing efficiency when multiple machines are statically checking large code projects is solved, and more efficient intelligent code file analysis is achieved.
Patent Information
- Application Number
- CN202411481286.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2044-10-23
AI Technical Summary
When multiple machines conduct static checks on large code projects, the complexity and file size of the code allocated by each machine are inconsistent, resulting in low processing efficiency and some machine tasks are queued for waiting.
An intelligent code file analysis method is proposed, and by obtaining the complexity of each code file in the code project to be inspected, tasks are dynamically allocated to different types of processing devices. The specific steps include: if the sum of complexity exceeds a preset threshold, input the task into the first processing device with excellent performance; if the first processing device is fully loaded, it is transferred to the tidal processing device; if all the equipment is fully loaded, the code files are grouped and allocated to the second processing device with poor performance than the first processing device for analysis.
It effectively improves the analysis efficiency of intelligent code file analysis, reduces the load of the first processing device, reduces the waiting time of the code items to be inspected, and improves the overall processing efficiency.
Smart Images

Figure CN119577761B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to, but is not limited to, the field of computer technology, and in particular to a method, device, electronic device, and storage medium for intelligent analysis of code files. Background Art
[0002] Static checking of code files refers to the use of automated tools to analyze source code to detect potential errors, vulnerabilities, bad practices, or parts that do not meet coding standards without executing the code. This scanning is usually done by static code analysis tools, which can check the syntax, structure, and patterns of the code to find various problems.
[0003] In the related art, when a large code project is analyzed by multiple machines, each machine is assigned with multiple code files from the large code project. Since the number of code lines and file sizes of the code files are different, when some machines complete the inspection task, other machines still have a large number of tasks waiting in line for processing, resulting in low overall processing efficiency. Summary of the invention
[0004] The following is a summary of the subject matter described in detail herein. This summary is not intended to limit the scope of the claims.
[0005] The embodiments of the present application provide a method, device, electronic device and storage medium for intelligent analysis of code files, which can effectively improve the analysis efficiency of intelligent analysis of code files.
[0006] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a code file intelligent analysis method, wherein the code analysis device group is used to perform code analysis on a code project to be checked, the code analysis device group includes a plurality of first processing devices, a plurality of second processing devices and a plurality of tidal processing devices, the performance of the first processing device is better than that of the second processing device, and the code file intelligent analysis method includes: obtaining the code project to be checked, obtaining the complexity of each code file to be checked in the code project to be checked; when the sum of the complexity of each code file to be checked in the code project to be checked is greater than a preset target complexity threshold, the code project is input into one of the in the first processing device; when the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than the target complexity threshold, and all of the first processing devices are in a fully loaded state, the code project to be checked is input into one of the tidal processing devices; when the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than the target complexity threshold, and all of the first processing devices and all of the tidal processing devices are in a fully loaded state, the code files to be checked in the code project to be checked are grouped based on the complexity to obtain multiple target file groups, and the target file groups are input into the second processing device.
[0007] In one embodiment, the code files to be checked in the code project to be checked are grouped based on the complexity to obtain multiple target file groups, including: arranging the code files to be checked from large to small based on the complexity of each code file to be checked, and determining a first complexity threshold based on the complexity of each code file to be checked; in the sorted code project to be checked, obtaining the complexity of each code file to be checked in turn, and when the complexity is greater than or equal to the latest first complexity threshold, placing the corresponding code file to be checked separately into a blank target file group, and determining a new first complexity threshold based on the complexity of the remaining code files to be checked; when the complexity is less than the latest first complexity threshold, determining a second complexity threshold based on the current code file to be checked and the latest first complexity threshold, and grouping the remaining code files to be checked based on the latest second complexity threshold.
[0008] In one embodiment, when the complexity is less than the latest first complexity threshold, a second complexity threshold is determined based on the current code file to be checked and the latest first complexity threshold, and the remaining code files to be checked are grouped based on the latest second complexity threshold, including: if the complexity of the current code file to be checked is less than the latest first complexity threshold, the current code file to be checked is placed in a new target file group; a second complexity threshold is determined based on the latest first complexity threshold and the complexity of the current code file to be checked, and the remaining code files to be checked are grouped based on the second complexity threshold; based on the complexity of the remaining code files to be checked, the first complexity threshold is re-determined, and the remaining code files to be checked are grouped based on the latest first complexity threshold, until all the code files to be checked are grouped.
[0009] In one embodiment, the second complexity threshold is determined according to the latest first complexity threshold and the complexity of the current code file to be checked, and the remaining code files to be checked are grouped based on the second complexity threshold, including: determining the second complexity threshold according to the difference between the latest first complexity threshold and the complexity of the current code file to be checked; obtaining the complexity of the remaining code files to be checked in turn, and when the complexity is less than or equal to the latest second complexity threshold, placing the corresponding code file to be checked into the current target file group, and determining a new second complexity threshold based on the complexity of the code file to be checked existing in the current target file group and the latest first complexity threshold; when traversing to the last code file to be checked in the current code project to be checked, if the sum of the complexity of the code files to be checked existing in the current target file group is less than the latest first complexity threshold, placing the last code file to be checked into the current target file group.
[0010] In one embodiment, determining the first complexity threshold based on the complexity of each of the code files to be checked includes: determining the sum of the complexities of the code files to be checked in the current code project to be checked; obtaining the target number of target file groups in the current code project to be checked, and determining the first complexity threshold based on the sum of the complexities of the current code project to be checked and the target number of groups.
[0011] In one embodiment, determining a new first complexity threshold based on the complexity of the remaining code files to be checked includes: determining the sum of the complexities of the code files to be checked that are not placed in the target file group; obtaining the remaining number of target file groups that are not placed in the code files to be checked, and determining a new first complexity threshold based on the sum of the complexities of the remaining code files to be checked and the remaining number of groups.
[0012] In one embodiment, the code file intelligent analysis method includes: when the sum of the complexity of each of the code files to be checked in the code project to be checked is less than or equal to the target complexity threshold, the code project to be checked is input into the second processing device; when the sum of the complexity of each of the code files to be checked in the code project to be checked is less than or equal to the target complexity threshold, each of the second processing devices is in a fully loaded state, and there is a tidal processing device that is not fully loaded, the code project to be checked is input into the tidal processing device that is not fully loaded; wherein, the second processing device and the tidal processing device are both used to simultaneously perform code analysis on multiple code projects to be checked whose sum of complexity is less than or equal to the target complexity threshold, and the second processing device is also used to simultaneously perform code analysis on multiple target file groups, or a combination of the target file group and the code project to be checked whose sum of complexity is less than or equal to the target complexity threshold.
[0013] In addition, to achieve the above-mentioned purpose, the second aspect of the present application proposes a code file intelligent analysis device, including: an acquisition module, used to obtain the code project to be checked, and obtain the complexity of each code file to be checked in the code project to be checked; a processing module, used to input the code project into one of the first processing devices when the sum of the complexity of each code file to be checked in the code project to be checked is greater than a preset target complexity threshold; the processing module is also used to input the code project to be checked into one of the tidal processing devices when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices are in a fully loaded state; the processing module is also used to group the code files to be checked in the code project to be checked based on the complexity when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices and all the tidal processing devices are in a fully loaded state, to obtain multiple target file groups, and input the target file groups into the second processing device.
[0014] To achieve the above-mentioned purpose, the third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, the memory stores a computer program, and the processor implements the code file intelligent analysis method described in the first aspect when executing the computer program.
[0015] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a storage medium, which is a computer-readable storage medium, and the storage medium stores a computer program. When the computer program is executed by a processor, the code file intelligent analysis method described in the first aspect is implemented.
[0016] The embodiments of the present application include at least the following beneficial effects: after obtaining the code project to be checked, the complexity of each code file to be checked in the code project to be checked is obtained, and when the sum of the complexity of all the code files to be checked in the code project to be checked is calculated to be greater than the target complexity threshold, all the code files to be checked in the code project to be checked are input into the same first processing device, and the first processing device performs code analysis. If all the first processing devices are in a fully loaded state, the code project to be checked is sent to the tidal processing device, thereby reducing the load burden of the first processing device, reducing the waiting time of the code project to be checked, and improving the code analysis efficiency of the code project to be checked; when all the first processing devices and the tidal processing devices are in a fully loaded state, since the performance of the second processing device is inferior to that of the first processing device, the code files to be checked in the code project to be checked are grouped to ensure that the sum of the complexity of each target file group is less than the sum of the complexity of the code project to be checked, and the second processing device can perform code analysis on the target file group, thereby also reducing the load burden of the first processing device and the tidal processing device, reducing the waiting time of the code project to be checked, and improving the code analysis efficiency of the code project to be checked.
[0017] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings are used to provide further understanding of the technical solution of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the technical solution of the present application and do not constitute a limitation on the technical solution of the present application.
[0019] Figure 1 An optional flowchart of the code file intelligent analysis method provided in the embodiment of the present application;
[0020] Figure 2A schematic diagram of an optional flow chart for allocating a second processing device provided in an embodiment of the present application;
[0021] Figure 3 An optional specific flow chart of grouping code files to be checked provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of an optional flow chart for calculating a first complexity threshold provided in an embodiment of the present application;
[0023] Figure 5 A schematic diagram of an optional flow chart for re-determining the first complexity threshold to group code files to be checked provided in an embodiment of the present application;
[0024] Figure 6 Another optional specific flow chart of grouping code files to be checked provided in an embodiment of the present application;
[0025] Figure 7 An optional specific flow chart of grouping code files to be checked based on a second complexity threshold provided in an embodiment of the present application;
[0026] Figure 8 A schematic diagram of an optional architecture of a code analysis device group provided in an embodiment of the present application;
[0027] Fig. 9 Another optional structural diagram of the code analysis device group provided in the embodiment of the present application;
[0028] Fig.10 A schematic diagram of another optional flow chart for grouping code files to be checked based on a first complexity threshold provided in an embodiment of the present application;
[0029] Fig.11 A schematic diagram of another optional flow chart for grouping code files to be checked based on a second complexity threshold provided in an embodiment of the present application;
[0030] Fig.12 An optional structural diagram of a code file intelligent analysis device provided in this embodiment;
[0031] Fig.13 A schematic diagram of an optional hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0033] In the description of this application, “several” means one or more, “more” means more than two, “greater than”, “less than”, “exceed”, etc. are understood to exclude the number, and “above”, “below”, “within”, etc. are understood to include the number.
[0034] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims or the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0035] It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the target object such as target object attribute information or attribute information set, the permission or consent of the target object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. Among them, the target object can be a user. In addition, when the embodiment of the present application needs to obtain the target object attribute information, the target object's separate permission or separate consent will be obtained by means of a pop-up window or jumping to a confirmation page, etc., and after the separate permission or separate consent of the target object is clearly obtained, the necessary target object-related data for enabling the normal operation of the embodiment of the present application will be obtained.
[0036] To facilitate understanding of the technical solutions provided in the embodiments of the present application, some key terms used in the embodiments of the present application are explained here:
[0037] Code review is a quality assurance measure in the software development process, which involves the process of having other developers (usually colleagues on the same team) review and evaluate a piece of code. The purpose of code analysis is to improve code quality, find potential errors, improve code readability and maintainability, and ensure that the code follows project coding standards and best practices. Code analysis can be done through code review meetings, using code review tools (such as Gerrit, Codebase, GitHub Pull Requests, etc.), or through automated static code analysis tools. Automated tools can check patterns in the code to help identify common programming errors and adverse events. Code analysis is an important part of improving software quality and team collaboration, helping to reduce software defects and development costs, while promoting knowledge sharing and learning among team members.
[0038] Code static analysis refers to checking the syntax, structure, and logic of code through automated tools or manual work without executing the code to find potential errors, vulnerabilities, code smells, or problems that do not meet coding standards. This analysis focuses on the characteristics of the code itself rather than the behavior of the code at runtime. Code static analysis is an important part of modern software development practice, which helps improve code quality, reduce maintenance costs, and improve software security and stability.
[0039] In the related art, when static checking is performed on a large code project through multiple machines, each machine is assigned with multiple code files from the large code project. Due to the different complexity of the code files, when some machines complete the inspection task, other machines still have a large number of tasks waiting in line for processing, resulting in low overall processing efficiency.
[0040] Based on this, the embodiments of the present application provide a method, device, electronic device and storage medium for intelligent analysis of code files, which can effectively improve the analysis efficiency of intelligent analysis of code files.
[0041] The code file intelligent analysis method, device, electronic device and storage medium provided in the embodiments of the present application are specifically described through the following embodiments. First, the code file intelligent analysis method in the embodiments of the present application is described.
[0042] The code file intelligent analysis method provided in the embodiment of the present application relates to the field of computer technology. The code file intelligent analysis method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server side, and can also be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the code file intelligent analysis method, etc., but is not limited to the above forms.
[0043] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0044] The embodiments of the present application are further described below in conjunction with the accompanying drawings.
[0045] like Figure 1 As shown, Figure 1 An optional flow chart of a code file intelligent analysis method provided in an embodiment of the present application, the code file intelligent analysis method can be executed by a server, or can also be executed by a terminal, or can also be executed by a server in cooperation with a terminal, the code file intelligent analysis method code analysis device group is used to perform code analysis on the code project to be inspected, the code analysis device group includes a plurality of first processing devices, a plurality of second processing devices and a plurality of tidal processing devices, the performance of the first processing device is better than that of the second processing device, the code file intelligent analysis method includes but is not limited to the following steps S110 to S140:
[0046] Step S110, obtaining a code project to be checked, and obtaining the complexity of each code file to be checked in the code project to be checked;
[0047] Step S120, when the sum of the complexity of each code file to be checked in the code project to be checked is greater than a preset target complexity threshold, the code project is input into one of the first processing devices;
[0048] Step S130, when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold, and all the first processing devices are in a fully loaded state, the code project to be checked is input into one of the tidal processing devices;
[0049] Step S140, when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold, and all the first processing devices and all the tidal processing devices are in a fully loaded state, the code files to be checked in the code project to be checked are grouped based on the complexity to obtain multiple target file groups, and the target file groups are input into the second processing device.
[0050] In a specific implementation manner, the complexity of the code file to be checked may be the number of code lines in the code file to be checked, the file size, or a combination of the two, which will not be limited herein.
[0051] It can be understood that after obtaining the code project to be checked, the complexity of each code file to be checked in the code project to be checked is obtained, and when the sum of the complexity of all the code files to be checked in the code project to be checked is calculated to be greater than the target complexity threshold, all the code files to be checked in the code project to be checked are input into the same first processing device, and the first processing device performs code analysis. If all the first processing devices are in a fully loaded state, the code project to be checked is sent to the tidal processing device, thereby reducing the load burden of the first processing device, reducing the waiting time of the code project to be checked, and improving the code analysis efficiency of the code project to be checked; when all the first processing devices and the tidal processing devices are in a fully loaded state, since the performance of the second processing device is inferior to that of the first processing device, the code files to be checked in the code project to be checked are grouped to ensure that the sum of the complexity of each target file group is less than the sum of the complexity of the code project to be checked, and the second processing device can perform code analysis on the target file group, thereby also reducing the load burden of the first processing device and the tidal processing device, reducing the waiting time of the code project to be checked, and improving the code analysis efficiency of the code project to be checked.
[0052] In a specific embodiment, the code analysis device group includes multiple computers, each of which is provided with a central processing unit, and a single computer or a single central processing unit is a processing unit, or the central processing unit includes multiple processing cores, and a single processing core is a processing unit.
[0053] In a specific implementation, a distributed version control system (Git) is built in the code analysis device group, and a variety of code analysis tools are integrated in the distributed version control system, including but not limited to: ESLint: used for static analysis of JavaScript and TypeScript code, checking syntax errors, code style issues, etc.; Pylint: a static analysis tool for Python code, checking code errors and style issues; SonarQube: a code quality management platform that supports multiple languages, providing code static analysis, code coverage, code complexity and other functions; Checkstyle: mainly used for static analysis of Java code, checking code style and standards.
[0054] After static code inspection of the code project to be inspected, the processing unit in the code analysis device group generates an inspection report and uploads the inspection report to the SonarQube code quality management platform. For the code project to be inspected with problems, the SonarQube code quality management platform builds an incremental code exclusive project. The SonarQube code quality management platform performs static problem level analysis on the code problems marked in the incremental code exclusive project. In static code inspection, the problem level is usually divided into several categories, such as: Blocker: These problems are the most serious and usually cause the software to fail to compile or run, and must be resolved immediately; Critical: These problems may cause serious runtime errors or security vulnerabilities and need to be resolved first; Major: These problems may cause some parts of the program to not work properly, but will not prevent the software from running; Minor: These problems are usually about code style and best practices and have little impact on the operation of the software; Info: These are usually not considered problems, but provide some suggestions that may help improve the code. Static code analysis tools identify problems in the code based on preset rules or patterns and assign levels based on the potential impact of these problems. For example, a tool might classify uninitialized variables, resource leaks, or potential buffer overflows as serious issues, while classifying inconsistent coding style or unused variables as minor issues.
[0055] After completing the problem level classification for the incremental code-specific project, the SonarQube code quality management platform sends the incremental code-specific project to the corresponding platform users and notifies the platform users to check and modify it.
[0056] In addition, refer to Figure 2 , Figure 8 and Fig. 9 As shown, in some embodiments of the present application, the code file intelligent analysis method further includes but is not limited to the following steps S210 to S220:
[0057] Step S210, when the sum of the complexity of each code file to be checked in the code project to be checked is less than or equal to the target complexity threshold, the code project to be checked is input into the second processing device;
[0058] Step S220, when the sum of the complexity of each code file to be checked in the code project to be checked is less than or equal to the target complexity threshold, each second processing device is in a full load state, and there is a tidal processing device in a non-full load state, the code project to be checked is input into the tidal processing device in a non-full load state.
[0059] Among them, the second processing device and the tidal processing device are both used to simultaneously perform code analysis on multiple code items to be checked whose total complexity is less than or equal to the target complexity threshold, and the second processing device is also used to simultaneously perform code analysis on multiple target file groups, or a combination of target file groups and code items to be checked whose total complexity is less than or equal to the target complexity threshold.
[0060] For the convenience of description, the code projects to be checked whose sum of complexity is greater than the target complexity threshold are named large code projects, and the code projects to be checked whose sum of complexity is less than or equal to the target complexity threshold are named small code projects.
[0061] Specifically, the large code project is sent to the first processing device, and each first processing device is responsible for code analysis work of a specific number of large code projects at the same time. Each first processing device can start 256 high-number threads to run.
[0062] When the total number of large code projects waiting to be checked and being checked is greater than the number that the first processing device can process simultaneously, that is, all first processing devices are fully loaded, the unallocated large code projects are sent to the tidal processing device. One tidal processing device can be responsible for the code analysis work of a specific number of large code projects at the same time.
[0063] The small code items are sent to the second processing device. Each second processing device can perform code analysis on multiple code items to be checked at the same time. The second processing device can start 16 low-thread operations.
[0064] When all the second processing devices are in a fully loaded state, the working state of the tidal processing device is obtained. When the tidal processing device is in an idle state, the unallocated small code items are sent to the tidal processing device in the idle state. Each tidal processing device can perform code analysis on multiple small code items at the same time.
[0065] When there are both unallocated large code projects and small code projects, the tidal processing device gives priority to code analysis on the large code projects. Each first processing device and each tidal device only supports code analysis on a specific number of large code projects. When all first processing devices and all tidal processing devices are fully loaded, the unallocated large code projects are grouped to obtain multiple target file groups. At this time, each target file group can be approximately regarded as a small code project. The target file group is allocated to the second processing device. Each second processing device can perform code analysis on multiple target file groups at the same time. Alternatively, the second processing device can input small code projects and target file groups at the same time and analyze the small code projects and target file groups at the same time.
[0066] Specifically, when allocating small code projects or target file groups to the second processing device, the code analysis device group allocates the small code projects and target file groups according to the number of small code projects and target file groups currently stored in the second processing device to ensure that the total number of small codes and target file groups being processed in each second processing device is as close as possible.
[0067] Exemplarily, the code analysis device group includes two second processing devices, each of which can analyze five small code projects, target file groups or a combination thereof at the same time. Assuming that there are now three small code projects and five target file groups waiting to be analyzed, the two second processing devices are both input with a total of four small code projects or a combination of target file groups. For example, one of the second processing devices can be input with three small code projects and one target file group, and the other second processing device is input with four target file groups, or one of the second processing devices is input with one small code project and three target file groups, and the other second processing device is input with two small code projects and two target file groups; for another example, assuming that there are now five small code projects and six target file groups, and assuming that one of the second processing devices is input with two small code projects and three target file groups, and the other second processing device is input with three small code projects and two target file groups, when any second processing device completes the analysis of one of the small code projects or target file groups, the remaining target file groups are input into the second processing device with idle positions.
[0068] It can be understood that when all the second processing devices are in a fully loaded state and there is a tidal processing device in a non-fully loaded state, the unallocated small code items can be allocated to the tidal processing device. The allocation method is similar to the above specific example and will not be elaborated here. The tidal processing device in a non-fully loaded state means that the tidal processing device is idle, or the tidal processing device is processing small code items, but the number of small code items in the tidal processing device is less than the maximum number that can be processed simultaneously.
[0069] It can be understood that by setting up multiple first processing devices and multiple second processing devices, the first processing device can start high-thread operation and be responsible for the inspection of large code projects, and the second processing device can start low-thread operation and be responsible for the inspection of small code projects, thereby effectively saving equipment resources and costs; at the same time, by setting up a tidal processing device, the priority of the tidal processing device in processing large code projects is higher than the priority of processing small code projects. When the first processing device is fully loaded, the tidal processing device checks the code projects to be inspected corresponding to the large code projects. When the second processing device is fully loaded, and only when the tidal processing device is idle, the tidal processing device checks the code projects to be inspected corresponding to the small code projects, thereby enabling large code projects with higher importance and urgency to be processed first. When the tidal processing device is idle, the idle tidal processing device can also process small code projects when the second processing device is fully loaded, thereby effectively improving the inspection and processing efficiency of the code projects to be inspected.
[0070] In addition, refer to Figure 3 As shown, some embodiments of the present application, Figure 1 The method step S140 includes but is not limited to the following steps S310 to S330:
[0071] Step S310, arranging the code files to be checked from large to small based on the complexity of each code file to be checked, and determining a first complexity threshold based on the complexity of each code file to be checked;
[0072] Step S320, in the sorted code items to be checked, the complexity of each code file to be checked is obtained in turn, and when the complexity is greater than or equal to the latest first complexity threshold, the corresponding code file to be checked is placed separately in a blank target file group, and a new first complexity threshold is determined based on the complexity of the remaining code files to be checked;
[0073] Step S330: when the complexity is less than the latest first complexity threshold, determine the second complexity threshold according to the current code file to be checked and the latest first complexity threshold, and group the remaining code files to be checked based on the latest second complexity threshold.
[0074] In a specific embodiment, referring to Fig.10 As shown, an integer array is constructed, the number of elements in the integer array is equal to the number of code files to be checked in the current code project to be checked, the complexity of the code files to be checked is input into the integer array, each element in the integer array stores the complexity of each code file to be checked, each element in the integer array corresponds to a code file to be checked one by one, each element in the integer array corresponds to the address of the code file to be checked, and the integer array is arranged from large to small based on the complexity in the element.
[0075] In the sorted integer array, determine the first element, that is, the code file to be checked corresponding to the maximum complexity. Since the code file to be checked is indivisible, the code file is placed separately in one of the blank target file groups. Calculate the complexity of the remaining code files to be checked divided by the number of remaining target file groups to which the code files to be checked are not assigned, and determine the new first complexity threshold.
[0076] Then, the code file to be checked corresponding to the second element in the integer array is obtained. If the complexity of the code file to be checked is greater than or equal to the latest first complexity threshold, the code file to be checked is also placed separately in one of the blank target file groups.
[0077] In the process of traversing the sorted integer data, if the complexity of the code file to be checked is less than the latest first complexity threshold, the code file to be checked is placed in one of the blank target file groups. At this time, the sum of the complexity in the target file group is less than the latest first complexity threshold. Therefore, the difference between the sum of the complexity in the target file group and the latest first complexity threshold is calculated to determine the second complexity threshold, and the subsequent part of the integer array is traversed to select the code file to be checked and put it into the target file group so that the sum of the complexity in the current target file group is just greater than the latest first complexity threshold.
[0078] It should be noted that, in the process of traversing the integer array and placing the code files to be checked into the target file group according to the above rules, if the code file to be checked is placed into the target file group, the element corresponding to the code file to be checked is removed from the integer array, thereby avoiding multiple traversals of the element and avoiding the same code file to be checked from being placed in multiple target file groups at the same time.
[0079] In addition, refer to Figure 4 As shown, some embodiments of the present application, Figure 3 The method step S310 includes but is not limited to the following steps S410 to S420:
[0080] Step S410, determining the sum of the complexity of the code files to be checked in the current code project to be checked;
[0081] Step S420 , obtaining the target number of target file groups in the current code project to be checked, and determining a first complexity threshold based on the sum of the complexities of the current code project to be checked and the target number of groups.
[0082] In a specific implementation, the target group number is the number of target file groups, and the target group number is equal to the number of processing units in the code analysis device group allocated to process the current code project to be inspected.
[0083] In a specific implementation, the first complexity threshold is equal to the quotient of the sum of the complexities in the current code items to be checked and the target number of groups. When grouping the code files to be checked, the goal is to minimize the sum of squares of the residuals between the sum of the complexities in each target file group and the first complexity threshold.
[0084] In addition, refer to Figure 5 As shown, some embodiments of the present application, Figure 3 The method step S330 includes but is not limited to the following steps S510 to S520:
[0085] Step S510, determining the sum of the complexity of the code files to be checked that are not put into the target file group;
[0086] Step S520, obtaining the number of remaining target file groups that are not included in the code files to be checked, and determining a new first complexity threshold based on the sum of the complexities of the remaining code files to be checked and the number of remaining target file groups.
[0087] In a specific implementation, the new first complexity threshold is equal to the quotient between the complexity of the remaining code files to be checked and the number of the remaining unassigned target file groups.
[0088] It can be understood that, since the code files to be checked are indivisible, when the code files to be checked are grouped and combined, there must be some target file groups whose sum of complexity is greater than the first complexity threshold calculated initially, and some target file groups whose sum of complexity is less than the second complexity threshold calculated initially. In the process of traversing the integer array, in order to reduce the idle time of the processing unit, if the first complexity threshold calculated initially is always taken as the target to ensure that the sum of complexity of the target file groups in the traversal process is just greater than the first complexity threshold calculated initially, then there is at least one target file group whose sum of complexity is less than the first complexity threshold calculated initially, and the difference between the sum of complexity and the first complexity threshold calculated initially is just equal to the previous target. The difference between the sum of the complexities of the file group and the initially calculated first complexity threshold value indirectly increases the idle time of some processing units. Even, some target file groups may not be divided into code files to be checked, which causes the corresponding processing units to always be idle. Therefore, after traversing the integer data and the target file group and defining the code files to be checked for the target file group, a new first complexity threshold value is calculated based on the remaining code files to be checked, and the code files to be checked are defined for subsequent target file groups based on the new first complexity threshold value. In this way, the sum of the complexities of each target file group can be dynamically planned in the process of traversing the integer array, ensuring that each target file group is divided into enough code files to be checked, thereby achieving local optimization of the grouping of the code files to be checked.
[0089] In addition, refer to Figure 6As shown, some embodiments of the present application, Figure 3 The method step S330 in the embodiment includes but is not limited to the following steps S610 to S630:
[0090] Step S610, if the complexity of the current code file to be checked is less than the latest first complexity threshold, the current code file to be checked is placed into a new target file group;
[0091] Step S620, determining a second complexity threshold according to the latest first complexity threshold and the complexity of the current code file to be checked, and grouping the remaining code files to be checked based on the second complexity threshold;
[0092] Step S630: re-determine the first complexity threshold based on the complexity of the remaining code files to be checked, and group the remaining code files to be checked based on the latest first complexity threshold until all the code files to be checked are grouped.
[0093] In a specific implementation, in the process of traversing the integer array, if the complexity of the current code file to be checked is less than the latest first complexity threshold, the current code file to be checked is first placed in a new target file group; then, the difference between the latest first complexity threshold and the complexity of the current code file to be checked is calculated to determine the second complexity threshold; then, the subsequent elements in the integer array are traversed, and the remaining code files to be checked are placed in the current target file group based on the second complexity threshold, so that the sum of the complexities of the current target file group is just greater than the latest first complexity threshold; then, the remaining elements of the integer array are traversed, the first complexity threshold is repeatedly calculated, and the code files to be checked are grouped based on the latest first complexity threshold until all the code files to be checked are placed in one of the target file groups.
[0094] In addition, refer to Figure 7 As shown, some embodiments of the present application, Figure 6 The method step S620 includes but is not limited to the following steps S710 to S730:
[0095] Step S710, determining a second complexity threshold according to the difference between the latest first complexity threshold and the complexity of the current code file to be checked;
[0096] Step S720, sequentially obtaining the complexity of the remaining code files to be checked, and when the complexity is less than or equal to the latest second complexity threshold, placing the corresponding code files to be checked into the current target file group, and determining a new second complexity threshold based on the complexity of the code files to be checked existing in the current target file group and the latest first complexity threshold;
[0097] Step S730, when traversing to the last code file to be checked in the current code project to be checked, if the sum of the complexity of the code files to be checked in the current target file group is less than the latest first complexity threshold, the last code file to be checked is placed in the current target file group.
[0098] In a specific embodiment, referring to Fig.11 As shown, in the process of traversing the integer data, if the complexity of the current code file to be checked is less than the latest first complexity threshold, first, the current code file to be checked is placed in an empty target file group; then, the second complexity threshold is determined based on the difference between the latest first complexity threshold and the complexity of the current code file to be checked; then, the integer array is continued to be traversed, and when the complexity of the code file to be checked is equal to the second complexity threshold, the code file to be checked is placed in the current target file group. At this time, the sum of the complexities in the current target file group is equal to the latest first complexity threshold, so the current target file group is determined, and the remaining elements of the integer array are traversed to define the next target file group; and when the complexity of the code file to be checked is less than the second complexity threshold, the code file to be checked is placed in the current target file group. In the process, a new second complexity threshold is determined based on the latest first complexity threshold and the complexity of all code files to be checked in the current target file group. Specifically, the second complexity threshold is equal to the difference between the latest first complexity threshold and the sum of the complexity of all code files to be checked in the current target file group; then, based on the latest second complexity threshold, the above steps are repeated until the sum of the complexity in the current target file group is equal to the latest first complexity threshold; then, when traversing to the last element of the integer array, if the sum of the complexity of the code files to be checked in the current target file group is less than the latest first complexity threshold, then regardless of the size relationship between the complexity of the last code file to be checked and the latest second complexity threshold, the last code file to be checked is placed in the current target file group to determine the current target file group.
[0099] In a specific implementation, after the last code file to be checked is placed in the current target file group, if the total complexity of the current target file group is less than the latest first complexity threshold, after removing the last element from the integer array, traverse the integer array from back to front, and place the code files to be checked corresponding to the elements in the current target file group one by one, until the total complexity in the current target file group is greater than or equal to the latest first complexity threshold, stop traversing the integer array, and determine the current target file group.
[0100] In addition, refer to Fig.12 As shown, the embodiment of the present application also proposes a code file intelligent analysis device 1200, including:
[0101] An acquisition module 1201 is used to acquire a code project to be checked and acquire the complexity of each code file to be checked in the code project to be checked;
[0102] The processing module 1202 is used to input the code project into one of the first processing devices when the sum of the complexity of each code file to be checked in the code project to be checked is greater than a preset target complexity threshold;
[0103] The processing module 1202 is further configured to input the code project to be checked into one of the tidal processing devices when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices are in a fully loaded state;
[0104] The processing module 1202 is also used to group the code files to be checked in the code project to be checked based on the complexity when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices and all the tidal processing devices are in a fully loaded state, to obtain multiple target file groups, and input the target file groups into the second processing device.
[0105] It can be understood that the specific implementation of the code file intelligent analysis device is basically the same as the specific implementation example of the above-mentioned model training method, and will not be repeated here.
[0106] In addition, refer to Fig.13 , Fig.13 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0107] The processor 1301 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0108] The memory 1302 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1302 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1302, and the processor 1301 calls and executes the code file intelligent analysis method of the embodiment of the application, for example, executing the above-described Figure 1 Steps S110 to S140 of the method, Figure 2 Steps S210 to S220 of the method, Figure 3 Steps S310 to S330 of the method, Figure 4 Steps S410 to S420 of the method, Figure 5 Steps S510 to S520 of the method, Figure 6 Steps S610 to S630 of the method, Figure 7 Steps S710 to S730 of the method;
[0109] Input / output interface 1303, used to implement information input and output;
[0110] The communication interface 1304 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0111] A bus 1305 that transmits information between various components of the device (e.g., the processor 1301, the memory 1302, the input / output interface 1303, and the communication interface 1304);
[0112] The processor 1301 , the memory 1302 , the input / output interface 1303 and the communication interface 1304 are connected to each other in communication within the device via a bus 1305 .
[0113] The embodiment of the present application also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned code file intelligent analysis method, for example, to execute the above-described Figure 1 Steps S110 to S140 of the method, Figure 2 Steps S210 to S220 of the method, Figure 3 Steps S310 to S330 of the method, Figure 4 Steps S410 to S420 of the method, Figure 5 Steps S510 to S520 of the method, Figure 6 Steps S610 to S630 of the method, Figure 7 Steps S710 to S730 of the method;
[0114] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0115] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0116] It can be understood by those skilled in the art that Figures 1 to 7 The technical solutions shown in the figure do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than those shown in the figure, or a combination of certain steps, or different steps.
[0117] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0118] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0119] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0120] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0121] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0122] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0123] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0124] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0125] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A code file intelligent analysis method, characterized in that: Applied to a code analysis device group, the code analysis device group is used to perform code analysis on a code project to be inspected, the code analysis device group includes a plurality of first processing devices, a plurality of second processing devices and a plurality of tidal processing devices, the performance of the first processing device is better than that of the second processing device, and the code file intelligent analysis method includes: Obtain the code project to be checked, and obtain the complexity of each code file to be checked in the code project to be checked; When the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than a preset target complexity threshold, inputting the code project into one of the first processing devices; When the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than the target complexity threshold, and all of the first processing devices are in a fully loaded state, inputting the code project to be checked into one of the tidal processing devices; When the sum of the complexities of each of the code files to be checked in the code project to be checked is greater than the target complexity threshold, and all of the first processing devices and all of the tidal processing devices are in a fully loaded state, the code files to be checked in the code project to be checked are grouped based on the complexity to obtain multiple target file groups, and the target file groups are input into the second processing device.
2. The code file intelligent analysis method according to claim 1, characterized in that: The step of grouping the code files to be checked in the code project to be checked based on the complexity to obtain a plurality of target file groups includes: Arrange the code files to be checked from large to small based on the complexity of each of the code files to be checked, and determine a first complexity threshold based on the complexity of each of the code files to be checked; In the sorted code items to be checked, the complexity of each code file to be checked is obtained in turn; when the complexity is greater than or equal to the latest first complexity threshold, the corresponding code file to be checked is placed separately in the blank target file group, and a new first complexity threshold is determined based on the complexity of the remaining code files to be checked; When the complexity is less than the latest first complexity threshold, a second complexity threshold is determined according to the current code file to be checked and the latest first complexity threshold, and the remaining code files to be checked are grouped based on the latest second complexity threshold.
3. The code file intelligent analysis method according to claim 2, characterized in that: When the complexity is less than the latest first complexity threshold, determining a second complexity threshold according to the current code file to be checked and the latest first complexity threshold, and grouping the remaining code files to be checked based on the latest second complexity threshold, including: If the complexity of the current code file to be checked is less than the latest first complexity threshold, putting the current code file to be checked into a new target file group; Determine a second complexity threshold according to the latest first complexity threshold and the complexity of the current code file to be checked, and group the remaining code files to be checked based on the second complexity threshold; The first complexity threshold is re-determined based on the complexity of the remaining code files to be checked, and the remaining code files to be checked are grouped based on the latest first complexity threshold until all the code files to be checked are grouped.
4. The code file intelligent analysis method according to claim 3, characterized in that: The determining a second complexity threshold according to the latest first complexity threshold and the complexity of the current code file to be checked, and grouping the remaining code files to be checked based on the second complexity threshold, comprises: Determine a second complexity threshold according to a difference between the latest first complexity threshold and the complexity of the current code file to be checked; Obtaining the complexity of the remaining code files to be checked in sequence, and when the complexity is less than or equal to the latest second complexity threshold, placing the corresponding code files to be checked into the current target file group, and determining a new second complexity threshold based on the complexity of the code files to be checked existing in the current target file group and the latest first complexity threshold; When traversing to the last code file to be checked in the current code project to be checked, if the sum of the complexity of the code files to be checked in the current target file group is less than the latest first complexity threshold, the last code file to be checked is placed in the current target file group.
5. The code file intelligent analysis method according to claim 2, characterized in that: The determining a first complexity threshold based on the complexity of each of the code files to be checked includes: Determine the sum of the complexities of the code files to be checked in the current code project to be checked; The target number of target file groups in the current code project to be checked is obtained, and a first complexity threshold is determined based on the sum of the complexities in the current code project to be checked and the target number of groups.
6. The code file intelligent analysis method according to claim 2, characterized in that: The determining the new first complexity threshold based on the complexity of the remaining code files to be checked includes: Determine the sum of the complexities of the code files to be checked that are not placed in the target file group; The number of remaining target file groups that are not put into the code file to be checked is obtained, and a new first complexity threshold is determined based on the sum of the complexities of the remaining code files to be checked and the number of remaining target file groups.
7. The code file intelligent analysis method according to claim 1, characterized in that: The code file intelligent analysis method comprises: When the sum of the complexity of each of the code files to be checked in the code project to be checked is less than or equal to the target complexity threshold, inputting the code project to be checked into the second processing device; When the sum of the complexity of each of the code files to be checked in the code project to be checked is less than or equal to the target complexity threshold, each of the second processing devices is in a fully loaded state, and there is a tidal processing device in a non-fully loaded state, inputting the code project to be checked into the tidal processing device in a non-fully loaded state; Among them, the second processing device and the tidal processing device are both used to simultaneously perform code analysis on multiple code items to be checked whose sum of complexity is less than or equal to the target complexity threshold, and the second processing device is also used to simultaneously perform code analysis on multiple target file groups, or a combination of the target file groups and the code items to be checked whose sum of complexity is less than or equal to the target complexity threshold.
8. A code file intelligent analysis device, characterized in that: Set in a code analysis device group, the code analysis device group is used to perform code analysis on the code project to be inspected, the code analysis device group includes a plurality of first processing devices, a plurality of second processing devices and a plurality of tidal processing devices, the performance of the first processing device is better than that of the second processing device, and the code file intelligent analysis device includes: An acquisition module, used for acquiring the code project to be checked, and acquiring the complexity of each code file to be checked in the code project to be checked; A processing module, configured to input the code project into one of the first processing devices when the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than a preset target complexity threshold; The processing module is further configured to input the code project to be checked into one of the tidal processing devices when the sum of the complexity of each of the code files to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices are in a fully loaded state; The processing module is also used to group the code files to be checked in the code project to be checked based on the complexity when the sum of the complexity of each code file to be checked in the code project to be checked is greater than the target complexity threshold and all the first processing devices and all the tidal processing devices are in a fully loaded state, to obtain multiple target file groups, and input the target file groups into the second processing device.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the code file intelligent analysis method according to any one of claims 1 to 7 when executing the computer program.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the code file intelligent analysis method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
System and method for industrial automation project code analysis
CN112579154A
Code risk prediction method and system based on machine learning
CN112711530A