Tracking data generation method and device and electronic equipment

By calculating the time difference between function calls and return type branch instructions, trace data is generated only when the difference exceeds a threshold, solving the problem of excessive trace data volume and improving the efficiency and availability of performance analysis.

CN121934894APending Publication Date: 2026-04-28LOONGSON TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LOONGSON TECH CORP
Filing Date
2025-12-05
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

In existing technologies, the amount of trace data generated during program execution is too large, resulting in low efficiency of performance analysis.

Method used

By recording instruction-related information of branch instructions submitted by the processor and calculating the time difference between branch instructions of function call type and branch instructions of function return type, trace data is generated only when the time difference is not less than a preset threshold, so as to filter trace data related to short leaf functions.

Benefits of technology

This effectively reduces the total amount of tracking data, improves the efficiency of performance analysis, and ensures that analysts focus on functions with longer execution times and greater performance impact.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121934894A_ABST
    Figure CN121934894A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a trace data generation method and device and electronic equipment, and relates to the technical field of processors, in the method, a branch instruction submitted by a processor serves as a first branch instruction, and under the condition that the branch type of the first branch instruction is a function call type, instruction related information of the first branch instruction is recorded. And taking a next branch instruction submitted by the processor after the first branch instruction as a second branch instruction, and under the condition that the branch type of the second branch instruction is a function return type, calculating a difference value between the time-related information of the second branch instruction and the time-related information of the first branch instruction as a time information difference. And under the condition that the time information difference is not smaller than a preset time threshold value, generating corresponding tracking data for the first branch instruction based on the instruction related information of the first branch instruction, and generating corresponding tracking data for the second branch instruction based on the instruction related information of the second branch instruction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of processor technology, and in particular to a method, apparatus and electronic device for generating tracking data. Background Technology

[0002] Currently, in order to optimize the program, performance analysis is required. Accordingly, it is necessary to obtain trace data generated during program execution to facilitate performance analysis based on this data.

[0003] In related technologies, trace data is often generated directly based on the instruction information of each branch instruction submitted by the processor during program execution. This approach suffers from the problem of generating excessively large amounts of trace data. Summary of the Invention

[0004] This invention provides a tracking data generation method, apparatus, and electronic device that can solve the problem of excessively large amounts of generated tracking data.

[0005] To address the aforementioned problems, this invention discloses a tracking data generation method, the method comprising: The branch instruction submitted by the processor is taken as the first branch instruction, and if the branch type of the first branch instruction is a function call type, the instruction-related information of the first branch instruction is recorded. The next branch instruction submitted by the processor after the first branch instruction is taken as the second branch instruction. If the branch type of the second branch instruction is a function return type, the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction is calculated as the time information difference. The first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call. When the time information difference is not less than a preset time threshold, corresponding tracking data is generated for the first branch instruction based on the instruction-related information of the first branch instruction, and corresponding tracking data is generated for the second branch instruction based on the instruction-related information of the second branch instruction.

[0006] On the other hand, embodiments of the present invention disclose a tracking data generation apparatus, the apparatus comprising: The first processing module is used to take the branch instruction submitted by the processor as the first branch instruction, and when the branch type of the first branch instruction is a function call type, record the instruction-related information of the first branch instruction. The second processing module is used to take the next branch instruction submitted by the processor after the first branch instruction as the second branch instruction, and when the branch type of the second branch instruction is a function return type, calculate the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction as the time information difference; the first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call; The first generation module is configured to generate corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, and to generate corresponding tracking data for the second branch instruction based on the instruction-related information of the second branch instruction, provided that the time information difference is not less than a preset time threshold.

[0007] In another aspect, embodiments of the present invention disclose an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, the executable instruction causing the processor to execute the aforementioned method.

[0008] This invention also discloses a machine-readable medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described above.

[0009] The embodiments of the present invention have the following advantages: In the trace data generation method provided by the embodiments of the present invention, the branch instruction submitted by the processor is taken as the first branch instruction, and when the branch type of the first branch instruction is a function call type, the instruction-related information of the first branch instruction is recorded. The next branch instruction submitted by the processor after the first branch instruction is taken as the second branch instruction, and when the branch type of the second branch instruction is a function return type, the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction is calculated as the time information difference; the first branch instruction of function call type is used to call the function, and the second branch instruction of function return type is used to end the function call. When the time information difference is not less than a preset time threshold, corresponding trace data is generated for the first branch instruction based on the instruction-related information of the first branch instruction, and corresponding trace data is generated for the second branch instruction based on the instruction-related information of the second branch instruction. In the embodiments of the present invention, when the time information difference between the successively submitted function call type branch instruction and function return type branch instruction is not less than the preset time threshold, corresponding trace data is generated for this pair of branch instructions. In this way, the number of generated trace data can be reduced, thereby reducing the overall data volume of trace data and avoiding the problem of excessively large trace data volume. Attached Figure Description

[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a flowchart of the steps of a tracking data generation method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a processing flow provided in an embodiment of the present invention; Figure 3 This is a schematic diagram illustrating the implementation of a hardware tracking branch recording device provided in an embodiment of the present invention; Figure 4 This is a block diagram of a tracking data generation device provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] Figure 1 This is a flowchart of the steps of a tracking data generation method provided in an embodiment of the present invention, as follows: Figure 1 As shown, the tracking data generation method may include the following steps: Step 101: Take the branch instruction submitted by the processor as the first branch instruction, and if the branch type of the first branch instruction is a function call type, record the instruction-related information of the first branch instruction.

[0014] Step 102: The next branch instruction submitted by the processor after the first branch instruction is taken as the second branch instruction. If the branch type of the second branch instruction is a function return type, the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction is calculated as the time information difference. The first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call.

[0015] Step 103: If the time information difference is not less than a preset time threshold, generate corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, and generate corresponding tracking data for the second branch instruction based on the instruction-related information of the second branch instruction.

