Calling method and electronic equipment

By generating call identifiers in asynchronous calls and using Hook methods to record call relationships, the problem of difficulty in tracing asynchronous call paths is solved, achieving complete restoration of the asynchronous call process and performance optimization.

CN122019067APending Publication Date: 2026-05-12HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2024-11-08
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In asynchronous calls, the calling point and the called point are located in different threads, making it difficult to trace the execution path and accurately analyze performance consumption.

Method used

By generating a call identifier, the method that initiates the call and the method that is called are associated. The Hook method is used to insert processing logic without changing the original code, record the call relationship and execution information, and realize the complete tracing of the asynchronous call path.

Benefits of technology

It simplifies the complexity of asynchronous call tracing, optimizes the management of asynchronous calls, and improves the traceability and performance analysis capabilities of the asynchronous call process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019067A_ABST
    Figure CN122019067A_ABST
Patent Text Reader

Abstract

The invention provides a calling method and electronic equipment, relates to the technical field of electronics, and aims to solve the technical problems that asynchronous calling is difficult to trace and the whole execution path of asynchronous calling is difficult to obtain. The method is applied to the electronic equipment and comprises the steps that in the process of executing a first method through a first thread, a second method is called in response to indication of the first method, a calling identifier is generated, and the calling identifier is used for obtaining the calling relation between the first method and the second method; storing a first relationship through the first thread, wherein the first relationship comprises the calling identifier and a relationship among the first method and the second method; in the process of executing the second method through the second thread, the execution process is marked by calling the identifier.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic technology, and more particularly to a method of invoking and an electronic device. Background Technology

[0002] Synchronous and asynchronous calls are two ways of invoking programs. For example, in a synchronous call, when the program reaches the calling point, it sends a request to the called point and waits for the called point to complete its processing and return the result before executing subsequent code. In a synchronous call, the calling point and the called point typically execute in the same thread. In an asynchronous call, when the program reaches the calling point, it sends a request to the calling point and returns immediately, while the program continues executing subsequent code. The calling point responds to the request by executing its processing logic in another thread, and returns the result after processing. In an asynchronous call, the calling point and the called point typically execute in different threads. The calling point is used to initiate the call and is usually a method or function; the called point is used to execute the call and is usually another method or function. For example, if method A calls method B, method A is the calling point, and method B is the called point.

[0003] In synchronous calls, the calling and called points execute within the same thread, and their call stacks are linear. Therefore, the entire execution path of a synchronous call can be clearly traced. However, in asynchronous calls, the calling and called points execute in different threads, making tracing difficult and rendering the entire execution path of an asynchronous call impossible. Summary of the Invention

[0004] This application provides a calling method and an electronic device that associates the calling method and the called method through a calling identifier to obtain a complete instruction path. This simplifies the tracing difficulties in asynchronous calls and optimizes the management of asynchronous calls.

[0005] To achieve the above objectives, this application adopts the following technical solution:

[0006] In a first aspect, this application provides a calling method applied to an electronic device. The method includes: during the execution of a first method by a first thread, in response to an instruction from the first method to call a second method, generating a calling identifier, the calling identifier being used to obtain the calling relationship between the first method and the second method; saving a first relationship by the first thread, the first relationship including the calling identifier and the relationship between the first method and the second method; and marking the execution process by the calling identifier during the execution of the second method by the second thread.

[0007] In this application, the call relationship of asynchronous methods is stored by calling identifiers, which increases the traceability of the program. It allows for easy tracing of the call chain of asynchronous methods across multiple threads, accurately reconstructing the asynchronous call process. This simplifies the difficulty of tracing asynchronous calls, optimizes the management of asynchronous calls, and enables accurate analysis of the performance consumption of asynchronous calls.

[0008] According to the first aspect, or any implementation of the first aspect above, during the execution of the first method by the first thread, before generating the call identifier in response to the first method's instruction to call the second method, the method further includes: generating a third method according to the second method, the third method including the second method and processing logic, the processing logic being used to instruct the saving of the first relationship.

[0009] For example, the third method includes a Hook method that encapsulates the second method and the processing logic.

[0010] In this application, the third method inserts additional processing logic without changing the original code of the second method. This processing logic is used to implement functions such as recording. This improves the maintainability and scalability of the code, simplifies the tracing problem during asynchronous calls, and helps to trace the execution path of asynchronous calls. It enhances functionality, optimizes the asynchronous call process, and improves the overall performance of asynchronous calls without affecting the implementation of the second method.

[0011] According to the first aspect, or any implementation of the first aspect above, the first relationship is saved by the first thread, including: the first thread executes the processing logic in the third method to save the first relationship.

[0012] In some examples, after the first method generates the call identifier, the electronic device passes the call identifier as a parameter to the third method corresponding to the second method through the first thread.

[0013] In some examples, the electronic device executes the processing logic in the third method through the first thread, saving the first relationship.

