CN-122019067-A - Calling method and electronic equipment
Abstract
The application 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 back and the whole execution path of asynchronous calling is difficult to acquire. The method is applied to electronic equipment, and comprises the steps of responding to a first method instruction to call a second method in the process of the first method through a first line Cheng Zhihang, generating a call identifier, wherein the call identifier is used for acquiring a call relation between the first method and the second method, the first relation comprises the call identifier, the first method and the second method in the process of executing the second method through a second thread through the first line Cheng Baocun, and the process is executed through the call identifier in the process of executing the second method through the second thread.
Inventors
- LEI SHAOGANG
- WANG JUNTAO
- CHUAI ZHENZHONG
- XIA ZHONGLIN
Assignees
- 华为技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20241108
Claims (11)
- 1. A calling method, applied to an electronic device, the method comprising: In the process of a first method through a first line Cheng Zhihang, responding to the first method instruction to call a second method, and generating a call identifier, wherein the call identifier is used for acquiring a call relation between the first method and the second method; A first relationship through the first line Cheng Baocun, the first relationship including a relationship between the call identifier, the first method, and the second method; During execution of the second method by the second thread, the execution is marked by the call identification.
- 2. The method of claim 1, wherein during the first method through the first line Cheng Zhihang, in response to the first method indicating a call to a second method, the method further comprises, prior to generating a call identifier: according to the second method, a third method is generated, the third method comprising the second method and processing logic for instructing to save the first relationship.
- 3. The method of claim 2, wherein the saving, by the first thread, of the first relationship comprises: The processing logic in the third method is executed by the first thread to preserve the first relationship.
- 4. A method according to any one of claims 1-3, wherein said performing a procedure by said call identification tag comprises: And respectively adding the calling identification at the starting position and the ending position of the second method to be called through the second thread.
- 5. The method according to claim 4, wherein the method further comprises: saving a start time of adding the call identifier at the start position; and saving the end time of adding the call identifier at the end position.
- 6. The method of claim 5, wherein the method further comprises: And storing a second relation, wherein the second relation comprises a relation between the calling identifier, the starting time, the ending time and the thread number of the second thread.
- 7. The method according to any one of claims 1-6, further comprising: Acquiring the calling identifier; acquiring information of the execution process of the first relation and the second method according to the calling identification; and determining the execution paths of the first method and the second method according to the information of the execution process of the first relation and the second method.
- 8. An electronic device comprising a processor and a memory coupled to the processor, the memory for storing computer readable instructions that, when read from the memory by the processor, cause the electronic device to perform the method of any of claims 1-7.
- 9. A system on a chip comprising at least one processor and at least one interface circuit, the at least one interface circuit configured to perform a transceiving function and to send instructions to the at least one processor, the at least one processor executing the instructions, the at least one processor performing the method of any of claims 1-7.
- 10. A computer readable storage medium, characterized in that the computer readable storage medium comprises a computer program which, when run on an electronic device, causes the electronic device to perform the method according to any of claims 1-7.
- 11. A computer program product, characterized in that it comprises a computer program or instructions which, when run on a computer, cause the computer to carry out the method according to any one of claims 1-7.
Description
Calling method and electronic equipment Technical Field The present application relates to the field of electronic technologies, and in particular, to a calling method and an electronic device. Background Synchronous calls and asynchronous calls are two ways of program calls. For example, in synchronous call, when the program is executed to the call point, a request is sent to the called point, and after the called point finishes processing and returns a processing result, the program can execute the subsequent code. The call site and the called site are typically executed in the same thread during the synchronous call. In asynchronous calls, when program execution reaches the call site, a request is sent to the call site and immediately returned, and the program continues to execute subsequent code. The call point responds to the request to execute processing logic in another thread, and returns a processing result after processing is completed. The call site and the called site are typically executed in different threads during an asynchronous call. Wherein the call site is used to initiate a call, typically a method or function, and the called site is used to execute a call, typically another method or function. For example, method A calls method B, method A is the call site, and method B is the called site. The call point and the called point of the synchronous call are executed in the same thread, and the call stack of the call point and the call stack of the called point are linear. Thus, the entire execution path of the synchronous call can be traced back clearly. And the calling point and the called point of the asynchronous call are executed in different threads, so that tracing is difficult, and the whole execution path of the asynchronous call cannot be traced. Disclosure of Invention The application provides a calling method and electronic equipment, wherein a calling method and a called method are associated through a calling identifier, and a complete instruction path is obtained. The tracing difficulty in asynchronous call is simplified, and the management of asynchronous call is optimized. In order to achieve the above purpose, the application adopts the following technical scheme: In a first aspect, the application provides a calling method applied to electronic equipment, the method comprises the steps of responding to a first method instruction to call a second method in the process of the first method through a first line Cheng Zhihang, generating a calling identifier, wherein the calling identifier is used for acquiring a calling relation between the first method and the second method, the first relation comprises the calling identifier and the relation between the first method and the second method through a first line Cheng Baocun, and the process is executed through a calling identifier mark in the process of executing the second method through a second thread. According to the method and the device, the calling relation of the asynchronous method is saved through the calling identification, the traceability of the program is improved, the calling chain of the asynchronous method can be traced back easily in a plurality of threads, and the asynchronous calling process can be accurately restored. The difficulty of asynchronous call tracing is simplified, and the management of asynchronous call is optimized so as to accurately analyze the performance consumption of asynchronous call. According to the first aspect, or any implementation manner of the first aspect, in a process of the first method through the first line Cheng Zhihang, before the call identifier is generated in response to the first method indicating to call the second method, the method further includes generating a third method according to the second method, where the third method includes the second method and processing logic, and the processing logic is configured to instruct to save the first relationship. The third method, illustratively, includes a Hook method encapsulating the second method and the processing logic. In the application, the third method inserts additional processing logic for realizing functions such as recording under the condition of not changing the original second method code. The maintainability and the expandability of codes are improved, the tracing problem during asynchronous call is simplified, and the tracing of the execution path of asynchronous call is facilitated. The implementation of the second method is not affected, the function is enhanced, the asynchronous call flow is optimized, and the overall performance of asynchronous call is improved. In accordance with the first aspect, or any implementation of the first aspect above, the first relationship is maintained by a first line Cheng Baocun, including by processing logic in a third method of the first line Cheng Zhihang. In some examples, after generating the call identifier, the electronic device passes the call identifier as a