[0016] The tracking data generation method provided in this invention can be applied to electronic devices, specifically to a tracking data generation device within an electronic device. This tracking data generation device can also be called a hardware tracking branch recording device, which can be located within a processor. This tracking data generation method can be executed during program execution, and the program can be any program under test within the electronic device. The program under test can include functions containing multiple instructions, and execution of the program under test is achieved by executing the instructions within the program under test. During execution, the processor can submit instructions to be tracked, such as branch instructions. The processor can submit the currently executed branch instructions to the hardware tracking branch recording device. It should be noted that the instructions to be tracked may include non-branch instructions; therefore, for instructions submitted by the processor, it can be first determined whether the instruction is a branch instruction.

[0017] For a branch instruction submitted by the processor, this branch instruction can be used as the first branch instruction. Combining this first branch instruction with its next branch instruction (i.e., the second branch instruction), it is determined whether to generate corresponding trace data for these two branch instructions. The second branch instruction can be the next branch instruction submitted after the first one. Specifically, branch instructions can also be called branch type instructions, which change the control flow of program execution. For example, the branch type of a branch instruction can include function call type, function return type, indirect jump type, unconditional jump type, conditional jump type, unconditional loop type, and conditional loop type, etc. Since the function call type corresponds to a single function call (i.e., the branch type is executed when the function is called), and the function return type corresponds to the end of the called function's execution (i.e., the branch type is executed when the called function finishes executing), the branch type ends the current function call. Therefore, in this embodiment of the invention, the time information difference between the second branch instruction and the first branch instruction is calculated only when the branch type of the first branch instruction is a function call type and the branch type of the second branch instruction is a function return type. This ensures that the calculated time information difference can accurately measure the execution time of the called function, thereby ensuring that the trace data of functions with shorter execution times can be filtered. Instruction-related information includes information required to generate trace data. The types of information included in the instruction-related information can be set according to actual needs, and this embodiment of the invention does not impose any limitations on this. For example, instruction-related information may include instruction type, timestamp, branch instruction program pointer, target address, offset address, and performance counter information. The performance counter information may be the current value of a specified performance counter.

[0018] The instruction information for the first branch instruction is submitted by the processor when committing the first branch instruction. This instruction information includes time-related information for the first branch instruction. Specifically, after the first branch instruction is executed, the processor sends the first branch instruction and its instruction information to the hardware branch tracking device to complete the commit. Similarly, the instruction information for the second branch instruction is submitted by the processor when committing the second branch instruction. This instruction information includes time-related information for the second branch instruction. Likewise, after the second branch instruction is executed, the processor sends the second branch instruction and its instruction information to the hardware branch tracking device to complete the commit. The first and second branch instructions can be any branch instruction in the program under test.

[0019] The system can track the branch instructions submitted by the processor, determining whether the instruction type in the instruction information of the first branch instruction is a function call type. If so, the instruction information of the first branch instruction can be temporarily stored in an information register for recording. Simultaneously, the timing information of the first branch instruction can also be recorded. Then, the system continues to track subsequent branch instructions submitted by the processor. For the submitted second branch instruction, it determines whether the instruction type in the instruction information of the second branch instruction is a function return type. If it is a function return type, the difference between the timing information of the second branch instruction and the timing information of the first branch instruction can be calculated as the timing information difference.

[0020] In this system, the first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call. That is, the first branch instruction of the function call type and the second branch instruction of the function return type correspond to one execution process of the called function. The time-related information of the instructions reflects the instruction submission time, and the preset time threshold is the threshold corresponding to the time information difference. Accordingly, the difference between the time-related information of the instructions can characterize the instruction submission time difference. If the difference between the time-related information of the second branch instruction and that of the first branch instruction is larger, it indicates a larger instruction submission time difference, which means a longer execution time for the called function corresponding to the branch instruction. If the difference between the time-related information is smaller, it indicates a smaller instruction submission time difference, which means a shorter execution time for the called function corresponding to the branch instruction.

[0021] Optionally, time-related information can be a timestamp at the time of instruction submission, the number of processor clock cycles, or a performance counter value. The timestamp at the time of instruction submission can directly represent the instruction submission time; for example, the value of a timer at the time of instruction submission can be used as the timestamp. Correspondingly, the difference between time-related information is the instruction submission time difference itself, and the preset time threshold can be a preset timestamp difference threshold. A larger number of processor clock cycles at the time of instruction submission indicates a later instruction submission time; therefore, the number of processor clock cycles at the time of instruction submission can characterize the instruction submission time. Correspondingly, the difference between time-related information is the difference between the number of processor clock cycles; the preset time threshold can be a preset clock cycle difference threshold. A larger difference between the number of processor clock cycles indicates a larger instruction submission time difference. Furthermore, a larger performance counter value at the time of instruction submission indicates a later instruction submission time; therefore, the performance counter value at the time of instruction submission can characterize the instruction submission time. Correspondingly, the difference between time-related information is the difference between the performance counter values; the preset time threshold can be a preset performance counter value difference threshold. A larger difference between the performance counter values ​​indicates a larger instruction submission time difference. This provides multiple implementation methods. In addition to determining whether to generate corresponding trace data based on the timestamp, it can also determine whether to generate corresponding trace data based on the number of processor clock cycles and the performance counter value, thus providing greater flexibility.