[0014] The first relationship includes the relationship between the call stack information of the first method and the call identifier. The call stack information of the first method includes the first method and the second method. That is, the first relationship includes the relationship between the call identifier, the first method, and the second method.

[0015] The first relationship also includes the upload method that calls the first method, and the number of parent methods of the first method can be one or more. The first relationship includes the call identifier, the parent methods of the first method, and the relationship between the first method and the second method.

[0016] In this application, a third method is used to save the first relationship, which includes a call identifier, a first method, and a second method. This allows for the rapid determination of the call relationship of the first method based on the call identifier when tracing the execution path later, thus improving traceability.

[0017] According to the first aspect, or any implementation of the first aspect above, the execution process is marked by a call identifier, including: adding a call identifier at the start and end positions of the second method call by a second thread.

[0018] According to the first aspect, or any implementation of the first aspect above, the method further includes: saving the start time at which a call identifier is added at the start position; and saving the end time at which a call identifier is added at the end position.

[0019] According to the first aspect, or any implementation of the first aspect above, the method further includes: saving a second relationship, the second relationship including the relationship between the call identifier, start time, end time, and thread number of the second thread.

[0020] For example, the second relationship includes the relationship between the execution information of the second method and the call identifier. The execution information of the second method includes the start time, the end time, and the thread number of the second thread.

[0021] In the application, during the execution of the first method, the execution time of the second method is recorded according to the call identifier, which can provide data support for subsequent tracing of the execution path.

[0022] According to the first aspect, or any implementation of the first aspect above, the method further includes: obtaining a call identifier; obtaining information about the execution process of the first relationship and the second method based on the call identifier; and determining the execution path of the first method and the second method based on the information about the execution process of the first relationship and the second method.

[0023] In some examples, information about the execution process of the first relationship and the second method is retrieved from stored information based on the call identifier.

[0024] The information in the execution process of the second method includes the second relationship, which includes the execution information and the call identifier of the second method.

[0025] In some examples, the call stack information of the first method is determined based on the first relationship; the execution stack information of the second method is determined based on the execution process information of the second method; and the electronic device determines the execution paths of the first method and the second method based on the call stack information of the first method and the execution stack information of the second method.

[0026] This application uses call identifiers to precisely trace the execution process of a method during an asynchronous call, achieving a complete reconstruction of the asynchronous call path and reducing the complexity of asynchronous call tracing. Based on the complete execution path, developers can better understand the behavior and performance of asynchronous calls, enabling effective subsequent performance analysis of asynchronous calls.

[0027] In a second aspect, this application provides a calling device comprising: a processor and a memory coupled to the processor, the memory being used to store computer-readable instructions, wherein when the processor reads the computer-readable instructions from the memory, the electronic device performs the method as described in the first aspect and any embodiment thereof.

[0028] Thirdly, this application provides an electronic device comprising: a processor and a memory, the memory being coupled to the processor, the memory being used to store computer-readable instructions, wherein when the processor reads the computer-readable instructions from the memory, the electronic device causes the electronic device to perform the method as described in the first aspect and any embodiment of the first aspect.

[0029] Fourthly, this application provides a chip system including at least one processor and at least one interface circuit. The at least one interface circuit is used to perform transceiver functions and send instructions to the at least one processor. The at least one processor executes the instructions and performs the method as described in the first aspect and any embodiment of the first aspect.

[0030] Fifthly, this application provides a computer-readable storage medium including a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in the first aspect and any embodiment of the first aspect.

[0031] In a sixth aspect, this application provides a computer program product comprising: a computer program or instructions that, when executed on a computer, cause the computer to perform a method as described in the first aspect and any of the embodiments described in the first aspect.

[0032] The technical effects corresponding to any implementation method of aspects two through six, as well as any aspect, can be found in the first aspect and the technical effects corresponding to any implementation method of the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0033] Figure 1 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;

[0034] Figure 2 Illustration of a calling scenario provided in the embodiments of this application Figure 1 ;

[0035] Figure 3 A flowchart illustrating the invocation method provided in this application embodiment. Figure 1 ;

[0036] Figure 4 Illustration of a calling scenario provided in the embodiments of this application Figure 2 ;

[0037] Figure 5 A flowchart illustrating the invocation method provided in this application embodiment. Figure 2 ;

[0038] Figure 6 Illustration of a calling scenario provided in the embodiments of this application Figure 3 ;

[0039] Figure 7 Illustration of a calling scenario provided in the embodiments of this application Figure 4 ;

[0040] Figure 8 Illustration of a calling scenario provided in the embodiments of this application Figure 5 ;

[0041] Figure 9 Illustration of a calling scenario provided in the embodiments of this application Figure 6 ;

[0042] Figure 10 A schematic diagram of the calling device provided in the embodiments of this application;

[0043] Figure 11 This is a schematic diagram of the chip system provided in an embodiment of this application. Detailed Implementation

