Code compilation time determination method, device, electronic device and storage medium
By setting comment tags in C++ code and calculating the compilation time difference, the problem of inability to accurately locate code segments that lead to excessive compilation time in the existing technology is solved, and the accurate analysis and adjustment of part of the source code file is achieved, which shortens the Overall compilation time.
Patent Information
- Application Number
- CN202010097048.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-02-17
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2040-02-17
AI Technical Summary
The prior art cannot accurately determine which part of the code in the C++ code causes the overall compilation time to be too long. It can only analyze the source code file as granularity, and it is impossible to accurately locate specific code segments.
Set the comment tag in the code to be compiled. By obtaining the code part between the tags, calculate the compilation time difference to determine the duration of the target code, and set the tag in the source code file to determine the local code whose compilation time is greater than the threshold. Source code file.
It realizes the accurate compilation time determination of any part of the code of the source code file, helping users adjust the corresponding code segments to shorten the overall compilation time.
Smart Images

Figure CN113268242B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a method, device, electronic device and storage medium for determining code compilation time. Background Art
[0002] In the related art, some codes, such as C++ codes, have the problem of slow compilation speed. A code contains multiple source code files. In the related art, some tools, such as cmake tools, can be used to determine the compilation time of each source code file, so that users can determine which source code file causes the overall code compilation time to be too long based on the compilation time.
[0003] However, the current method can only determine the compilation time based on the granularity of the source code file, but it is not enough for the user to accurately determine which part of the code in the source code file causes the overall compilation time to be too long. Summary of the invention
[0004] The present disclosure provides a method, device, electronic device and storage medium for determining code compilation time, so as to at least solve the technical problems in the related art. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, a method for determining code compilation time is proposed, comprising:
[0006] Set n comment tags in the code to be compiled, n>1;
[0007] Obtaining a first portion of code before an i-th comment tag among the n comment tags, and a second portion of code before a j-th comment tag among the n comment tags, 1≤i<j≤n;
[0008] Compile the first part of code and the second part of code respectively, and obtain a first part of time for compiling the first part of code and a second part of time for compiling the second part of code;
[0009] The duration of compiling the target code between the i-th comment tag and the j-th comment tag is determined according to the difference between the duration of the second part and the duration of the first part.
[0010] Optionally, the code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the method further includes:
[0011] Determine, from the m source code files, a target source code file where the local code having a compilation time greater than a preset time threshold is located;
[0012] The step of setting n comment tags in the code to be compiled includes:
[0013] The n comment tags are set in the local code of the target source code file.
[0014] Optionally, each of the source code files further includes a header file, and the target source code file where the local code whose compilation time is determined to be greater than a preset time threshold in the m source code files includes:
[0015] Compile a p-th source code file among the m source code files and a header file in the p-th source code file respectively, and obtain a p-th source code file compiling time of the p-th source code file and a p-th header file compiling time of the header file in the p-th source code file, wherein 1≤p≤m;
[0016] Calculate the pth difference between the pth source code file duration and the pth header file duration;
[0017] Determine a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files.
[0018] Optionally, before obtaining the first portion of code before the i-th comment tag among the n comment tags and the second portion of code before the j-th comment tag among the n comment tags, the method further includes:
[0019] Specify the compiler as the default agent;
[0020] The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation;
[0021] Run the preset agent program.
[0022] Optionally, the compiling the first part of code and the second part of code respectively, and obtaining a first part of duration for compiling the first part of code and a second part of duration for compiling the second part of code comprises:
[0023] Compile the first part of code and the second part of code respectively, and obtain a first intermediate file length obtained by compiling the first part of code to obtain a first intermediate file, and a second intermediate file length obtained by compiling the second part of code to obtain a second intermediate file;
[0024] Acquire a first executable file duration for generating a first executable file according to the first intermediate file, and a second executable file duration for generating a second executable file according to the second intermediate file;
[0025] After determining the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part, the method further includes:
[0026] Determine, according to the difference between the duration of the second intermediate file and the duration of the first intermediate file, a target intermediate file duration for compiling the target code to obtain a target intermediate file, and, according to the difference between the duration of the second executable file and the duration of the first executable file, determine the target executable file duration for generating a target executable file according to the target intermediate file;
[0027] An image is generated according to the dependency relationship among the target code, the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
[0028] According to a second aspect of an embodiment of the present disclosure, a device for determining code compilation duration is provided, comprising:
[0029] The label setting module is configured to execute setting n comment labels in the code to be compiled, where n>1;
[0030] A code acquisition module is configured to execute acquisition of a first portion of code before an i-th comment tag among the n comment tags, and a second portion of code before a j-th comment tag among the n comment tags, 1≤i<j≤n;
[0031] A code compiling module is configured to compile the first part of code and the second part of code respectively, obtain a first part of time for compiling the first part of code, and a second part of time for compiling the second part of code;
[0032] The duration determination module is configured to determine the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part.
[0033] Optionally, the code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the apparatus further includes:
[0034] A file determination module is configured to execute a target source code file where a local code having a compilation time greater than a preset time threshold is located and determined from among the m source code files;
[0035] The tag setting module is configured to execute setting of the n comment tags in the local code of the target source code file.
[0036] Optionally, each of the source code files also includes a header file, and the file determination module includes:
[0037] a compiling submodule configured to compile a p-th source code file among the m source code files and a header file in the p-th source code file, respectively, and obtain a p-th source code file compiling time for the p-th source code file and a p-th header file compiling time for the header file in the p-th source code file, wherein 1≤p≤m;
[0038] A calculation submodule is configured to calculate a p-th difference duration between the duration of the p-th source code file and the duration of the p-th header file;
[0039] The determination submodule is configured to determine a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files.
[0040] Optionally, the device further comprises:
[0041] A program execution module is configured to execute a specified compiler program as a preset agent program;
[0042] The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation;
[0043] The program running module is configured to execute and run the preset agent program.
[0044] Optionally, the code compilation module is configured to compile the first part of the code and the second part of the code respectively, obtain a first intermediate file duration of compiling the first part of the code to obtain a first intermediate file, and a second intermediate file duration of compiling the second part of the code to obtain a second intermediate file; and obtain a first executable file duration of generating a first executable file according to the first intermediate file, and a second executable file duration of generating a second executable file according to the second intermediate file;
[0045] The duration determination module is further configured to determine the target intermediate file duration of compiling the target code to obtain the target intermediate file according to the difference between the second intermediate file duration and the first intermediate file duration, and to determine the target executable file duration of generating the target executable file according to the target intermediate file according to the difference between the second executable file duration and the first executable file duration;
[0046] The device also includes:
[0047] An image generation module generates an image according to the target code, the dependency relationship between the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
[0048] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, including:
[0049] processor;
[0050] a memory for storing instructions executable by the processor;
[0051] The processor is configured to execute the instructions to implement the method for determining the code compilation duration as described in any of the above embodiments.
[0052] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is proposed. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the code compilation duration determination method described in any of the above embodiments.
[0053] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, wherein the computer program product is configured to execute the method for determining the code compilation duration described in any of the above embodiments.
[0054] According to an embodiment of the present disclosure, by setting comment tags in the code to be compiled, the time required to compile the code between any two comment tags can be determined during the code compilation process, so that the user can accurately determine the compilation time required to compile any part of the code in the source code file, so as to adjust the corresponding part of the code and shorten the compilation time of the source code file as a whole.
[0055] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0057] Figure 1 It is a schematic flow chart of a method for determining code compilation time according to an embodiment of the present disclosure.
[0058] Figure 2 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0059] Figure 3 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0060] Figure 4 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0061] Figure 5 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0062] Figure 6 It is a schematic diagram of a flame graph according to an embodiment of the present disclosure.
[0063] Figure 7 It is a schematic diagram showing the time required to compile a source code file according to an embodiment of the present disclosure.
[0064] Figure 8 It is a schematic diagram showing the time required to compile native code according to an embodiment of the present disclosure.
[0065] Fig. 9 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0066] Fig.10 It is a schematic block diagram of a device for determining code compilation duration according to an embodiment of the present disclosure.
[0067] Fig.11 It is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure.
[0068] Fig.12 It is a schematic block diagram of a file determination module according to an embodiment of the present disclosure.
[0069] Fig.13 It is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure.
[0070] Fig.14 It is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure.
[0071] Fig.15It is a hardware structure diagram of a device where a device for determining a code compilation duration is located according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0072] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0073] 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 interchanged 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. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0074] Figure 1 The present invention is a schematic flow chart of a method for determining the code compilation time according to an embodiment of the present invention. The method described in this embodiment can be applied to an electronic device capable of compiling code, which can be a terminal or a server, and the terminal includes but is not limited to a mobile phone, a tablet computer, a wearable device, a personal computer, etc.
[0075] like Figure 1 As shown, the method for determining the code compilation time may include the following steps:
[0076] In step S101, n comment tags are set in the code to be compiled, where n>1; the code to be compiled may be C++ code or other code, such as Java code.
[0077] In step S102, a first portion of code before the i-th comment tag among the n comment tags and a second portion of code before the j-th comment tag among the n comment tags are obtained, 1≤i<j≤n;
[0078] In step S103, the first part of code and the second part of code are respectively compiled to obtain a first part of time for compiling the first part of code and a second part of time for compiling the second part of code;
[0079] In step S104, the duration of compiling the target code between the i-th comment tag and the j-th comment tag is determined according to the difference between the duration of the second part and the duration of the first part.
[0080] In one embodiment, a user (eg, a code writer) may set n comment tags in the code to be compiled, and the form of the comment tags may be set as required.
[0081] By setting comment tags, during the process of using a compiler to compile the code, operations can be performed based on the comment tags. For example, the first part of the code before the i-th comment tag among the n comment tags and the second part of the code before the j-th comment tag among the n comment tags can be obtained, and then the first part of the code and the second part of the code can be compiled separately.
[0082] For example, all the codes to be compiled can be copied into an empty file, and then the codes after the i-th comment tag can be deleted, so that only the first part of the codes before the i-th comment tag is retained in the file, and then the file can be compiled, and the compilation time is the first part of the time; similarly, all the codes to be compiled can be copied into an empty file, and then the codes after the j-th comment tag can be deleted, so that only the second part of the codes before the j-th comment tag is retained in the file, and then the file can be compiled, and the compilation time is the second part of the time.
[0083] Among them, a specific command, such as the linux time command, can be used to obtain the first part of the time it takes for the compiler to compile the first part of the code, and the second part of the time it takes to compile the second part of the code. The extra part of the second part of the code relative to the first part of the code is the code between the i-th comment tag to the j-th comment tag. Then the difference between the second part of the time and the first part of the time is the time it takes to compile the code between the i-th comment tag to the j-th comment tag.
[0084] For example, a piece of code obtained from the code to be compiled is as follows:
[0085]
[0086] Users can add comment tags to the above code as needed. The form of the comment tags can be set as needed. For example, the form of the comment tag is / / GCC_PROFILER (it can also be set to other forms as needed, such as / *GCC_PROFILER* / ). Then, after adding the comment tags to the above code, it will be as follows:
[0087]
[0088]
[0089] Since the code obtained from the code to be compiled is not complete, compiling it directly may result in compilation failure. Therefore, you can add completion code to the obtained code, such as #endif in the above code.
[0090] Accordingly, when compiling the code with the comment tags, the time required to compile the code between any two comment tags / / GCC_PROFILER can be determined.
[0091] According to an embodiment of the present disclosure, by setting comment tags in the code to be compiled, the time required to compile the code between any two comment tags can be determined during the code compilation process, so that the user can accurately determine the compilation time required to compile any part of the code in the source code file, so as to adjust the corresponding part of the code and shorten the compilation time of the source code file as a whole.
[0092] Figure 2 FIG. 1 is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure. Figure 2 As shown, the code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the method further includes:
[0093] In step S105, a target source code file containing local code having a compilation time greater than a preset time threshold is determined from among the m source code files;
[0094] The step of setting n comment tags in the code to be compiled includes:
[0095] In step S1011, the n comment tags are set in the local code of the target source code file.
[0096] In one embodiment, before setting n comment tags in the code to be compiled, the target source code file containing the local code with a longer compilation time (for example, greater than a preset time threshold) can be determined among the m source code files. Since the compilation time required to compile the local code in the target source code file is longer, it can be determined that the local code in the target source code file causes the compilation time of the code to be compiled to be longer.
[0097] Then, according to steps S101 to S104, the n comment tags can be set in the local code of the target source code file to specifically determine which code segment in the local code of the target source code file requires too long to compile, thereby eliminating the need to judge the compile time of the code in other source code files other than the target source code file, which is conducive to quickly determining the code segment that causes the overall compilation time of the code to be compiled to be longer, and then determining the compilation time required to compile the code segment.
[0098] Figure 3 FIG. 1 is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure. Figure 3 As shown, each of the source code files also includes a header file, and the target source code file where the local code whose compilation time is greater than the preset time threshold is located in the m source code files includes:
[0099] In step S1051, the pth source code file among the m source code files and the header file in the pth source code file are respectively compiled to obtain the pth source code file compiling time of the pth source code file and the pth header file compiling time of the header file in the pth source code file, wherein 1≤p≤m;
[0100] In step S1052, the pth difference duration between the duration of the pth source code file and the duration of the pth header file is calculated;
[0101] In step S1053, a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files is determined.
[0102] In one embodiment, since the source code file includes local code and header files, the compilation time required for the source code file itself and the header files therein can be determined by methods in the relevant technology without adopting the methods described in steps S101 to S104.
[0103] Then, in order to determine which source code file has a too long compilation time for the local code, each source code file among the m source code files and the header file in the source code file can be compiled separately. For example, for the pth source code file, the pth source code file and the header file in the pth source code file can be compiled separately to obtain the pth source code file compilation time of the pth source code file and the pth header file compilation time of the header file in the pth source code file.
[0104] The pth difference duration between the duration of the pth source code file and the duration of the pth header file is the compilation duration of the local code in the pth source code file. Therefore, among the m difference durations corresponding to the m source code files, a larger target difference duration (for example, greater than a preset duration threshold) can be determined first, and then it can be determined that the target difference duration is the longer compilation duration of the local code in the corresponding target source code file.
[0105] Figure 4 FIG. 1 is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure. Figure 4 As shown, before obtaining the first part of the code before the i-th comment tag among the n comment tags and the second part of the code before the j-th comment tag among the n comment tags, the method further includes:
[0106] In step S106, the compiler program is designated as a default proxy program;
[0107] The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation;
[0108] In step S107, the preset agent program is run.
[0109] It should be noted that step S106 and step S107 can be performed as follows: Figure 4 As shown, it is executed before step S101, and the execution order can also be adjusted as needed, as long as it is ensured to be executed before step S102.
[0110] In one embodiment, the code to be compiled can be compiled by a compiler, for example, the code to be compiled is C++ code, and the compiler includes at least one of the following: g++, ar, ld. However, directly compiling the code by the compiler will only perform a compilation operation once, and it is difficult to perform multiple compilations according to steps S101 to S104, for example, compiling the first part of the code and the second part of the code respectively.
[0111] In this embodiment, the compiler is designated as a preset agent program, and the preset agent program is pre-compiled and includes at least a first command, a second command, and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation.
[0112] Accordingly, when executing the preset agent program, the commands in the preset agent program can be executed. For example, by executing the first command, each part of the code to be compiled can be obtained; by executing the second command, the compiler can be called to perform at least one compilation operation, and the object of the compilation operation can be specified by setting other commands. Accordingly, different objects can be compiled separately by the compiler, for example, the first part of the code and the second part of the code can be compiled separately; by executing the third command, the duration of each compilation operation of the compiler can be obtained. For example, the third command can be the linux time command, so that the first part of the duration for compiling the first part of the code and the second part of the duration for compiling the second part of the code can be obtained.
[0113] The compiler can be specified as the preset agent program by executing the make command. Specifically, the make command can read the makefile file, and the compiler can be specified as the preset agent program by setting the makefile environment variable. When the make program is executed, the preset agent program will be triggered to execute the commands in the preset agent program.
[0114] In addition, a preset agent program can be set to communicate with the data collection process running in the electronic device, for example, through the rpyc (Remote Python Call) protocol, so that the acquired information such as the first part duration and the second part duration can be sent to the data collection process for aggregation.
[0115] Figure 5 FIG. 1 is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure. Figure 5 As shown, the compiling the first part of the code and the second part of the code respectively, obtaining the first part of the duration of compiling the first part of the code, and the second part of the duration of compiling the second part of the code include:
[0116] In step S1031, the first part of code and the second part of code are respectively compiled to obtain a first intermediate file duration obtained by compiling the first part of code to obtain a first intermediate file, and a second intermediate file duration obtained by compiling the second part of code to obtain a second intermediate file;
[0117] In step S1032, a first executable file duration for generating a first executable file according to the first intermediate file and a second executable file duration for generating a second executable file according to the second intermediate file are obtained;
[0118] After determining the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part, the method further includes:
[0119] In step S108, the target intermediate file duration of a target intermediate file obtained by compiling the target code is determined according to the difference between the duration of the second intermediate file and the duration of the first intermediate file, and the target executable file duration of a target executable file generated according to the target intermediate file is determined according to the difference between the duration of the second executable file and the duration of the first executable file;
[0120] In step S109, an image is generated according to the target code, the dependency relationship between the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
[0121] In one embodiment, the process of compiling a source code file can be divided into two steps. The first step is to compile the source code file to obtain an intermediate file (also called a target file), and the second step is to generate an executable file based on the intermediate file (for example, by combining the code in the intermediate file with other codes through a connector to generate an executable file). There is a dependency relationship between the source code file, the intermediate file and the executable file, and the dependency relationship can be represented by a tree diagram.
[0122] Therefore, for the target code between the i-th comment tag and the j-th comment tag, compiling the target code to generate the target executable file can also be divided into two steps. The first step is to compile the target code to obtain the target intermediate file, and the second step is to generate the target executable file based on the target intermediate file. For these two steps, the time required for the operation can be determined separately.
[0123] Specifically, the first part of the code and the second part of the code can be compiled respectively to obtain the first intermediate file duration of the first intermediate file obtained by compiling the first part of the code, and the second intermediate file duration of the second intermediate file obtained by compiling the second part of the code. Therefore, the target intermediate file duration of the target intermediate file obtained by compiling the target code can be determined according to the difference between the second intermediate file duration and the first intermediate file duration.
[0124] The first executable file duration of generating the first executable file according to the first intermediate file and the second executable file duration of generating the second executable file according to the second intermediate file may also be obtained, so that the target executable file duration of generating the target executable file according to the target intermediate file may be determined according to the difference between the second executable file duration and the first executable file duration.
[0125] Furthermore, the target intermediate file length for compiling the target code to obtain the target intermediate file can be determined based on the difference between the second intermediate file length and the first intermediate file length, and the target executable file length for generating the target executable file based on the target intermediate file can be determined based on the difference between the second executable file length and the first executable file length.
[0126] Then, an image can be generated based on the dependency relationship among the target code, the target intermediate file and the target executable file, as well as the target intermediate file duration and the target executable file duration. For example, the image can be a flame graph, where the horizontal axis of the flame graph represents time and the vertical axis represents the dependency relationship. Based on the generated image, the user can intuitively determine the dependency relationship among the target code, the target intermediate file and the target executable file, and can also determine the target intermediate file duration and the target executable file duration.
[0127] In one embodiment, if it is necessary to generate the intermediate file duration and executable file duration corresponding to the code between every two adjacent comment tags, j=i+1 can be set, then for all i, Figure 5 The illustrated embodiment performs operations to obtain the intermediate file duration and executable file duration corresponding to the code between every two adjacent comment tags.
[0128] Figure 6 It is a schematic diagram of a flame graph according to an embodiment of the present disclosure.
[0129] like Figure 6 As shown, each rectangular box represents a section of code, and the connection relationship between multiple rectangular boxes in the vertical direction represents the dependency relationship between the codes, wherein the dependency relationship may include but is not limited to the dependency relationship between the target code, the target intermediate file and the target executable file. The length of the rectangular box in the horizontal direction represents the time required to compile the code in the rectangular box, or represents the time required to generate another file based on the code in the rectangular box.
[0130] By generating images, users can intuitively see how long it takes to compile each piece of code and quickly identify the dependencies between codes. It also provides search functions, such as Figure 6 A search box is displayed in the upper right corner of the flame graph. You can enter the name of the file to be searched, or the comment tag corresponding to the target code to be searched, etc. in the search box. The flame graph can then display the content corresponding to the search results, such as zooming in to display the dependency relationship between a certain section of target code and other files and the time required for compilation.
[0131] In addition, for each source code file in the code to be compiled, the time required for compilation can be determined separately, and the path of the source code file and the corresponding time can be displayed, for example Figure 7 As shown:
[0132] The time required to compile the source code file with the file path .build / dbg / targets / teams / ad / ad_server / libkconf.a is 11.10m (minutes).
[0133] Furthermore, for each local code in the source code file, the time required for compilation can also be determined, and the path of the local code and the corresponding time can be displayed, for example Figure 8 As shown:
[0134] The time required to compile the main code whose file path is teams / ad / ad_server / util / kconf / kconf.cc is 9.77m (minutes).
[0135] in, Figure 6 to Figure 7 The images shown may be displayed in different pages or in the same page, and the page may be an HTML page.
[0136] Fig. 9 It is a schematic flow chart of another method for determining code compilation time according to an embodiment of the present disclosure.
[0137] In one embodiment, the overall process of the method for determining the code compilation time can be as follows: Fig. 9 As shown:
[0138] In step SA, this embodiment can be implemented based on a linux makefile compilation tool to generate a linuxmakefile file for subsequent reading when executing a make command.
[0139] In step SB, a data collection process is started. The data collection process may be a background process and may communicate with a preset agent program through rpyc.
[0140] In step SC, the makefile allows the compiler to be specified as other programs through environment variables. Based on this, when executing the make command, the called compiler can be specified as the preset agent program by replacing the environment variables of the read makefile file, so that the preset agent program can be triggered to run when the make program is executed subsequently.
[0141] In step SD, the make program is executed.
[0142] In step SE, executing the make program can trigger the compiler program to run, but since the compiler program has been designated as the preset agent program, the preset agent program will be triggered to run.
[0143] In step SF, when the preset agent program is running, it will call a compiler, such as g++, ar, ld, etc., to compile the code, and for the code before different comment tags, the compiler can be called multiple times for compilation, thereby recording the time required for the compilation operation, for example, recording the compilation of the first part of the code and the second part of the code respectively, obtaining the first part of the time for compiling the first part of the code, and the second part of the time for compiling the second part of the code.
[0144] In step SG, the preset agent program can determine the compilation time required to compile the code between two comment tags through analysis, for example; based on the difference between the second part duration and the first part duration, determine the time to compile the target code between the i-th comment tag to the j-th comment tag.
[0145] In step SH, the preset agent program may send the determined compilation time to the data collection process. In addition to sending the compilation time, information such as dependency relationships may also be sent.
[0146] In step S1, the data collection process can aggregate the received information to generate an image, for example, Figures 6 to 8 The image shown is for the user to view.
[0147] Corresponding to the embodiment of the aforementioned method for determining code compilation duration, the present disclosure also proposes an embodiment of an apparatus for determining code compilation duration.
[0148] Fig.10 This is a schematic block diagram of a device for determining code compilation duration according to an embodiment of the present disclosure. The device described in this embodiment can be applied to an electronic device capable of compiling code, which can be a terminal or a server, and the terminal includes but is not limited to a mobile phone, a tablet computer, a wearable device, a personal computer, etc.
[0149] like Fig.10 As shown, the code compilation time determination device may include:
[0150] The label setting module 101 is configured to set n comment labels in the code to be compiled, where n>1;
[0151] The code acquisition module 102 is configured to execute acquisition of a first portion of code before an i-th comment tag among the n comment tags, and a second portion of code before a j-th comment tag among the n comment tags, 1≤i<j≤n;
[0152] The code compiling module 103 is configured to compile the first part of the code and the second part of the code respectively, and obtain a first part of the time for compiling the first part of the code and a second part of the time for compiling the second part of the code;
[0153] The duration determination module 104 is configured to determine the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part.
[0154] Fig.11 FIG. 1 is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure. Fig.11 As shown, the code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the device further includes:
[0155] The file determination module 105 is configured to execute a target source code file where a local code having a compilation time greater than a preset time threshold is located and determined from among the m source code files;
[0156] The tag setting module 101 is configured to set the n comment tags in the local code of the target source code file.
[0157] Fig.12 FIG. 1 is a schematic block diagram of a file determination module according to an embodiment of the present disclosure. Fig.12 As shown, each of the source code files also includes a header file, and the file determination module 105 includes:
[0158] The compiling submodule 1051 is configured to compile the pth source code file in the m source code files and the header file in the pth source code file respectively, and obtain the pth source code file compiling time of the pth source code file and the pth header file compiling time of the header file in the pth source code file, wherein 1≤p≤m;
[0159] The calculation submodule 1052 is configured to calculate the pth difference duration between the duration of the pth source code file and the duration of the pth header file;
[0160] The determination submodule 1053 is configured to determine a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files.
[0161] Fig.13 FIG. 1 is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure. Fig.13 As shown, the device also includes:
[0162] A program execution module 106, configured to execute a specified compiled program as a preset agent program;
[0163] The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation;
[0164] The program running module 107 is configured to execute the preset agent program.
[0165] Fig.14 FIG. 1 is a schematic block diagram of another device for determining code compilation duration according to an embodiment of the present disclosure. Fig.14 As shown, the code compilation module is configured to compile the first part of the code and the second part of the code respectively, obtain a first intermediate file duration of compiling the first part of the code to obtain a first intermediate file, and a second intermediate file duration of compiling the second part of the code to obtain a second intermediate file; and obtain a first executable file duration of generating a first executable file according to the first intermediate file, and a second executable file duration of generating a second executable file according to the second intermediate file;
[0166] The duration determination module is further configured to determine the target intermediate file duration of compiling the target code to obtain the target intermediate file according to the difference between the second intermediate file duration and the first intermediate file duration, and to determine the target executable file duration of generating the target executable file according to the target intermediate file according to the difference between the second executable file duration and the first executable file duration;
[0167] The device also includes:
[0168] The image generation module 108 generates an image according to the target code, the dependency relationship between the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
[0169] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0170] The embodiment of the device for determining the code compilation duration shown in the embodiments of the present disclosure can be applied to electronic devices such as terminals or servers. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the device in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory and running them. From the hardware level, if Fig.15 FIG. 1 is a hardware structure diagram of a device where a device for determining the code compilation duration is located according to an embodiment of the present disclosure, except Fig.15 In addition to the processor, network interface, memory and non-volatile memory shown, the device in the embodiment where the apparatus is located may generally include other hardware, such as a forwarding chip responsible for processing messages, etc.; from a hardware structure perspective, the device may also be a distributed device, which may include multiple interface cards to expand message processing at the hardware level.
[0171] The embodiment of the present disclosure further provides an electronic device, including:
[0172] processor;
[0173] a memory for storing instructions executable by the processor;
[0174] The processor is configured to execute the instructions to implement the method for determining the code compilation duration described in any of the above embodiments.
[0175] An embodiment of the present disclosure further provides a storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute the method for determining the code compilation duration described in any of the above embodiments.
[0176] An embodiment of the present disclosure further provides a computer program product, which is configured to execute the method for determining the code compilation duration described in any of the above embodiments.
[0177] Alternatively, the storage medium may be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0178] An embodiment of the present disclosure further provides a computer program product, which is configured to execute the method for determining the code compilation duration described in any of the above embodiments.
[0179] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. The present disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0180] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
[0181] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprises" or any other variants 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, the elements defined by the statement "comprises a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0182] The method and device provided in the embodiments of the present disclosure are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present disclosure. The description of the above embodiments is only used to help understand the method of the present disclosure and its core idea. At the same time, for those skilled in the art, according to the idea of the present disclosure, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present disclosure.
Claims
1. A method for determining code compilation time, characterized in that: The method is applicable to code compilation scenarios, including: n comment tags are set in the code to be compiled, where n>1; the comment tags can be set as needed; Obtaining a first portion of code before an i-th comment tag among the n comment tags, and a second portion of code before a j-th comment tag among the n comment tags, 1≤i<j≤n; Compile the first part of code and the second part of code respectively, and obtain a first part of time for compiling the first part of code and a second part of time for compiling the second part of code; The duration of compiling the target code between the i-th comment tag and the j-th comment tag is determined according to the difference between the duration of the second part and the duration of the first part.
2. The method according to claim 1, characterized in that The code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the method further includes: Determine, from the m source code files, a target source code file where the local code having a compilation time greater than a preset time threshold is located; The step of setting n comment tags in the code to be compiled includes: The n comment tags are set in the local code of the target source code file.
3. The method according to claim 2, characterized in that Each of the source code files also includes a header file, and the target source code file where the local code whose compilation time is greater than a preset time threshold is located in the m source code files includes: Compile a p-th source code file among the m source code files and a header file in the p-th source code file respectively, and obtain a p-th source code file compiling time of the p-th source code file and a p-th header file compiling time of the header file in the p-th source code file, wherein 1≤p≤m; Calculate the pth difference between the pth source code file duration and the pth header file duration; Determine a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files.
4. The method according to any one of claims 1 to 3, characterized in that Before obtaining the first part of the code before the i-th comment tag among the n comment tags and the second part of the code before the j-th comment tag among the n comment tags, the method further includes: Specify the compiler as the default agent; The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation; Run the preset agent program.
5. The method according to any one of claims 1 to 3, characterized in that The step of respectively compiling the first part of the code and the second part of the code, and obtaining a first part of the duration for compiling the first part of the code and a second part of the duration for compiling the second part of the code comprises: Compile the first part of code and the second part of code respectively, and obtain a first intermediate file length obtained by compiling the first part of code to obtain a first intermediate file, and a second intermediate file length obtained by compiling the second part of code to obtain a second intermediate file; Acquire a first executable file duration for generating a first executable file according to the first intermediate file, and a second executable file duration for generating a second executable file according to the second intermediate file; After determining the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part, the method further includes: Determine, according to the difference between the duration of the second intermediate file and the duration of the first intermediate file, a target intermediate file duration for compiling the target code to obtain a target intermediate file, and, according to the difference between the duration of the second executable file and the duration of the first executable file, determine the target executable file duration for generating a target executable file according to the target intermediate file; An image is generated according to the dependency relationship among the target code, the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
6. A device for determining code compilation time, characterized in that: The device is applicable to code compilation scenarios, including: A label setting module is configured to set n comment labels in the code to be compiled, where n>1; the comment labels can be set as needed; A code acquisition module is configured to execute acquisition of a first portion of code before an i-th comment tag among the n comment tags, and a second portion of code before a j-th comment tag among the n comment tags, 1≤i<j≤n; A code compiling module is configured to compile the first part of code and the second part of code respectively, obtain a first part of time for compiling the first part of code, and a second part of time for compiling the second part of code; The duration determination module is configured to determine the duration of compiling the target code between the i-th comment tag and the j-th comment tag according to the difference between the duration of the second part and the duration of the first part.
7. The device according to claim 6, characterized in that The code to be compiled includes m source code files, each of which includes local code, wherein m≥1, and before setting n comment tags in the code to be compiled, the device further includes: A file determination module is configured to execute a target source code file in which a local code having a compilation time greater than a preset time threshold is determined among the m source code files; The tag setting module is configured to execute setting of the n comment tags in the local code of the target source code file.
8. The device according to claim 7, characterized in that Each of the source code files also includes a header file, and the file determination module includes: a compiling submodule configured to compile a p-th source code file among the m source code files and a header file in the p-th source code file, respectively, and obtain a p-th source code file compiling time for the p-th source code file and a p-th header file compiling time for the header file in the p-th source code file, wherein 1≤p≤m; A calculation submodule is configured to calculate a p-th difference duration between the duration of the p-th source code file and the duration of the p-th header file; The determination submodule is configured to determine a target source code file corresponding to a target difference duration greater than the preset duration threshold among the m difference durations corresponding to the m source code files.
9. The device according to any one of claims 6 to 8, characterized in that The device also includes: A program execution module is configured to execute a specified compiler program as a preset agent program; The preset agent program includes at least a first command, a second command and a third command, wherein the first command is used to obtain each part of the code to be compiled, the second command is used to call the compiler to perform at least one compilation operation, and the third command is used to obtain the duration of each compilation operation; The program running module is configured to execute and run the preset agent program.
10. The device according to any one of claims 6 to 8, characterized in that The code compiling module is configured to compile the first part of the code and the second part of the code respectively, obtain a first intermediate file duration of compiling the first part of the code to obtain a first intermediate file, and obtain a second intermediate file duration of compiling the second part of the code to obtain a second intermediate file; and obtaining a first executable file duration for generating a first executable file according to the first intermediate file, and a second executable file duration for generating a second executable file according to the second intermediate file; The duration determination module is further configured to determine the target intermediate file duration of compiling the target code to obtain the target intermediate file according to the difference between the second intermediate file duration and the first intermediate file duration, and to determine the target executable file duration of generating the target executable file according to the target intermediate file according to the difference between the second executable file duration and the first executable file duration; The device also includes: An image generation module generates an image according to the target code, the dependency relationship between the target intermediate file and the target executable file, and the duration of the target intermediate file and the duration of the target executable file.
11. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method for determining the code compilation duration as described in any one of claims 1 to 5.
12. A storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method for determining the code compilation duration as claimed in any one of claims 1 to 5.