[0022] Furthermore, the preset time threshold can be pre-set by the user according to their needs. If the time difference between the current pair of branch instructions is less than the preset time threshold, it indicates that the pair of branch instructions are branch instructions corresponding to a short leaf function. That is, these two branch instructions are the branch instructions executed when calling the short leaf function and when execution ends. Here, a short leaf function refers to a leaf function whose time difference between the corresponding pair of branch instructions is less than the preset time threshold. In other words, in this embodiment of the invention, if the time difference between a function call type branch instruction and a function return type branch instruction is less than the preset time threshold, it indicates that the called function is a short leaf function. The corresponding pair of branch instructions includes a function call type branch instruction and a function return type branch instruction. In this embodiment of the invention, if the time interval between the function return type branch instruction and the function call type branch instruction corresponding to the short leaf function is less than the preset time threshold, no corresponding trace data is generated. The preset time threshold can be regarded as a pre-specified leaf function execution time threshold, which can characterize the minimum execution time of the leaf function that generates trace data. Trace data is only generated for these two branch instructions if the time information difference is not less than a preset time threshold, i.e., if the called function corresponding to the current two branch instructions (function call type branch instruction and function return type branch instruction) is not a short leaf function. This effectively filters trace data related to short leaf functions from the final trace data, allowing the filtered leaf functions to be included in other larger code segments for analysis, thus reducing unimportant trace data.

[0023] Specifically, leaf functions are functions that do not allocate stack space, call other functions, store non-volatile registers, or perform exception handling. Because leaf functions have short execution times, they have little impact on the overall program performance. In this embodiment of the invention, by not generating corresponding trace data for the branch instructions corresponding to short leaf functions, analysts can ignore short leaf functions in subsequent performance analysis based on the trace data, allowing them to focus only on functions with longer execution times and greater performance impact. Furthermore, since there are many short leaf functions in a program, they typically generate a large amount of trace data. Therefore, filtering out trace data related to unimportant short leaf functions can effectively reduce the amount of trace data.

[0024] Furthermore, the instruction-related information of the first branch instruction can be used as the trace data corresponding to the first branch instruction to generate corresponding trace data for the first branch instruction. Similarly, the instruction-related information of the second branch instruction can be used as the trace data corresponding to the second branch instruction to generate corresponding trace data for the second branch instruction. This achieves the purpose of recording the relevant information of branch instructions during program execution. The trace data can ultimately be written to a designated memory buffer, which is a specially allocated memory buffer for storing trace data. Accordingly, the trace data for these branch instructions is recorded sequentially in the memory buffer. It should be noted that in this embodiment of the invention, the branch instruction can be an instruction from any instruction set architecture, and this embodiment of the invention does not impose any limitations on this. Alternatively, the received branch instruction itself can be temporarily stored, and the instruction-related information of the branch instruction, along with the branch instruction itself, can be used as the trace data corresponding to that branch instruction.

[0025] In summary, the tracking data generation method provided in this embodiment of the invention uses the branch instruction submitted by the processor as the first branch instruction, and records the instruction-related information of the first branch instruction when the branch type of the first branch instruction is a function call type. The next branch instruction submitted by the processor after the first branch instruction is used as the second branch instruction, and calculates the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction when the branch type of the second branch instruction is a function return type, as the time information difference. The first branch instruction of function call type is used to call the function, and the second branch instruction of function return type is used to end the function call. When the time information difference is not less than a preset time threshold, corresponding tracking data is generated for the first branch instruction based on the instruction-related information of the first branch instruction, and corresponding tracking data is generated for the second branch instruction based on the instruction-related information of the second branch instruction. In this embodiment of the invention, corresponding tracking data is only generated for this pair of branch instructions when the time information difference between the successively submitted function call type branch instructions and function return type branch instructions is not less than a preset time threshold. This reduces the number of generated tracking data, thereby reducing the overall data volume of the tracking data and avoiding the problem of excessively large tracking data volume.

[0026] In this embodiment of the invention, tracking data related to short leaf functions can be further filtered using the tracking data generation method provided in this embodiment, based on other tracking data filtering mechanisms. Specifically, it can be detected whether the branch instruction is a branch instruction that needs to be filtered in the tracking data filtering mechanism. If so, corresponding tracking data is not generated for that branch instruction, thus achieving filtering according to the tracking data filtering mechanism. If not, corresponding tracking data can be generated for that branch instruction only when the tracking data generation method provided in this embodiment determines that corresponding tracking data needs to be generated for that branch instruction.

[0027] Optionally, before the step of generating corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, the present invention embodiment further includes the following steps: Step S21: Determine whether the privilege level of the first branch instruction is a preset filtering level, and determine whether the branch type of the first branch instruction is a preset filtering type.

[0028] Accordingly, the step of generating corresponding trace data for the first branch instruction based on the instruction-related information of the first branch instruction may specifically include: step 1031, if the privilege level of the first branch instruction is not the filtering level and the branch type of the first branch instruction is not the filtering type, then generating corresponding trace data for the first branch instruction based on the instruction-related information of the first branch instruction.

[0029] Before the step of generating corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction, the present invention embodiment further includes the following steps: Step S22: Determine whether the privilege level of the second branch instruction is the filtering level, and determine whether the branch type of the second branch instruction is the filtering type.

[0030] Accordingly, the step of generating corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction may specifically include: step 1032, if the privilege level of the second branch instruction is not the filtering level and the branch type of the second branch instruction is not the filtering type, then generating corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction.

[0031] Filtering based on preset filter levels can be considered a tracking data filtering mechanism. By disabling specific privilege levels, security can be ensured. Filtering based on preset filter types can also be considered a tracking data filtering mechanism. Thus, filtering by branch type and privilege level can effectively reduce tracking data. Further filtering of tracking data related to short leaf functions can further reduce tracking data.

[0032] Specifically, when privilege level filtering is enabled, it can determine whether the privilege level of the branch instructions (the first and second branch instructions mentioned above) is a preset filtering level, that is, whether it is a branch instruction that needs to be filtered in the filtering mechanism based on the filtering level. When type filtering is enabled, it can determine whether the branch type of the branch instructions (the first and second branch instructions mentioned above) is a preset filtering type, that is, whether it is a branch instruction that needs to be filtered in the filtering mechanism based on the filtering type.