[0044] The technical solutions of the embodiments of this application are described below with reference to the accompanying drawings. In the description of the embodiments of this application, the terminology used in the following embodiments is for the purpose of describing specific embodiments only and is not intended to be a limitation of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one” and “one or more” refer to one or more (including two).

[0045] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized. The term "connection" includes direct connections and indirect connections, unless otherwise stated. "First" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated.

[0046] In the embodiments of this application, the words "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of the words "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.

[0047] Currently, in asynchronous call scenarios, because the calling and called points reside in different threads, it's difficult to trace the entire execution path of the asynchronous call, leading to tracing difficulties and making it hard for developers to understand how asynchronous methods are triggered. Furthermore, when analyzing the performance of asynchronous calls, only performance information for the current thread can be obtained. The inability to link the two threads involved in the asynchronous call makes it impossible to obtain actual performance information during execution, making it difficult to assess the resource consumption of asynchronous calls.

[0048] In view of this, this application provides a calling method. For each asynchronous call, a call identifier is generated. Based on this identifier, the call stack information of the initiating method and the execution stack information of the called method are determined. The execution path of the asynchronous call is then determined based on these call stack and execution stack information. The execution processes of asynchronous calls are linked together using the same identifier, resulting in a complete execution path. This simplifies the complexity of tracing asynchronous calls and optimizes the management of asynchronous calls.

[0049] The electronic devices described in this application may include, but are not limited to, devices in any field such as smart terminals, vehicles, smart homes, industry, municipal facilities, medical care, and education.

[0050] Taking the field of smart terminals as an example, the electronic devices described in the embodiments of this application may include, but are not limited to, smartphones, netbooks, tablet computers, handheld computers, in-vehicle computers, personal computers (PCs), personal digital assistants (PDAs), artificial intelligence (AI) devices, portable multimedia players (PMPs), augmented reality (AR) / virtual reality (VR) devices, smart TVs, projection devices, or motion-sensing game consoles in human-computer interaction scenarios. Of course, the electronic devices described in the embodiments of this application may also be wearable devices, such as smartwatches, smart bracelets, phone watches, or other types or structures of electronic devices; this application is not limited to these.

[0051] like Figure 1 As shown, the electronic device 100 may include a processor 110, a memory 120, and a display screen 130, etc.

[0052] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors. The controller can generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution.

[0053] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0054] In some embodiments, processor 110 may include one or more interfaces. These one or more interfaces can be used to connect processor 110 to memory 120, display 130, etc.

[0055] In some embodiments of this application, the processor 110 can generate a call identifier during an asynchronous call and obtain the execution path of the asynchronous call based on the call identifier. The processor 110 can also process asynchronous methods to obtain Hook methods. Please refer to the following text for details.

[0056] The memory 120 can be used to store executable program code, including instructions. The memory 120 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a given function (such as image playback), etc. The data storage area may store data created during the use of the electronic device 100. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the memory 120 and / or instructions stored in memory located within the processor.

[0057] Electronic device 100 implements display functions through a GPU, display screen 130, and application processor. The GPU is a microprocessor for image processing, connected to the display screen 130 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0058] The display screen 130 is used to display images, videos, etc. The display screen 130 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N display screens 130, where N is a positive integer greater than 1.

[0059] In some embodiments of this application, the display screen 130 can be used to display various interfaces. For example, during the sampling process of a performance analysis tool, it can display sampling data.

[0060] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device may include... Figure 1 The diagram shows more or fewer components, or combinations of components, or separate components, or different arrangements of components. The components shown can be implemented in hardware, software, or a combination of both.

[0061] The invocation method in this application embodiment can be applied to any asynchronous call tracing scenario. For example, performance analysis, error analysis, business optimization, etc.

[0062] Performance analysis can be used to analyze program performance or system performance. For example, ... Figure 2 As shown, when developers or performance tuners perform performance analysis on a program, they can use the calling method described in this application to obtain the complete execution path of asynchronous calls. Based on this complete execution path, they can analyze the execution time of each asynchronous call, resource usage, and the calling relationships between threads. Developers can then optimize the architecture and scheduling strategies based on the analysis results to improve system performance.

[0063] Error analysis includes locating, analyzing, and fixing errors. For example, based on the execution path of asynchronous calls defined in this application, it helps developers quickly locate errors, analyze the error-related context, promptly resolve vulnerabilities in asynchronous calls, and fix errors.

[0064] Business optimization includes optimizing critical paths and optimizing architecture. For example, based on the execution path of a call determined in this application, key points in the business process are identified. Based on these key points, the architecture is adjusted to optimize the calling process and improve user experience. This application does not limit the application scenarios of the calling method.

[0065] The following detailed description of the calling methods of the embodiments of this application is provided through specific examples and accompanying drawings. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0066] Figure 3 This is a flowchart illustrating a calling method provided in an embodiment of this application, applied to an electronic device. For example... Figure 3 As shown, the method may include:

