Data processing method and related products
Patent Information
- Application Number
- PCT/RU2023/000407
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2025-10-16
AI Technical Summary
Existing profile-guided optimization (PGO) methods in C/C++ compilers consume a large number of counters for collecting profile data, leading to high overhead, especially in high-load scenarios like server applications and graphic libraries, making instrumentation unsuitable due to excessive power consumption.
A two-stage approach is proposed, where sample-based profile data is first collected using a profiler, and then instrumentation is performed with a reduced number of counters based on identified hot and cold paths, ensuring accuracy while reducing overhead.
This method maintains instrumentation accuracy while significantly reducing runtime overhead, enabling PGO in high-load applications that were previously unsuitable due to excessive overhead.
Abstract
Description
DATA PROCESSING METHOD AND RELATED PRODUCTSTECHNICAL FIELD
[0001] The present disclosure relates to the field of profile-guided optimization technologies, and in particular, to a data processing method and related products.BACKGROUND
[0002] Profile-guided optimization (PGO, also known as Feedback-Driven Optimization, FDO) is an approach for optimization which uses profile data to make decisions in different optimizations (e.g. inline function or not, or how to rearrange basic blocks, etc.). This profile data is detail information about an execution of a program, such as a function call stack and time consumption of a tuned function in the program.
[0003] This background information is provided to reveal information believed by the applicant to be of possible relevance to the present disclosure. No admission is necessarily intended, nor should be construed, that any of the preceding information constitutes prior art against the present disclosure.SUMMARY
[0004] In a first aspect, an embodiment of the present disclosure provides a data processing method, where the method includes: performing instrumentation on a program based on first profile data with a first number of counters, where the first profile data is indicative of at least one cold path and at least one hot path of the program, where the first number of counters are used for counting the number of times for which each of first branches on the at least one cold path is executed and the number of times for which each of second branches ion the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path.
[0005] In this way, by setting counters whose number is less than the number of branches, the overhead of the program is reduced, and the runtime overhead of program is further reduced while the instrumentation accuracy is maintained.
[0006] In a possible implementation of the first aspect, where performing instrumentation on the program based on the first profile data with the first number of counters includes: determining the at least one cold path and the at least one hot path of the program based on the first profile data; and inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
[0007] In this way, since the hot and cold path can be determined based on the first profile data, to-be-inserted branches on the hot and cold paths can be determined flexibly, and the number of counters for instrumentation can be reduced, thereby overhead of the program and runtime overhead of the program can be reduced.
[0008] In a possible implementation of the first aspect, where inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path includes: inserting a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches; and for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair.
[0009] In a possible implementation of the first aspect, where inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path further includes:inserting one counter into each of remaining branches among the first branches and the second branches.
[0010] Similarly, since the hot and cold path can be determined based on the first profile data, to-be-inserted branches on the hot and cold paths can be determined flexibly, and the number of counters for instrumentation can be reduced, thereby overhead of the program and runtime overhead of the program can be reduced.
[0011] In a possible implementation of the first aspect, where each of the first branches is inserted with one counter among the first number of counters.
[0012] In this way, by performing instrumentation mostly on branches of the cold path(s) of the function, the runtime overhead of instrumented version is reduced compared to that of non-instrumented. And this way also allows to use instrumentationbased profiling for high load applications, for which this kind of profiling was unsuitable before because of too large overhead.
[0013] In a possible implementation of the first aspect, where for each directed acyclic component of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters.
[0014] In a possible implementation of the first aspect, where each of the second branches is inserted with one counter among the first number of counters.
[0015] In this way, the counters can be inserted into the branches flexibly, and the number of counters for instrumentation can be reduced, thereby overhead of the program and runtime overhead of the program can be reduced.
[0016] In a possible implementation of the first aspect, where the method further includes: obtaining the first profile data.
[0017] In a possible implementation of the first aspect, where obtaining the first profile data includes: sampling the program using a profiler to obtain the first profile data.
[0018] In a possible implementation of the first aspect, where the method further includes: obtaining a minimal spanning tree (MST) for the program using a compiler;where performing instrumentation on the program based on the first profile data with the first number of counters includes: performing, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
[0019] In a possible implementation of the first aspect, where the method further includes: checking the first profile data with second profile data derived from the instrumentation, where the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
[0020] By using the second profile data to check the first profile data, the obtained profile data is more reliable, thus being better used for profile-guided optimization.
[0021] In a possible implementation of the first aspect, where the method further includes: performing profile-guided optimization (PGC) on the program based on the instrumentation.
[0022] In a possible implementation of the first aspect, where the program is a C language program or a C++ language program with a load greater than a predefined value.
[0023] The proposed solution may be especially useful in high load scenarios, so such predefined value can be set to provide more flexibility in applying the proposed solution.
[0024] In a second aspect, an embodiment of the present disclosure provides a data processing apparatus, where the apparatus includes: a performing module, configured to perform instrumentation on a program based on first profile data with a first number of counters, where the first profile data is indicative of at least one cold path and at least one hot path of the program, where the first number of counters are used for counting the number of times for which each of first branches on the at least one cold path is executed and the number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold pathand the second branches on the at least one hot path.
[0025] In a possible implementation of the second aspect, where the performing module is configured to: determine the at least one cold path and the at least one hot path of the program based on the first profile data; and insert the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
[0026] In a possible implementation of the second aspect, where the performing module is further configured to: insert a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches, and for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, insert one counter for the each pair.
[0027] In a possible implementation of the second aspect, where the performing module is further configured to: inserting one counter into each of remaining branches among the first branches and the second branches.
[0028] In a possible implementation of the second aspect, where each of the first branches is inserted with one counter among the first number of counters.
[0029] In a possible implementation of the second aspect, where for each directed acyclic component of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters.
[0030] In a possible implementation of the second aspect, where each of the second branches is inserted with one counter among the first number of counters.
[0031] In a possible implementation of the second aspect, where the apparatus further includes: a first obtaining module, configured to obtain the first profile data.
[0032] In a possible implementation of the second aspect, where the obtaining moduleis configured to: sample the program using a profiler to obtain the first profile data.
[0033] In a possible implementation of the second aspect, where the apparatus further includes: a second obtaining module, configured to obtain a minimal spanning tree (MST) for the program using a compiler; where the performing module is configured to: perform, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
[0034] In a possible implementation of the second aspect, where the apparatus further includes: a checking module, configured to check the first profile data with second profile data derived from the instrumentation, where the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
[0035] In a possible implementation of the second aspect, where the performing module is further configured to: perform profile-guided optimization (PGC) on the program based on the instrumentation.
[0036] In a possible implementation of the second aspect, where the program is a C language program or a C++ language program with a load greater than a predefined value.
[0037] In a third aspect, an embodiment of the present disclosure provides an electronic device including processing circuitry for executing the data processing method according to the first aspect or any possible implementation of the first aspect.
[0038] In a fourth aspect, an embodiment of the present disclosure provides a chip, including an input / output (I / O) interface and a processor, wherein the processor is configured to call and run a computer program stored in a memory, to enable a device installing with the chip to perform the method according to the first aspect or any possible implementation of the first aspect.
[0039] In a fifth aspect, an embodiment of the present disclosure provides a computer- readable medium storing computer execution instructions which, when executed by aprocessor, causes the processor to execute the data processing method according to the first aspect or any possible implementation of the first aspect.
[0040] In a sixth aspect, an embodiment of the present disclosure provides a computer program product including computer execution instructions which, when executed by a processor, causes the processor to execute the data processing method according to the first aspect or any possible implementation of the first aspect.
[0041] In the data processing method according to the present disclosure, perform instrumentation on a program based on first profile data with a first number of counters, where the first profile data is indicative of at least one cold path and at least one hot path of the program, wherein the first number of counters are used for counting the number of times for which each of first branches on the at least one cold path is executed and the number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path. In this way, by setting counters whose number is less than the number of branches, the overhead of the program is reduced, and the runtime overhead of program is further reduced while the instrumentation accuracy is maintained.BRIEF DESCRIPTION OF DRAWINGS
[0042] FIG. 1 illustrates a schematic flowchart of a data processing method according to one or more embodiments of the present disclosure.
[0043] FIG. 2 illustrates an exemplary schematic diagram of performing instrumentation on a program according to one or more embodiments of the present disclosure.
[0044] FIG. 3 illustrates a schematic flowchart of performing instrumentation on a program according to one or more embodiments of the present disclosure.
[0045] FIG. 4 is a schematic structural diagram of a data processing apparatus according to one or more embodiments of the present disclosure.DESCRIPTION OF EMBODIMENTS
[0046] To describe the technical solutions in embodiments of the present disclosure or in the prior art more clearly, the following briefly introduces the accompanying drawings needed for describing the embodiments or the prior art.
[0047] In the following description, reference is made to the accompanying figures, which form part of the present disclosure, and which show, by way of illustration, specific aspects of embodiments of the present disclosure or specific aspects in which embodiments of the present disclosure may be used. It is understood that embodiments of the present disclosure may be used in other aspects and include structural or logical changes not depicted in the figures. The following detailed description, therefore, is not to be taken in a limiting sense, and the scope of the present disclosure is defined by the appended claims.
[0048] Profile data generally includes detailed information about a program’s execution, which can be used for (Profile-guided optimization) PGO of a program. In the related art, the profile data can be gathered in two ways: 1) sampling with a profiler, 2) performing instrumentation with additional codes. However, since the profiler generally samples the execution information roughly, so the way using the profiler has lower runtime overhead but lower accuracy, while the latter way has higher accuracy but runtime overhead.
[0049] Currently in C / C++ compilers instrumentation is done in the following way: firstly a compiler builds a control-flow graph (CFG) of a function of a program which should be instrumented, then based on the CFG it builds a minimal spanning tree (MST), and each leaf of the MST is considered as a place to insert a counter for profiling. And as a last step, the compiler creates an array of counters for each function in a static area of a memory.
[0050] Therefore, when this program is executed, then each invoked function will increment counters, which are corresponding to execution paths inside function. When this program finished, then all counters are wrote to a profile data file (which contains the profile data mentioned above). This file can be used later for PGO.
[0051] Current approach for gathering the profile data by instrumentation shows good results, but on other hand it has some problems, and one of these problems, which is targeted by the present disclosure, is that it consumes a large number of counters for collecting the profile data, that will be especially power consuming in high load scenarios (like some of server applications, OS components, or intensively used graphic libraries for mobile applications). In fact, in these high load scenarios, since instrumentation has too big overhead to use, this overhead makes scenario changes (e.g. graphic library in case of big latencies starts using more simpler algorithms, so profile of using this library changes compared to default production scenario).
[0052] For the above case, the present disclosure proposes to divide instrumentation in two stages: first collect sample-based profile data of an application (or a program), e.g., using a profiler, and then instrument the application by using the sample-based profile data collected to reduce overhead from instrumentation, and during the later instrumentation stage, less counters are used on paths as possible, which will described in detail below.
[0053] Therefore, by virtue of the above two-stage solution, the profile data collected in the first stage can be used to determine the hot path(s) and the cold path(s) of the application, and then counters can be added to the determined hot path(s) and the cold path(s) to complete the instrumentation, since the counters in the second stage of instrumentation are added on the basis of known information (information about the hot path(s) and the cold path(s)), instead of adding counters on all paths, it is possible to just add counters on required branches of these paths. In this way, the addition of counters on paths ensures the accuracy of the instrumentation, while the reduction of the number of counters reduces the overall overhead, so as to realize the balance between the accuracy and the overhead.
[0054] The solution proposed by the present disclosure can be applied to many scenarios, for example, scenarios with high loaded C / C++ programs (like server applications, OS components, graphic libraries, or components, which should handle user inputs as fast as possible, etc.), which generally cannot use instrumentation forgathering profile data due to high load, and may change hot paths if execution time is too high (due to instrumentation overhead). Taking the server application as an example of such application, some data is get by the network and should be handled fast, but if the handling takes too long, then server application starts to handle the data with a simpler algorithm. In this case, instrumented version will show that a lot of work in done in a function with a simple algorithm, but it is actually not real scenario in production. So, this case is suitable for the solution proposed by the present disclosure.
[0055] The embodiments of the present disclosure will be elaborated with reference to accompanying figures. The present disclosure provides a data processing method for a compiler. Reference may be made to FIG. 1 , the data processing method may include the following steps.
[0056] SI 01, perform instrumentation on a program based on first profile data with a first number of counters.
[0057] Specifically, the first profile data is indicative of at least one cold path and at least one hot path of the program, where the first number of counters are used for counting the number of times for which each of first branches on the at least one cold path is executed and the number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path.
[0058] Here the program may be reflected as program codes, for example, it may be an application and may include one or more functions. In a possible implementation of the present disclosure, the program is a C language program or a C++ language program with a load greater than a predefined value, here the predefined value is a threshold for measuring the load of the program, as stated in the previous part, the solution may be especially useful in high load scenarios, so such predefined value can be set to provide more flexibility in applying the proposed solution. The predefined value can be set (e.g., by a user) according to actual applications, which is not limited in the embodiments of the present disclosure. io
[0059] In a possible implementation of the present disclosure, the program can include multiple basic blocks (which are also referred as code blocks herein), the basic block refers to a chunk of low level code (byte code, assembly or machine code) with sequentially executed instructions, and the program can include at least one hot path, and at least one cold path. The hot path of the program refers to a most frequently used chain of basic blocks in the program for a specific scenario, and the cold path of the program refers to a path opposite to the hot path.
[0060] The instrumentation on the program can be performed, for example, but virtue of inserting profile counter(s) (which is also referred to as counter herein) into function(s) of the program (e.g., during compilation), the counter(s) may be used for collection of the first profile data. In a possible implementation, instrumentation phase of compilation requires (or may require) such profile data for decision making about locations in instrumentation points (i.e., branches of the program that needs to be inserted).
[0061] In a possible implementation of the present disclosure, there may be at least one cold path and at least one hot path in the program, and each of the at least one cold path and the at least one hot path has multiple first branches and multiple second branches respectively. During the execution of a program, at some point, the execution may require a determination of a condition, the result of the determination may vary, that is, the condition may be met or may not be met, due to such determination, the execution will be subject to different basic blocks, or be subject to different paths, so a branch is generated in such point, where different subsequent executions may appear.
[0062] In a possible implementation, the first profile data is obtained by sampling the program using a profiler, where the sampling refers to collection of the first profile data with using a profiler (e.g., perf for Linux). For example, the profiler performs sampling on the program to obtain the first profile data (which is also referred as sample-based profile data), then the complier obtains the first profile data from the profiler. It should be note that the first profile data can be obtained in various ways, as long as the first profile data can realize the function of indicating hot and cold paths. In a possibleimplementation, the first profile data can include information of the hot path(s) and the cold path(s), or include information for indicating the hot path(s) and the cold path(s), so that the hot path(s) and the cold path(s) can be determined based on the first profile data. In the way of obtaining the first profile data using the profile, since the profile is an external tool, the runtime overhead is lower but the accuracy of the profile data is lower, therefore, later stage of instrumentation based on the first profile data is required for obtaining accurate execution information.
[0063] In a possible implementation, the first branch can be a branch on the cold path of the program, and the second branch can be a branch on the hot path of the program. There can be multiple first branches on one cold path and multiple second branches on one hot path. As shown in FIG. 2 below, the first branch can be, for example, blocks of If else#l, If else#2 and If else#3 on the right side of the figure, and the second branch can be, for example, blocks of If then#l, If then#2 and If then#3 on the left side of the figure, and a first branch can have a corresponding second branch or not, and accordingly, a second branch can have a corresponding first branch or not. For example, the second branches, If then#l, If then#2 and If then#3 respectively correspond to the first branches, If else#l, If else#2 and If else#3 as shown in FIG. 2.
[0064] In a possible implementation, the counter is used for counting the number of times for which the branch on which the counter is located is executed, that is, the counter inserted in a branch is used for counting the number of times for which this branch is executed. The counter can be realized in form of specific codes or other forms, which is not limited in the embodiments of the present disclosure.
[0065] In a possible implementation, an example where there is one cold path and one hot path in the program would be taken to illustrate, but it should be understood that the solution of the present disclosure is also applicable for the case where the program includes one cold path and multiple hot paths, the case where the program includes multiple cold paths and one hot path, and the case where the program includes multiple cold paths and multiple hot paths. The execution times of the program (e.g., the number of times for which the program is called) may be equal to the sum of execution timesof a first branch on the cold path and execution times of a corresponding second branch on the hot path, where the first branch and the corresponding second branch can be referred as a pair of the first and second branches, and the total numbers of executions of different pairs of the first and second branches in the program are the same.
[0066] In a possible implementation, the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path. For example, there are two pairs of the first and second branches, each of the first and second branches in the first pair is inserted with one counter, and the first branch in the second pair is inserted with one counter, but the second branch is not inserted with a counter, and the number of times for which the second branch in the second pair is executed can be calculated by subtracting the number of times for which the first branch in the second pair is executed from the execution times of the program, and the execution times of the program can be calculated as the sum of the two counters in the first pair. Therefore, the number of times for which each branch is executed can be obtained without inserting a counter into each branch. Take FIG. 2 as an example, the total number of executions can be the number of times recorded by the counters at If. then#3 and If. else#3, then since this total number should also be the sum of the number of times for which If. then#2 and If. else#2 are executed, so if we know the number of times recorded by the counter at If. else#2, then the number of times for which If. then#2 can be determined by subtraction between the total number and the number of times recorded by the counter at If. else#2.
[0067] In this way, by setting counters whose number is less than the number of branches, the overhead of the program is reduced, and the runtime overhead of program is further reduced while the instrumentation accuracy is maintained.
[0068] In a possible implementation of the present disclosure, step S 101 of performing instrumentation on the program based on the first profile data with the first number of counters includes the following steps, FIG. 3 illustrates a schematic flowchart of a performing instrumentation on a program according to one or more embodiments of the present disclosure.
[0069] SI 011, determine the at least one cold path and the at least one hot path of the program based on the first profile data.
[0070] In a possible implementation of the present disclosure, before step SI 011 of determining the at least one cold path and the at least one hot path of the program based on the first profile data, the method includes: obtaining the first profile data. As described above, the first profile data can be obtained by sampling the program using a profiler, or the first profile data can be obtained by any other ways as long as the obtained first profile data can realize the function of indicating hot and cold paths. Then, the hot path(s) and the cold path(s) can be determined based on the first profile data for subsequent instrumentation, that is, using preliminary gathered sample-based profile data (first profile data) for instrumentation phase to determine the hot path(s) and the cold path(s).
[0071] Two exemplary segments of codes for instrumentation using the related art and the present disclosure are shown below.
[0072] Example 1 : default version of instrumentation void foo() { / / code block if ( ... ) / / “then” code block. Compiler instruments it else / / “else” code block / / code block
[0073] In the existing way, every branch on the program could be inserted with a counter, which causes a high overhead.
[0074] Example 2: Instrumentation with using sample-based profile data void foo() { / / code block if ( ... ) / / “then” code block. Hot path (according to a profile data). else / / “else” code block. Cold Path. Compiler instruments it / / code block
[0075] In the way proposed by the present disclosure, instrumentation with using the sample-based profile data will determine cold paths and rearrange insertion of profile counters to make as less overhead on hot path as possible.
[0076] In a possible implementation of the present disclosure, step S 101 of performing instrumentation on the program based on the first profile data with the first number of counters further includes the following steps.
[0077] SI 012, insert the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
[0078] In a possible implementation of the present disclosure, step SI 012 of inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path includes:A: inserting a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches, andB: for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair.
[0079] In a possible implementation, there may be one or more remaining pairs of first and second branches, since the execution times of the program may be equal to the sum of execution times of a first branch on the cold path and execution times of a corresponding second branch on the hot path, thus, the execution times of the program can be determined at Step A, and in the remaining pairs, only one counter is inserted into each of the remaining pairs, and the number of times for which corresponding branch in each of the remaining pairs that is not inserted with the counter is executedcan be determined accordingly.
[0080] Here the second number of counters refer to counters that are inserted on one or more pairs of first and corresponding second branches, so if there exists still one pair or multiple pairs of first and corresponding second branches, each of the first and second branches is inserted with a counter, so the second number is two times the number of pairs for which two counters have been inserted for both branches.
[0081] In addition to the at least one of the second branches and at least one first branch corresponding to the at least one of the second branches mentioned above, the remaining branches also include one or more pairs of first and corresponding second branches, but for said one or more pairs, only one counter is inserted in each pair.
[0082] In a possible implementation of the present disclosure, when there is a second branch on a hot path which does not have a corresponding first branch on a cold path, or for a first branch on a cold path which does not have a corresponding second branch on a hot path, step S 1012 of inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path further includes:
[0083] C: inserting one counter into each of remaining branches among the first branches and the second branches.
[0084] For the branch on a hot path which does not have a corresponding branch on a cold path, or for a branch on a cold path which does not have a corresponding branch on a hot path, a counter is always required.
[0085] In the case where there is one cold path and one hot path in the program, the execution times of the program may be equal to the sum of execution times of a first branch on the cold path and execution times of a corresponding second branch on the hot path, where the first branch and the corresponding second branch can be referred as a pair of the first and second branches, for example, the first branch If else#l shown in FIG. 2 has the corresponding second branch If then#l, and If then#l and If else#l can be referred as a pair of branches, and the total numbers of executions of different pairs of the first and second branches in the program are equal.
[0086] The second number of counters are inserted for at least one pair of branches, and used for counting the execution times of the program, so it is two times the number of pairs for which two counters are inserted. For example, there are four first branches on the cold path and two second branches on the hot path, where there are two pairs of the first and second branches, that is, the two second branches have their corresponding first branches, and two first branches among the fourth first branches do not have corresponding second branches. Inserting a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can be: inserting 2 counters into simply one pair of the first and second branches. It should be noted that when there are multiple pairs of first and second branches, not all of the multiple pairs are inserted with two counters, there is at least one pair which is inserted with two counters so as to obtain the execution times of the program, but there is also at least one pair which is not inserted with two counters but simply one counter so as to ensure that the total number of counters used for instrumentation is smaller than the execution times of the program, or smaller than the total number of the first branches on the at least one cold path and the second branches on the at least one hot path. For example, when we choose to insert two counters for each of two or more of the multiple pairs, the sums of counters for the two or more pairs should be the same, so such insertion can be used as a double check of the execution times of the program. For the branch on a hot path which does not have a corresponding branch on a cold path, or for a branch on a cold path which does not have a corresponding branch on a hot path, a counter is always required.
[0087] The first number of counters are used for counting the number of times for which each of first branches and the number of times for which each of second branches is executed, that is, used for counting the number of times for which each of all branches in the hot path and cold path. The first number of counters includes the second number of counters. In the above example, for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can be, inserting one counter into the remainingpair of first and second branches, and inserting one counter into each of remaining branches among the first branches and the second branches can be, inserting one counter into each of two first branches that do not have corresponding second branches, and the first number of counters is 5.
[0088] In a possible implementation of the present disclosure, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: for one pair of first and second branches, inserting two counters into respective branches in the pair of first and second branches, to count the execution times of the program, and the second number is 2; each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: for each remaining pair of first and second branches, inserting one counter into this pair, a preferable way is to insert such counter to the branch on the cold path since it will be less likely to invoke such counter, and inserting one counter into each of remaining branches among the first branches and the second branches can include: if there is still a first branch (first branches) which does (do) not have a corresponding second branch (second branches), it is possible to insert one counter into the first branch or each of first branches; or if there is still a second branch (second branches) which does (do) not have a corresponding first branch (first branches), it is possible to insert one counter into the second branch or each of second branches, that is a first branch without a corresponding second branch or a second branch without a corresponding first branch will be inserted with a counter,
[0089] In a possible implementation, when the number of the first branches on the one cold path is larger than that of the second branches on the one hot path, for example, there are at least three first branches and at least two second branches, and there are at least two pairs of the first and the second branches.
[0090] In a case where there are two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: for onepair of first and second branches, inserting 2 counters into the first branch and its corresponding second branch in the one pair, to count the execution times of the program (or to count the total number of the execution times of the first branch and the second branch in this pair), and the second number is 2; for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: inserting one counter into the remaining pair of the first and the second branches (either the first branch or the second branch); and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into a first branch without a corresponding second branch and / or a second branch without a corresponding first branch.
[0091] For example, if there are three first branches and two second branches, these two second branches have their corresponding first branches among the three first branches, that is, there are two pairs of first and second branches, for one pair of the first and the second branches, 1 counter is inserted into one of one first branch and one corresponding second branch; 2 counters are inserted into the remaining pair of the first and the second branches, to count the total number of the execution times of the first branch and the second branch in each pair; and 1 counter is inserted into the remaining first branch without a corresponding second branch. The total number of counters inserted is 4, which is smaller than the total number (the first number mentioned above) of the first and the second branches of 5.
[0092] In a case where there are more than two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: for each of the more than two pairs of first and second branches, selecting one pair and inserting two counters into respective branches in the pair of first and second branches, to count the execution times of the program; for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: inserting onecounter into each of the remaining first and second branch pairs; and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into a first branch without a corresponding second branch and / or a second branch without a corresponding first branch.
[0093] For example, there are five first branches, four second branches, of which three second branches have corresponding first branches among the five first branches, that is, there are three pairs of first and second branches. The insertion of the counter can be done in following possible ways:1) for the three pairs of the first and the second branches, 4 counters are inserted into respective branches in the two pairs of first and second branches, so the second number is 4, and 1 counter is inserted into one pair of the first and the second branches (either in the first branch or the second branch); 2 counters are inserted into the remaining two first branches without the corresponding second branches, and 1 counter is inserted into the remaining second branch without the corresponding first branch, where the total number of counters inserted is 8, which is smaller than the total number of the first and the second branches of 9;2) for each of two pairs of the first and the second branches, 1 counter is inserted into one of one first branch and one corresponding second branch, 2 counters are inserted into the remaining pair of the first and the second branches (so the second number equals to 2); 2 counters are inserted into the remaining two first branches without the corresponding second branches, 1 counter is inserted into the remaining second branch without the corresponding first branch, where the total number of counters inserted is 7, which is smaller than the total number of the first and the second branches of 9.
[0094] It should be noted that the specific values such as 2, 3, 4 and 5 used for describing the first and second branches are just exemplary, other values may also be set for realizing the above purpose, which is not limited in the embodiments of the present disclosure.
[0095] In a possible implementation, when the number of the first branches on the onecold path is equal to that of the second branches on the one hot path, for example, there are at least two first branches and at least two corresponding second branches, and there are at least two pairs of the first and the second branches.
[0096] In this case where there are two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: for one pair of first and second branches, inserting 2 counters into the first branch and its corresponding second branch in the one pair, to count the execution times of the program (or to count the total number of the execution times of the first branch and the second branch in this pair), and the second number is 2; for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: inserting one counter into the remaining pair of the first and the second branches (either in the first branch or the second branch); and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into a first branch without a corresponding second branch and / or a second branch without a corresponding first branch. For example, there are two first branches, two second branches, and these two second branches correspond to the two first branches respectively, that is, there are two pairs of first and second branches, for one pair of the first and the second branches, 2 counter are inserted into one pair of first and its corresponding second branch in the one pair; and 1 counter is inserted into the remaining pair of the first and the second branches. The total number of counters inserted is 3, which is smaller than the total number of the first and the second branches of 4.
[0097] In this case where there are more than two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: selecting one pair or several pairs of first and second branches from the more than two pairs, and for each of the selected pairs, two counters are inserted (one for thefirst branch and one for its corresponding second branch); for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: for the remaining pairs, one counter is inserted into each of the remaining first and second branch pairs; and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into a first branch without a corresponding second branch and / or a second branch without a corresponding first branch.
[0098] For example, there are three first branches, three second branches, and these three second branches correspond to the three first branches respectively, that is, there are three pairs of first and second branches. The compiler inserting the counter can be done in following possible ways:1) for each of two pairs of the first and the second branches, 2 counters are inserted into the first branch and its corresponding second branch; 1 counter is inserted into the remaining pair of the first and the second branches (either in the first branch or the second branch), where the total number of counters inserted is 5, which is smaller than the total number of the first and the second branches of 6;2) for each of two pairs of the first and the second branches, 1 counter is inserted into one of one first branch and one corresponding second branch; 2 counters are inserted into the remaining pair of the first and the second branches, where the total number of counters inserted is 4, which is smaller than the total number of the first and the second branches of 6.
[0099] The latter way is exemplarily shown in FIG. 2, a process in which counters are inserted into cold and hot paths of a program is illustrated. As shown in FIG. 2, the function of the program includes four code blocks (or referred to as basic blocks), code block #1, code block #2, code block #3, code block #4, the four code blocks are common blocks that are to be executed when the program is executed. The compiler may determine the cold and hot paths in the function based on the first profile data, where the hot path is indicated by dash line on the right side of the figure, and there arethree second branches on the hot path, branch LI (If then#l), branch L2 (If then#2) and branch L3 (If then#3), the cold path is on the left side of the figure, and there are three first branches on the cold path, branch R1 (If else#l), branch R2 (If else#2) and branch R3 (If else#3). These three second branches correspond to the three first branches respectively, that is, there are three pairs of first and second branches. The insertion of the counter includes: for each of the first two pairs of first and second branches, 1 counter is inserted into one of one first branch and one corresponding second branch, that is, counter 1 is inserted into branch R1 (If else#l) in the first pair, and counter 2 is inserted into branch R2 (If else#2) in the second pair; and for the third pair of the first and the second branches, 2 counters are inserted into the first and the second branches respectively, that is, counter 3 and counter 4 are inserted into branch R3 (If else#3) and branch L3 (If then#3) respectively, so the second number is 2. The total number of counters inserted is 4, which is smaller than the total number of the first and the second branches of 6. In addition, counter 3 corresponding to branch R3 and counter 4 corresponding to branch L3 can count the total number of the execution times of the function, for example, counter 3 counts the number of times for which branch R3 is executed as 20, and counter 4 counts the number of times for which branch L3 is executed as 80, then the total number of the execution times of the function can be determined as 100. The total number of the execution times of the first branch and the second branch in each pair is the same, counter 1 corresponding to branch R1 can count the number of times for which branch R1 is executed, for example, the number is 10, and the number of times for which branch LI is executed can be determined based on the total number of the execution times of the function and the number of times for which branch R1 is executed, the number of times for which branch LI is executed is calculated as 90 by subtracting 10 from 100. It should be note that the hot and cold paths can be converted into each other based on the first profile data, and the to-be- inserted branch can be re-determined based on the new hot and cold paths.
[0100] In a possible implementation, when the number of the first branches on the one cold path is smaller than that of the second branches on the one hot path, for example,there are at least two first branches and at least three second branches, and there are at least two pairs of the first and the second branches.
[0101] In this case where there are two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: for one pair of first and second branches, inserting 2 counters into the first branch and its corresponding second branch in the one pair, to count the execution times of the program (or to count the total number of the execution times of the first branch and the second branch in this pair), and the second number is 2; for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: inserting one counter into the remaining pair of the first and the second branches (either the first branch or the second branch), and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into each of second branches without a corresponding first branch and / or each of first branches without a corresponding second branch. For example, there are two first branches, three second branches, and these two first branches have corresponding second branches among the three second branches, that is, there are two pairs of first and second branches, for one pair of the first and the second branches, 2 counters are inserted into the one pair of first and its corresponding second branch in the one pair, to count the total number of the execution times of the first branch and the second branch in each pair; 1 counter is inserted into the remaining pair of the first and the second branches; and 1 counter is inserted into the remaining second branch without a corresponding first branch. The total number of counters inserted is 4, which is smaller than the total number of the first and the second branches of 5.
[0102] In this case where there are more than two pairs of first and second branches, inserting the second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches can include: selecting one pair or several pairs of first and second branches from the morethan two pairs, and for each of the selected pairs, two counters are inserted (one for the first branch and one for its corresponding second branch); for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair can include: inserting one counter into each of the remaining first and second branch pairs; and inserting one counter into each of remaining branches among the first branches and the second branches can include: inserting one counter into a first branch without a corresponding second branch and / or a second branch without a corresponding first branch.
[0103] For example, there are four first branches, five second branches, of which three second branches have corresponding first branches among the four first branches, that is, there are three pairs of first and second branches. Inserting the counter can be done in following possible ways:1) for the three pairs of the first and the second branches, 4 counters are inserted into respective branches in the two pairs of first and second branches, so the second number is 4, and 1 counter is inserted into one pair of the first and the second branches (either in the first branch or the second branch); 1 counter is inserted into the remaining first branch without the corresponding second branch, and 2 counters are inserted into the remaining two second branches without the corresponding first branches, where the total number of counters inserted is 8, which is smaller than the total number of the first and the second branches of 9;2) for each of two pairs of the first and the second branches, 1 counter is inserted into one of one first branch and one corresponding second branch; 2 counters are inserted into the remaining pair of the first and the second branches (so the second number equals to 2), 1 counter is inserted into the remaining first branch without the corresponding second branch; and 2 counters are inserted into the remaining two second branches without the corresponding first branches, where the total number of counters inserted is 7, which is smaller than the total number of the first and the second branches of 9.
[0104] It also should be noted that the specific values such as 2, 3, 4 and 5 used fordescribing the first and second branches are just exemplary, other values may also be set for realizing the above purpose, which is not limited in the embodiments of the present disclosure.
[0105] Besides, it should be noted that although the above examples are illustrated by taking one cold path and one hot path as an example, the solution also applies to the case where there are multiple cold paths and / or multiple hot paths, when adopting the solution, the same principle applies.
[0106] In a possible implementation of the present disclosure, each of the first branches is inserted with one counter among the first number of counters. At least one of the second branches that has the corresponding first branch on the hot path is not inserted with a counter, and each second branch that does not have a corresponding first branch should be inserted a counter. In a possible implementation, as described above in connection with FIG. 2, the three first branches on the cold path, branch Rl, branch R2 and branch R3 are inserted with counter 1 , counter 2 and counter 3 respectively, and two second branches on the hot path are not inserted with the counter. It should be understood that this implementation is also applicable for the case where the number of the first branches on the one cold path is larger or smaller than that of the second branches on the one hot path, although the case where the number of the first branches on the one cold path is equal to that of the second branches on the one hot path is illustrated in this implementation.
[0107] In this way, by making instrumentation mostly on branches of the cold path of the function, the runtime overhead of instrumented version is reduced compared to that of non-instrumented. And this way also allows to use instrumentation-based profiling for high load applications, for which this kind of profiling was unsuitable before because of too large overhead.
[0108] In a possible implementation of the present disclosure, for each directed acyclic component of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters. During instrumentation phase, counters are inserted on the first branches on the cold path, onlyone counter per one directed acyclic component is inserted on the hot path. Continuing to refer to FIG. 2, only one second branch on the hot path is inserted with one counter, that is, only branch L3 on the hot path is inserted with counter 4, and each of the first branches on the cold path is inserted with the counter. It also should be understood that this implementation is also applicable for the case where the number of the first branches on the one cold path is larger or smaller than that of the second branches on the one hot path, although the case where the number of the first branches on the one cold path is equal to that of the second branches on the one hot path is illustrated in this implementation.
[0109] In a possible implementation of the present disclosure, each of the second branches is inserted with one counter among the first number of counters. At least one of the first branches that have the corresponding second branches on the cold path is not inserted with a counter, and each first branch that does not have a corresponding second branch should be inserted a counter.
[0110] In a possible implementation of the present disclosure, the method further includes: obtaining a minimal spanning tree (MST) for the program using a compiler; where performing instrumentation on the program based on the first profile data with the first number of counters includes: performing, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
[0111] In a possible implementation, after or at the same time when the first profile data is obtained, the compiler builds a control-flow graph (CFG) of a function of the program, then builds a minimal spanning tree (MST) based on the CFG, and performs, based on the first profile data and the MST, instrumentation on the program with the first number of counters.
[0112] In a possible implementation of the present disclosure, the method further includes: checking the first profile data with second profile data derived from the instrumentation, where the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
[0113] In a possible implementation of the present disclosure, the method further includes: performing profile-guided optimization (PGC) on the program based on the instrumentation.
[0114] In a possible implementation, firstly obtain the sample-based profile (which is also referred as the first profile data mentioned above), then perform instrumentation on the program of an application with the first profile data to get instrumentation-based profile data (which is also referred as the second profile data), where the second profile data can be verified against preliminary sample-based profile data to check the similarity between them. Then, preform profile-guided optimization on the program of the application with said instrumentation-based profile data, so as to get more optimized version of application.
[0115] FIG. 4 shows a schematic structural diagram of a data processing apparatus according to an embodiment of the present disclosure. As shown in FIG. 4, the data processing apparatus 400 may include: a performing module 401, configured to perform instrumentation on a program based on first profile data with a first number of counters, where the first profile data is indicative of at least one cold path and at least one hot path of the program, where the first number of counters are used for counting the number of times for which each of first branches on the at least one cold path is executed and the number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path.
[0116] In a possible implementation, where the performing module 401 is configured to: determine the at least one cold path and the at least one hot path of the program based on the first profile data; and insert the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
[0117] In a possible implementation, where the performing module 401 is furtherconfigured to: insert a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches, and for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, insert one counter for the each pair.
[0118] In a possible implementation, where the performing module 401 is further configured to: inserting one counter into each of remaining branches among the first branches and the second branches.
[0119] In a possible implementation, where each of the first branches is inserted with one counter among the first number of counters.
[0120] In a possible implementation, where for each directed acyclic component of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters.
[0121] In a possible implementation, where each of the second branches is inserted with one counter among the first number of counters.
[0122] In a possible implementation, where the apparatus further includes: a first obtaining module, configured to obtain the first profile data.
[0123] In a possible implementation, where the obtaining module is configured to: sample the program using a profiler to obtain the first profile data.
[0124] In a possible implementation, where the apparatus further includes: a second obtaining module, configured to obtain a minimal spanning tree (MST) for the program using a compiler; where the performing module is configured to: perform, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
[0125] In a possible implementation, where the apparatus further includes:a checking module, configured to check the first profile data with second profile data derived from the instrumentation, where the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
[0126] In a possible implementation, where the performing module 400 is further configured to: perform profile-guided optimization (PGC) on the program based on the instrumentation.
[0127] In a possible implementation, where the program is a C language program or a C++ language program with a load greater than a predefined value.
[0128] An embodiment of the present disclosure provides an electronic device including processing circuitry for executing any of the above data processing methods.
[0129] In a possible implementation, the electronic device may include a transceiver, a processor, and a memory. The memory may be configured to store code, instructions, and the like executed by the processor.
[0130] It should be understood that the processor may be an integrated circuit chip and has a signal processing capability. In an implementation process, steps of the foregoing method embodiments may be completed by using a hardware integrated logic circuit in the processor, or by using instructions in a form of software. The processor may be a general-purpose processor, a central processing unit (CPU), a graphics processing unit (GPU), a neural processing unit (NPU), a system on chip (SoC) or another programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. The processor may implement or perform the methods, the steps, and the logical block diagrams that are disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor, or the processor may be any conventional processor or the like. The steps of the methods disclosed with reference to the embodiments of the present application may be directly performed and completed by a hardware decoding processor, or may be performed and completed by using a combination of hardware in the decoding processor and a software module. The software module may be located in a mature storage medium in the art, such as a random-access memory, a flash memory, a read-only memory, aprogrammable read-only memory, an electrically erasable programmable memory, or a register. The storage medium is located in the memory, and the processor reads information in the memory and completes the steps of the foregoing methods in combination with hardware in the processor.
[0131] It may be understood that the memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both a volatile memory and a non-volatile memory. The non-volatile memory may be a readonly memory (Read-Only Memory, ROM), a programmable read-only memory (Programmable ROM, PROM), an erasable programmable read-only memory (Erasable PROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, EEPROM), or a flash memory. The volatile memory may be a random-access memory (Random Access Memory, RAM) and is used as an external cache. By way of example rather than limitation, many forms of RAMs may be used, and are, for example, a static random access memory (Static RAM, SRAM), a dynamic random access memory (Dynamic RAM, DRAM), a synchronous dynamic random access memory (Synchronous DRAM, SDRAM), a double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDR SDRAM), an enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), a synchronous link dynamic random access memory (Synchronous link DRAM, SLDRAM), and a direct rambus random access memory (Direct Rambus RAM, DR RAM).
[0132] It should be noted that the memory in the systems and the methods described in this specification includes but is not limited to these memories and a memory of any other appropriate type.
[0133] An embodiment of the present disclosure provides a chip, including an input / output (I / O) interface and a processor, wherein the processor is configured to call and run a computer program stored in a memory, to enable a device installing with the chip to perform any of the above data processing methods.
[0134] An embodiment of the present disclosure provides a computer-readablemedium storing computer execution instructions which, when executed by a processor, causes the processor to execute any of the above data processing methods.
[0135] Optionally, the storage medium may be specifically a memory.
[0136] An embodiment of the present disclosure provides a computer program product including computer execution instructions which, when executed by a processor, causes the processor to execute any of the above data processing methods.
[0137] A person of ordinary skill in the art may be aware that, in combination with the examples described in the embodiments disclosed in this specification, units and algorithm steps can be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed by hardware or software depends on particular applications and design constraints of the technical solutions. A person skilled in the art may use different methods to implement the described functions for each particular application, but it should not be considered that the implementation goes beyond the scope of this application.
[0138] It may be clearly understood by a person skilled in the art that, for the purpose of convenient and brief description, for a detailed working process of the foregoing system, apparatus, and unit, refer to a corresponding process in the foregoing method embodiment. Details are not described herein again.
[0139] In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the described apparatus embodiment is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented through some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms.
[0140] The units described as separate parts may be or may not be physically separate,and parts displayed as units may be or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected based on actual requirements to achieve the objectives of the solutions of the embodiments.
[0141] In addition, functional units in the embodiments of this application may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.
[0142] When the functions are implemented in a form of a software functional unit and sold or used as an independent product, the functions may be stored in a computer readable storage medium. Based on such an understanding, the technical solutions in this application essentially, or the part contributing to the prior art, or some of the technical solutions may be implemented in a form of a software product. The computer software product is stored in a storage medium, and includes several instructions for instructing a computer device (which may be a personal computer, a server, a network device, or the like) to perform all or some of the steps of the methods described in the embodiments of this application. The foregoing storage medium includes: any medium that can store program code, such as a USB flash drive, a removable hard disk, a readonly memory (Read-Only Memory, ROM), a random-access memory (Random Access Memory, RAM), a magnetic disk, or an optical disc.
[0143] The foregoing descriptions are merely specific implementations of this application, but are not intended to limit the protection scope of this application. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in this application shall fall within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the claims.
[0144] Although the present disclosure describes methods and processes with steps in a certain order, one or more steps of the methods and processes may be omitted or altered as appropriate. One or more steps may take place in an order other than that in which they are described, as appropriate.
[0145] Note that the expression “at least one of A or B”, as used herein, is interchangeable with the expression “A and / or B”. It refers to a list in which you may select A or B or both A and B. Similarly, “at least one of A, B, or C”, as used herein, is interchangeable with “A and / or B and / or C” or “A, B, and / or C”. It refers to a list in which you may select: A or B or C, or both A and B, or both A and C, or both B and C, or all of A, B and C. The same principle applies for longer lists having a same format.
[0146] Although the present disclosure is described, at least in part, in terms of methods, a person of ordinary skill in the art will understand that the present disclosure is also directed to the various components for performing at least some of the aspects and features of the described methods, be it by way of hardware components, software or any combination of the two. Accordingly, the technical solution of the present disclosure may be embodied in the form of a software product. A suitable software product may be stored in a pre-recorded storage device or other similar non-volatile or non-transitory computer readable medium, including DVDs, CD-ROMs, USB flash disk, a removable hard disk, or other storage media, for example. The software product includes instructions tangibly stored thereon that enable a processing device (e.g., a personal computer, a server, or a network device) to execute examples of the methods disclosed herein. The machine-executable instructions may be in the form of code sequences, configuration information, or other data, which, when executed, cause a machine (e.g., a processor or other processing device) to perform steps in a method according to examples of the present disclosure.
[0147] The present disclosure may be embodied in other specific forms without departing from the subject matter of the claims. The described example embodiments are to be considered in all respects as being only illustrative and not restrictive. Selected features from one or more of the above-described embodiments may be combined to create alternative embodiments not explicitly described, features suitable for such combinations being understood within the scope of this disclosure.
Claims
CLAIMS1. A data processing method, comprising: performing instrumentation on a program based on first profile data with a first number of counters, wherein the first profile data is indicative of at least one cold path and at least one hot path of the program, wherein the first number of counters are used for counting a number of times for which each of first branches on the at least one cold path is executed and a number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path.
2. The method according to claim 1, wherein performing instrumentation on the program based on the first profile data with the first number of counters comprises: determining the at least one cold path and the at least one hot path of the program based on the first profile data; and inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
3. The method according to claim 2, wherein inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path comprises: inserting a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches; and for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, inserting one counter for the each pair.
4. The method according to claim 3, wherein inserting the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path further comprises: inserting one counter into each of remaining branches among the first branchesand the second branches.
5. The method according to claim 4, wherein each of the first branches is inserted with one counter among the first number of counters.
6. The method according to claim 5, wherein for each directed acyclic component of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters.
7. The method according to claim 4, wherein each of the second branches is inserted with one counter among the first number of counters.
8. The method according to any one of claims 1 to 7, further comprising: obtaining the first profile data.
9. The method according to claim 8, wherein obtaining the first profile data comprises: sampling the program using a profiler to obtain the first profile data.
10. The method according to any one of claims 1 to 9, further comprising: obtaining a minimal spanning tree (MST) for the program using a compiler; wherein performing instrumentation on the program based on the first profile data with the first number of counters comprises: performing, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
11. The method according to any one of claims 1 to 10, further comprising: checking the first profile data with second profile data derived from the instrumentation, wherein the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
12. The method according to any one of claims 1 to 11, further comprising: performing profile-guided optimization (PGC) on the program based on the instrumentation.
13. The method according to any one of claims 1 to 12, wherein the program is a C language program or a C++ language program with a load greater than a predefined value.
14. A data processing apparatus, comprising: a performing module, configured to perform instrumentation on a program based on first profile data with a first number of counters, wherein the first profile data is indicative of at least one cold path and at least one hot path of the program, wherein the first number of counters are used for counting a number of times for which each of first branches on the at least one cold path is executed and a number of times for which each of second branches on the at least one hot path is executed, and the first number is smaller than a total number of the first branches on the at least one cold path and the second branches on the at least one hot path.
15. The apparatus according to claim 14, wherein the performing module is configured to: determine the at least one cold path and the at least one hot path of the program based on the first profile data; and insert the first number of counters into the first branches on the at least one cold path and the second branches on the at least one hot path.
16. The apparatus according to claim 15, wherein the performing module is further configured to: insert a second number of counters into at least one of the second branches and at least one first branch corresponding to the at least one of the second branches, and for each pair of at least one remaining first branch and at least one second branch corresponding to the at least one remaining first branch, insert one counter for the each pair.
17. The apparatus according to claim 16, wherein the performing module is further configured to: insert one counter into each of remaining branches among the first branches and the second branches.
18. The apparatus according to claim 17, wherein each of the first branches is inserted with one counter among the first number of counters.
19. The apparatus according to claim 18, wherein for each directed acycliccomponent of the program, one counter is inserted into a second branch, and other second branches are skipped of being inserted with counters.
20. The apparatus according to claim 17, wherein each of the second branches is inserted with one counter among the first number of counters.
21. The apparatus according to any one of claims 14 to 20, further comprising: a first obtaining module, configured to obtain the first profile data.
22. The apparatus according to claim 21, wherein the obtaining module is configured to: sample the program using a profiler to obtain the first profile data.
23. The apparatus according to any one of claims 14 to 22, further comprising: a second obtaining module, configured to obtain a minimal spanning tree (MST) for the program using a compiler; wherein the performing module is configured to: perform, based on the first profile data and the MST, instrumentation on the program with the first number of counters using the compiler.
24. The apparatus according to any one of claims 14 to 23, further comprising: a checking module, configured to check the first profile data with second profile data derived from the instrumentation, wherein the second profile data is indicative of the at least one cold path and the at least one hot path of the program.
25. The apparatus according to any one of claims 14 to 24, wherein the performing module is further configured to: perform profile-guided optimization (PGC) on the program based on the instrumentation.
26. The apparatus according to any one of claims 14 to 25, wherein the program is a C language program or a C++ language program with a load greater than a predefined value.
27. An electronic device, comprising processing circuitry for executing the method according to any one of claims 1 to 14.
28. A chip, comprising an input / output (I / O) interface and a processor, wherein theprocessor is configured to call and run a computer program stored in a memory, to enable a device installing with the chip to perform the method according to any one of claims 1 to 14.
28. A computer-readable medium storing computer execution instructions which, when executed by a processor, causes the processor to execute the method according to any one of claims 1 to 14.
29. A computer program product comprising program code for performing the method according to any one of claims 1-14.