[0033] The preset filtering level can be the privilege level of branch instructions that do not require trace data generation. Privilege levels can include kernel mode, user mode, and virtualization mode. If the branch instruction is in kernel code, its privilege level is determined to be kernel mode; if it is in user code, its privilege level is determined to be user mode; and if it is in virtualization code, its privilege level is determined to be virtualization mode. For any privilege level, disabling it will set it as the filtering level. The preset filtering type can be the instruction type of branch instructions that do not require trace data generation. The filtering level and type can be preset by the user according to actual needs. For any branch type, disabling it will set it as the filtering type. For example, the Last Branch Record (LBR) select register can provide fields corresponding to each privilege level and branch type. Setting a field to 1 enables the corresponding privilege level or branch type. Setting a field to 0 disables the corresponding privilege level or branch type.

[0034] Accordingly, if the field corresponding to the privilege level of a branch instruction is 0, it can be determined that the privilege level of the branch instruction is a preset filtering level; otherwise, it can be determined that the privilege level of the branch instruction is not a preset filtering level. Similarly, if the field corresponding to the branch type of a branch instruction is 0, it can be determined that the branch type of the branch instruction is a preset filtering type; otherwise, it can be determined that the branch type of the branch instruction is not a preset filtering type.

[0035] If the privilege level of the first branch instruction is a filtering level or the branch type of the first branch instruction is a filtering type, then corresponding trace data can be generated for the first branch instruction without relying on its instruction-related information, thus achieving filtering. Conversely, if the privilege level of the first branch instruction is not a filtering level and the branch type of the first branch instruction is not a filtering type, then corresponding trace data will be generated for the first branch instruction based on its instruction-related information only if the time information difference is not less than a preset time threshold.

[0036] If the privilege level of the second branch instruction is a filtering level or the branch type of the second branch instruction is a filtering type, then corresponding trace data can be generated for the second branch instruction without relying on its instruction-related information, thus achieving filtering. Conversely, if the privilege level of the second branch instruction is not a filtering level and the branch type of the second branch instruction is not a filtering type, then corresponding trace data will be generated for the second branch instruction based on its instruction-related information only if the time information difference is not less than a preset time threshold.

[0037] Optionally, the preset time threshold is pre-stored in the threshold storage bit of a designated register via a preset register write command. Accordingly, embodiments of the present invention may further include the following steps: Step S31: Based on the preset register read command, read the value of the threshold storage bit of the specified register.

[0038] Step S32: Determine the value of the threshold storage bit read as the preset time threshold.

[0039] The designated register can be a configuration register supported by the instruction set architecture followed by the program under test. This designated register can be selected from reserved registers of that instruction set architecture and is used to configure a preset time threshold. The preset time threshold can be configured by pre-writing a threshold to the threshold storage bits of the designated register using software code that configures the designated register, employing a preset register write command. The threshold storage bits, also known as leaf function filtering threshold bits, can be used to store the time threshold filtered by the leaf functions, i.e., the aforementioned preset time threshold. The threshold storage bits can be n bits, where n can be set according to the length of the required threshold to ensure that the threshold storage bits can accommodate the required threshold.

[0040] The preset register write and read commands can be any write and read commands supported by the instruction set architecture. For example, the preset register write command can be the `csrwr` or `csrxchg` command, and the preset register read command can be the `csrrd` command. Furthermore, when it is necessary to compare the time information difference with a preset time threshold, a preset register read command can be used to read the current value of the threshold storage bit from a specified register as the preset time threshold.

[0041] In this embodiment of the invention, a preset time threshold can be configured by writing a threshold value into the threshold storage bit of a specified register in advance using a preset register write command. Subsequently, the preset time threshold can be determined by reading the threshold storage bit of the specified register using a register read command. The configuration and determination of the threshold are relatively convenient, thus resulting in higher processing efficiency.

[0042] Optionally, the designated register further includes a function enable bit. Accordingly, embodiments of the present invention may further include the following steps: Step S41: Based on the register read command, read the value of the function enable bit of the specified register.

[0043] Step S42: If the value of the function enable bit indicates that it is not enabled, then the corresponding trace data is generated directly for the branch instruction based on the instruction-related information of the branch instruction.

[0044] Accordingly, the step of using the branch instruction submitted by the processor as the first branch instruction can specifically include: Step 1011: If the value of the function enable bit indicates that the function is enabled, then the branch instruction submitted by the processor is taken as the first branch instruction.

[0045] The function enable bit can be 1 bit. This bit, also known as the leaf function filtering enable bit, enables the leaf function filtering function for branch records. When enabled, the operation of treating the processor-submitted branch instruction as the first branch instruction can be executed, allowing for determination based on a preset time threshold whether to generate corresponding trace data for the first and second branch instructions. When disabled, the operation of treating the processor-submitted branch instruction as the first branch instruction is not executed, meaning the determination of whether to generate corresponding trace data for the first and second branch instructions is not based on the preset time threshold. This allows users to flexibly control whether filtering is performed based on a preset time threshold, improving the flexibility of the solution. It should be noted that in another implementation, the leaf function filtering function can be enabled by default, i.e., step 101 is executed by default. This embodiment of the invention does not impose any restrictions on this.

[0046] The function enable bit of a specified register can be configured by pre-writing a value to it using a preset register write command. For example, a 0 or a 1 can be written to the function enable bit. The specified register, also known as the leaf function filtering mechanism related configuration register, can include the register bits described in Table 1 below:

[0047] Table 1 The leaf function filtering enable bit and the leaf function filtering threshold bit can be located in the same register, and they do not overlap. For example, the designated register can be a 64-bit register, the leaf function filtering enable bit can be bit 64 of the designated register, and the leaf function filtering threshold bits can be bits 47 to 63 of the designated register. Specifically, a preset register read command can be used to read the value of the function enable bit from the designated register. If the value of the function enable bit indicates that it is not enabled, it can be determined that the leaf function filtering mechanism is not currently enabled. That is, execution does not need to start from the step where the branch instruction submitted by the processor is used as the first branch instruction; instead, the corresponding trace data can be generated directly based on the instruction information of the branch instruction. If the value of the function enable bit indicates that it is enabled, it can be determined that the leaf function filtering mechanism is currently enabled. That is, execution starts from the step where the branch instruction submitted by the processor is used as the first branch instruction, so as to determine whether to generate trace data based on whether the time information difference is not less than a preset time threshold. In other words, in this embodiment of the invention, specifically, when the leaf function filtering mechanism is enabled and the time information difference between a branch instruction of function return type and a branch instruction of function call type is less than a preset time threshold, corresponding trace data is not generated for these two branch instructions. Specifically, when the function enable bit is 0, it is determined that the function enable bit indicates that it is not enabled. When the function enable bit is 1, it is determined that the function enable bit indicates that it is enabled.