[0067] S301. During the execution of the first method by the first thread, in response to the instruction of the first method to call the second method, a call identifier is generated. This call identifier is used to obtain the call relationship between the first method and the second method.

[0068] Here, the first thread is the thread that executes the first method. The first method is the method or function that is invoked during the program call process; it can also be described as the call point.

[0069] The second method refers to the method or function invoked during program execution, which can also be described as the call point. The second method is an asynchronous method. An asynchronous method is a method or function that does not block the calling thread after execution.

[0070] Optionally, this solution can be applied to asynchronous call processes in native languages.

[0071] It's understandable that the process of the first method calling the second method is an asynchronous call. In this call, the first method is the initiator and can execute other tasks without waiting for the second method to complete its processing. The second method is the executor, completing its processing in another thread and then notifying the first method of the result of the asynchronous operation through callbacks or other mechanisms.

[0072] The call identifier is an identifier used to identify this asynchronous call. The call identifier can help trace or associate a series of operations within this asynchronous call. For example, the call identifier can be a trace identifier (traceID).

[0073] In some examples, the electronic device can generate a call identifier using a universally unique identifier (UUID). Alternatively, the electronic device can generate a call identifier using a call timestamp and a random number.

[0074] It is understood that the embodiments of this application do not limit the specific implementation method of the electronic device generating the call identifier.

[0075] Understandably, the call identifier is generated each time an asynchronous call is executed, and is used to identify each asynchronous call. The call identifier generated for each asynchronous call is different. For example, the call identifier for calling the same asynchronous method at different times will be different.

[0076] For example, let's take thread A as the first thread, method A as the first method, and method B as the second method, where method B is an asynchronous method. During the execution of method A by the electronic device through thread A, in response to method A's instruction to call method B, the electronic device generates a call identifier 1. This call identifier 1 is used to identify this call from method A to method B, ensuring that the operation of method A calling method B can be traced.

[0077] In this embodiment of the application, during the execution of the first method by the electronic device through the first thread, before generating a call identifier in response to the first method's instruction to call the second method, the electronic device also generates a third method based on the second method. The third method includes the second method and processing logic, which is used to instruct the storage of a first relationship, which includes the call identifier and the relationship between the first method and the second method.

[0078] The third method includes a Hook method, which encapsulates the second method and the processing logic.

[0079] In the embodiments of this application, for asynchronous methods (i.e., the second method) in a program or system, the electronic device uses a hook approach to process each asynchronous method. For example, processing logic is inserted before or after the asynchronous method, and the processing logic and the asynchronous method are encapsulated to obtain the hook method (i.e., the third method) corresponding to the asynchronous method.

[0080] Hooking is a programming technique that allows developers to insert custom logic or code when a specific event or program call occurs, in order to modify or extend program behavior. Hook can also be described as a hook.

[0081] The third method essentially encapsulates the processing logic together with the second method, forming a proxy pattern. The third method acts as a proxy for the second method.

[0082] Understandably, without modifying the original code of the second method, a third method is obtained by inserting custom execution logic before or after the second method. This replaces the second method with the third method, and replaces calls to the second method with calls to the third method. Thus, when the second method is called, the third method is directly invoked, which then executes the additional processing logic and calls the second method.

[0083] The processing logic includes logic for storing the call stack of the method that initiated the asynchronous call, logic for saving the call identifier of the asynchronous call, etc.

[0084] For example, consider the scenario where method B is an asynchronous method. For method B, create a new Hook method, for example, method C. Method C internally calls method B, and adds processing logic within method C. Subsequently, the call to method B is redirected to method C. Thus, each time method B is called, method C is executed. Method C first executes its internal processing logic, and then calls method B.

[0085] In some examples, method B is redirected to method C by modifying the address. Alternatively, method B is redirected to method C by modifying the routing configuration.

[0086] For example, electronic devices contain symbol tables that store information about various identifiers in a program or system, along with the memory address of each identifier. Identifiers include methods, functions, variables, etc. Symbol tables are typically key-value data structures. The key can be an identifier (such as the method name of an asynchronous method), and the value can be information associated with that identifier (such as memory address, data type, etc.). For example, if the asynchronous method is method B, and the memory address of method B is 0x0004, then the information stored in the symbol table could be "method B—0x0004".

[0087] Based on the example above, the address of the newly created method C is 0x0005. The electronic device modifies the information of method B in the symbol table according to the address of method C, changing the key-value pair of method B to "method B—0x0005". Thus, when method B is called, method C is called based on "method B—0x0005" in the symbol table. Method C first executes its internal processing logic, and then calls method B.

[0088] It is understood that the embodiments of this application do not limit the specific implementation of the electronic device processing the second method into the third method.

[0089] It's understandable that the process of converting the second method into a third method is done during program or system development. In practical applications, when the second method is called, the third method can act as a proxy, achieving asynchronous invocation.

