Resource allocation method, device and equipment for code performance analysis
Through word embedding and homomorphic encryption technology, code embedding vectors are obtained and encrypted, and resource allocation model is input to obtain allocation schemes, which solves the problem that resource allocation methods in the existing technology cannot guarantee user data security, and realizes efficient and secure resource allocation and code performance analysis.
Patent Information
- Application Number
- CN202411535358.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-10-30
AI Technical Summary
The existing resource allocation methods for code performance analysis cannot ensure the security of user data and pose a risk of privacy leakage.
The code embedding vector corresponding to the code is obtained through word embedding and homomorphically encrypted. Then, the encrypted code embedding vector is input to the pre-trained resource allocation model to obtain the resource allocation scheme and resource allocation.
This method avoids privacy leakage by removing specific code content, and improves data security through homomorphic encryption, ensuring the security of user data, and improving resource utilization and code performance.
Smart Images

Figure CN119025436B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a resource allocation method, device and equipment for code performance analysis. Background Art
[0002] Code performance analysis is the process of identifying and optimizing performance bottlenecks by measuring and analyzing the execution behavior of code. The goal is to improve code efficiency, reduce resource consumption, and ensure system response time and throughput. Computing resource scheduling refers to the process of rationally allocating and managing available resources (such as CPU, memory, storage, and network bandwidth) in a computing system to optimize task execution efficiency. The goal is to maximize resource utilization, minimize task execution time, and ensure system stability and availability. With the popularity of technologies such as Artificial Intelligence Generated Content (AIGC), the demand for computing resources is growing exponentially. In this context, computing resource scheduling technology is gaining increasing attention. Combining code performance analysis and computing resource scheduling can achieve more efficient resource utilization and more optimized code performance. Predicting resource usage patterns based on analyzing code behavior and dynamically adjusting resource allocation can significantly improve system performance and resource utilization.
[0003] At present, the resource allocation method for code performance analysis is based on source code, that is, readable code, which cannot guarantee the security of user data and has the risk of privacy leakage. Therefore, a safe and reliable resource allocation method for code performance analysis is urgently needed. Summary of the invention
[0004] The present invention provides a resource allocation method, device and equipment for code performance analysis to solve the problem that the existing methods are prone to privacy leakage.
[0005] In a first aspect, the present disclosure provides a resource allocation method for code performance analysis, comprising:
[0006] Obtain the code embedding vector corresponding to the code of the resource to be allocated through word embedding;
[0007] Homomorphically encrypt the code embedding vector corresponding to the code to be allocated resources to obtain an encrypted code embedding vector;
[0008] Input the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation plan. The resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan.
[0009] Resources are allocated to the code of the resources to be allocated according to the obtained resource allocation plan.
[0010] In some embodiments, obtaining a code embedding vector corresponding to a code of a resource to be allocated through word embedding includes:
[0011] Preprocess the code to be allocated resources;
[0012] Decompose the preprocessed code into multiple words;
[0013] Use the trained Word2Vec model to determine the embedding vector for each word;
[0014] The average value of the embedding vectors of all words is determined as the code embedding vector corresponding to the code of the resource to be allocated.
[0015] In some embodiments, preprocessing the code of the resource to be allocated includes: removing comments and blank characters in the code of the resource to be allocated.
[0016] In some embodiments, when training the Word2Vec model, the dimension of the embedding vector is specified to be 10, the context window size is 5, and the minimum number of word occurrences is 1.
[0017] In some embodiments, the resource allocation model is constructed based on a regression model, and the training process of the resource allocation model includes:
[0018] Constructing a training data set, where each training sample in the training data set includes a code embedding vector as a feature and a corresponding resource allocation scheme as a label, where the resource allocation scheme is determined according to the computing resource usage when running the code corresponding to the code embedding vector;
[0019] The code embedding vector of each training sample in the training data set is input into the resource allocation model, and the corresponding resource allocation scheme is used as the expected output of the resource allocation model. The resource allocation model is trained until the iteration termination condition is met.
[0020] In some embodiments, performing homomorphic encryption on a code embedding vector corresponding to a code to be allocated resources includes:
[0021] The code embedding vector corresponding to the code of the resource to be allocated is encoded and encryption is performed based on the encoding result.
[0022] In a second aspect, the present disclosure provides a resource allocation device for code performance analysis, comprising:
[0023] An acquisition module, used for acquiring a code embedding vector corresponding to the code of the resource to be allocated through word embedding;
[0024] An encryption module, used for performing homomorphic encryption on a code embedding vector corresponding to the code to be allocated resources to obtain an encrypted code embedding vector;
[0025] A prediction module is used to input the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation plan. The resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan;
[0026] The allocation module is used to allocate resources to the code of the resources to be allocated according to the obtained resource allocation plan.
[0027] In a third aspect, the present disclosure provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described in the above aspects.
[0028] In a fourth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the method described in the above aspects when executed by a processor.
[0029] In a fifth aspect, the present disclosure provides a computer program product, including a computer program, which implements the steps of the method described in the above aspects when executed by a processor.
[0030] The present disclosure provides a resource allocation method, device and equipment for code performance analysis, which obtains the code embedding vector corresponding to the code of the resource to be allocated through word embedding; homomorphically encrypts the code embedding vector corresponding to the code of the resource to be allocated to obtain the encrypted code embedding vector; inputs the encrypted code embedding vector into a pre-trained resource allocation model to obtain the corresponding resource allocation plan, and the resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan; and allocates resources to the code of the resource to be allocated according to the obtained resource allocation plan. The code embedding vector retains the necessary features for resource allocation, removes the specific code content, avoids privacy leakage, and ensures the security of user data; homomorphic encryption further improves data security. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The present disclosure will be described in more detail below based on embodiments and with reference to the accompanying drawings:
[0032] Figure 1 A schematic diagram of a flow chart of a resource allocation method for code performance analysis provided in an embodiment of the present disclosure;
[0033] Figure 2 A schematic diagram of the structure of a resource allocation device for code performance analysis provided in an embodiment of the present disclosure.
[0034] In the drawings, the same reference numerals are used for the same components, and the drawings are not drawn to scale. DETAILED DESCRIPTION
[0035] In order to enable those skilled in the art to better understand the technical solution of the present disclosure, and to fully understand and implement how the present disclosure applies technical means to solve technical problems and achieve the corresponding technical effects, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only embodiments of a part of the present disclosure, not all of the embodiments. The embodiments of the present disclosure and the various features in the embodiments can be combined with each other without conflict, and the technical solutions formed are all within the scope of protection of the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work should fall within the scope of protection of the present disclosure.
[0036] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure 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 disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0037] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0038] At present, the resource allocation method for code performance analysis is based on source code, that is, readable code, which cannot guarantee the security of user data and has the risk of privacy leakage. So how to ensure the security of user data under the premise of ensuring system performance, that is, to take into account the resource utilization of the system and the security of user data, has become an urgent problem to be solved. Based on this, the present application proposes a resource allocation method for code performance analysis, which uses homomorphic encryption and word embedding technology to implement resource allocation and avoid privacy leakage. The following will be explained in detail through specific embodiments.
[0039] Embodiment 1
[0040] Figure 1 The following is a flow chart of a resource allocation method for code performance analysis provided by an embodiment of the present disclosure. Figure 1As shown, the resource allocation method for code performance analysis provided in this embodiment may include:
[0041] S101. Obtain a code embedding vector corresponding to the code of the resource to be allocated through word embedding.
[0042] The code of the resources to be allocated in this embodiment can be a code segment that is about to be executed in the system and needs to allocate system computing resources. Word embedding is a technology in natural language processing (NLP) that is used to represent words as real number vectors. The word embedding model can map high-dimensional discrete words to low-dimensional continuous vector space, so that the semantic relationship between words can be represented and measured by the geometric relationship of vectors (such as the distance and angle of vectors). In this embodiment, the code of the resources to be allocated is converted into the corresponding code embedding vector through word embedding, which can capture the semantic information in the code without exposing the specific code content and avoiding privacy leakage. Moreover, compared with the code of the resources to be allocated, the dimension of the code embedding vector is lower, the processor will be more efficient, and it will also help to improve the efficiency of resource allocation.
[0043] S102. Perform homomorphic encryption on the code embedding vector corresponding to the code of the resource to be allocated to obtain an encrypted code embedding vector.
[0044] The homomorphic encryption in this embodiment is fully homomorphic encryption. Since the homomorphically encrypted data is processed to obtain an output, the decrypted output is the same as the output obtained by processing the unencrypted original data in the same way. Therefore, in order to further improve security, in this embodiment, the code embedding vector corresponding to the code to be allocated resources is homomorphically encrypted and then processed subsequently.
[0045] In this embodiment, there is no limitation on the specific algorithm of homomorphic encryption, for example, a fully homomorphic encryption algorithm CKKS (Cheon-Kim-Kim-Song) based on a polynomial ring may be used, and algorithms such as BGV and BFV may also be used. In some optional implementations, performing homomorphic encryption on the code embedding vector corresponding to the code of the resource to be allocated may specifically include: performing encoding processing on the code embedding vector corresponding to the code of the resource to be allocated and performing encryption processing based on the encoding result.
[0046] S103: input the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation plan, where the resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan.
[0047] After obtaining the encrypted code embedding vector, input it into the pre-trained resource allocation model to obtain the corresponding resource allocation plan. The resource allocation model in this embodiment is obtained based on a machine learning algorithm. Compared with the source code, the code embedding vector is more suitable for resource allocation model processing. The resource allocation model in this embodiment is trained based on the code embedding vector annotated with the resource allocation plan. It should be noted that the resource allocation plan in the training data is determined by collecting resource usage during the code running process. Determining the resource allocation plan based on the resource allocation model can not only improve the efficiency of resource allocation, but also improve the accuracy of resource allocation.
[0048] S104: Allocate resources for the codes of the resources to be allocated according to the obtained resource allocation plan.
[0049] After obtaining the resource allocation plan, resources can be allocated to the code according to the resource allocation plan.
[0050] The resource allocation method for code performance analysis provided in this embodiment obtains the code embedding vector corresponding to the code of the resource to be allocated through word embedding; performs homomorphic encryption on the code embedding vector corresponding to the code of the resource to be allocated to obtain an encrypted code embedding vector; inputs the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation plan, and the resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan; and performs resource allocation for the code of the resource to be allocated according to the obtained resource allocation plan. The code embedding vector retains the necessary features sufficient for resource allocation, removes the specific code content, avoids privacy leakage, and ensures the security of user data; homomorphic encryption further improves data security. Determining the resource allocation plan based on the resource allocation model can not only improve the efficiency of resource allocation, but also improve the accuracy of resource allocation.
[0051] Embodiment 2
[0052] Based on the above embodiments, the following will further explain in detail how to obtain the code embedding vector corresponding to the code of the resource to be allocated. Based on the above embodiments, in the resource allocation method for code performance analysis provided in this embodiment, the code embedding vector corresponding to the code of the resource to be allocated is obtained through word embedding, which can specifically include: preprocessing the code of the resource to be allocated; decomposing the preprocessed code into multiple words; using the trained Word2Vec model to determine the embedding vector of each word; and determining the average value of the embedding vectors of all words as the code embedding vector corresponding to the code of the resource to be allocated.
[0053] In this embodiment, the code of the resource to be allocated is preprocessed, which may specifically include: removing comments and blank characters in the code of the resource to be allocated, so that the code can be more concise, which can not only reduce the amount of data processing but also improve the resource allocation efficiency.
[0054] The preprocessed code is segmented, and the preprocessed code fragments are decomposed into words and marked. Then the trained Word2Vec model is used to determine the embedding vector corresponding to each word, and finally the average value of the embedding vectors of all words is determined as the code embedding vector corresponding to the code to be allocated. It can be understood that taking the average value of the embedding vectors of all words can weaken the influence of abnormal vectors and help improve the accuracy of resource allocation. The average value in this embodiment can be an arithmetic mean or a weighted average. It should be noted that when processing the code, the code is divided into small units (tokens), which are the "words" in the code. The "words" of the code include not only identifiers (such as variable names, function names), but also keywords (such as if, for), operators (such as +, ==), separators (such as;, {}), literals (such as numbers, string constants), etc.
[0055] In this embodiment, when training the Word2Vec model, the dimension of the embedding vector is specified to be 10, the context window size is 5, and the minimum number of word occurrences is 1, ensuring that all words are taken into account.
[0056] The word embedding model can capture the semantic information in the code and convert it into a vector representation suitable for processing by the machine learning model. By converting the code into a vector representation, the original code is desensitized. The specific code content is removed: Through the embedding model, the code is represented as a series of vectors that capture the semantic information of the code but do not contain the original code text. And the necessary features are retained: Although the specific code content is hidden, the embedding vector still retains the necessary features, which are sufficient for predicting computing resources.
[0057] Embodiment 3
[0058] On the basis of the above-mentioned embodiments, the following will further explain in detail how to obtain a trained resource allocation model. On the basis of the above-mentioned embodiments, in the resource allocation method for code performance analysis provided in this embodiment, the resource allocation model is constructed based on a regression model, and the training process of the resource allocation model includes: constructing a training data set, each training sample in the training data set includes a code embedding vector as a feature and its corresponding resource allocation scheme as a label, and the resource allocation scheme is determined according to the computing resource usage when running the code corresponding to the code embedding vector; the code embedding vector of each training sample in the training data set is input into the resource allocation model, and the corresponding resource allocation scheme is used as the expected output of the resource allocation model, and the resource allocation model is trained until the iteration termination condition is met.
[0059] In this embodiment, the resource allocation model is constructed based on a regression model, for example, random forest regression, support vector regression and neural network can be used, and this embodiment does not limit the specific structure of the resource allocation model. The iteration termination condition in this embodiment can be, for example, that the number of iterations reaches a preset value, the value of the loss function is less than a preset threshold, the change of the model parameters in continuous iterations is less than a certain threshold, that is, the model converges, etc., which can be set according to actual needs.
[0060] It is understandable that a resource allocation model that has learned the resource usage of a large number of codes during runtime can more accurately predict the resource allocation plan of the code to be allocated resources, which helps to improve the reliability of resource allocation.
[0061] Embodiment 4
[0062] Figure 2 The structure diagram of a resource allocation device for code performance analysis provided by an embodiment of the present disclosure is shown in FIG. Figure 2 As shown, the resource allocation device 20 for code performance analysis provided by this embodiment includes: an acquisition module 201, an encryption module 202, a prediction module 203 and an allocation module 204.
[0063] An acquisition module 201 is used to acquire a code embedding vector corresponding to a code of a resource to be allocated through word embedding;
[0064] An encryption module 202 is used to perform homomorphic encryption on the code embedding vector corresponding to the code to be allocated resources to obtain an encrypted code embedding vector;
[0065] Prediction module 203, used to input the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation plan, the resource allocation model is trained based on the code embedding vector annotated with the resource allocation plan;
[0066] The allocation module 204 is used to allocate resources to the code to be allocated resources according to the obtained resource allocation plan.
[0067] The device of this embodiment can be used to perform Figure 1 The technical solution of the method embodiment shown has similar implementation principles and technical effects, which will not be repeated here.
[0068] In some embodiments, the acquisition module 201 is used to acquire the code embedding vector corresponding to the code of the resource to be allocated through word embedding, which may specifically include:
[0069] Preprocess the code to be allocated resources;
[0070] Decompose the preprocessed code into multiple words;
[0071] Use the trained Word2Vec model to determine the embedding vector for each word;
[0072] The average value of the embedding vectors of all words is determined as the code embedding vector corresponding to the code of the resource to be allocated.
[0073] In some embodiments, the acquisition module 201 is used to pre-process the code of the resource to be allocated, which may specifically include: removing comments and blank characters in the code of the resource to be allocated.
[0074] In some embodiments, when training the Word2Vec model, the dimension of the embedding vector is specified to be 10, the context window size is 5, and the minimum number of word occurrences is 1.
[0075] In some embodiments, the resource allocation model is constructed based on a regression model, and the training process of the resource allocation model includes:
[0076] Constructing a training data set, where each training sample in the training data set includes a code embedding vector as a feature and a corresponding resource allocation scheme as a label, where the resource allocation scheme is determined according to the computing resource usage when running the code corresponding to the code embedding vector;
[0077] The code embedding vector of each training sample in the training data set is input into the resource allocation model, and the corresponding resource allocation scheme is used as the expected output of the resource allocation model. The resource allocation model is trained until the iteration termination condition is met.
[0078] In some embodiments, the encryption module 202 is used to perform homomorphic encryption on the code embedding vector corresponding to the code to be allocated resources, which may specifically include:
[0079] The code embedding vector corresponding to the code of the resource to be allocated is encoded and encryption is performed based on the encoding result.
[0080] Embodiment 5
[0081] Based on the above embodiments, this embodiment provides an application example.
[0082] In order to solve the problem that the existing methods are based on source code, that is, readable code, when allocating resources, which poses a risk of privacy leakage. The present application provides a code performance prediction method using homomorphic encryption and word embedding technology. Word Embedding Models is a technology in natural language processing (NLP) that is used to represent words as real number vectors. The word embedding model maps high-dimensional discrete words to a low-dimensional continuous vector space, so that the semantic relationship between words can be represented and measured by the geometric relationship of the vectors (such as the distance and angle of the vectors). Code embedding is a subset of word embedding and is an embedding model specifically for code, such as Code2Vec or CodeBERT. Through the word embedding model, the semantic information in the code can be captured and converted into a vector representation suitable for processing by a machine learning model.
[0083] Word embedding embeds the code snippet and generates the corresponding vector representation. The specific process is as follows:
[0084] 1) Code preprocessing:
[0085] •Remove comments and extra whitespace characters from the code to make it more concise.
[0086] 2) Code segmentation:
[0087] •Break the preprocessed code snippet into words (tokens).
[0088] 3) Training the Word2Vec model:
[0089] • Use the Word2Vec model in the gensim library to train the segmented code snippets.
[0090] •vector_size=10 specifies that the dimension of the embedding vector is 10.
[0091] •window=5 means the context window size is 5.
[0092] •min_count=1 ensures that all words are considered.
[0093] 4) Generate code embedding vector:
[0094] •Average the embedding vectors of all words in each code snippet to get the vector representation of the entire code snippet.
[0095] 5) Output results
[0096] It should be noted that the variables in the above code are for illustration only and are not intended to be limiting.
[0097] The word embedding model converts the code into a vector representation, and the original code is desensitized: not only the specific code content is removed, but also the necessary features are retained.
[0098] The specific code content is removed: Through the embedding model, the code is represented as a series of vectors that capture the semantic information of the code but do not contain the original code text.
[0099] Necessary features are retained: Although the specific code content is hidden, the embedding vector still retains the necessary features, which are sufficient for prediction of computing resources.
[0100] The code embedding vector is matched with the corresponding computing resource usage as features and labels for training machine learning models. Common regression models include random forest regression, support vector regression, and neural networks.
[0101] The user end uses an encryption module to encrypt the new code vector of the allocated resources, and sends the encrypted vector to the resource prediction unit. The resource prediction unit uses homomorphic encryption and can perform predictions on the machine learning model based on the encrypted vector without decrypting the vector.
[0102] In summary, the resource allocation method for code performance analysis provided by this application retains the necessary features for resource allocation through code embedding vectors, removes specific code content, avoids privacy leakage, and ensures user data security; homomorphic encryption further improves data security. Determining the resource allocation plan based on the resource allocation model can not only improve the efficiency of resource allocation, but also improve the accuracy of resource allocation.
[0103] Embodiment 6
[0104] On the basis of the above embodiments, this embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described in the above embodiments.
[0105] In some implementations of this embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the above embodiment are implemented.
[0106] In some implementations of this embodiment, a computer program product is provided, including a computer program, which implements the steps of the method described in the above embodiment when executed by a processor.
[0107] The processor may include, but is not limited to, one or more processors or microprocessors, etc. Each processor may be an application specific integrated circuit (ASIC), a digital signal processor (DSP), a digital signal processing device (DSPD), a programmable logic device (PLD), a field programmable gate array (FPGA), a controller, a microcontroller, a microprocessor or other electronic components to execute the methods in the above embodiments.
[0108] The computer-readable storage medium may be implemented by any type of volatile or non-volatile storage device or a combination thereof, and the computer-readable storage medium may include but is not limited to, for example, random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, computer storage media (e.g., hard disk, floppy disk, solid-state drive, removable disk, CD-ROM, DVD-ROM, Blu-ray disc, etc.).
[0109] The computer-readable storage medium may also store at least one computer executable program / instruction, which may be, for example, a computer-readable instruction. The computer-readable storage medium includes, but is not limited to, for example, a volatile memory and / or a non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The computer-readable storage medium may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. For example, a non-transitory computer-readable storage medium may be connected to a computing device such as a computer, and then, when the computing device runs the computer-readable instructions stored on the computer-readable storage medium, the various methods described above may be performed.
[0110] In addition, the computer device may also include (but not limited to) a data bus, an input / output (I / O) bus, a display, and input / output devices (eg, keyboard, mouse, speaker, etc.), etc.
[0111] The processor may communicate with external devices via an I / O bus via a wired or wireless network.
[0112] In one embodiment, the at least one computer executable instruction may also be compiled into or constitute a software product / computer program product, wherein one or more computer executable instructions are executed by a processor to perform the various functions and / or method steps in the embodiments described in the present technology.
[0113] In the embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0114] It should be noted that in the present disclosure, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element limited by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0115] Although the embodiments disclosed in the present disclosure are as above, the above contents are only embodiments adopted for facilitating the understanding of the present disclosure and are not intended to limit the present disclosure. Any technician in the technical field to which the present disclosure belongs can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in the present disclosure, but the scope of patent protection of the present disclosure shall still be subject to the scope defined in the attached claims.
Claims
1. A resource allocation method for code performance analysis, characterized in that: include: Obtain the code embedding vector corresponding to the code of the resource to be allocated through word embedding; Homomorphically encrypting the code embedding vector corresponding to the code of the resource to be allocated to obtain an encrypted code embedding vector; Inputting the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation solution, wherein the resource allocation model is trained based on the code embedding vector annotated with the resource allocation solution; Allocate resources for the code of the resource to be allocated according to the obtained resource allocation scheme; The step of obtaining a code embedding vector corresponding to the code of the resource to be allocated by word embedding includes: Preprocessing the code of the resource to be allocated; Decompose the preprocessed code into multiple words; Use the trained Word2Vec model to determine the embedding vector for each word; The average value of the embedding vectors of all words is determined as the code embedding vector corresponding to the code of the resource to be allocated.
2. The method according to claim 1, characterized in that The preprocessing of the code of the resource to be allocated includes: removing comments and blank characters in the code of the resource to be allocated.
3. The method according to claim 1, characterized in that When training the Word2Vec model, the dimension of the embedding vector is specified to be 10, the context window size is 5, and the minimum number of word occurrences is 1.
4. The method according to any one of claims 1 to 3, characterized in that: The resource allocation model is constructed based on a regression model, and the training process of the resource allocation model includes: Constructing a training data set, wherein each training sample in the training data set includes a code embedding vector as a feature and a corresponding resource allocation scheme as a label, wherein the resource allocation scheme is determined according to the computing resource usage when running the code corresponding to the code embedding vector; The code embedding vector of each training sample in the training data set is input into the resource allocation model, and the corresponding resource allocation scheme is used as the expected output of the resource allocation model to train the resource allocation model until an iteration termination condition is met.
5. The method according to any one of claims 1 to 3, characterized in that: The performing homomorphic encryption on the code embedding vector corresponding to the code of the resource to be allocated includes: The code embedding vector corresponding to the code of the resource to be allocated is encoded and encrypted based on the encoding result.
6. A resource allocation device for code performance analysis, characterized in that: include: An acquisition module, used for acquiring a code embedding vector corresponding to the code of the resource to be allocated through word embedding; An encryption module, used for homomorphically encrypting the code embedding vector corresponding to the code of the resource to be allocated to obtain an encrypted code embedding vector; A prediction module, configured to input the encrypted code embedding vector into a pre-trained resource allocation model to obtain a corresponding resource allocation solution, wherein the resource allocation model is trained based on the code embedding vector annotated with the resource allocation solution; An allocation module, configured to allocate resources to the code of the resource to be allocated according to the obtained resource allocation scheme; The acquisition module is used to acquire a code embedding vector corresponding to the code of the resource to be allocated through word embedding, including: Preprocessing the code of the resource to be allocated; Decompose the preprocessed code into multiple words; Use the trained Word2Vec model to determine the embedding vector for each word; The average value of the embedding vectors of all words is determined as the code embedding vector corresponding to the code of the resource to be allocated.
7. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Resource processing method and apparatus
CN107038073A
Interactive code searching method and device based on structured embedding
CN111159223A