[0048] In this embodiment of the invention, the value of the function enable bit of a specified register is read based on a register read command. If the value of the function enable bit indicates that the function is disabled, corresponding trace data is directly generated for the branch instruction based on the instruction-related information of the branch instruction. If the value of the function enable bit indicates that the function is enabled, the branch instruction submitted by the processor is used as the first branch instruction. In this way, by configuring the value of the function enable bit of a specified register, it is possible to conveniently control whether the leaf function filtering mechanism is enabled.

[0049] Optionally, embodiments of the present invention may further include the following steps: Step S51: If the time information difference is less than the preset time threshold, do not generate corresponding tracking data for the first branch instruction and the second branch instruction.

[0050] Step S52: If the preset termination condition has not been met, return to the step of taking the branch instruction submitted by the processor as the first branch instruction and continue execution.

[0051] In this embodiment of the invention, when the time information difference is less than a preset time threshold, the relevant information of the first branch instruction and the second branch instruction can be directly discarded. For example, the temporarily stored instruction-related information and the time information difference calculated for these two branch instructions can be discarded, and corresponding tracking data cannot be generated for the first branch instruction and the second branch instruction. Furthermore, the preset termination condition can include all instructions of the program under test being executed, i.e., the program under test has completed execution. In other words, after executing step 103 or step S51, if there are still instructions that have not been executed, meaning the preset termination condition has not yet been met, subsequent branch instructions submitted by the processor can be used as new first branch instructions, and execution can restart from step 101 until the program under test has completed execution. It should be noted that the above trace data generation method can also end if the branch record configuration is modified, for example, by changing the function enable bit to 0 or disabling the leaf function filtering function.

[0052] In this embodiment of the invention, if the time information difference is less than a preset time threshold, corresponding trace data is not generated for the first branch instruction and the second branch instruction. If the preset termination condition has not been met, execution returns to the step of treating the branch instruction submitted by the processor as the first branch instruction. In this way, it is possible to continuously determine whether to generate corresponding trace data for branch instructions based on the preset time threshold during the execution of the program under test, thereby ensuring the filtering effect.

[0053] Optionally, embodiments of the present invention may further include the following steps: Step S61: If the branch type of the second branch instruction is not a function return type, generate corresponding trace data for the target instruction based on the instruction-related information of the target instruction; the target instruction includes the first branch instruction, the second branch instruction, the function return instruction corresponding to the first branch instruction, and other instructions, wherein the other instructions are instructions submitted by the processor after the second branch instruction and before the function return instruction.

[0054] In this embodiment of the invention, if the branch type of the first branch instruction is a function call type, but the branch type of the second branch instruction is not a function return type, it indicates that there are other instructions submitted by the processor between the first branch instruction and the function return instruction corresponding to the first branch instruction (including the current second branch instruction and instructions submitted after the second branch instruction and before the function return instruction). The function return instruction corresponding to the first branch instruction refers to a branch instruction of the function return type executed after the function called by the first branch instruction has been executed. The destination address of the function return instruction corresponding to the first branch instruction is the address of the next instruction after the first branch instruction.

[0055] If the next branch instruction submitted after a function call type branch instruction is not a function return type branch instruction, then it can be determined that the current condition does not meet the leaf function filtering requirement. Therefore, corresponding trace data can be directly generated for the function call type branch instruction (i.e., the current first branch instruction), the second branch instruction, the instruction submitted after the second branch instruction and before the function return instruction corresponding to the first branch instruction, and the function return instruction itself. For example, suppose the first branch instruction is a function call type branch instruction (instruction a), and the second branch instruction is a conditional jump instruction (instruction b). After receiving instruction b, the processor submits an indirect jump instruction (instruction c) and its related instruction information. After receiving instruction c, the processor submits a function return instruction (instruction d) and its related instruction information. Then, instruction c is the instruction submitted by the processor after the second branch instruction and before the function return instruction. Accordingly, instructions a, b, c, and d can be used as target instructions. For any target instruction, based on its related instruction information, corresponding trace data can be generated. The related instruction information of the target instruction and the target instruction itself can be used as the trace data corresponding to the target instruction to generate corresponding trace data for that target instruction. It should be noted that after executing step S61, if there are instructions that have not yet been executed, that is, if the preset termination condition has not been met, the subsequent branch instructions submitted by the processor can be used as the new first branch instructions, and execution can start again from step 101 above until the program under test is completed.

[0056] In this embodiment of the invention, when the branch type of the second branch instruction is not a function return type, corresponding trace data is directly generated for the target instruction based on the instruction-related information of the target instruction. This avoids filtering out the corresponding trace data when there are other instructions between the function call and return, thereby ensuring that subsequent analysts can detect situations where there are other instructions between the function call and return.

[0057] It should be noted that, in one implementation, the processor can generate corresponding trace data for branch instructions by default; in another implementation, the processor can set a branch recording mechanism enable bit. When this enable bit is set to a valid value (e.g., set to 1), the branch recording mechanism is enabled. Specifically, in this embodiment of the invention, the above-described trace data generation method can be executed when the processor's branch recording mechanism is enabled. Enabling the branch recording mechanism refers to enabling the function of generating corresponding trace data for branch instructions.

