Information collection method and device, electronic device, and computer-readable storage medium
By writing target link information into environment variables, the target information collection script automatically collects the pipeline dependency installation time, solving the problems of low efficiency and stability in existing technologies and achieving efficient and stable information collection.
Patent Information
- Application Number
- CN202310118631.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-30
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2043-01-30
AI Technical Summary
In existing technologies, the installation time of the data acquisition pipeline is usually measured manually, which is inefficient and intrudes on the original compilation script, affecting stability.
By writing target link information into environment variables to point to the target information collection script, the target information collection script can automatically collect preset information during the compilation process, ensuring that the stability of the compilation script is not affected.
This approach improves information gathering efficiency, saves labor costs, and ensures the stability of the compilation script without intruding on the original compilation script.
Smart Images

Figure CN115981665B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of code compilation technology, and in particular to an information acquisition method and apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] A pipeline refers to the entire process of compiling code into a program that can run on an online platform, following a compilation script. To analyze and optimize the pipeline, it's often necessary to collect a large amount of metric data during the compilation process. Among these metrics, dependency installation time reflects the duration of installing dependency packages and is closely related to pipeline performance.
[0003] In existing technologies, the time consumed by dependency installation in the pipeline is often measured manually, resulting in low collection efficiency. While adding information collection-related commands to the compilation script can automate information collection and improve efficiency, it also intrudes on the original compilation script, affecting its stability. Summary of the Invention
[0004] This disclosure provides an information acquisition method and apparatus, electronic device, and computer-readable storage medium to at least solve the problem in the related art of how to improve information acquisition efficiency without affecting the stability of the compiled script, or it may not solve any of the above problems.
[0005] According to a first aspect of this disclosure, an information collection method is provided, the information collection method comprising: writing target linking information into an environment variable, wherein the environment variable is used to store program linking information, the program linking information pointing to a program to be run required to execute a target compilation script, the target linking information pointing to a target information collection script, the target information collection script being used to continue executing commands in the target compilation script and collect preset information characterizing the execution performance of the target compilation script; in response to an access instruction triggered based on the target linking information in the environment variable, determining the target information collection script pointed to by the target linking information, wherein the target linking information in the environment variable is accessed when executing the current compilation command in the target compilation script, and the current compilation command is determined; executing the target information collection script to continue executing the current compilation command and collect the preset information.
[0006] Optionally, in the environment variables, the first access priority of the target link information is higher than the second access priority, where the second access priority is the priority of the program link information corresponding to the current compilation command. The target information collection script includes a link deletion script and an action execution script. Executing the target information collection script to continue executing the current compilation command and collect the preset information includes: executing the link deletion script to delete the target link information in the environment variables, obtaining updated environment variables; and executing the action execution script to continue executing the current compilation command based on the updated environment variables and collect the preset information.
[0007] Optionally, continuing to execute the current compilation command based on the updated environment variable includes: continuing to execute the current compilation command; querying the updated environment variable, accessing the program linking information corresponding to the current compilation command in the updated environment variable to determine the program to be run corresponding to the current compilation command; and executing the current compilation command based on the program to be run.
[0008] Optionally, the target information collection script further includes a link recovery script, wherein, after executing the action execution script to continue executing the current compilation command based on the updated environment variables and collecting the preset information, executing the target information collection script to continue executing the current compilation command and collecting the preset information further includes: executing the link recovery script to restore the target link information in the updated environment variables, thereby obtaining the environment variables.
[0009] Optionally, the target information collection script includes a pre-script and a post-script. Executing the target information collection script to continue executing the current compilation command and collect the preset information includes: executing the pre-script to determine whether the current compilation command is a target installation command, and if it is determined to be a target installation command, obtaining the current time as the start time; continuing to complete the execution of the current compilation command; in response to the completion of the current compilation command, executing the post-script to record the current time as the end time; and determining the installation time based on the start time and the end time, and collecting the preset information including the installation time.
[0010] Optionally, writing the target link information into the environment variable includes: writing multiple link information corresponding to each of the multiple package management tools into the environment variable, wherein each link information points to the information collection script of the package management tool corresponding to the link information, the multiple link information includes the target link information, the target information collection script pointed to by the target link information is for the target package management tool, and the target package management tool is the package management tool corresponding to the current compilation command.
[0011] Optionally, executing the target information collection script to continue executing the current compilation command and collecting the preset information includes: executing the target information collection script to continue executing the current compilation command; determining the target package management tool corresponding to the target information collection script, obtaining tool information, and collecting the preset information including the tool information.
[0012] According to a second aspect of this disclosure, an information acquisition device is provided, comprising: a preparation unit configured to write target linking information into an environment variable, wherein the environment variable stores program linking information, the program linking information pointing to a program to be run required to execute a target compilation script, the target linking information pointing to a target information acquisition script, the target information acquisition script being used to continue executing commands in the target compilation script and acquire preset information characterizing the execution performance of the target compilation script; a determination unit configured to determine the target information acquisition script pointed to by the target linking information in response to an access instruction triggered based on the target linking information in the environment variable, wherein the target linking information in the environment variable is accessed when executing the current compilation command in the target compilation script, and the current compilation command is determined; and an execution unit configured to execute the target information acquisition script to continue executing the current compilation command and acquire the preset information.
[0013] Optionally, in the environment variables, the first access priority of the target linking information is higher than the second access priority, where the second access priority is the priority of the program linking information corresponding to the current compilation command.
[0014] Optionally, the target information collection script includes a link deletion script and an action execution script. The execution unit is further configured to: execute the link deletion script to delete the target link information in the environment variables to obtain updated environment variables; execute the action execution script to continue executing the current compilation command based on the updated environment variables and collect the preset information.
[0015] Optionally, the execution unit's execution of continuing to execute the target compilation command based on the updated environment variable includes: continuing to execute the current compilation command; querying the updated environment variable, accessing the program linking information corresponding to the current compilation command in the updated environment variable to determine the program to be run corresponding to the current compilation command; and executing the current compilation command based on the program to be run.
[0016] Optionally, the target information acquisition script further includes a link recovery script, and the execution unit is further configured to execute the link recovery script to recover the target link information in the updated environment variables and obtain the environment variables.
[0017] Optionally, the target information collection script includes a pre-script and a post-script, and the execution unit is further configured to: execute the pre-script to determine whether the current compilation command is a target installation command, and if the current compilation command is determined to be a target installation command, obtain the current time as the start time; continue to complete the execution of the current compilation command; in response to the completion of the current compilation command, execute the post-script to record the current time as the end time; determine the installation time based on the start time and the end time, and collect the preset information including the installation time.
[0018] Optionally, the preparation unit is further configured to: write multiple link information corresponding to multiple package management tools into the environment variables, wherein each link information points to the information collection script of the package management tool corresponding to the link information, the multiple link information includes the target link information, the target information collection script pointed to by the target link information is for the target package management tool, and the target package management tool is the package management tool corresponding to the current compilation command.
[0019] Optionally, the execution unit is further configured to: execute the target information collection script to continue executing the current compilation command; determine the target package management tool corresponding to the target information collection script, obtain tool information, and collect the preset information including the tool information.
[0020] According to a third aspect of this disclosure, an electronic device is provided, the electronic device comprising: at least one processor; at least one memory storing computer-executable instructions, wherein the computer-executable instructions, when executed by the at least one processor, cause the at least one processor to perform an information acquisition method according to this disclosure.
[0021] According to a fourth aspect of this disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by at least one processor, causes the at least one processor to perform an information acquisition method according to this disclosure.
[0022] According to a fifth aspect of this disclosure, a computer program product is provided, including computer instructions that, when executed by at least one processor, implement the information acquisition method according to this disclosure.
[0023] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects:
[0024] According to the information collection method and information collection device of the embodiments of this disclosure, by configuring a target information collection script independent of the target compilation script and writing target link information pointing to the target information collection script into the environment variables, the target link information can be accessed, the target information collection script can be read and executed when the environment variables are queried during the execution of the target compilation script. Thus, the collection of preset information can be completed with the help of the target information collection script without intruding on the target compilation script. This can greatly improve the efficiency of information collection, save labor costs, and ensure the stability of the original target compilation script.
[0025] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0026] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0027] Figure 1 This is a schematic diagram illustrating an information acquisition system according to an exemplary embodiment of the present disclosure;
[0028] Figure 2 This is a flowchart illustrating an information acquisition method according to an exemplary embodiment of the present disclosure;
[0029] Figure 3 This is a flowchart illustrating an information collection method according to a specific embodiment of the present disclosure;
[0030] Figure 4 This is a block diagram illustrating an information acquisition device according to an exemplary embodiment of the present disclosure;
[0031] Figure 5 This is a block diagram illustrating an electronic device according to exemplary embodiments of the present disclosure. Detailed Implementation
[0032] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0033] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following examples do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0034] It should be noted that the phrase "at least one of several items" in this disclosure refers to three parallel cases: "any one of the several items", "a combination of any number of the several items", and "all of the several items". For example, "including at least one of A and B" includes the following three parallel cases: (1) including A; (2) including B; (3) including A and B. As another example, "performing at least one of step one and step two" indicates the following three parallel cases: (1) performing step one; (2) performing step two; (3) performing both step one and step two.
[0035] It should be noted that the user information involved in this disclosure (including but not limited to user device information, user personal information, etc.) is all information authorized by the user or fully authorized by all parties.
[0036] A pipeline refers to the entire process of compiling code into a program that can run on an online platform, following a compilation script. Specifically, programmers write code on a PC and compile it on the same PC to obtain a program that the computer can recognize and run. The program can then be uploaded to a platform server to enable the corresponding platform functions.
[0037] To analyze and optimize pipelines, it is often necessary to collect a large amount of metrics during the compilation process. Among these metrics, dependency installation time reflects the time spent installing dependency packages and is closely related to pipeline performance.
[0038] In existing technologies, the time consumed by dependency installation in the pipeline is often measured manually, resulting in low collection efficiency. While adding information collection-related commands to the compilation script can automate information collection and improve efficiency, it also intrudes on the original compilation script, affecting its stability.
[0039] To address the aforementioned issues, this disclosure provides an information collection method that can complete information collection without intruding on the original compilation script, using an independent target information collection script. This method can significantly improve information collection efficiency, save labor costs, and ensure the stability of the original compilation script.
[0040] Figure 1 This is a schematic diagram illustrating an information acquisition system according to an exemplary embodiment of the present disclosure. (Refer to...) Figure 1 In this implementation scenario, the information acquisition system includes a PC (101) and a server (102). Programmers (as users) can write and debug compilation scripts on the PC (101), and also edit environment variables and write and debug target information acquisition scripts on the PC (101). The target compilation script is the object to be compiled. During the compilation process, when the operating system of the PC (101) executes a line of command in the target compilation script and needs to run a program, this program to be run is often not in the directory where the target compilation script is located. The `path` variable in the environment variables is used to store the path information (i.e., link information) of searchable directories. Specifically, it is stored in the form of key-value pairs (the key is the variable, and the value is the directory path information corresponding to the variable), so that the operating system searches the directories corresponding to each variable in turn. If the program to be run is found in these directories, the operating system can run it, thereby achieving the successful execution of the target compilation script. According to the exemplary embodiments of this disclosure, the target link information pointing to the target information collection script (i.e., the path information of the directory where the target information collection script is located) is written into the environment variables. This allows the target information collection script to be searched for and executed when the environment variables are accessed during the execution of the target compilation script. Thus, the target information collection script is automatically executed without intruding on the target compilation script, achieving the collection of preset information. After collecting the preset information, the PC 101 can send the preset information to the server 102. The server 102 can be the platform server corresponding to the target compilation script, or it can be another server independent of the platform server, specifically used for information collection; this disclosure does not limit this. Furthermore, it should be understood that in addition to implementing information collection on the PC 101, a dedicated server can also be configured to implement information collection. In this case, the target compilation script, environment variables, and target information collection script can be synchronized to this server. This is also an implementation method of this disclosure and falls within the protection scope of this disclosure.
[0041] Below, we will refer to Figures 2 to 4 This invention provides a detailed description of an information acquisition method and an information acquisition apparatus according to exemplary embodiments of the present disclosure.
[0042] Figure 2 This is a flowchart illustrating an information acquisition method according to an exemplary embodiment of the present disclosure. Figure 3This is a flowchart illustrating an information collection method according to an exemplary embodiment of the present disclosure. It should be understood that the information collection method according to an exemplary embodiment of the present disclosure can be implemented in terminal devices such as smartphones, tablets, and personal computers (PCs), or in devices such as servers. It should be noted that, since this disclosure involves the execution of two scripts—a target compilation script and a target information collection script—control will switch between the compiler and the information collector during device operation as the executing scripts switch. This disclosure is described from the perspective of the information collector; that is, all steps described below are performed by the information collector.
[0043] Reference Figure 2 In step 201, the target linking information is written into the environment variables. The environment variables are used to store program linking information, which points to the program to be run required to execute the target compilation script. The target linking information points to the target information collection script, which is used to continue executing the commands in the target compilation script and collect preset information characterizing the execution performance of the target compilation script.
[0044] It should be noted that the target compilation script usually contains multiple compilation commands. Some compilation commands can be run directly, while others require additional configuration of the program to be run. The program linking information is specifically the path information of the directory where the program to be run by the compilation command is located.
[0045] In step 202, in response to an access instruction triggered based on target link information in environment variables, the target information acquisition script pointed to by the target link information is determined. The target link information in the environment variables is accessed when the current compilation command in the target compilation script is executed, and the current compilation command is determined. When the compiler queries the environment variables to execute the current compilation command in the target compilation script, access to the target link information triggers an access instruction, thereby transferring control to the information acquisition party and entering the target information acquisition script.
[0046] In step 203, the target information acquisition script is executed to continue executing the current compilation command and collect preset information. Since the compiler has not yet executed the current compilation command, control is transferred to the information acquisition party, causing the execution of the target compilation script to be interrupted. By continuing to execute the current compilation command of the target compilation script while the target information acquisition script is executing, the normal execution of the target compilation script can be guaranteed, thereby monitoring specific execution processes of the target compilation script and collecting the corresponding preset information.
[0047] According to the exemplary embodiment of the present disclosure, the information collection method can access the target link information, read and execute the target information collection script, by specially configuring a target information collection script for collecting preset information and writing the target link information pointing to the target information collection script into the environment variable. This allows the compiler to access the target link information, read and execute the target information collection script when querying the environment variable to execute the current compilation command in the target compilation script. Thus, the preset information can be collected by means of the target information collection script without intruding on the target compilation script. This can greatly improve the efficiency of information collection, save labor costs, and ensure the stability of the target compilation script.
[0048] Optionally, in the environment variables, the first access priority of the target linking information is higher than the second access priority, where the second access priority is the priority of the program linking information corresponding to the current compilation command. That is, in step 201, the first access priority can be increased when writing the target linking information. By making the first access priority higher than the second access priority, it can be ensured that the compiler accesses the target linking information before the program linking information corresponding to the current compilation command, ensuring a timely transfer of control. As an example, since the existing environment variables are accessed sequentially according to the order of the linking information, in order to make the first access priority higher than the second access priority, the target linking information can be placed before the program linking information corresponding to the current encoding command when executing step 201.
[0049] It should be understood that the current encoding command refers to the compilation command being executed when the target compilation script is executed. However, when step 201 is executed, the target compilation script has not yet been executed. Therefore, when step 201 is actually executed, the first access priority will be higher than the access priority of the program linking information corresponding to at least one specific compilation command. For example, the target linking information may be placed before the program linking information corresponding to these at least one specific compilation command, so that when these specific compilation commands in the target compilation script are executed, the target linking information is accessed first, and then the target information collection script is executed. Correspondingly, there may be one or more compilation commands whose corresponding program linking information has a higher access priority than the first access priority. For these compilation commands, since the corresponding program linking information can be accessed successfully, the target linking information will not be accessed. Based on this, for existing environment variables, the first access priority can be configured by adjusting the specific writing position of the target linking information in step 201, that is, by placing the target linking information before the program linking information corresponding to the aforementioned specific compilation commands.
[0050] Furthermore, the first access priority of the target link information can be set to the highest access priority in the environment variables, for example, placing the target link information at the beginning of the environment variables. By configuring the highest access priority for the target link information, it can be accessed whenever the environment variables are queried when executing any compilation command in the target compilation script. This allows for quick writing of the target link information into the environment variables, reducing the additional computational load and time caused by configuring the first access priority, thus reducing computational burden, improving collection efficiency, and minimizing the impact on compilation efficiency. On the other hand, it reduces the risk of the first access priority being lower than the access priority of the compilation command to be monitored due to misoperation. For example, when the order of program link information in the environment variables changes, the target link information may be placed after the program link information corresponding to the compilation command to be monitored due to improper adjustment of its position. It should be understood that since the current compilation command in the target compilation script will continue to be executed when the target information collection script is executed, the current compilation command can be executed normally when it is a compilation command that does not need to be monitored, and the inability to collect preset information will not affect information collection. Specifically, how to prevent the collection of preset information for these compilation commands that do not require monitoring can be achieved by properly configuring the target information collection script, and this disclosure does not impose any restrictions on this.
[0051] As an example, refer to Figure 3 Step 201 can create target link information in the plugin script and insert it into the original environment variables according to the required first access priority, thereby changing the environment variables, specifically the path variable.
[0052] It is not difficult to see that when the current compilation command is executed in step 203, the environment variables will still be queried. If no configuration is made at this time, it will cause the target linking information to continue to be accessed, resulting in an infinite loop and the current compilation command cannot be executed normally.
[0053] In some embodiments, this configuration can be to set a maximum number of consecutive accesses to the target link information and assign it a value of 1, meaning that the target link information cannot be accessed twice consecutively. This allows the target link information to be skipped and the program link information corresponding to the current compilation command to be accessed when the environment variables are searched in order to execute the current compilation command after the target link information has been accessed once and the target information collection script has started to be executed.
[0054] In other embodiments, the target information acquisition script includes a link deletion script and an action execution script. Accordingly, step 203 includes: executing the link deletion script to delete the target link information from the environment variables, obtaining updated environment variables; and executing the action execution script to continue executing the current compilation command based on the updated environment variables, and acquiring preset information. By executing the link deletion script first when executing the target information acquisition script, updated environment variables without target link information can be easily obtained—that is, the original environment variables before the target link information was written—thus ensuring the normal execution of the current compilation command, ensuring compilation stability, and ensuring the successful acquisition of preset information.
[0055] Optionally, the specific operations of the execution script include: continuing to execute the current compilation command; querying and updating environment variables, accessing the program linking information corresponding to the current compilation command in the updated environment variables to determine the program to be run corresponding to the current compilation command; and executing the current compilation command based on the program to be run. When querying and updating environment variables to execute the current compilation command, since the target linking information no longer exists, the program linking information corresponding to the current compilation command can be accessed, thereby finding the corresponding program to be run, and ultimately achieving the normal execution of the current compilation command.
[0056] Furthermore, the target information acquisition script also includes a link recovery script. Accordingly, after executing the action execution script, step 203 further includes: executing the link recovery script to restore the target link information in the updated environment variables, thereby obtaining the environment variables. By restoring the deleted target link information after collecting the preset information, that is, writing the target link information into the updated environment variables according to the first access priority, the environment variables in step 201 can be obtained again. This facilitates rapid access to the target link information and execution of the target information acquisition script when executing other compilation commands of the target compilation script or other compilation scripts in the future, achieving reliable acquisition of the preset information. It is not necessary to re-add the target link information to the updated environment variables every time the preset information needs to be collected, which helps to reduce time consumption and improve information acquisition efficiency and compilation efficiency.
[0057] The following section uses the installation time of dependency packages as an example to illustrate how to collect preset information.
[0058] Optionally, the target information collection script includes a pre-script and a post-script. Step 203 includes: executing the pre-script to determine whether the current compilation command is a target installation command, and if it is determined to be a target installation command, obtaining the current time as the start time; continuing to complete the execution of the current compilation command; in response to the completion of the current compilation command, executing the post-script to record the current time as the end time; and determining the installation time based on the start time and end time, and collecting preset information including the installation time. The target installation command is specifically a command that instructs the start of installing dependency packages. By combining the start and end of the target installation command and recording the start and end times respectively, automatic timing of dependency package installation time can be achieved. This eliminates the need for manual operation, reduces labor costs, improves statistical speed, and reduces errors in manual statistics, thereby improving overall statistical efficiency. It should be understood that when combined with the embodiment of the target information collection script including the link deletion script and the action execution script in the preceding text, the action execution script further includes the pre-script and post-script here, and the steps of executing the action execution script include the steps of executing the pre-script, continuing to complete the execution of the current compilation command, and executing the post-script here.
[0059] As an example, in step 203, after the post-script is executed, the installation time can be uncertain, and preset information including the start and end times can be directly collected, which can significantly reduce the amount of computation. This is also an implementation method of this disclosure and falls within the protection scope of this disclosure.
[0060] Specifically, the installation of dependency packages often requires the use of package management tools (package management tools are collections used for continuous automation of programs, such as installation, upgrades, configuration, and uninstallation). Different package management tools correspond to different parent commands, but they all share a common parent command to run. The program linking information points to this parent command's executable program, while the compilation command is a sub-command under that parent command, used to perform specific actions. Different sub-commands often have different user parameters, which are the input parameters written by the programmer. Therefore, when executing a compilation command, it is necessary to first query the environment variables to find the parent command to run, and then determine which sub-command it is based on the user parameters before executing it. User parameters include the specific command and other related parameters. The specific form of user parameters will differ between different sub-commands, and the content of other related parameters will also vary slightly, but these other parameters often begin with specific symbols, such as "--" and "http". Therefore, to determine whether the current compilation command in the target build script is the target installation command, we can first filter the user parameters of the current compilation command, removing other parameters, such as those starting with "--" and "http". What remains is the specific command, which can then be used to determine if it is the target installation command. For example, commonly used package management tools include npm, yarn, and pnpm. For the package management tool npm, its installation command (npm install command) has forms such as ci, clean-install, ic, install-clean, isntall-clean, i, add, isntall, and install. Therefore, we can check if the first item of the filtered user parameters (which may be followed by other parameters) is one of the commands in the above forms. If it is, then the current compilation command is determined to be the npm install command. For the package management tool yarn, its installation command (yarn install command) has forms such as empty and install. Therefore, we can check if the first item of the filtered user parameters exists. If it does not exist, then the current compilation command is determined to be the yarn install command. If it exists, then we check if it is the install command. If it is, then it is determined to be the yarn install command. For the package management tool pnpm, its installation command (pnpm install command) has forms such as install and i. Therefore, it can be determined whether the first item of the filtered user parameters is one of the above forms of command. If so, it is determined that the current compilation command is the pnpm install command.
[0061] In conjunction with the above, it should also be noted that when the compiler queries environment variables, it searches for and accesses the program linking information pointing to the parent command's program to be run, based on the parent command to which the current compilation command belongs. Therefore, the target linking information pointing to the target information collection script also needs to be configured as the linking information of that parent command, so that the compiler will actively access the target linking information when querying environment variables based on the current compilation command. For comparison with program linking information, the target linking information of the same parent command can be regarded as the custom linking information of that parent command. Further, in step 201, at least one parent command's custom linking information can be written according to information collection requirements. If the parent command to which the current compilation command of the target compilation script belongs is command A, the custom linking information of command A can be used as the target linking information and accessed when querying environment variables. If the target linking information of command A is not written in the environment variables, the program linking information of command A will be accessed when querying environment variables, and the information collection process will not be executed.
[0062] Optionally, step 201 includes: writing multiple link information corresponding to each of the multiple package management tools into environment variables, wherein each link information points to the information collection script of the package management tool corresponding to the link information, the multiple link information includes target link information, the target link information points to a target information collection script for a target package management tool, and the target package management tool is the package management tool corresponding to the current compilation command. By pre-storing the link information corresponding to the information collection scripts of multiple package management tools in environment variables, the ability to collect information related to multiple package management tools can be achieved, expanding the applicability of the information collection method according to the exemplary embodiments of this disclosure. Specifically, for the parts of the information collection scripts that are common to different package management tools, they can be written centrally and then synchronously applied to the information collection scripts corresponding to each package management tool, which helps to improve the efficiency of editing and maintaining the information collection scripts.
[0063] In a pipeline, the package management tool used is defined by the programmer and written in the `build.sh` script. Therefore, the tool information describing the package management tool used by the pipeline is not publicly displayed and needs to be determined by examining the `build.sh` script. Since the script content can be very complex, directly determining whether the `build.sh` script contains fields such as `npm`, `yarn`, and `pnpm` is not very accurate. Current technology typically uses manual review to collect tool information, which is inefficient.
[0064] Optionally, to achieve efficient tool information collection, step 203 includes: executing the target information collection script to continue executing the current compilation command; determining the target package management tool corresponding to the target information collection script, obtaining tool information, and collecting preset information including tool information. Although the target compilation script does not have explicit tool information, as mentioned above, when querying environment variables by executing the current compilation command in the target encoding script, only the linking information corresponding to the package management tool used (i.e., the target package management tool) is accessed. Therefore, in step 202, the target linking information corresponding to the target package management tool is accessed. The information collection script and the corresponding linking information are specifically created for different package management tools to achieve information collection. Therefore, the package management tool corresponding to a specific information collection script and specific linking information is known, that is, explicit. Therefore, after determining the target information collection script in step 202, the target package management tool corresponding to the target information collection script can be determined in step 203. Thus, using the target information collection script as a bridge, the tool information is extracted, realizing the automated collection of non-explicit tool information, thereby improving the efficiency of information collection.
[0065] Next, combine Figure 3 This document describes an information collection method according to a specific embodiment of the present disclosure. For ease of explanation, the actions of both the information collector and the compiler are also described here. In this specific embodiment, the package management tool used is npm, the target link information can be considered as custom npm link information, and the target installation command is the npm install command. See also... Figure 3 The method mainly includes the following steps:
[0066] 1. The information collector creates a custom target link in the plugin script that points to the target information collection script, using symbolic links.
[0067] 2. The information collector updates the path environment variable, placing the custom target link information at the beginning.
[0068] 3. The compiler executes the target compilation script. The target compilation script contains various types of scripts to achieve different functions. Among them, npm scripts are scripts that install dependency packages based on the npm tool. Depending on whether the current compilation command being executed by the compiler is an npm script, step 3 specifically includes:
[0069] a. Execute the npm script. Step a specifically includes:
[0070] i. The compiler queries environment variables, accesses target link information, and determines the target information collection script. The target information collection script includes link deletion scripts, pre-requisite scripts, post-requisite scripts, and link restoration scripts.
[0071] ii. The information collector executes a link deletion script to delete the target link information from the environment variables and obtain updated environment variables.
[0072] iii. The information collector executes a pre-processing script, including:
[0073] ① Determine if the current compilation command is the npm install command.
[0074] ② If yes, record the start time; otherwise, do not record it.
[0075] iv. The information collector continues to execute the current compilation command. At this point, the information collector queries and updates environment variables, and can access the program linking information of the npm command. Therefore, control returns to the compiler, which completes the execution of the current compilation command.
[0076] v. The information collection party executes the post-script, records the end time, determines the duration from the start time to the end time as the installation time, and reports preset information including the installation time.
[0077] vi. The information collector executes the link recovery script, placing the custom target link information at the beginning of the updated environment variables to obtain the environment variables.
[0078] b. Execute other scripts.
[0079] In general, the compiler executes the compilation commands one by one. Each time an npm compilation command is executed, control is exchanged with the information collector, and step a is executed once. After step a is completed, the information collector returns control to the compiler, which then continues executing the next compilation command. During step a, the start time is recorded only if the currently executed npm compilation command is `npm install`. This record, combined with the end time, allows for the collection of installation time. If the currently executed npm compilation command is not `npm install`, the start time is not recorded, and even if the end time is recorded, the installation time cannot be obtained. Alternatively, it can be configured to execute subsequent scripts only if the start time is recorded. Furthermore, when the compiler executes other scripts, since the target link information (used as custom npm link information) is not accessed when querying environment variables, the target information collection script is not executed; instead, the target compilation script continues to execute.
[0080] Figure 4 This is a block diagram illustrating an information collection apparatus according to exemplary embodiments of the present disclosure. It should be understood that the information collection apparatus according to exemplary embodiments of the present disclosure can be implemented in terminal devices such as smartphones, tablets, and personal computers (PCs) in a software, hardware, or software-hardware combination manner, or it can be implemented in devices such as servers.
[0081] Reference Figure 4 The information acquisition device 400 includes a preparation unit 401, a determination unit 402, and an execution unit 403.
[0082] The preparation unit 401 can write target linking information into environment variables. The environment variables are used to store program linking information, which points to the program to be run required to execute the target compilation script. The target linking information points to the target information acquisition script, which is used to continue executing the commands in the target compilation script and collect preset information characterizing the execution performance of the target compilation script.
[0083] The determining unit 402 can respond to an access instruction triggered based on the target link information in the environment variable to determine the target information acquisition script pointed to by the target link information, wherein the target link information in the environment variable is accessed when the current compilation command in the target compilation script is executed, and the current compilation command is determined.
[0084] Execution unit 403 executes the target information acquisition script to continue executing the current compilation command and acquire preset information.
[0085] Optionally, in the environment variables, the first access priority of the target linking information is higher than the second access priority, where the second access priority is the priority of the program linking information corresponding to the current compilation command.
[0086] Optionally, the target information collection script includes a link deletion script and an action execution script. The execution unit 403 may also: execute the link deletion script to delete the target link information in the environment variables and obtain updated environment variables; execute the action execution script to continue executing the current compilation command based on the updated environment variables and collect preset information.
[0087] Optionally, the execution unit 403 executes the target compilation command based on the updated environment variables, which includes: continuing to execute the current compilation command; querying the updated environment variables and accessing the program linking information corresponding to the current compilation command in the updated environment variables to determine the program to be run corresponding to the current compilation command; and executing the current compilation command based on the program to be run.
[0088] Optionally, the target information acquisition script also includes a link recovery script, and the execution unit 403 may further: execute the link recovery script to recover the target link information in the environment variable update and obtain the environment variable.
[0089] Optionally, the target information collection script includes a pre-script and a post-script. The execution unit 403 may also: execute the pre-script to determine whether the current compilation command is a target installation command, and if it is determined that the current compilation command is a target installation command, obtain the current time as the start time; continue to complete the execution of the current compilation command; in response to the completion of the current compilation command, execute the post-script to record the current time as the end time; and determine the installation time based on the start time and the end time, and collect preset information including the installation time.
[0090] Optionally, the execution unit 403 may also: collect preset information including start time and end time.
[0091] Optionally, the preparation unit 401 may also: write multiple linking information corresponding to multiple package management tools into the environment variables, wherein each linking information points to the information collection script of the package management tool corresponding to the linking information, the multiple linking information includes target linking information, the target information collection script pointed to by the target linking information is for the target package management tool, and the target package management tool is the package management tool corresponding to the current compilation command.
[0092] Optionally, the execution unit 403 may also: execute the target information collection script to continue executing the current compilation command; determine the target package management tool corresponding to the target information collection script, obtain tool information, and collect preset information including tool information.
[0093] Regarding the apparatus in the above embodiments, the specific manner in which each unit performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0094] Figure 5 This is a block diagram of an electronic device according to exemplary embodiments of the present disclosure.
[0095] Reference Figure 5 The electronic device 500 includes at least one memory 501 and at least one processor 502. The at least one memory 501 stores a set of computer-executable instructions. When the set of computer-executable instructions is executed by the at least one processor 502, an information acquisition method according to an exemplary embodiment of the present disclosure is performed.
[0096] As an example, electronic device 500 may be a PC, tablet, personal digital assistant, smartphone, or other device capable of executing the aforementioned set of instructions. Here, electronic device 500 is not necessarily a single electronic device, but may be a collection of any devices or circuits capable of executing the aforementioned instructions (or instruction sets) individually or in combination. Electronic device 500 may also be part of an integrated control system or system manager, or may be configured to interconnect with a portable electronic device locally or remotely (e.g., via wireless transmission) through an interface.
[0097] In electronic device 500, processor 502 may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. By way of example and not limitation, processor may also include analog processors, digital processors, microprocessors, multi-core processors, processor arrays, network processors, etc.
[0098] The processor 502 can execute instructions or code stored in the memory 501, which can also store data. Instructions and data can also be sent and received over a network via a network interface device, which can employ any known transmission protocol.
[0099] The memory 501 may be integrated with the processor 502, for example, by arranging RAM or flash memory within an integrated circuit microprocessor. Alternatively, the memory 501 may include a separate device, such as an external disk drive, a storage array, or other storage device usable by any database system. The memory 501 and the processor 502 may be operatively coupled, or may communicate with each other, for example, via I / O ports, network connections, etc., enabling the processor 502 to read files stored in the memory.
[0100] In addition, electronic device 500 may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, mouse, touch input device, etc.). All components of electronic device 500 can be interconnected via a bus and / or network.
[0101] According to exemplary embodiments of the present disclosure, a computer-readable storage medium may also be provided, which, when instructions in the computer-readable storage medium are executed by at least one processor, causes at least one processor to perform an information acquisition method according to exemplary embodiments of the present disclosure. Examples of computer-readable storage media include: read-only memory (ROM), random access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disc storage, hard disk drive (HDD), solid-state drive (SSD), card storage (such as multimedia cards, secure digital (SD) cards, or ultra-fast digital (XD) cards), magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device, hard disk, solid-state drive, and any other device configured to store a computer program and any associated data, data files, and data structures in a non-transitory manner and to provide the computer program and any associated data, data files, and data structures to a processor or computer so that the processor or computer can execute the computer program. The computer program in the aforementioned computer-readable storage medium can run in an environment deployed in computer devices such as clients, hosts, agent devices, servers, etc. Furthermore, in one example, the computer program and any associated data, data files, and data structures are distributed across a networked computer system, such that the computer program and any associated data, data files, and data structures are stored, accessed, and executed in a distributed manner through one or more processors or computers.
[0102] According to exemplary embodiments of the present disclosure, a computer program product may also be provided, the computer program product including computer instructions, which, when executed by at least one processor, cause at least one processor to perform an information acquisition method according to exemplary embodiments of the present disclosure.
[0103] According to the exemplary embodiments of the present disclosure, the information acquisition method and apparatus, electronic device, and computer-readable storage medium configure a target information acquisition script independent of the target compilation script and write target link information pointing to the target information acquisition script into the environment variables. When the target compilation script is executed and the environment variables are queried, the target link information can be accessed, the target information acquisition script can be read and executed, and thus the acquisition of preset information can be completed with the help of the target information acquisition script without intruding on the target compilation script. This can greatly improve the efficiency of information acquisition, save labor costs, and ensure the stability of the original target compilation script.
[0104] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0105] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. An information collection method, characterized in that, The information collection method includes: The target linking information is written into the environment variable, wherein the environment variable is used to store program linking information, the program linking information points to the program to be run required to execute the target compilation script, the target linking information points to the target information collection script, and the target information collection script is used to continue to execute the commands in the target compilation script and collect preset information characterizing the execution performance of the target compilation script; In response to an access instruction triggered based on the target link information in the environment variable, the target information collection script pointed to by the target link information is determined, wherein the target link information in the environment variable is accessed when the current compilation command in the target compilation script is executed, and the current compilation command is determined. In the environment variable, the first access priority of the target link information is higher than the second access priority, the second access priority being the priority of the program link information corresponding to the current compilation command. The target information collection script includes a link deletion script and an action execution script. The target information collection script is executed to continue executing the current compilation command and collect the preset information. This includes: executing the link deletion script to delete the target link information in the environment variables to obtain updated environment variables; and executing the action execution script to continue executing the current compilation command based on the updated environment variables and collect the preset information.
2. The information collection method as described in claim 1, characterized in that, The step of continuing to execute the current compilation command based on the updated environment variables includes: Continue executing the current compilation command; Query the updated environment variable, access the program linking information in the updated environment variable corresponding to the current compilation command, and determine the program to be run corresponding to the current compilation command; Based on the program to be run, execute the current compilation command.
3. The information collection method as described in claim 1, characterized in that, The target information collection script further includes a link recovery script, wherein, after executing the action execution script to continue executing the current compilation command based on the updated environment variables and collecting the preset information, the execution of the target information collection script to continue executing the current compilation command and collecting the preset information further includes: Execute the link recovery script to restore the target link information in the updated environment variables, and obtain the environment variables.
4. The information collection method as described in claim 1, characterized in that, The target information collection script includes a pre-script and a post-script. Executing the target information collection script to continue executing the current compilation command and collect the preset information includes: The pre-script is executed to determine whether the current compilation command is the target installation command, and if the current compilation command is determined to be the target installation command, the current time is obtained as the start time; Continue executing the current compilation command; In response to the completion of the current compilation command, the post-script is executed to record the current time as the end time; Based on the start time and the end time, the installation time is determined, and the preset information including the installation time is collected.
5. The information acquisition method according to any one of claims 1 to 4, characterized in that, The step of writing the target link information into environment variables includes: Multiple link information corresponding to multiple package management tools is written into the environment variables. Each link information points to the information collection script of the package management tool corresponding to the link information. The multiple link information includes the target link information. The target information collection script pointed to by the target link information is for the target package management tool, which is the package management tool corresponding to the current compilation command.
6. The information acquisition method as described in claim 5, characterized in that, The execution of the target information collection script, to continue executing the current compilation command and collect the preset information, includes: Execute the target information collection script to continue executing the current compilation command; Identify the target package management tool corresponding to the target information collection script, obtain tool information, and collect the preset information including the tool information.
7. An information acquisition device, characterized in that, The information acquisition device includes: The preparation unit is configured to write target linking information into environment variables, wherein the environment variables are used to store program linking information, the program linking information points to the program to be run required to execute the target compilation script, the target linking information points to the target information collection script, and the target information collection script is used to continue executing the commands in the target compilation script and collect preset information characterizing the execution performance of the target compilation script; The determining unit is configured to, in response to an access instruction triggered based on the target link information in the environment variable, determine the target information collection script pointed to by the target link information, wherein the target link information in the environment variable is accessed when the current compilation command in the target compilation script is executed, and the current compilation command is determined; in the environment variable, a first access priority of the target link information is higher than a second access priority, the second access priority being the priority of the program link information corresponding to the current compilation command; the target information collection script includes a link deletion script and an action execution script. The execution unit is configured to execute the target information collection script to continue executing the current compilation command and collect the preset information, including: executing the link deletion script to delete the target link information in the environment variables to obtain updated environment variables; and executing the action execution script to continue executing the current compilation command based on the updated environment variables and collect the preset information.
8. An electronic device, characterized in that, include: At least one processor; At least one memory that stores computer-executable instructions. Wherein, when the computer-executable instructions are executed by the at least one processor, the at least one processor causes the at least one processor to perform the information acquisition method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor causes the at least one processor to perform the information acquisition method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Program compiling method and device, electronic equipment and storage medium
CN111767058A