WO2019134291A1 - Method for recording call information between program interfaces, and electronic device - Google Patents
Method for recording call information between program interfaces, and electronic device Download PDFInfo
- Publication number
- WO2019134291A1 WO2019134291A1 PCT/CN2018/082354 CN2018082354W WO2019134291A1 WO 2019134291 A1 WO2019134291 A1 WO 2019134291A1 CN 2018082354 W CN2018082354 W CN 2018082354W WO 2019134291 A1 WO2019134291 A1 WO 2019134291A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- program interface
- information
- call
- call information
- execution
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
- G06F8/315—Object-oriented languages
Definitions
- the present invention relates to the field of electronic technologies, and in particular, to a method, an electronic device, and a readable storage medium for recording information between program interfaces.
- interface call information is recorded in such a manner that code for recording call information is embedded in each interface to be recorded.
- code for recording call information is embedded in each interface to be recorded.
- the main drawback of this method is that each interface must be added with a record code, which is inefficient. At the same time, the record codes added by each interface are difficult to be unified, so that the recorded call information is inconsistent.
- Embodiments of the present invention provide a method, an electronic device, and a readable storage medium for recording information between program interface interfaces, which are used to provide a call information for unifying each program interface without repeatedly adding a record code to a program interface.
- the logging method keeps the recorded call log information consistent.
- the present invention provides a method for recording information between program interface interfaces, wherein a preset hook class is registered in an application program, and the preset hook class is programmed with a pre-execution method and a program interface execution method.
- the method includes:
- the program interface After the program interface is executed, the program interface is executed, and the method is executed by the program interface, and the second private call information of the program interface is generated, based on the call information and the information transmitted by the upper program interface. Decoding the first private information and the second private information, splicing out the call information that needs to be recorded, and recording the call information that needs to be recorded to the log file.
- the method of the pre-execution of the program interface includes: a method for setting an identifier of a program interface call, where the generating the first private call information of the program interface includes:
- the calling information that is transmitted by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, where the The call information of the lower level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- the method for executing the pre-execution of the program interface includes: acquiring a time when the program interface starts to be executed, where the generating the first private call information of the program interface includes:
- the method after the execution of the program interface includes a method for acquiring a time when the program interface ends execution, where the generating the second private call information of the program interface includes:
- the splicing out the call information that needs to be recorded including:
- Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
- the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier or A variety of combinations.
- an embodiment of the present invention provides an electronic device, where a preset hook class is registered in an application item in the electronic device, and a method before the execution of the program interface and a method after the program interface are written in the preset hook class
- the electronic device includes:
- a first calling unit configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the first program interface by using the program interface
- the call information transmitted by the upper program interface is extracted from the header information of the http request, the first private call information of the program interface is generated, the call information that needs to be passed to the lower program interface is determined, and the call needs to be transmitted to the lower program interface. Encapsulating information to the header information of the second http request;
- a second calling unit configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the upper program
- the calling information delivered by the interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
- the method in the pre-execution of the program interface includes a method for setting an identifier of a program interface call, where the first calling unit is used to:
- the calling information delivered by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, where the need to be transmitted to
- the call information of the lower level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- the method in the pre-execution of the program interface includes a method for acquiring a time when the program interface starts to be executed, where the first calling unit is used to:
- the method after the execution of the program interface includes a method for acquiring a time at which the program interface ends execution, and the second calling unit is configured to:
- the second calling unit is used to:
- Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
- the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier or A variety of combinations.
- an embodiment of the present invention provides an electronic device, where the electronic device includes a processor, and the processor is configured to implement a recording program interface as described in the foregoing first embodiment when executing a computer program stored in a memory. The steps of the method of invoking information.
- an embodiment of the present invention provides a readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the inter-programme interface call is implemented as described in the foregoing first embodiment. The steps of the method of information.
- the preset hook class is registered in the application project, and the pre-execution method and the program interface execution method are written in the preset hook class;
- calling the pre-execution method of the program interface extracting the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, generating the first private call information of the program interface, determining that the transfer is required Calling information to the lower level program interface; after the program interface is executed, calling the program interface to execute the method, generating the second private calling information of the program interface, based on the calling information, the first private information and the second private information transmitted by the upper program interface,
- the call information to be recorded is spliced; the call information to be recorded is recorded to the log file, and the call information that needs to be passed to the lower program interface is encapsulated to the header information of the second http request.
- FIG. 1 is a flowchart of a method for recording information between program interface interfaces in the first embodiment of the present invention
- FIG. 2 is a schematic diagram of an electronic device in a second embodiment of the present invention.
- FIG. 3 is a schematic diagram of an electronic device in a third embodiment of the present invention.
- Embodiments of the present invention provide a method, an electronic device, and a readable storage medium for recording information between program interface interfaces, which are used to provide a call information for unifying each program interface without repeatedly adding a record code to a program interface.
- the logging method keeps the recorded call log information consistent.
- the preset hook class is registered in the application project, and the pre-execution method and the program interface post-execution method are written in the preset hook class, and the method includes: the program interface in the application project is called by the upper program interface Executing the pre-execution method of the program interface, and extracting, by using the pre-execution method of the program interface, the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, and generating the program interface
- the first private call information determines the call information that needs to be delivered to the lower-level program interface, and encapsulates the call information that needs to be delivered to the lower-level program interface to the header information of the second http request; after the execution of the program interface, the call site a method of executing a program interface, executing a post-method by the program interface, generating a second private call information of the program interface, based on the call information, the first private information, and the second Private information, splicing out the call information to be
- a first embodiment of the present invention provides a method for recording call information between program interfaces.
- a preset hook class is registered in an application program, and a method and a program interface are executed before a program interface is written in a preset hook class.
- the method comprises the following steps:
- the method before the execution of the program interface includes a method for setting an identifier of a program interface call, and a method for acquiring a time when the program interface starts to be executed.
- the method for executing the program interface includes a method for acquiring a time when the program interface ends execution. And generating, by the method for setting an identifier of the program interface, the first identifier of the program interface call, and acquiring, by the method for acquiring a time when the program interface starts to execute, acquiring a start time of the execution of the program interface, by using the acquiring program
- the method of ending the execution of the interface acquires the end time at which the program interface ends execution.
- the call information delivered by the upper program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the identifier of the upper program interface, and the call information that needs to be delivered to the lower program interface. And including any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the superior program interface, the call duration, and any one or more combinations of the first identifiers.
- the interception hook in the framework is used to record the program interface call information.
- This embodiment mainly describes the PHP as a development framework.
- the hook class is registered in the application project.
- the hook class is written with the method before the execution of the program interface and the method after the program interface is executed.
- the hook class creation process is as follows:
- step S101 a call of the method before the execution of the program interface is performed.
- the pre-execution of the program interface is called before each program interface is executed, and is configured to receive the header information of the first http request sent by the upper-level program interface, and initialize the program interface call information.
- the header information of the first http request is obtained through the global variable $_SERVER in PHP, and the information required for the link record is read in the header: the identifier id of the application item, the link identifier id of the calling request, and the identifier id of the upper program interface. Wait for the call information passed by the superior program interface.
- the unique identifier id (ie, the first identifier) of the program interface call is generated by the uniqid() function of PHP, and the uniqid function can randomly generate a unique id according to the current time.
- the second parameter is filled with CURLOPT_POSTFIELDS
- the third parameter is filled in the json string to set the header, the requested link identifier id, the application id of the application project, and b) generated in the step
- the first identifier is passed to the lower level program interface in the header information header of the second http request.
- step S102 a call of the method after the execution of the program interface is performed.
- the identifier id of the application item acquired by the foregoing method before the execution of the program interface, the link identifier id of the calling request, the identifier id of the upper-level program interface, the unique identifier id of the program interface call, and the method obtained by executing the method after the program interface Call the time value, the application name name is stored in the array, and the array is converted to a json string using the json_encode function.
- registering the hook method may include the following steps:
- a method method for recording the call information of the program interface is realized, and the method does not need to embed the code in each program interface, but can record information of all the program interfaces in the framework.
- the efficiency is very high.
- the method eliminates the tedious labor of repeatedly writing the code of the previous call information, and makes the code uniform and easy to manage.
- the registered hook information may be used to retrieve the header information of the first http request before the execution of the program interface, including: calling the requested link identifier id (identifying the unique id of each request call chain), and identifying the identifier of the application item.
- the id, the identifier of the superior program interface, and other information and generate information such as the unique id called by the program interface, the start time of the program interface call, and the like.
- the information such as the link identifier id of the calling request, the identifier id of the application item, and the unique id called by the program interface are put into the header information of the second http request, and then passed to the next interface.
- the call information such as the program interface call time is saved in the form of a log.
- the method in this embodiment does not need to embed the code for recording the call information in the interface, and only needs to add a hook in the program framework to perform a specific operation before and after the execution of the program interface. This eliminates the cumbersome operation of embedding code in each program interface, and unifies the call information recording method of each program interface, so that the recorded log information remains consistent. Therefore, using this method greatly improves the efficiency and facilitates the unified management of the code base.
- a second embodiment of the present invention provides an electronic device, where a preset hook class is registered in an application item in the electronic device, and the pre-execution method is programmed in the preset hook class.
- the electronic device includes:
- a first calling unit 201 configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the upper-level program interface by using the program interface Extracting the call information passed by the upper program interface from the header information of the http request, generating the first private call information of the program interface, determining the call information that needs to be passed to the lower program interface, and transmitting the need to the lower program interface. Invoking information encapsulated to the header information of the second http request;
- a second calling unit 202 configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the superior
- the call information transmitted by the program interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
- the method before the execution of the program interface includes a method for setting an identifier of a program interface call, and a method for acquiring a time when the program interface starts to be executed.
- the method for executing the program interface includes a method for acquiring a time when the program interface ends execution. And generating, by the method for setting an identifier of the program interface, the first identifier of the program interface call, and acquiring, by the method for acquiring a time when the program interface starts to execute, acquiring a start time of the execution of the program interface, by using the acquiring program
- the method of ending the execution of the interface acquires the end time at which the program interface ends execution.
- the call information delivered by the upper program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the identifier of the upper program interface, and the call information that needs to be delivered to the lower program interface. And including any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the superior program interface, the call duration, and any one or more combinations of the first identifiers.
- the electronic device is installed with a software development platform, and when the software development platform is used for application development, the interceptor hook in the framework is used to record the program interface call information.
- This embodiment mainly describes the PHP as a development framework.
- the hook class is registered in the application project, and the hook method is programmed with a pre-execution method and a post-execution method.
- the hook class creation process is as follows:
- the pre-execution of the program interface is called before each program interface is executed, and is used to receive the header information of the first http request sent by the upper-level program interface, and initialize the program. Interface call information.
- the header information of the first http request is obtained through the global variable $_SERVER in PHP, and the information required for the link record is read in the header: the identifier id of the application item, the link identifier id of the calling request, and the identifier id of the upper program interface. Wait for the call information passed by the superior program interface.
- the unique identifier id (ie, the first identifier) of the program interface call is generated by the uniqid() function of PHP, and the uniqid function can randomly generate a unique id according to the current time.
- the second parameter is filled with CURLOPT_POSTFIELDS
- the third parameter is filled in the json string to set the header, the requested link identifier id, the application id of the application project, and b) generated in the step
- the first identifier is passed to the lower level program interface in the header information header of the second http request.
- the second calling unit 202 calls the program interface to execute the post method, and records the call information.
- the hook class created in the foregoing a new public class is created, and the end method is included in the class.
- the method code is written. The writing steps are as follows:
- the identifier id of the application item acquired by the foregoing method before the execution of the program interface, the link identifier id of the calling request, the identifier id of the upper-level program interface, the unique identifier id of the program interface call, and the method obtained by executing the method after the program interface Call the time value, the application name name is stored in the array, and the array is converted to a json string using the json_encode function.
- registering the hook method may include the following steps:
- a method method for recording the call information of the program interface is realized, and the method does not need to embed the code in each program interface, but can record information of all the program interfaces in the framework.
- the efficiency is very high.
- the method eliminates the tedious labor of repeatedly writing the code of the previous call information, and makes the code uniform and easy to manage.
- the registered hook information may be used to retrieve the header information of the first http request before the execution of the program interface, including: calling the requested link identifier id (identifying the unique id of each request call chain), and identifying the identifier of the application item.
- the id, the identifier of the superior program interface, and other information and generate information such as the unique id called by the program interface, the start time of the program interface call, and the like.
- the call information such as the program interface call time is saved in the form of a log, and then the link identifier id of the call request, the identifier id of the application item, and the unique id called by the program interface are put into the first
- the header information of the two http request is passed to the next interface.
- the electronic device in this embodiment does not need to embed the code for recording the call information in the interface, and only needs to add a hook in the program frame to perform a specific operation before and after the execution of the program interface. This eliminates the cumbersome operation of embedding code in each program interface, and unifies the call information recording method of each program interface, so that the recorded log information remains consistent. Therefore, the efficiency is greatly improved, and the unified management of the code base is facilitated.
- a third embodiment of the present invention provides an electronic device, where the electronic device includes: a processor 301, a memory 302, and is stored in the memory and operable on the processor.
- a computer program for example, a program corresponding to a method of recording information between program interface interfaces in the first embodiment. The steps in the path detection in the first embodiment described above are implemented when the processor executes the computer program. Alternatively, the processor implements the functions of the modules/units in the electronic device of the second embodiment described above when the computer program is executed.
- the computer program can be partitioned into one or more modules/units that are stored in the memory and executed by the processor to perform the present invention.
- the one or more modules/units may be a series of computer program instruction segments capable of performing a particular function, the instruction segments being used to describe the execution of the computer program in the computer device.
- the computer program may be divided into functions of a first calling unit and a second calling unit, and a preset hook class is registered in an application item in the electronic device, and a program interface is executed in the preset hook class. Before the method and program interface are executed, the specific functions of each unit are as follows:
- a first calling unit configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the first program interface by using the program interface
- the call information transmitted by the upper program interface is extracted from the header information of the http request, the first private call information of the program interface is generated, the call information that needs to be passed to the lower program interface is determined, and the call needs to be transmitted to the lower program interface. Encapsulating information to the header information of the second http request;
- a second calling unit configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the upper-level program
- the calling information delivered by the interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
- the electronic device can include, but is not limited to, a processor, a memory. It will be understood by those skilled in the art that the schematic diagram 3 is merely an example of a computer device and does not constitute a limitation on an electronic device, and may include more or less components than those illustrated, or may combine certain components or different components.
- the electronic device may further include an input and output device, a network access device, a bus, and the like.
- the processor 301 may be a central processing unit (CPU), or may be other general-purpose processors, a digital signal processor (DSP), an application specific integrated circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.
- the general purpose processor may be a microprocessor or the processor or any conventional processor or the like, which is the control center of the computer device, which is connected to various parts of the entire computer device using various interfaces and lines.
- the memory 302 can be used to store the computer program and/or module, the processor implementing the method by running or executing a computer program and/or module stored in the memory, and invoking data stored in the memory Various functions of a computer device.
- the memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may be stored. Data created according to the use of the mobile phone (such as audio data, video data, etc.).
- the memory may include a high-speed random access memory, and may also include non-volatile memory such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC), and a Secure Digital (SD) card.
- non-volatile memory such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC), and a Secure Digital (SD) card.
- Flash Card at least one disk storage device, flash memory device, or other volatile solid-state storage device.
- processor 301 included in the electronic device further has the following functions:
- the method of the program interface includes a method for setting an identifier of a program interface call, and the method for setting an identifier of the program interface is used to generate a first identifier that is invoked by the program interface, where the first private call information includes the First identification.
- the calling information delivered by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, and the need to be transmitted to the lower-level program.
- the call information of the interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- processor 301 included in the electronic device further has the following functions:
- the method of the pre-execution of the program interface includes: acquiring a time when the program interface starts to be executed, and acquiring, by the method for acquiring a time when the program interface starts execution, the start time of the execution of the program interface, where the first private call information includes The starting moment.
- processor 301 included in the electronic device further has the following functions:
- the method after the execution of the program interface includes a method for acquiring a time at which the program interface ends execution, and acquiring, by the method for obtaining a time at which the program interface ends execution, an end time at which the program interface ends execution, where the second private call information includes The end time.
- processor 301 included in the electronic device further has the following functions:
- Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
- the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier. combination.
- a fourth embodiment of the present invention provides a computer readable storage medium having stored thereon a computer program, and the functional unit integrated by the electronic device in the second embodiment of the present invention is implemented in the form of a software functional unit and is independent When the product is sold or used, it can be stored in a computer readable storage medium.
- the present invention implements all or part of the flow of the method for invoking information between the recording program interfaces of the first embodiment, and may also be completed by a computer program to instruct related hardware, and the computer program may be stored in In a computer readable storage medium, the computer program, when executed by a processor, implements the steps of the various method embodiments described above.
- the computer program comprises computer program code, which may be in the form of source code, object code form, executable file or some intermediate form.
- the computer readable medium may include any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read-0nly Memory). , random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunications signals, and software distribution media.
- the content contained in the computer readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in a jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, computer readable media Does not include electrical carrier signals and telecommunication signals.
- the preset hook class is registered in the application project, and the pre-execution method and the program interface execution method are written in the preset hook class;
- calling the pre-execution method of the program interface extracting the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, generating the first private call information of the program interface, determining that the transfer is required Calling information to the lower level program interface; after the program interface is executed, calling the program interface to execute the method, generating the second private calling information of the program interface, based on the calling information, the first private information and the second private information transmitted by the upper program interface,
- the call information to be recorded is spliced; the call information to be recorded is recorded to the log file, and the call information that needs to be passed to the lower program interface is encapsulated to the header information of the second http request.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computing Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Abstract
A method for recording call information between program interfaces, and an electronic device, for providing a recording method for unifying call information of each program interface. A pre-set hook class is registered in an application program project, a method preceding program interface execution and a method after program interface execution are coded in the class. The method comprises: before a program interface in an application program project is called by an upper-layer program interface, calling the method preceding program interface execution to extract, from header information of a first http request of the upper-layer program interface, call information transferred by the upper-layer program interface, generating first private call information, determining call information needing to be transferred to a lower-layer program interface and encapsulating same into header information of a second http request (S101); and after the execution of the program interface, calling the method after program interface execution, generating second private call information of the program interface, splicing call information needing to be recorded and recording, to a log file, the call information needing to be recorded (S102).
Description
本发明涉及电子技术领域,尤其涉及一种记录程序接口间调用信息的方法、电子设备及可读存储介质。The present invention relates to the field of electronic technologies, and in particular, to a method, an electronic device, and a readable storage medium for recording information between program interfaces.
在应用程序开发过程中,可能会需要了解业务层和服务层程序接口的调用流程,获取接口的调用信息,例如:接口请求来源、接口地址、接口执行时间等。现有技术中,采用在每个需要记录的接口中嵌入记录调用信息的代码的方式来记录接口调用信息。这种方法的主要缺陷在于,每个接口都要添加记录代码,重复劳动效率低下。同时每个接口添加的记录代码难以统一,使得记录的调用信息不一致。During the application development process, you may need to understand the calling process of the business layer and the service layer program interface, and obtain the calling information of the interface, such as: interface request source, interface address, interface execution time, and so on. In the prior art, interface call information is recorded in such a manner that code for recording call information is embedded in each interface to be recorded. The main drawback of this method is that each interface must be added with a record code, which is inefficient. At the same time, the record codes added by each interface are difficult to be unified, so that the recorded call information is inconsistent.
发明内容Summary of the invention
本发明实施例提供了一种记录程序接口间调用信息的方法、电子设备及可读存储介质,用于提供一种不必重复在程序接口添加记录代码的情况下,统一每个程序接口的调用信息的记录方法,使记录的调用日志信息保持了一致。Embodiments of the present invention provide a method, an electronic device, and a readable storage medium for recording information between program interface interfaces, which are used to provide a call information for unifying each program interface without repeatedly adding a record code to a program interface. The logging method keeps the recorded call log information consistent.
第一方面,本发明提供了一种记录程序接口间调用信息的方法,应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,所述方法包括:In a first aspect, the present invention provides a method for recording information between program interface interfaces, wherein a preset hook class is registered in an application program, and the preset hook class is programmed with a pre-execution method and a program interface execution method. The method includes:
在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;Before the program interface in the application project is called by the upper program interface, calling the program interface pre-execution method, and executing the pre-method from the header information of the first http request of the upper-level program interface by using the program interface Extracting the call information passed by the upper program interface, generating the first private call information of the program interface, determining the call information that needs to be passed to the lower program interface, and encapsulating the call information that needs to be passed to the lower program interface to the second http request Header information;
在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。After the program interface is executed, the program interface is executed, and the method is executed by the program interface, and the second private call information of the program interface is generated, based on the call information and the information transmitted by the upper program interface. Decoding the first private information and the second private information, splicing out the call information that needs to be recorded, and recording the call information that needs to be recorded to the log file.
可选的,所述程序接口执行前方法中包括设置程序接口调用的标识的方法,所述生成所述程序接口的第一私有调用信息,包括:Optionally, the method of the pre-execution of the program interface includes: a method for setting an identifier of a program interface call, where the generating the first private call information of the program interface includes:
通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,所述第一私有调用信息包括所述第一标识。And generating, by the method for setting an identifier of the program interface, a first identifier of the program interface call, where the first private call information includes the first identifier.
可选的,所述上级程序接口传递的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合, 所述需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的链路标识、所述第一标识中任意一种或多种组合。Optionally, the calling information that is transmitted by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, where the The call information of the lower level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
可选的,所述程序接口执行前方法中包括获取程序接口开始执行的时间的方法,所述生成所述程序接口的第一私有调用信息,包括:Optionally, the method for executing the pre-execution of the program interface includes: acquiring a time when the program interface starts to be executed, where the generating the first private call information of the program interface includes:
通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开始时刻,所述第一私有调用信息包括所述开始时刻。And acquiring, by the method for acquiring a time when the program interface starts execution, a start time at which the program interface starts to be executed, where the first private call information includes the start time.
可选的,所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法,所述生成所述程序接口的第二私有调用信息,包括:Optionally, the method after the execution of the program interface includes a method for acquiring a time when the program interface ends execution, where the generating the second private call information of the program interface includes:
通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻,所述第二私有调用信息包括所述结束时刻。Obtaining, by the method for obtaining the time of execution of the program interface, an end time of ending execution of the program interface, where the second private call information includes the end time.
可选的,所述拼接出需要记录的调用信息,包括:Optionally, the splicing out the call information that needs to be recorded, including:
基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长,所述需要记录的调用信息包括所述调用信息。Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
可选的,所述需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。Optionally, the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier or A variety of combinations.
第二方面,本发明实施例提供一种电子设备,所述电子设备中的应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,所述电子设备包括:In a second aspect, an embodiment of the present invention provides an electronic device, where a preset hook class is registered in an application item in the electronic device, and a method before the execution of the program interface and a method after the program interface are written in the preset hook class The electronic device includes:
第一调用单元,用于在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;a first calling unit, configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the first program interface by using the program interface The call information transmitted by the upper program interface is extracted from the header information of the http request, the first private call information of the program interface is generated, the call information that needs to be passed to the lower program interface is determined, and the call needs to be transmitted to the lower program interface. Encapsulating information to the header information of the second http request;
第二调用单元,用于在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。a second calling unit, configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the upper program The calling information delivered by the interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
可选的,所述程序接口执行前方法中包括设置程序接口调用的标识的方法,所述第一调用单元用于:Optionally, the method in the pre-execution of the program interface includes a method for setting an identifier of a program interface call, where the first calling unit is used to:
通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,所述第一私有调用信息包括所述第一标识。And generating, by the method for setting an identifier of the program interface, a first identifier of the program interface call, where the first private call information includes the first identifier.
可选的,所述上级程序接口传递的调用信息包括所述应用程序项目的标 识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合,所述需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的链路标识、所述第一标识中任意一种或多种组合。Optionally, the calling information delivered by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, where the need to be transmitted to The call information of the lower level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
可选的,所述程序接口执行前方法中包括获取程序接口开始执行的时间的方法,所述第一调用单元用于:Optionally, the method in the pre-execution of the program interface includes a method for acquiring a time when the program interface starts to be executed, where the first calling unit is used to:
通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开始时刻,所述第一私有调用信息包括所述开始时刻。And acquiring, by the method for acquiring a time when the program interface starts execution, a start time at which the program interface starts to be executed, where the first private call information includes the start time.
可选的,所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法,所述第二调用单元用于:Optionally, the method after the execution of the program interface includes a method for acquiring a time at which the program interface ends execution, and the second calling unit is configured to:
通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻,所述第二私有调用信息包括所述结束时刻。Obtaining, by the method for obtaining the time of execution of the program interface, an end time of ending execution of the program interface, where the second private call information includes the end time.
可选的,所述第二调用单元用于:Optionally, the second calling unit is used to:
基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长,所述需要记录的调用信息包括所述调用信息。Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
可选的,所述需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。Optionally, the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier or A variety of combinations.
第三方面,本发明实施例提供一种电子设备,所述电子设备包括处理器,所述处理器用于执行存储器中存储的计算机程序时实现如前述第一方面实施例中所述的记录程序接口间调用信息的方法的步骤。In a third aspect, an embodiment of the present invention provides an electronic device, where the electronic device includes a processor, and the processor is configured to implement a recording program interface as described in the foregoing first embodiment when executing a computer program stored in a memory. The steps of the method of invoking information.
第四方面,本发明实施例提供了一种可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如前述第一方面实施例中所述的记录程序接口间调用信息的方法的步骤。In a fourth aspect, an embodiment of the present invention provides a readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the inter-programme interface call is implemented as described in the foregoing first embodiment. The steps of the method of information.
本申请实施例中的上述一个或多个技术方案,至少具有如下一种或多种技术效果:The above one or more technical solutions in the embodiments of the present application have at least one or more of the following technical effects:
在本发明实施例的技术方案中,在进行应用程序开发时,在应用程序项目中注册预设hook类,预设hook类中编写有程序接口执行前方法和程序接口执行后方法;在程序接口被上级程序接口调用前,调用程序接口执行前方法,从上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息;在程序接口执行后,调用程序接口执行后方法,生成程序接口的第二私有调用信息,基于上级程序接口传递的调用信息、第一私有信息与第二私有信息,拼接出需要记录的调用信息;将需要记录的调用信息记录至日志文件,将需要传递至下级程序接口的调用信息封装至第二http请求的头部信息。由于 不需要在每个程序接口中嵌入记录调用信息的代码,只需要在程序框架中注册一个hook类,使其在程序接口执行前后进行特定的操作。这样既省去的在每个程序接口嵌入代码的繁琐操作,又统一了每个程序接口的调用信息记录方法,使记录出的日志信息保持了一致,所以,极大地提高了效率,并且有利于代码库的统一管理。In the technical solution of the embodiment of the present invention, when the application is developed, the preset hook class is registered in the application project, and the pre-execution method and the program interface execution method are written in the preset hook class; Before being called by the upper-level program interface, calling the pre-execution method of the program interface, extracting the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, generating the first private call information of the program interface, determining that the transfer is required Calling information to the lower level program interface; after the program interface is executed, calling the program interface to execute the method, generating the second private calling information of the program interface, based on the calling information, the first private information and the second private information transmitted by the upper program interface, The call information to be recorded is spliced; the call information to be recorded is recorded to the log file, and the call information that needs to be passed to the lower program interface is encapsulated to the header information of the second http request. Since there is no need to embed code that records the call information in each program interface, you only need to register a hook class in the program framework to perform specific operations before and after the program interface is executed. In this way, the cumbersome operation of embedding the code in each program interface is omitted, and the call information recording method of each program interface is unified, so that the recorded log information is kept consistent, so the efficiency is greatly improved, and it is advantageous. Unified management of the code base.
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief description of the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description It is a certain embodiment of the present invention, and other drawings can be obtained from those skilled in the art without any creative work.
图1为本发明第一实施例中的一种记录程序接口间调用信息的方法的流程图;1 is a flowchart of a method for recording information between program interface interfaces in the first embodiment of the present invention;
图2为本发明第二实施例中的电子设备的示意图;2 is a schematic diagram of an electronic device in a second embodiment of the present invention;
图3为本发明第三实施例中电子设备的示意图。3 is a schematic diagram of an electronic device in a third embodiment of the present invention.
本发明实施例提供了一种记录程序接口间调用信息的方法、电子设备及可读存储介质,用于提供一种不必重复在程序接口添加记录代码的情况下,统一每个程序接口的调用信息的记录方法,使记录的调用日志信息保持了一致。应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,该方法包括:在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。Embodiments of the present invention provide a method, an electronic device, and a readable storage medium for recording information between program interface interfaces, which are used to provide a call information for unifying each program interface without repeatedly adding a record code to a program interface. The logging method keeps the recorded call log information consistent. The preset hook class is registered in the application project, and the pre-execution method and the program interface post-execution method are written in the preset hook class, and the method includes: the program interface in the application project is called by the upper program interface Executing the pre-execution method of the program interface, and extracting, by using the pre-execution method of the program interface, the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, and generating the program interface The first private call information determines the call information that needs to be delivered to the lower-level program interface, and encapsulates the call information that needs to be delivered to the lower-level program interface to the header information of the second http request; after the execution of the program interface, the call site a method of executing a program interface, executing a post-method by the program interface, generating a second private call information of the program interface, based on the call information, the first private information, and the second Private information, splicing out the call information to be recorded, and recording the call information to be recorded to the date Zhi file.
下面通过附图以及具体实施例对本发明技术方案做详细的说明,应当理解本申请实施例以及实施例中的具体特征是对本申请技术方案的详细的说明,而不是对本申请技术方案的限定,在不冲突的情况下,本申请实施例以及实施例 中的技术特征可以相互组合。The technical solutions of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments. It is understood that the specific features of the embodiments and the embodiments of the present application are the detailed description of the technical solutions of the present application, and are not limited to the technical solutions of the present application. In the case of no conflict, the technical features in the embodiments of the present application and the embodiments may be combined with each other.
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。The term "and/or" in this context is merely an association describing the associated object, indicating that there may be three relationships, for example, A and / or B, which may indicate that A exists separately, and both A and B exist, respectively. B these three situations. In addition, the character "/" in this article generally indicates that the contextual object is an "or" relationship.
实施例Example
请参考图1,本发明第一实施例提供一种记录程序接口间调用信息的方法,应用程序项目中注册预设hook类,预设hook类中编写有程序接口执行前方法和程序接口执行后方法,该方法包括如下步骤:Referring to FIG. 1 , a first embodiment of the present invention provides a method for recording call information between program interfaces. A preset hook class is registered in an application program, and a method and a program interface are executed before a program interface is written in a preset hook class. The method comprises the following steps:
S101:在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;S101: before the program interface in the application project is called by the upper program interface, calling the pre-execution method of the program interface, and executing, by the program interface, a header of the first http request from the upper-level program interface Extracting the call information passed by the upper program interface, generating the first private call information of the program interface, determining the call information that needs to be passed to the lower program interface, and packaging the call information that needs to be passed to the lower program interface to the second Header information of the http request;
S102:在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。S102: After the program interface is executed, calling the program interface execution method, and executing the post method by the program interface, generating second private call information of the program interface, and using the call information transmitted by the upper program interface The first private information and the second private information are spliced together with call information that needs to be recorded, and the call information that needs to be recorded is recorded to a log file.
其中,所述程序接口执行前方法中包括设置程序接口调用的标识的方法、获取程序接口开始执行的时间的方法,所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法。通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开始时刻,通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻。所述第一私有调用信息包括所述第一标识、所述开始时刻,所述第二私有调用信息包括所述结束时刻。拼接出需要记录的调用信息,包括:基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长。The method before the execution of the program interface includes a method for setting an identifier of a program interface call, and a method for acquiring a time when the program interface starts to be executed. The method for executing the program interface includes a method for acquiring a time when the program interface ends execution. And generating, by the method for setting an identifier of the program interface, the first identifier of the program interface call, and acquiring, by the method for acquiring a time when the program interface starts to execute, acquiring a start time of the execution of the program interface, by using the acquiring program The method of ending the execution of the interface acquires the end time at which the program interface ends execution. The first private call information includes the first identifier, the start time, and the second private call information includes the end time. Splicing out the call information to be recorded includes: determining a call duration of the program interface based on the start time and the end time.
进一步,上级程序接口传递的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合,需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的链路标识、所述第一标识中任意一种或多种组合。需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。Further, the call information delivered by the upper program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the identifier of the upper program interface, and the call information that needs to be delivered to the lower program interface. And including any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier. The call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the superior program interface, the call duration, and any one or more combinations of the first identifiers.
具体的,在本实施例中,在进行应用程序开发时,利用框架中的拦截器 hook,进行程序接口调用信息的记录。本实施例主要以开发框架为PHP进行详细描述。应用程序项目中注册了hook类,该hook类中编写有程序接口执行前方法和程序接口执行后方法。hook类创建过程如下:Specifically, in the embodiment, when the application development is performed, the interception hook in the framework is used to record the program interface call information. This embodiment mainly describes the PHP as a development framework. The hook class is registered in the application project. The hook class is written with the method before the execution of the program interface and the method after the program interface is executed. The hook class creation process is as follows:
首先,创建一个hook方法类First, create a hook method class
不管是在PHP框架还是在Go框架中,要先实现拦截器功能,首先要创建一个hook方法类。因此,首先需要创建一个hook类,在这个类中编写程序接口执行前方法代码和程序接口执行后方法代码。hook方法类注册在应用程序项目中。Whether in the PHP framework or in the Go framework, to implement the interceptor function first, you must first create a hook method class. Therefore, you first need to create a hook class in which to write the pre-execution method code and the post-execution method code. The hook method class is registered in the application project.
然后,通过步骤S101,进行程序接口执行前方法的调用。Then, through step S101, a call of the method before the execution of the program interface is performed.
在本实施例中,程序接口执行前方法在每个程序接口执行前被调用,用来接收上级程序接口传来的第一http请求的头部信息,并初始化该程序接口调用信息。In this embodiment, the pre-execution of the program interface is called before each program interface is executed, and is configured to receive the header information of the first http request sent by the upper-level program interface, and initialize the program interface call information.
在上述创建的hook类中,创建一个新的public类,该类中包括start方法,并在start中进行程序接口执行前代码编写,编写步骤包括如下几个步骤:In the hook class created above, create a new public class, which includes the start method, and write the code before the execution of the program interface in start. The writing steps include the following steps:
a)接收上级程序接口传来的第一http请求的头部header信息a) receiving the header information of the first http request from the upper-level program interface
通过PHP中的全局变量$_SERVER获取第一http请求的header信息,在header中读取链路记录需要的信息:应用程序项目的标识id、调用请求的链路标识id、上级程序接口的标识id等上级程序接口传递的调用信息。The header information of the first http request is obtained through the global variable $_SERVER in PHP, and the information required for the link record is read in the header: the identifier id of the application item, the link identifier id of the calling request, and the identifier id of the upper program interface. Wait for the call information passed by the superior program interface.
b)设置程序接口调用的唯一idb) set the unique id of the program interface call
通过PHP的uniqid()函数生成此次程序接口调用的唯一性标识id(即第一标识),uniqid函数可以根据当前时间精确微秒级随机出唯一id。The unique identifier id (ie, the first identifier) of the program interface call is generated by the uniqid() function of PHP, and the uniqid function can randomly generate a unique id according to the current time.
c)Request http header信息设置c) Request http header information setting
调用PHP的curl_setopt方法,第二个参数填CURLOPT_POSTFIELDS,第三个参数填入要设置header的json字符串,将调用请求的链路标识id、应应用程序项目的标识id以及b)步骤中生成的第一标识放入第二http请求的头部信息header中向下级程序接口传递。Call PHP's curl_setopt method, the second parameter is filled with CURLOPT_POSTFIELDS, the third parameter is filled in the json string to set the header, the requested link identifier id, the application id of the application project, and b) generated in the step The first identifier is passed to the lower level program interface in the header information header of the second http request.
d)获取程序接口开始执行的时间的方法d) method of obtaining the time at which the program interface starts executing
调用PHP的time()方法,获取程序接口开始执行的开始时刻startTime。Call the time() method of PHP to get the start time startTime of the program interface.
然后,通过步骤S102,进行程序接口执行后方法的调用。Then, through step S102, a call of the method after the execution of the program interface is performed.
通过上述程序接口执行前方法,已经完成了对上级程序接口传来的第一http请求头部信息header的接收,并初始化了程序接口调用的唯一性标识id。调用程序接口执行后方法,要对调用信息进行日志记录,在前述中创建的hook类中,创建一个新的public类,该类中包括end方法,并在end中进行程序 接口执行后方法代码编写,编写步骤如下:Through the execution of the pre-method of the above program interface, the reception of the first http request header information header transmitted from the upper-level program interface has been completed, and the unique identifier id of the program interface call is initialized. After calling the program interface to execute the method, log the call information. In the hook class created in the above, create a new public class, including the end method in the class, and execute the method code after executing the program interface in the end. , the writing steps are as follows:
a)计算程序接口执行时间a) Calculate the program interface execution time
再次调用PHP中的time()方法,获取程序接口执行后结束时刻endTime,使用endTime减去前述通过开始时刻startTime,得到程序接口调用时长value。Call the time() method in PHP again to get the endTime end of the program interface execution, and use the endTime minus the start time startTime to get the program interface call duration value.
b)拼接出要记录的调用信息b) stitching out the call information to be recorded
将前述通过程序接口执行前方法获取的应用程序项目的标识id、调用请求的链路标识id、上级程序接口的标识id、程序接口调用的唯一性标识id,以及通过程序接口执行后方法获取的调用时长value,应用程序名name存入数组中,使用json_encode函数将数组转化为json字符串。The identifier id of the application item acquired by the foregoing method before the execution of the program interface, the link identifier id of the calling request, the identifier id of the upper-level program interface, the unique identifier id of the program interface call, and the method obtained by executing the method after the program interface Call the time value, the application name name is stored in the array, and the array is converted to a json string using the json_encode function.
c)记录调用信息到log文件c) record the call information to the log file
使用date(″Y-m-d″)函数获取当天日期,使用fopen函数生成或打开当天日期的log文件,fopen函数第二个参数填a+,再使用fwrite函数将b)中拼接的字符串写入log文件中,fwrite第一个参数填入log文件句柄,第二个参数填入json字符串。Use the date ("Ymd") function to get the date of the day, use the fopen function to generate or open the log file of the day's date, the second parameter of the fopen function fills in a+, and then use the fwrite function to write the string spliced in b) into the log file. The first parameter of fwrite is filled in the log file handle, and the second parameter is filled in the json string.
通过上述步骤,完成了hook类方法的调用。所以在框架中,只需要对hook类进行注册即可记录链路信息。Through the above steps, the call of the hook class method is completed. So in the framework, you only need to register the hook class to record the link information.
具体的,对hook类方法进行注册可包括如下步骤:Specifically, registering the hook method may include the following steps:
1)建立hook.php文件,对hook注册进行集中管理。1) Create a hook.php file for centralized management of hook registration.
2)利用框架中的$hook[′pre_controller′],在控制器执行前注册start方法。给$hook[′pre_controller′]赋值一个数组,数组中class的值为本案创建的hook类名称、function的值为start,filename值为hook类方法所在文件名,filepath值为类方法所在文件路径。2) Use the $hook['pre_controller'] in the framework to register the start method before the controller executes. Assign an array to $hook['pre_controller']. The value of the class in the array is the name of the hook class created in this case, the value of function is start, the filename is the file name of the method of the hook class, and the filepath is the file path where the class method is located.
3)利用框架中的$hook[′post_controller′],在控制器执行前注册start方法。给$hook[′post_controller′]赋值一个数组,数组中的值与前述2)中除function值为end外其他值相同。3) Use the $hook['post_controller'] in the framework to register the start method before the controller executes. Assign an array to $hook['post_controller']. The values in the array are the same as those in the previous 2) except that the function value is end.
通过上述的在框架中创建hook方法并注册的过程,实现了记录程序接口调用信息的方法方法,该方法不需要在每个程序接口中嵌入代码,却可以对框架中所有程序接口进行信息记录,效率十分高,同时,该方法消除了之前记录调用信息重复写代码的繁琐劳动,使代码统一易管理。Through the above process of creating a hook method in the framework and registering, a method method for recording the call information of the program interface is realized, and the method does not need to embed the code in each program interface, but can record information of all the program interfaces in the framework. The efficiency is very high. At the same time, the method eliminates the tedious labor of repeatedly writing the code of the previous call information, and makes the code uniform and easy to manage.
进而,可通过注册的hook类,在程序接口执行前,取出第一http请求的header信息,包括:调用请求的链路标识id(标识每条请求调用链的唯一id)、应用程序项目的标识id、上级程序接口的标识id等信息,并生成该程序接口调用的唯一id、程序接口调用的开始时刻等信息。再将调用请求的链路标识 id、应用程序项目的标识id、该程序接口调用的唯一id等信息放入第二http请求的header信息中,传递给下一个接口。在程序接口执行后,将程序接口调用时间等调用信息以日志的形式保存下来。Further, the registered hook information may be used to retrieve the header information of the first http request before the execution of the program interface, including: calling the requested link identifier id (identifying the unique id of each request call chain), and identifying the identifier of the application item. The id, the identifier of the superior program interface, and other information, and generate information such as the unique id called by the program interface, the start time of the program interface call, and the like. Then, the information such as the link identifier id of the calling request, the identifier id of the application item, and the unique id called by the program interface are put into the header information of the second http request, and then passed to the next interface. After the program interface is executed, the call information such as the program interface call time is saved in the form of a log.
本实施例中的方法,不需要在接口中嵌入记录调用信息的代码,只需要在程序框架中增加一个hook,使其在程序接口执行前后进行特定的操作。这样既省去的在每个程序接口嵌入代码的繁琐操作,又统一了每个程序接口的调用信息记录方法,使记录出的日志信息保持了一致。所以利用此方法,极大地提高了效率,并且有利于代码库的统一管理。The method in this embodiment does not need to embed the code for recording the call information in the interface, and only needs to add a hook in the program framework to perform a specific operation before and after the execution of the program interface. This eliminates the cumbersome operation of embedding code in each program interface, and unifies the call information recording method of each program interface, so that the recorded log information remains consistent. Therefore, using this method greatly improves the efficiency and facilitates the unified management of the code base.
请参见图2,本发明的第二实施例提供了一种电子设备,所述电子设备中的应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,所述电子设备包括:Referring to FIG. 2, a second embodiment of the present invention provides an electronic device, where a preset hook class is registered in an application item in the electronic device, and the pre-execution method is programmed in the preset hook class. After the program interface executes the method, the electronic device includes:
第一调用单元201,用于在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;a first calling unit 201, configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the upper-level program interface by using the program interface Extracting the call information passed by the upper program interface from the header information of the http request, generating the first private call information of the program interface, determining the call information that needs to be passed to the lower program interface, and transmitting the need to the lower program interface. Invoking information encapsulated to the header information of the second http request;
第二调用单元202,用于在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。a second calling unit 202, configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the superior The call information transmitted by the program interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
其中,所述程序接口执行前方法中包括设置程序接口调用的标识的方法、获取程序接口开始执行的时间的方法,所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法。通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开始时刻,通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻。所述第一私有调用信息包括所述第一标识、所述开始时刻,所述第二私有调用信息包括所述结束时刻。拼接出需要记录的调用信息,包括:基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长。The method before the execution of the program interface includes a method for setting an identifier of a program interface call, and a method for acquiring a time when the program interface starts to be executed. The method for executing the program interface includes a method for acquiring a time when the program interface ends execution. And generating, by the method for setting an identifier of the program interface, the first identifier of the program interface call, and acquiring, by the method for acquiring a time when the program interface starts to execute, acquiring a start time of the execution of the program interface, by using the acquiring program The method of ending the execution of the interface acquires the end time at which the program interface ends execution. The first private call information includes the first identifier, the start time, and the second private call information includes the end time. Splicing out the call information to be recorded includes: determining a call duration of the program interface based on the start time and the end time.
进一步,上级程序接口传递的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合,需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的 链路标识、所述第一标识中任意一种或多种组合。需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。Further, the call information delivered by the upper program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the identifier of the upper program interface, and the call information that needs to be delivered to the lower program interface. And including any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier. The call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the superior program interface, the call duration, and any one or more combinations of the first identifiers.
具体的,在本实施例中,该电子设备安装有软件开发平台,再利用该软件开发平台进行应用程序开发时,利用框架中的拦截器hook,进行程序接口调用信息的记录。Specifically, in this embodiment, the electronic device is installed with a software development platform, and when the software development platform is used for application development, the interceptor hook in the framework is used to record the program interface call information.
本实施例主要以开发框架为PHP进行详细描述。具体的,在应用程序项目中注册了hook类,该hook类中编写有程序接口执行前方法和程序接口执行后方法。hook类创建过程如下:This embodiment mainly describes the PHP as a development framework. Specifically, the hook class is registered in the application project, and the hook method is programmed with a pre-execution method and a post-execution method. The hook class creation process is as follows:
首先,创建一个hook方法类First, create a hook method class
不管是在PHP框架还是在Go框架中,要先实现拦截器功能,首先要创建一个hook方法类。因此,首先需要创建一个hook类,在这个类中编写程序接口执行前方法代码和程序接口执行后方法代码。Whether in the PHP framework or in the Go framework, to implement the interceptor function first, you must first create a hook method class. Therefore, you first need to create a hook class in which to write the pre-execution method code and the post-execution method code.
然后,进行程序接口执行前方法的编写。Then, write the method before the program interface is executed.
在本实施例中,通过第一调用单元201,程序接口执行前方法在每个程序接口执行前被调用,用来接收上级程序接口传来的第一http请求的头部信息,并初始化该程序接口调用信息。In this embodiment, by the first calling unit 201, the pre-execution of the program interface is called before each program interface is executed, and is used to receive the header information of the first http request sent by the upper-level program interface, and initialize the program. Interface call information.
在上述创建的hook类中,创建一个新的public类,该类中包括start方法,并在start中进行程序接口执行前代码编写,编写步骤包括如下几个步骤:In the hook class created above, create a new public class, which includes the start method, and write the code before the execution of the program interface in start. The writing steps include the following steps:
a)接收上级程序接口传来的第一http请求的头部header信息a) receiving the header information of the first http request from the upper-level program interface
通过PHP中的全局变量$_SERVER获取第一http请求的header信息,在header中读取链路记录需要的信息:应用程序项目的标识id、调用请求的链路标识id、上级程序接口的标识id等上级程序接口传递的调用信息。The header information of the first http request is obtained through the global variable $_SERVER in PHP, and the information required for the link record is read in the header: the identifier id of the application item, the link identifier id of the calling request, and the identifier id of the upper program interface. Wait for the call information passed by the superior program interface.
b)设置程序接口调用的唯一idb) set the unique id of the program interface call
通过PHP的uniqid()函数生成此次程序接口调用的唯一性标识id(即第一标识),uniqid函数可以根据当前时间精确微秒级随机出唯一id。The unique identifier id (ie, the first identifier) of the program interface call is generated by the uniqid() function of PHP, and the uniqid function can randomly generate a unique id according to the current time.
c)Request http header信息设置c) Request http header information setting
调用PHP的curl_setopt方法,第二个参数填CURLOPT_POSTFIELDS,第三个参数填入要设置header的json字符串,将调用请求的链路标识id、应应用程序项目的标识id以及b)步骤中生成的第一标识放入第二http请求的头部信息header中向下级程序接口传递。Call PHP's curl_setopt method, the second parameter is filled with CURLOPT_POSTFIELDS, the third parameter is filled in the json string to set the header, the requested link identifier id, the application id of the application project, and b) generated in the step The first identifier is passed to the lower level program interface in the header information header of the second http request.
d)获取程序接口开始执行的时间的方法d) method of obtaining the time at which the program interface starts executing
调用PHP的time()方法,获取程序接口开始执行的开始时刻startTime。Call the time() method of PHP to get the start time startTime of the program interface.
然后,进行程序接口执行后方法的编写。Then, the method is written after the execution of the program interface.
通过上述程序接口执行前方法,已经完成了对上级程序接口传来的第一http请求头部信息header的接收,并初始化了程序接口调用的唯一性标识id。进而,通过第二调用单元202,调用程序接口执行后方法,要对调用信息进行日志记录,在前述中创建的hook类中,创建一个新的public类,该类中包括end方法,并在end中进行程序接口执行后方法代码编写,编写步骤如下:Through the execution of the pre-method of the above program interface, the reception of the first http request header information header transmitted from the upper-level program interface has been completed, and the unique identifier id of the program interface call is initialized. Further, the second calling unit 202 calls the program interface to execute the post method, and records the call information. In the hook class created in the foregoing, a new public class is created, and the end method is included in the class. After the program interface is executed, the method code is written. The writing steps are as follows:
a)计算程序接口执行时间a) Calculate the program interface execution time
再次调用PHP中的time()方法,获取程序接口执行后结束时刻endTime,使用endTime减去前述通过开始时刻startTime,得到程序接口调用时长value。Call the time() method in PHP again to get the endTime end of the program interface execution, and use the endTime minus the start time startTime to get the program interface call duration value.
b)拼接出要记录的调用信息b) stitching out the call information to be recorded
将前述通过程序接口执行前方法获取的应用程序项目的标识id、调用请求的链路标识id、上级程序接口的标识id、程序接口调用的唯一性标识id,以及通过程序接口执行后方法获取的调用时长value,应用程序名name存入数组中,使用json_encode函数将数组转化为json字符串。The identifier id of the application item acquired by the foregoing method before the execution of the program interface, the link identifier id of the calling request, the identifier id of the upper-level program interface, the unique identifier id of the program interface call, and the method obtained by executing the method after the program interface Call the time value, the application name name is stored in the array, and the array is converted to a json string using the json_encode function.
c)记录调用信息到log文件c) record the call information to the log file
使用date(″Y-m-d″)函数获取当天日期,使用fopen函数生成或打开当天日期的log文件,fopen函数第二个参数填a+,再使用fwrite函数将b)中拼接的字符串写入log文件中,fwrite第一个参数填入log文件句柄,第二个参数填入json字符串。Use the date ("Ymd") function to get the date of the day, use the fopen function to generate or open the log file of the day's date, the second parameter of the fopen function fills in a+, and then use the fwrite function to write the string spliced in b) into the log file. The first parameter of fwrite is filled in the log file handle, and the second parameter is filled in the json string.
通过上述步骤,完成了hook类方法的编写。所以在框架中,只需要对hook类进行注册即可记录链路信息。Through the above steps, the writing of the hook class method is completed. So in the framework, you only need to register the hook class to record the link information.
具体的,对hook类方法进行注册可包括如下步骤:Specifically, registering the hook method may include the following steps:
1)建立hook.php文件,对hook注册进行集中管理。1) Create a hook.php file for centralized management of hook registration.
2)利用框架中的$hook[′pre_controller′],在控制器执行前注册start方法。给$hook[′pre_controller′]赋值一个数组,数组中class的值为本案创建的hook类名称、function的值为start,filename值为hook类方法所在文件名,filepath值为类方法所在文件路径。2) Use the $hook['pre_controller'] in the framework to register the start method before the controller executes. Assign an array to $hook['pre_controller']. The value of the class in the array is the name of the hook class created in this case, the value of function is start, the filename is the file name of the method of the hook class, and the filepath is the file path where the class method is located.
3)利用框架中的$hook[′post_controller′],在控制器执行前注册start方法。给$hook[′post_controller′]赋值一个数组,数组中的值与前述2)中除function值为end外其他值相同。3) Use the $hook['post_controller'] in the framework to register the start method before the controller executes. Assign an array to $hook['post_controller']. The values in the array are the same as those in the previous 2) except that the function value is end.
通过上述的在框架中创建hook方法并注册的过程,实现了记录程序接口调用信息的方法方法,该方法不需要在每个程序接口中嵌入代码,却可以对框架中所有程序接口进行信息记录,效率十分高,同时,该方法消除了之前记录 调用信息重复写代码的繁琐劳动,使代码统一易管理。Through the above process of creating a hook method in the framework and registering, a method method for recording the call information of the program interface is realized, and the method does not need to embed the code in each program interface, but can record information of all the program interfaces in the framework. The efficiency is very high. At the same time, the method eliminates the tedious labor of repeatedly writing the code of the previous call information, and makes the code uniform and easy to manage.
进而,可通过注册的hook类,在程序接口执行前,取出第一http请求的header信息,包括:调用请求的链路标识id(标识每条请求调用链的唯一id)、应用程序项目的标识id、上级程序接口的标识id等信息,并生成该程序接口调用的唯一id、程序接口调用的开始时刻等信息。在程序接口执行后,将程序接口调用时间等调用信息以日志的形式保存下来,再将调用请求的链路标识id、应用程序项目的标识id、该程序接口调用的唯一id等信息放入第二http请求的header信息中,传递给下一个接口。Further, the registered hook information may be used to retrieve the header information of the first http request before the execution of the program interface, including: calling the requested link identifier id (identifying the unique id of each request call chain), and identifying the identifier of the application item. The id, the identifier of the superior program interface, and other information, and generate information such as the unique id called by the program interface, the start time of the program interface call, and the like. After the program interface is executed, the call information such as the program interface call time is saved in the form of a log, and then the link identifier id of the call request, the identifier id of the application item, and the unique id called by the program interface are put into the first The header information of the two http request is passed to the next interface.
本实施例中的电子设备,不需要在接口中嵌入记录调用信息的代码,只需要在程序框架中增加一个hook,使其在程序接口执行前后进行特定的操作。这样既省去的在每个程序接口嵌入代码的繁琐操作,又统一了每个程序接口的调用信息记录方法,使记录出的日志信息保持了一致。所以,极大地提高了效率,并且有利于代码库的统一管理。The electronic device in this embodiment does not need to embed the code for recording the call information in the interface, and only needs to add a hook in the program frame to perform a specific operation before and after the execution of the program interface. This eliminates the cumbersome operation of embedding code in each program interface, and unifies the call information recording method of each program interface, so that the recorded log information remains consistent. Therefore, the efficiency is greatly improved, and the unified management of the code base is facilitated.
请参见图3,本发明的第三实施例提供了一种电子设备,该实施例的电子设备包括:处理器301、存储器302以及存储在所述存储器中并可在所述处理器上运行的计算机程序,例如第一实施例中记录程序接口间调用信息的方法对应的程序。所述处理器执行所述计算机程序时实现上述第一实施例中各路径检测中的步骤。或者,所述处理器执行所述计算机程序时实现上述第二实施例的电子设备中各模块/单元的功能。Referring to FIG. 3, a third embodiment of the present invention provides an electronic device, where the electronic device includes: a processor 301, a memory 302, and is stored in the memory and operable on the processor. A computer program, for example, a program corresponding to a method of recording information between program interface interfaces in the first embodiment. The steps in the path detection in the first embodiment described above are implemented when the processor executes the computer program. Alternatively, the processor implements the functions of the modules/units in the electronic device of the second embodiment described above when the computer program is executed.
示例性的,所述计算机程序可以被分割成一个或多个模块/单元,所述一个或者多个模块/单元被存储在所述存储器中,并由所述处理器执行,以完成本发明。所述一个或多个模块/单元可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述所述计算机程序在所述计算机装置中的执行过程。例如,所述计算机程序可以被分割成第一调用单元、第二调用单元的功能,所述电子设备中的应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,各单元具体功能如下:Illustratively, the computer program can be partitioned into one or more modules/units that are stored in the memory and executed by the processor to perform the present invention. The one or more modules/units may be a series of computer program instruction segments capable of performing a particular function, the instruction segments being used to describe the execution of the computer program in the computer device. For example, the computer program may be divided into functions of a first calling unit and a second calling unit, and a preset hook class is registered in an application item in the electronic device, and a program interface is executed in the preset hook class. Before the method and program interface are executed, the specific functions of each unit are as follows:
第一调用单元,用于在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;a first calling unit, configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the first program interface by using the program interface The call information transmitted by the upper program interface is extracted from the header information of the http request, the first private call information of the program interface is generated, the call information that needs to be passed to the lower program interface is determined, and the call needs to be transmitted to the lower program interface. Encapsulating information to the header information of the second http request;
第二调用单元,用于在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息, 基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。a second calling unit, configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the upper-level program The calling information delivered by the interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
所述电子设备可包括,但不仅限于,处理器、存储器。本领域技术人员可以理解,所述示意图3仅仅是计算机装置的示例,并不构成对电子设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如所述电子设备还可以包括输入输出设备、网络接入设备、总线等。The electronic device can include, but is not limited to, a processor, a memory. It will be understood by those skilled in the art that the schematic diagram 3 is merely an example of a computer device and does not constitute a limitation on an electronic device, and may include more or less components than those illustrated, or may combine certain components or different components. For example, the electronic device may further include an input and output device, a network access device, a bus, and the like.
所称处理器301可以是中央处理单元(Central Processing Unit,CPU),还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等,所述处理器是所述计算机装置的控制中心,利用各种接口和线路连接整个计算机装置的各个部分。The processor 301 may be a central processing unit (CPU), or may be other general-purpose processors, a digital signal processor (DSP), an application specific integrated circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc. The general purpose processor may be a microprocessor or the processor or any conventional processor or the like, which is the control center of the computer device, which is connected to various parts of the entire computer device using various interfaces and lines.
所述存储器302可用于存储所述计算机程序和/或模块,所述处理器通过运行或执行存储在所述存储器内的计算机程序和/或模块,以及调用存储在存储器内的数据,实现所述计算机装置的各种功能。所述存储器可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能、图像播放功能等)等;存储数据区可存储根据手机的使用所创建的数据(比如音频数据、视频数据等)等。此外,存储器可以包括高速随机存取存储器,还可以包括非易失性存储器,例如硬盘、内存、插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)、至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。The memory 302 can be used to store the computer program and/or module, the processor implementing the method by running or executing a computer program and/or module stored in the memory, and invoking data stored in the memory Various functions of a computer device. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may be stored. Data created according to the use of the mobile phone (such as audio data, video data, etc.). In addition, the memory may include a high-speed random access memory, and may also include non-volatile memory such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC), and a Secure Digital (SD) card. , Flash Card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
进一步,该电子设备所包括的处理器301还具有以下功能:Further, the processor 301 included in the electronic device further has the following functions:
所述程序接口执行前方法中包括设置程序接口调用的标识的方法,通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,所述第一私有调用信息包括所述第一标识。The method of the program interface includes a method for setting an identifier of a program interface call, and the method for setting an identifier of the program interface is used to generate a first identifier that is invoked by the program interface, where the first private call information includes the First identification.
进一步,所述上级程序接口传递的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合,所述需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的链路标识、所述第一标识中任意一种或多种组合。Further, the calling information delivered by the upper-level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the calling request, and the identifier of the upper-level program interface, and the need to be transmitted to the lower-level program. The call information of the interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
进一步,该电子设备所包括的处理器301还具有以下功能:Further, the processor 301 included in the electronic device further has the following functions:
所述程序接口执行前方法中包括获取程序接口开始执行的时间的方法,通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开 始时刻,所述第一私有调用信息包括所述开始时刻。The method of the pre-execution of the program interface includes: acquiring a time when the program interface starts to be executed, and acquiring, by the method for acquiring a time when the program interface starts execution, the start time of the execution of the program interface, where the first private call information includes The starting moment.
进一步,该电子设备所包括的处理器301还具有以下功能:Further, the processor 301 included in the electronic device further has the following functions:
所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法,通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻,所述第二私有调用信息包括所述结束时刻。The method after the execution of the program interface includes a method for acquiring a time at which the program interface ends execution, and acquiring, by the method for obtaining a time at which the program interface ends execution, an end time at which the program interface ends execution, where the second private call information includes The end time.
进一步,该电子设备所包括的处理器301还具有以下功能:Further, the processor 301 included in the electronic device further has the following functions:
基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长,所述需要记录的调用信息包括所述调用信息。Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
进一步,所述需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。Further, the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and the first identifier. combination.
本发明第四实施例提供了一种计算机可读存储介质,其上存储有计算机程序,本发明第二实施例中的所述电子设备集成的功能单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实现上述第一实施例的记录程序接口间调用信息的方法中的全部或部分流程,也可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-0nly Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读介质不包括电载波信号和电信信号。A fourth embodiment of the present invention provides a computer readable storage medium having stored thereon a computer program, and the functional unit integrated by the electronic device in the second embodiment of the present invention is implemented in the form of a software functional unit and is independent When the product is sold or used, it can be stored in a computer readable storage medium. Based on such understanding, the present invention implements all or part of the flow of the method for invoking information between the recording program interfaces of the first embodiment, and may also be completed by a computer program to instruct related hardware, and the computer program may be stored in In a computer readable storage medium, the computer program, when executed by a processor, implements the steps of the various method embodiments described above. Wherein, the computer program comprises computer program code, which may be in the form of source code, object code form, executable file or some intermediate form. The computer readable medium may include any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read-0nly Memory). , random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunications signals, and software distribution media. It should be noted that the content contained in the computer readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in a jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, computer readable media Does not include electrical carrier signals and telecommunication signals.
在本发明实施例的技术方案中,在进行应用程序开发时,在应用程序项目中注册预设hook类,预设hook类中编写有程序接口执行前方法和程序接口执行后方法;在程序接口被上级程序接口调用前,调用程序接口执行前方法,从上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息;在程序接口执行后,调用程序接口执行后方法,生成程序接口的第二私有调用信息,基于上级程序接口传递的调用信息、第一私有信息与第二私有信息,拼接出需要记录的调用信息;将需要记录的调用信息记录至日志文件,将 需要传递至下级程序接口的调用信息封装至第二http请求的头部信息。由于不需要在每个程序接口中嵌入记录调用信息的代码,只需要在程序框架中注册一个hook类,使其在程序接口执行前后进行特定的操作。这样既省去的在每个程序接口嵌入代码的繁琐操作,又统一了每个程序接口的调用信息记录方法,使记录出的日志信息保持了一致,所以,极大地提高了效率,并且有利于代码库的统一管理。In the technical solution of the embodiment of the present invention, when the application is developed, the preset hook class is registered in the application project, and the pre-execution method and the program interface execution method are written in the preset hook class; Before being called by the upper-level program interface, calling the pre-execution method of the program interface, extracting the call information transmitted by the upper-level program interface from the header information of the first http request of the upper-level program interface, generating the first private call information of the program interface, determining that the transfer is required Calling information to the lower level program interface; after the program interface is executed, calling the program interface to execute the method, generating the second private calling information of the program interface, based on the calling information, the first private information and the second private information transmitted by the upper program interface, The call information to be recorded is spliced; the call information to be recorded is recorded to the log file, and the call information that needs to be passed to the lower program interface is encapsulated to the header information of the second http request. Since there is no need to embed the code for calling the call information in each program interface, it is only necessary to register a hook class in the program framework to perform specific operations before and after the execution of the program interface. In this way, the cumbersome operation of embedding the code in each program interface is omitted, and the call information recording method of each program interface is unified, so that the recorded log information is kept consistent, so the efficiency is greatly improved, and it is advantageous. Unified management of the code base.
尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。While the preferred embodiment of the invention has been described, it will be understood that Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and the modifications and
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及It is apparent that those skilled in the art can make various modifications and variations to the invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the invention are within the scope of the invention
其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。The invention is also intended to cover such modifications and variations within the scope of the equivalents.
Claims (10)
- 一种记录程序接口间调用信息的方法,其特征在于,应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,所述方法包括:A method for recording information between program interface interfaces, wherein a preset hook class is registered in an application item, and the preset hook class is programmed with a pre-execution method and a program interface post-execution method, and the method includes :在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;Before the program interface in the application project is called by the upper program interface, calling the program interface pre-execution method, and executing the pre-method from the header information of the first http request of the upper-level program interface by using the program interface Extracting the call information passed by the upper program interface, generating the first private call information of the program interface, determining the call information that needs to be passed to the lower program interface, and encapsulating the call information that needs to be passed to the lower program interface to the second http request Header information;在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。After the program interface is executed, the program interface is executed, and the method is executed by the program interface, and the second private call information of the program interface is generated, based on the call information and the information transmitted by the upper program interface. Decoding the first private information and the second private information, splicing out the call information that needs to be recorded, and recording the call information that needs to be recorded to the log file.
- 如权利要求1所述的方法,其特征在于,所述程序接口执行前方法中包括设置程序接口调用的标识的方法,所述生成所述程序接口的第一私有调用信息,包括:The method of claim 1, wherein the method of the pre-execution of the program includes a method of setting an identifier of a program interface call, and the generating the first private call information of the program interface includes:通过所述设置程序接口调用的标识的方法生成所述程序接口调用的第一标识,所述第一私有调用信息包括所述第一标识。And generating, by the method for setting an identifier of the program interface, a first identifier of the program interface call, where the first private call information includes the first identifier.
- 如权利要求2所述的方法,其特征在于,所述上级程序接口传递的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识中任意一种或多种组合,所述需要传递至下级程序接口的调用信息包括所述应用程序项目的标识、所述调用请求的链路标识、所述第一标识中任意一种或多种组合。The method according to claim 2, wherein the call information transmitted by the upper program interface includes any one of an identifier of the application item, a link identifier of the call request, and an identifier of the upper program interface or In a plurality of combinations, the call information that needs to be delivered to the lower level program interface includes any one or more combinations of the identifier of the application item, the link identifier of the call request, and the first identifier.
- 如权利要求3所述的方法,其特征在于,所述程序接口执行前方法中包括获取程序接口开始执行的时间的方法,所述生成所述程序接口的第一私有调用信息,包括:The method of claim 3, wherein the method of executing the pre-execution of the program interface comprises: acquiring a time when the program interface starts to be executed, the generating the first private call information of the program interface, comprising:通过所述获取程序接口开始执行的时间的方法获取所述程序接口开始执行的开始时刻,所述第一私有调用信息包括所述开始时刻。And acquiring, by the method for acquiring a time when the program interface starts execution, a start time at which the program interface starts to be executed, where the first private call information includes the start time.
- 如权利要求4所述的方法,其特征在于,所述程序接口执行后方法中包括获取程序接口结束执行的时间的方法,所述生成所述程序接口的第二私有调用信息,包括:The method of claim 4, wherein the method of executing the program interface comprises: obtaining a method for ending the execution of the program interface, the generating the second private call information of the program interface, comprising:通过所述获取程序接口结束执行的时间的方法获取所述程序接口结束执行的结束时刻,所述第二私有调用信息包括所述结束时刻。Obtaining, by the method for obtaining the time of execution of the program interface, an end time of ending execution of the program interface, where the second private call information includes the end time.
- 如权利要求5所述的方法,其特征在于,所述拼接出需要记录的调用 信息,包括:The method according to claim 5, wherein said splicing out call information to be recorded comprises:基于所述开始时刻和所述结束时刻,确定所述程序接口的调用时长,所述需要记录的调用信息包括所述调用信息。Determining a call duration of the program interface based on the start time and the end time, and the call information to be recorded includes the call information.
- 如权利要求6所述的方法,其特征在于,所述需要记录的调用信息包括所述应用程序项目的标识、调用请求的链路标识、所述上级程序接口的标识、所述调用时长、所述第一标识中任意一种或多种组合。The method according to claim 6, wherein the call information to be recorded includes an identifier of the application item, a link identifier of the call request, an identifier of the upper program interface, the call duration, and a location Any one or more combinations of the first identifiers.
- 一种电子设备,其特征在于,所述电子设备中的应用程序项目中注册预设hook类,所述预设hook类中编写有程序接口执行前方法和程序接口执行后方法,所述电子设备包括:An electronic device, wherein a preset hook class is registered in an application item in the electronic device, wherein the preset hook class is programmed with a pre-execution method and a post-execution method, and the electronic device is include:第一调用单元,用于在所述应用程序项目中的程序接口被上级程序接口调用前,调用所述程序接口执行前方法,通过所述程序接口执行前方法从所述上级程序接口的第一http请求的头部信息中提取上级程序接口传递的调用信息,生成所述程序接口的第一私有调用信息,确定需要传递至下级程序接口的调用信息,将所述需要传递至下级程序接口的调用信息封装至第二http请求的头部信息;a first calling unit, configured to call the program interface pre-execution method before the program interface in the application project is called by the upper-level program interface, and execute the pre-method from the first program interface by using the program interface The call information transmitted by the upper program interface is extracted from the header information of the http request, the first private call information of the program interface is generated, the call information that needs to be passed to the lower program interface is determined, and the call needs to be transmitted to the lower program interface. Encapsulating information to the header information of the second http request;第二调用单元,用于在所述程序接口执行后,调用所述程序接口执行后方法,通过所述程序接口执行后方法,生成所述程序接口的第二私有调用信息,基于所述上级程序接口传递的调用信息、所述第一私有信息与所述第二私有信息,拼接出需要记录的调用信息,将所述需要记录的调用信息记录至日志文件。a second calling unit, configured to: after the program interface is executed, invoke the program interface execution method, and execute a post-method by the program interface to generate second private call information of the program interface, based on the upper program The calling information delivered by the interface, the first private information and the second private information are spliced together with call information to be recorded, and the call information required to be recorded is recorded to a log file.
- 一种电子设备,其特征在于,所述电子设备包括处理器,所述处理器用于执行存储器中存储的计算机程序时实现如权利要求1-7中任一项所述的记录程序接口间调用信息的方法的步骤。An electronic device, comprising: a processor, wherein the processor is configured to execute a call program information between the recording program interfaces according to any one of claims 1 to 7 when executing a computer program stored in a memory The steps of the method.
- 一种可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1-7中任一项所述的记录程序接口间调用信息的方法的步骤。A readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the method of recording information between program interface interfaces according to any one of claims 1-7 step.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810011867.5A CN108228165B (en) | 2018-01-05 | 2018-01-05 | Method for recording calling information between program interfaces and electronic equipment |
CN201810011867.5 | 2018-01-05 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019134291A1 true WO2019134291A1 (en) | 2019-07-11 |
Family
ID=62643071
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2018/082354 WO2019134291A1 (en) | 2018-01-05 | 2018-04-09 | Method for recording call information between program interfaces, and electronic device |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN108228165B (en) |
WO (1) | WO2019134291A1 (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110737592B (en) * | 2019-09-16 | 2024-01-30 | 平安科技(深圳)有限公司 | Link abnormality identification method, server and computer readable storage medium |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6886024B1 (en) * | 1999-10-26 | 2005-04-26 | Nec Corporation | Distributed application control system, control method and a program |
CN101626391A (en) * | 2008-07-08 | 2010-01-13 | 盛大计算机(上海)有限公司 | Method for processing resource of network game client |
CN101295280B (en) * | 2008-06-18 | 2010-12-01 | 腾讯科技(深圳)有限公司 | Automatic software debugging method and system |
CN103716313A (en) * | 2013-12-24 | 2014-04-09 | 中国科学院信息工程研究所 | User privacy information protection method and user privacy information protection system |
CN105095741A (en) * | 2014-05-13 | 2015-11-25 | 北京奇虎测腾科技有限公司 | Behavior monitoring method and behavior monitoring system of application program |
Family Cites Families (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH02197935A (en) * | 1989-01-27 | 1990-08-06 | Nec Corp | Output system for application state of control table |
CN102831043B (en) * | 2011-06-17 | 2015-05-20 | 阿里巴巴集团控股有限公司 | Monitoring method and device for application program |
CN105607986A (en) * | 2015-01-06 | 2016-05-25 | 北京志翔科技股份有限公司 | Acquisition method and device of user behavior log data |
CN106326099B (en) * | 2015-07-01 | 2019-10-29 | 阿里巴巴集团控股有限公司 | A kind of method, apparatus and electronic equipment for program tracking |
CN106681884B (en) * | 2016-06-28 | 2018-09-04 | 腾讯科技(深圳)有限公司 | A kind of monitoring method and device of system calling |
CN106649120A (en) * | 2016-12-28 | 2017-05-10 | 中国银联股份有限公司 | Data acquisition method, and data analysis method and system |
-
2018
- 2018-01-05 CN CN201810011867.5A patent/CN108228165B/en active Active
- 2018-04-09 WO PCT/CN2018/082354 patent/WO2019134291A1/en active Application Filing
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6886024B1 (en) * | 1999-10-26 | 2005-04-26 | Nec Corporation | Distributed application control system, control method and a program |
CN101295280B (en) * | 2008-06-18 | 2010-12-01 | 腾讯科技(深圳)有限公司 | Automatic software debugging method and system |
CN101626391A (en) * | 2008-07-08 | 2010-01-13 | 盛大计算机(上海)有限公司 | Method for processing resource of network game client |
CN103716313A (en) * | 2013-12-24 | 2014-04-09 | 中国科学院信息工程研究所 | User privacy information protection method and user privacy information protection system |
CN105095741A (en) * | 2014-05-13 | 2015-11-25 | 北京奇虎测腾科技有限公司 | Behavior monitoring method and behavior monitoring system of application program |
Also Published As
Publication number | Publication date |
---|---|
CN108228165B (en) | 2021-02-02 |
CN108228165A (en) | 2018-06-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109995713B (en) | Service processing method in micro-service framework and related equipment | |
CN109064334B (en) | Intelligent contract accounting method, computer device and readable storage medium | |
CN109656686A (en) | The upper deployment container cloud method of OpenStack, storage medium, electronic equipment and system | |
CN110096685B (en) | Equipment identifier generation method and device | |
WO2020001112A1 (en) | Application method for platform supporting multiple types of devices, and mobile terminal | |
US10594800B2 (en) | Platform runtime abstraction | |
WO2020000675A1 (en) | Method and device for publishing game resource package, terminal device and medium | |
WO2014194774A1 (en) | System and method for creating mobile application store | |
US9258355B2 (en) | Decentralized cloud workflows | |
WO2022174613A1 (en) | Application generation method and device based on android system, and storage medium | |
US10032006B2 (en) | Copyright generation and storage utility | |
US8260848B2 (en) | Re-headerer system and method | |
CN111563823A (en) | Block chain-based network work copyright transaction processing method, device and system | |
WO2019029451A1 (en) | Method for publishing mobile applications and electronic apparatus | |
TW201814546A (en) | Device component loading method, apparatus and internet of things system | |
CN111273942A (en) | Code generation method, storage medium, electronic device and system | |
CN104885058B (en) | The system and method that universal product line is carried out in virtual component generator environment | |
TWI828306B (en) | an electronic device | |
WO2019134291A1 (en) | Method for recording call information between program interfaces, and electronic device | |
CN114020689A (en) | Data processing method, data processing device, electronic device, and storage medium | |
CN107888399A (en) | A kind of platform services PaaS platform management method and device | |
US10970332B2 (en) | Electronic device and digital content managing method | |
CN111209283A (en) | Data processing method and device | |
CN116088829A (en) | Data processing method, device, storage medium and equipment | |
WO2020044093A1 (en) | Application program programming interface calling method and apparatus therefor |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18898102 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 18898102 Country of ref document: EP Kind code of ref document: A1 |