[0058] Figure 2 This is a schematic diagram of a processing flow provided by an embodiment of the present invention, such as... Figure 2 As shown, this processing flow can be implemented through both software and hardware in an electronic device. Specifically, the software can first configure preset time thresholds, enable leaf function filtering for branch records, and configure the branch record mechanism. Of course, in practical applications, other branch record configurations can be performed, such as configuring preset filtering levels and preset filtering types. Next, the program under test can be run through software for performance analysis. Then, the branch instruction submission operation is executed through hardware; for example, the processor can submit branch instructions and related information. The hardware then uses this branch instruction as the first branch instruction, such as... Figure 2 As shown, it can be determined whether the branch type of the first branch instruction is a function call type. Specifically, if it is not a function call type, corresponding trace data can be directly generated for the first branch instruction. Then, the first branch instruction can be updated to the newly submitted branch instruction by the processor, and execution continues from the point where it was determined whether the branch type of the first branch instruction is a function call type. If it is a function call type, the first branch instruction and its related information can be temporarily stored. Then, it is determined whether the branch type of the second branch instruction is a function return type, and whether the time difference between the second branch instruction and the first branch instruction is less than a preset time threshold. If these conditions are met, corresponding trace data does not need to be generated. If not, leaf function filtering is not required, and corresponding trace data can be generated.

[0059] It should be noted that when the leaf function filtering function is not enabled, corresponding trace data can be directly generated for branch instructions. For the second branch instruction, it can first be determined whether the branch type of the second branch instruction is a function return type. If so, it can be further determined whether the time information difference between the second branch instruction and the first branch instruction is less than a preset time threshold. If so, the leaf function filtering mechanism is satisfied, and corresponding trace data is not generated, thus filtering this pair of function call and function return instructions. Furthermore, hardware can be used to repeatedly execute until a preset termination condition is reached, such as the completion of the program under test or the modification of the branch record configuration. When the preset termination condition is reached, hardware tracing branch records can be disabled via software, i.e., the trace data generation function can be turned off, and the trace data can be exported.

[0060] Furthermore, the hardware tracing branch recording device may include the hardware and software required to implement the filtering of tracing data related to short leaf functions. For example, it may include the aforementioned designated register, software for configuring the designated register, software for implementing the aforementioned tracing data generation method, and hardware components required to run the aforementioned tracing data generation method.

[0061] Figure 3 This is a schematic diagram illustrating the implementation of a hardware tracking branch recording device provided in an embodiment of the present invention, as shown below. Figure 3 As shown, the hardware tracing branch recording device may include branch type judgment logic, timestamp difference logic, leaf function filtering judgment logic, instruction information temporary register, tracing data generator, and tracing data storage buffer. The branch type judgment logic, timestamp difference logic, and leaf function filtering judgment logic can be the circuit structure of the hardware tracing branch recording device, and the temporary register can be a memory with storage function, such as a register.

[0062] The processor's commit logic can commit branch instructions and their instruction-related information to the instruction information register. Furthermore, it can commit the instruction type to the branch type determination logic and the time-related information of the branch instruction to the timestamp difference logic, such as the timestamp at the time of instruction commit and the performance counter value at the time of instruction commit. The instruction-related information includes both the instruction type and time-related information. Correspondingly, the branch type determination logic can also retrieve the instruction type from the instruction information register, and the instruction information register can submit the time-related information to the timestamp difference logic. Alternatively, the processor's timer or performance counter can submit the time-related information of the branch instruction to the timestamp difference logic; this embodiment of the invention does not limit this approach.

[0063] Furthermore, the branch type judgment logic determines whether the branch type of the first branch instruction is a function call type and whether the branch type of the second branch instruction is a function return type. The trace data generator generates trace data, and the leaf function filtering judgment logic can determine whether the branch type of the first branch instruction is a function call type based on the judgment result submitted by the branch type judgment logic. If it is not a function call type, the instruction-related information in the instruction information register can be directly passed to the trace data generator, which generates the corresponding trace data and caches it in the trace data storage register, then writes it to the memory buffer via the last-level cache.

[0064] If the branch type of the first branch instruction is a function call type, the instruction information register can be used to temporarily store the instruction information related to the first branch instruction. The judgment result of the branch type judgment logic can be submitted to the leaf function filtering judgment logic. The timestamp difference logic can calculate the difference between the time information related to the second branch instruction and the temporarily stored time information related to the first branch instruction, and use this as the time information difference, and submit the calculation result to the leaf function filtering judgment logic. Of course, the timestamp difference logic can also calculate the time information difference only if the next instruction submitted after the first branch instruction is a function return type branch instruction. This embodiment of the invention does not impose any restrictions on this. The leaf function filtering judgment logic can determine whether the next instruction submitted after the first branch instruction is a function return type branch instruction based on the judgment result, and whether the calculation result is less than a preset time threshold. If it is a function return type branch instruction and the calculation result is less than the preset time threshold, the instruction information related to the first branch instruction and the instruction information related to the second branch instruction are discarded. Otherwise, the instruction information related to the first branch instruction and the instruction information related to the second branch instruction provided by the instruction information register are given to the trace data generator, which generates the corresponding trace data. If the branch instruction is not a function return type, the instruction-related information is directly handed over to the trace data generator, which then generates the corresponding trace data.

[0065] This invention can be specifically applied to the fields of post-silicon performance analysis and performance monitoring of microprocessors. In practical scenarios, code segments such as functions, loops, and basic blocks are often the main code locations where performance bottlenecks occur. Accordingly, current performance analysis transforms the analysis of the entire program into the analysis of specific code segments such as functions, loops, and basic blocks within the program. During program execution, these code segments are demarcated by branch instructions; branch instructions are executed when these code segments begin or end execution. Therefore, by generating corresponding trace data for branch instructions, performance data support can be provided for performance analysis. For example, by reading this trace data, analysts can obtain performance data and execution time when the program execution control flow changes, and further performance analysis can be performed on code segments such as functions, loops, and basic blocks within the control flow analysis demarcated by branch instructions.