[0090] In this application, the Hook method inserts additional processing logic without changing the original asynchronous method code. This processing logic is used to implement functions such as logging. This improves code maintainability and scalability, simplifies tracing issues during asynchronous calls, and helps to trace the execution path of asynchronous calls. It enhances functionality, optimizes the asynchronous call flow, and improves the overall performance of asynchronous calls without affecting the implementation of the asynchronous method.

[0091] S302. The first relationship is saved through the first thread. The first relationship includes the call identifier and the relationship between the first method and the second method.

[0092] The electronic device sends the call identifier to the third method corresponding to the second method through the first thread.

[0093] In some examples, after the first method generates the call identifier, the electronic device passes the call identifier as a parameter to the third method corresponding to the second method through the first thread.

[0094] As can be understood from the above, the second method has been replaced by the third method. When the second method is called, it is actually executed by the corresponding third method. Therefore, the first method needs to pass the parameters required for the asynchronous call to the third method.

[0095] For example, based on the example in S301 above, the Hook method of method B is method C, and the first method is method A. When method A calls method B, it sends call identifier 1 to method C.

[0096] In some examples, the electronic device executes a third method through a first thread to determine the call stack information and call identifier of the first method.

[0097] Understandably, when a method in a program is called, it is executed within a thread. A thread creates a call stack, which records the execution process of method calls. The call stack stores each method executed by the thread in sequence. When a method is called by a thread, it is pushed onto the stack; when the method finishes execution, it is popped from the stack.

[0098] In this embodiment of the application, when the electronic device executes the third method through the first thread, it first executes the processing logic in the third method, and then executes the asynchronous method in the third method.

[0099] In this embodiment, the electronic device executes the processing logic of the third method through a first thread and saves the first relationship. The first relationship includes the relationship between the call stack information of the first method and the call identifier. The call stack information of the first method includes the first method and the second method. That is, the first relationship includes the call identifier, the relationship between the first method and the second method.

[0100] Optionally, the call stack information of the first method may also include all parent methods that called the first method. In this case, the first relationship stored by the electronic device includes the call identifier, the parent methods of the first method, and the relationship between the first method and the second method. The number of parent methods of the first method can be one or more.

[0101] For example, the processing logic in the third method executed by the electronic device includes: obtaining the call stack information of the first method; and storing the call stack information and call identifier of the first method together to save the first relationship.

[0102] For example, the electronic device obtains the call stack information of the first method using stack capture technology. The first relationship between the call identifier and the call stack information of the first method (i.e., the first method and the second method) is stored in key-value pairs. This application does not limit the specific implementation method of how the electronic device stores the first relationship.

[0103] It's understandable that when the first method calls the second method, the thread containing the first method will initiate a call to the corresponding third method, pushing the third method onto the call stack. The processing logic in the third method and the second method will then be executed. When the third method calls the second method, the thread containing the first method pushes the second method onto the call stack, but most of the second method's content is not executed by the thread containing the first method. Instead, a new thread is created, and this new thread executes the second method. Therefore, the call stack information for the first method includes the second method.

[0104] Understandably, the call stack information for the first method is used to represent the call relationships between methods during the original execution of the program. The third method, however, is a proxy method introduced in this solution; therefore, the call stack information for the first method does not include the third method.

[0105] For example, based on the example in S301 above, method A calls method B, and the thread in which method A resides is thread A. Thread A calls method A, pushing method A onto its call stack. During the execution of method A, thread A needs to call method B. Since method B is proxied by method C, method C is pushed onto thread A's call stack. During the execution of method C, thread A needs to call method B, so method B is pushed onto thread A's call stack. Method B is actually executed in thread B. Therefore, the call stack information of method A includes: method A and method B. It can also be described as "[method A, method B]", and "[method A, method B]" can also represent the call relationship between method A and method B, where method A calls method B. Thread A stores the first relationship 1: call identifier 1—[method A, method B].

[0106] It is understandable that the first method can also include a parent method, which calls the first method. Based on the above example, method A also includes a parent method, such as method Q, which calls method A. Before thread A calls method A, thread A calls method Q and pushes method Q onto its call stack. During the execution of method Q, thread A needs to call method A before pushing method A onto its call stack. In this case, the call stack information of method A includes "[method Q, method A, method B]". Thread A stores the first relationship 2: call identifier 1—[method Q, method A, method B].

[0107] As you can understand, the above example illustrates the processing of the thread that calls the asynchronous call. The following details the processing of the thread that calls the asynchronous call.

[0108] S303. During the execution of the second method through the second thread, the execution process is carried out by calling the flag marker.

[0109] In this embodiment, the second method is an asynchronous method, executed by the electronic device through a second thread. The second thread is different from the first thread.

[0110] In some examples, a second thread adds call markers at the start and end points of the second method call to record the start and end times of the second method.