[0066] In related technologies, processor manufacturers offer various hardware tracing branch recording solutions, such as LBR and Processor Trace (PT). However, these solutions directly generate corresponding trace data for every committed branch instruction, requiring the hardware to record trace data for all branch instructions. Since programs often contain a large number of branch instructions, this leads to excessive trace data volume. This necessitates significant storage space, resulting in higher hardware costs and area overhead, as well as higher power consumption for generating and storing trace data. Furthermore, excessive trace data volume increases trace data export time, impacting processor performance and increasing performance analysis time overhead. Additionally, generating trace data for a large number of branch instructions may cause instruction commit pauses during program execution, further increasing execution time and reducing performance.

[0067] In this embodiment of the invention, a leaf function filtering mechanism is added to the hardware tracing branch recording device. Based on a user-set preset time threshold, tracing data is not generated for a pair of branch instructions whose time information difference is less than the preset time threshold. This avoids generating tracing data for short leaf functions with short execution times, effectively reducing the number of tracing data, thereby reducing the recording of unimportant performance data, reducing redundant tracing data, and effectively reducing the amount of tracing data, allowing for better subsequent analysis. Simultaneously, due to the reduced amount of tracing data, storage space required for tracing data is saved, reducing hardware costs and hardware area overhead, reducing power consumption for generating and storing tracing data, saving tracing data export time, improving processor performance, and reducing performance analysis time. Furthermore, it avoids the problem of instruction submission pauses during program execution caused by generating tracing data, which increases program execution time and reduces program performance.

[0068] Reference Figure 4 The diagram shows a block diagram of a tracking data generation device provided in an embodiment of the present invention, such as... Figure 4 As shown, the tracking data generation device may specifically include: The first processing module 201 is used to take the branch instruction submitted by the processor as the first branch instruction, and when the branch type of the first branch instruction is a function call type, record the instruction-related information of the first branch instruction. The second processing module 202 is used to take the next branch instruction submitted by the processor after the first branch instruction as the second branch instruction, and when the branch type of the second branch instruction is a function return type, calculate the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction as the time information difference; the first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call; The first generation module 203 is used to generate corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, and to generate corresponding tracking data for the second branch instruction based on the instruction-related information of the second branch instruction, provided that the time information difference is not less than a preset time threshold.

[0069] The first processing module 201 includes the aforementioned branch type judgment logic and instruction information register, while the second processing module 202 includes the aforementioned timestamp difference logic. The first processing module 201 judges the instructions submitted by the processor using the branch type judgment logic. If it determines that it has received a first branch instruction of function call type or a second branch instruction of function return type, it submits the instruction-related information in the instruction information register to the timestamp difference logic in the second processing module 202. The second processing module 202 calculates the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction using the timestamp difference logic, and uses this difference as the time information difference. The first generation module 203 includes the aforementioned leaf function filtering judgment logic, a trace data generator, and a trace data storage buffer. The first generation module 203 determines whether to generate corresponding trace data for the branch instruction based on the time information difference calculated by the timestamp difference logic, using the leaf function filtering judgment logic. If the time information difference is not less than a preset time threshold, the tracking data generator generates corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, and generates corresponding tracking data for the second branch instruction based on the instruction-related information of the second branch instruction, and stores it in the tracking data storage cache.

[0070] Optionally, the preset time threshold is pre-stored in the threshold storage bit of a designated register via a preset register write command; the device further includes: The first read module is used to read the value of the threshold storage bit of the specified register based on a preset register read command; The determination module is used to determine the value of the threshold storage bit read from the module as the preset time threshold.

[0071] Optionally, the designated register further includes a function enable bit; the device further includes: The second read module is used to read the value of the function enable bit of the specified register based on the register read command; The second generation module is used to generate corresponding trace data for the branch instruction directly based on the instruction-related information of the branch instruction if the value of the function enable bit indicates that it is not enabled. The first processing module 201 is specifically used to: if the value of the function enable bit indicates that the function is enabled, then the branch instruction submitted by the processor is used as the first branch instruction.

[0072] Optionally, the device further includes: The third processing module is used to prevent the generation of corresponding tracking data for the first branch instruction and the second branch instruction when the time information difference is less than the preset time threshold. The return module is used to return to the step of taking the branch instruction submitted by the processor as the first branch instruction and continue execution if the preset termination condition has not been met.

[0073] Optionally, the device further includes: The third generation module is used to generate corresponding trace data for the target instruction based on the instruction-related information of the target instruction when the branch type of the second branch instruction is not a function return type. The target instructions include the first branch instruction, the second branch instruction, the function return instruction corresponding to the first branch instruction, and other instructions, wherein the other instructions are instructions submitted by the processor after the second branch instruction and before the function return instruction.

[0074] Optionally, the time-related information may be the timestamp of the instruction submission, the number of processor clock cycles, or the performance counter value.

[0075] Optionally, the device further includes: The first judgment module is used to determine whether the privilege level of the first branch instruction is a preset filtering level, and to determine whether the branch type of the first branch instruction is a preset filtering type. The first generation module 203 is specifically used to: if the privilege level of the first branch instruction is not the filtering level and the branch type of the first branch instruction is not the filtering type, then generate corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction; The device further includes: a second determination module, configured to determine whether the privilege level of the second branch instruction is the filtering level, and to determine whether the branch type of the second branch instruction is the filtering type; The first generation module 203 is further configured to: if the privilege level of the second branch instruction is not the filtering level and the branch type of the second branch instruction is not the filtering type, then generate corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction.