[0111] Specifically, when the electronic device executes the second method in the second thread, it records the start time of the second method (i.e., the start time when the call identifier is added at the beginning) by using a call marker at the beginning of the second method. At the end of the second method, it records the end time (i.e., the end time when the call identifier is added at the end) by using a call marker at the end. The electronic device determines the execution information of the second method based on the thread number of the second thread in which the asynchronous method runs, the start time of the second method, and the end time of the second method. The electronic device can associate and store the call identifier and execution information to save a second relationship for subsequent analysis of the execution path. This second relationship includes the relationship between the execution information of the second method and the call identifier. The execution information of the second method includes the start time, end time, and the thread number of the second thread. In other words, the second relationship includes the relationship between the call identifier, the start time, the end time, and the thread number of the second thread.

[0112] The thread number is a unique identifier for a thread in the system, and it can be represented by a number.

[0113] For example, an example of calling method B based on method A above, where method A does not include the parent method. Figure 4 The diagram shows the method call flowchart when an electronic device performs an asynchronous call. Based on the example above, thread A of the electronic device calls method A, runs method A, and generates call identifier 1. When it reaches the code that calls method B, thread A calls method C and runs method C. During the execution of method C, thread A obtains the call stack information of method A, stores the call stack information and call identifier 1 of method A, and starts method B.

[0114] In response to thread A initiating method B, the electronic device runs method B within thread B. It marks the beginning of method B with a call identifier 1 to record the start time 1, and the end of method B with a call identifier 1 to record the end time 1. It also determines the thread number of thread B, such as 1XX. The electronic device integrates the start time 1, end time 1, and 1XX into the execution information of method B. The electronic device stores a second relation 1: call identifier 1 — (start time 1, end time 1, and 1XX).

[0115] It is understood that, in the embodiments of this application, during the execution of the second method, the execution time of the second method is recorded according to the call identifier, which can provide data support for subsequent tracing of the execution path.

[0116] It is understandable that S301-S303 described above are the specific implementation methods for executing asynchronous calls in electronic devices. During the asynchronous call process, the electronic device can also sample the asynchronous call to determine the execution path and further analyze the performance of the asynchronous call process.

[0117] The following details the specific implementation method for obtaining the execution path of asynchronous calls, such as... Figure 5 The diagram shows a flowchart of an electronic device obtaining the execution path of an asynchronous call. The method includes:

[0118] S501. The electronic device obtains the first relationship associated with the call identifier based on the call identifier.

[0119] In some examples, the electronic device can obtain the first relationship based on the call identifier.

[0120] For example, based on the above example of method A calling method B in S302, where method A does not include an example of an upper-level method. The electronic device obtains the first relationship 1 corresponding to the call identifier 1 from the stored information according to the call identifier 1: call identifier 1—[method A, method B].

[0121] For example, such as Figure 6 As shown, the data within the dashed box represents the call stack information captured by the electronic device corresponding to the call identifier "0xe062e2c1".

[0122] S502. The electronic device obtains information about the execution process of the second method based on the call identifier.

[0123] The information in the execution process of the second method includes the second relationship, which includes the execution information and the call identifier of the second method.

[0124] In some examples, the system retrieves the execution information corresponding to the call identifier from stored information based on the call identifier. The execution information includes the thread number of the thread containing the asynchronous method, the start time of the asynchronous method, and the end time of the asynchronous method.

[0125] For example, based on the above example of method A calling method B in S303, where method A does not include an example of an upper-level method. The electronic device obtains the execution information of method B corresponding to call identifier 1 from the stored information, including start time 1, end time 1, and 1XX, according to call identifier 1.

[0126] S503. The electronic device determines the execution path of the first method and the second method based on the information of the execution process of the first relationship and the second method.

[0127] In this embodiment of the application, the electronic device determines the call stack information of the first method based on the first relationship; the electronic device determines the execution stack information of the second method based on the execution process information of the second method; and the electronic device determines the execution path of the first method and the second method based on the call stack information of the first method and the execution stack information of the second method.

[0128] In some examples, the electronic device determines the call stack information of the first method in the first relationship; the electronic device samples data through performance analysis tools, filters the sampled data based on the information of the execution process of the second method (i.e. the execution information of the second method), and selects to determine the execution stack information of the asynchronous method.

[0129] For example, based on the examples of S501 and S502 above, the electronic device determines the call stack information of method A in the first relationship 1 as: [method A, method B]. The electronic device uses a performance analysis tool, such as hiperf, to perform data sampling, setting the process or program to be monitored, and the sampling parameters. For example, method A and method B are both methods that run in program A when program A is executed. The sampling parameters include the sampling frequency and sampling time, for example, 1000 samples per second. During the execution of program A, the electronic device samples according to the sampling parameters to obtain sampled data. The electronic device obtains the execution information of method B according to call identifier 1, and filters the sampled data according to the start time 1, end time 1, and 1XX in the execution information of method B. Based on the execution information of method B, it determines that method B runs in thread B with thread number 1XX, and the stack information during the time period from start time 1 to end time 1. For example, if there is only one method during this time period, such as method D, then the execution stack information of method B is method D.