[0076] In summary, the tracking data generation device provided in this embodiment of the invention uses the branch instruction submitted by the processor as the first branch instruction, and records the instruction-related information of the first branch instruction when the branch type of the first branch instruction is a function call type. The next branch instruction submitted by the processor after the first branch instruction is used as the second branch instruction, and calculates the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction when the branch type of the second branch instruction is a function return type, as the time information difference. The first branch instruction of function call type is used to call the function, and the second branch instruction of function return type is used to end the function call. When the time information difference is not less than a preset time threshold, corresponding tracking data is generated for the first branch instruction based on the instruction-related information of the first branch instruction, and corresponding tracking data is generated for the second branch instruction based on the instruction-related information of the second branch instruction. In this embodiment of the invention, corresponding tracking data is only generated for this pair of branch instructions when the time information difference between the successively submitted function call type branch instructions and function return type branch instructions is not less than a preset time threshold. This reduces the number of generated tracking data, thereby reducing the overall data volume of the tracking data and avoiding the problem of excessively large tracking data volume.

[0077] Reference Figure 5 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Figure 5 As shown, the electronic device includes: a processor, a memory, a communication interface, and a communication bus.

[0078] The processor, the memory, and the communication interface communicate with each other via the communication bus; the memory stores at least one executable instruction, which causes the processor to execute the trace data generation method of the aforementioned embodiment. The executable instructions can form a program.

[0079] This invention provides a machine-readable medium storing instructions that, when executed by one or more processors, enable the processors to perform the tracking data generation method of the foregoing embodiments.

[0080] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0081] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0082] It should be noted that all actions involving the acquisition of signals, information, or data in this application are carried out in compliance with the relevant data protection laws and policies of the country where the application is located, and with the authorization granted by the owner of the relevant device.

[0083] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0084] These computer program instructions may also be stored in a computer-readable storage medium capable of directing a computer or other programmable data processing terminal device to operate in a predictive manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0085] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0086] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the present invention.

[0087] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0088] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0089] The foregoing has provided a detailed description of a tracking data generation method, a tracking data generation device, an electronic device, and one or more readable media provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for generating tracking data, characterized in that, The method includes: The branch instruction submitted by the processor is taken as the first branch instruction, and if the branch type of the first branch instruction is a function call type, the instruction-related information of the first branch instruction is recorded. The next branch instruction submitted by the processor after the first branch instruction is taken as the second branch instruction. If the branch type of the second branch instruction is a function return type, the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction is calculated as the time information difference. The first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call. When the time information difference is not less than a preset time threshold, corresponding tracking data is generated for the first branch instruction based on the instruction-related information of the first branch instruction, and corresponding tracking data is generated for the second branch instruction based on the instruction-related information of the second branch instruction.

2. The method according to claim 1, characterized in that, The preset time threshold is pre-stored in the threshold storage bit of a designated register by a preset register write command; The method further includes: Based on a preset register read command, the value of the threshold storage bit of the specified register is read; The value of the threshold storage bit read is determined as the preset time threshold.

3. The method according to claim 2, characterized in that, The designated register also includes a function enable bit; The method further includes: Based on the register read command, read the value of the function enable bit of the specified register; If the value of the function enable bit indicates that it is not enabled, then the corresponding trace data is directly generated for the branch instruction based on the instruction-related information of the branch instruction. The step of using the branch instruction submitted by the processor as the first branch instruction includes: if the value of the function enable bit indicates that the function is enabled, then the branch instruction submitted by the processor is used as the first branch instruction.

4. The method according to claim 1, characterized in that, The method further includes: If the time information difference is less than the preset time threshold, no corresponding tracking data will be generated for the first branch instruction and the second branch instruction; If the preset termination condition has not been met, return to the step of taking the branch instruction submitted by the processor as the first branch instruction and continue execution.

5. The method according to claim 1, characterized in that, The method further includes: If the branch type of the second branch instruction is not a function return type, corresponding trace data is generated for the target instruction based on the instruction-related information of the target instruction. The target instructions include the first branch instruction, the second branch instruction, the function return instruction corresponding to the first branch instruction, and other instructions, wherein the other instructions are instructions submitted by the processor after the second branch instruction and before the function return instruction.

6. The method according to any one of claims 1-5, characterized in that, The time-related information includes the timestamp when the instruction was submitted, the number of processor clock cycles, or the performance counter value.

7. The method according to any one of claims 1-5, characterized in that, The method further includes: Determine whether the privilege level of the first branch instruction is a preset filtering level, and determine whether the branch type of the first branch instruction is a preset filtering type; The step of generating corresponding trace data for the first branch instruction based on the instruction-related information of the first branch instruction includes: if the privilege level of the first branch instruction is not the filtering level and the branch type of the first branch instruction is not the filtering type, then generating corresponding trace data for the first branch instruction based on the instruction-related information of the first branch instruction. The method further includes: determining whether the privilege level of the second branch instruction is the filtering level, and determining whether the branch type of the second branch instruction is the filtering type; The step of generating corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction includes: if the privilege level of the second branch instruction is not the filtering level and the branch type of the second branch instruction is not the filtering type, then generating corresponding trace data for the second branch instruction based on the instruction-related information of the second branch instruction.

8. A tracking data generation device, characterized in that, The device includes: The first processing module is used to take the branch instruction submitted by the processor as the first branch instruction, and when the branch type of the first branch instruction is a function call type, record the instruction-related information of the first branch instruction. The second processing module is used to take the next branch instruction submitted by the processor after the first branch instruction as the second branch instruction, and when the branch type of the second branch instruction is a function return type, calculate the difference between the time-related information of the second branch instruction and the time-related information of the first branch instruction as the time information difference; the first branch instruction of the function call type is used to call the function, and the second branch instruction of the function return type is used to end the function call; The first generation module is configured to generate corresponding tracking data for the first branch instruction based on the instruction-related information of the first branch instruction, and to generate corresponding tracking data for the second branch instruction based on the instruction-related information of the second branch instruction, provided that the time information difference is not less than a preset time threshold.

9. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store executable instructions that cause the processor to perform the method as described in any one of claims 1 to 7.

10. One or more machine-readable media, characterized in that, It stores instructions that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-7.