[0130] Hiperf is a performance analysis tool suitable for monitoring and debugging high-performance applications. Hiperf can provide data on CPU utilization, memory usage, thread status, and other aspects.

[0131] For example, such as Figure 7The image shows the interface for displaying the execution stack information of asynchronous methods filtered by a performance analysis tool in an electronic device. This interface displays information about thread number 6380, such as the trace swimlane graph, hiperf swimlane graph, and execution stack information for thread 6380. The trace swimlane graph for thread 6380 includes the recorded start and end times of the asynchronous methods. The hiperf swimlane graph for thread 6380 is the swimlane graph for the thread during the time period from start to end. The dashed box shows the execution stack information of the sampled asynchronous methods in thread 6380 from start to end, which includes multiple methods.

[0132] In some examples, the electronic device associates the call stack information of the first method with the execution stack information of the asynchronous method to obtain the execution path of the first and second methods. This execution path is a continuous execution path.

[0133] For example, based on the example of method A calling method B in S302 above, where method A does not include the example of the parent method. The call stack information of method A is "[method A, method B]", and the execution stack information of method B is "method D". Based on the above two pieces of information, the execution path of method A calling method B is "[method A, method B, method D]".

[0134] For example, such as Figure 8 The diagram shows the execution path of method A calling method B, excluding the execution path of the parent method. The execution path, from top to bottom, is method A, method B, and method D.

[0135] For example, such as Figure 9 The diagram illustrates the process of an electronic device executing an asynchronous call and obtaining its execution path. The electronic device executes a first method via a first thread. Responding to the first method's instruction, the first thread calls a second method, generates a call identifier, and executes a third method. During the execution of the third method, a first relationship is saved, and the second method is started. The first relationship includes the call identifier and the call stack information of the first method. The electronic device executes the second method via a second thread, marking the execution process with the call identifier. The electronic device saves the execution process information of the second method, including the second relationship, which includes the call identifier and the execution information of the second method. During the execution of the second method by the second thread, the execution stack information of the second method is determined based on the execution process information. The call stack information of the first method and the execution stack information of the second method in the first relationship are determined based on the call identifier. The execution paths of the first and second methods are determined based on the execution stack information of the second method.

[0136] In this application, the execution process of asynchronous calls is linked through traceID, making the execution process of each asynchronous call traceable. By chaining the execution paths of asynchronous calls together using traceID, a complete reconstruction of the asynchronous call path is achieved, reducing the complexity of tracing asynchronous calls. Furthermore, through the hook proxy method, performance monitoring and debugging capabilities are added without affecting the original asynchronous methods, helping developers better understand the behavior and performance of asynchronous calls for subsequent effective performance analysis.

[0137] The foregoing mainly describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the above functions, it includes corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0138] This application embodiment can divide the above-described electronic device into functional modules based on the method example described above. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing module. The integrated modules can be implemented in hardware or as software functional modules. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.

[0139] Based on the same inventive concept, embodiments of this application provide a calling device. The calling device provided in embodiments of this application is applied to... Figure 1 The electronic device shown. For example... Figure 10 The diagram shown is a structural schematic of a calling device provided in an embodiment of this application. The calling device can be used to implement the methods described in the above method embodiments. For example, the calling device may specifically include: a processing module 1001, a transceiver module 1002, and a display module 1003.

[0140] The processing module 1001 is used to support the execution of the calling device. Figure 3 or Figure 5 The transceiver module 1002 is used to support the calling device in executing any of the processing functions. Figure 3 or Figure 5 The display module 1003 is used to support the execution of any item in the call device. Figure 3or Figure 5 The display function of any item in it.

[0141] Figure 10 The technical effects of the calling device shown can be referred to the technical effects of the method described in the above method embodiments, and will not be repeated here. Figure 10 The processing module 1001 involved in the calling device shown can be implemented by a processor or processor-related circuit components, and can be a processor or a processing module.

[0142] This application also provides a chip system, such as... Figure 11 As shown, the chip system 1100 includes at least one processor 1101 and at least one interface circuit 1102. As an example, when the chip system 1100 includes a processor and an interface circuit, the processor can be... Figure 11 The processor 1101 shown in the solid box (or the processor 1101 shown in the dashed box) may have an interface circuit that can be... Figure 11 The interface circuit 1102 is shown in the solid box (or the dashed box). When the chip system 1100 includes two processors and two interface circuits, the two processors include... Figure 11 The processor 1101 shown in the solid box and the processor 1101 shown in the dashed box, the two interface circuits include Figure 11 Interface circuit 1102 shown in solid boxes and interface circuit 1102 shown in dashed boxes. No limitations are imposed on this.

[0143] Processor 1101 and interface circuit 1102 can be interconnected via a line. For example, interface circuit 1102 can be used to receive signals. As another example, interface circuit 1102 can be used to send signals to other devices (e.g., processor 1101). Exemplarily, interface circuit 1102 can read instructions stored in memory and send the instructions to processor 1101. When the instructions are executed by processor 1101, the steps in the above embodiments can be performed. Of course, the chip system may also include other discrete devices, and this application embodiment does not specifically limit this.

[0144] Optionally, there can be one or more processors in the chip system. The processor can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, integrated circuit, etc. When implemented in software, the processor can be a general-purpose processor that reads software code stored in memory.

[0145] Optionally, the chip system may also include a memory ( Figure 11(As shown in the image), the memory can be one or more, and can be integrated with the processor or set separately from the processor; this application is not limited to this. For example, the memory can be a non-transient processor, such as read-only memory (ROM), which can be integrated with the processor on the same chip or set separately on different chips. This application does not specifically limit the type of memory or the arrangement of the memory and processor. For example, the chip system can be a field-programmable gate array (FPGA), an application-specific integrated circuit (ASIC), a system-on-a-chip (SoC), a central processing unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD), or other integrated chips.

[0146] It should be understood that each step in the above method embodiments can be completed by integrated logic circuits in the processor hardware or by instructions in software form. The method steps disclosed in the embodiments of this application can be directly manifested as being executed by a hardware processor, or being executed by a combination of hardware and software modules in the processor.

[0147] This application also provides a computer storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the method described in the above-described method embodiments.

[0148] Computer-readable storage media include, but are not limited to, any of the following: USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and other media capable of storing program code.

[0149] This application provides a computer program product, which includes a computer program or instructions that, when run on a computer, cause the computer to perform the methods described in the above-described method embodiments.

[0150] In addition, this application also provides an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the apparatus to perform the methods in the above-described method embodiments.

[0151] In addition, this application also provides a system, which may specifically be a chip, component or module. The system may include a connected processor and a memory. The memory is used to store computer execution instructions. When the system is running, the processor can execute the computer execution instructions stored in the memory to enable the system to perform the methods in the above-described method embodiments.

[0152] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.

[0153] The steps of the methods or algorithms described in conjunction with the embodiments of this application can be implemented in hardware or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory, erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, compact disc read-only memory (CD-ROM), or any other form of storage medium well known in the art. An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an application-specific integrated circuit (ASIC).

[0154] Through the above description of the embodiments, those skilled in the art will clearly understand that, for the sake of convenience and brevity, the division of the above functional modules is only used as an example. In practical applications, the above functions can be assigned to different functional modules as needed; that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0155] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The embodiments can be combined with or referenced to each other without conflict. The apparatus embodiments described above are merely illustrative; for example, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0156] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0157] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0158] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0159] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A calling method, characterized in that, Applied to electronic devices, the method includes: During the execution of the first method by the first thread, in response to the instruction of the first method to call the second method, a call identifier is generated. The call identifier is used to obtain the call relationship between the first method and the second method. The first relationship is saved through the first thread, and the first relationship includes the call identifier, the relationship between the first method and the second method; During the execution of the second method via the second thread, the execution process is marked by the call identifier.

2. The method according to claim 1, characterized in that, During the execution of the first method via the first thread, before generating a call identifier in response to the first method instructing the invocation of the second method, the method further includes: A third method is generated based on the second method, the third method including the second method and processing logic, the processing logic being used to instruct the saving of the first relationship.

3. The method according to claim 2, characterized in that, The step of saving the first relationship through the first thread includes: The first thread executes the processing logic in the third method to save the first relationship.

4. The method according to any one of claims 1-3, characterized in that, The process executed via the call identifier includes: The second thread adds the call identifier at the start and end positions of the second method call.

5. The method according to claim 4, characterized in that, The method further includes: Save the start time at the starting position where the call identifier is added; Save the end time of the call identifier at the end position.

6. The method according to claim 5, characterized in that, The method further includes: Save the second relationship, which includes the relationship between the call identifier, the start time, the end time, and the thread number of the second thread.

7. The method according to any one of claims 1-6, characterized in that, The method further includes: Obtain the call identifier; Based on the call identifier, obtain information about the execution process of the first relationship and the second method; Based on the information from the execution process of the first relationship and the second method, the execution paths of the first method and the second method are determined.

8. An electronic device, characterized in that, The electronic device includes a processor and a memory coupled to the processor, the memory being used to store computer-readable instructions, which, when read from the memory by the processor, cause the electronic device to perform the method as described in any one of claims 1-7.

9. A chip system, characterized in that, It includes at least one processor and at least one interface circuit, the at least one interface circuit being used to perform transceiver functions and send instructions to the at least one processor, the at least one processor executing the instructions, and the at least one processor performing the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes: a computer program or instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1-7.