CN108228165B - Method for recording calling information between program interfaces and electronic equipment - Google Patents
Method for recording calling information between program interfaces and electronic equipment Download PDFInfo
- Publication number
- CN108228165B CN108228165B CN201810011867.5A CN201810011867A CN108228165B CN 108228165 B CN108228165 B CN 108228165B CN 201810011867 A CN201810011867 A CN 201810011867A CN 108228165 B CN108228165 B CN 108228165B
- Authority
- CN
- China
- Prior art keywords
- program interface
- information
- calling
- program
- identifier
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
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
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
The embodiment of the invention provides a method for recording calling information between program interfaces and electronic equipment, which are used for providing a recording method for unifying the calling information of each program interface. The method comprises the following steps that a preset hook class is registered in an application program item, a method before program interface execution and a method after program interface execution are compiled in the class, and the method comprises the following steps: before a program interface in an application program item is called by a superior program interface, calling the program interface to execute a pre-execution method, extracting calling information transmitted by the superior program interface from header information of a first http request of the superior program interface, generating first private calling information, determining calling information needing to be transmitted to a subordinate program interface, and packaging the calling information to header information of a second http request; after the program interface is executed, calling the method after the program interface is executed, generating second private calling information of the program interface, splicing the calling information to be recorded, and recording the calling information to be recorded to a log file.
Description
Technical Field
The present invention relates to the field of electronic technologies, and in particular, to a method for recording call information between program interfaces, an electronic device, and a readable storage medium.
Background
During the development of the application program, it may be necessary to know the call flow of the service layer and the service layer program interface, and obtain the call information of the interface, for example: interface request source, interface address, interface execution time, etc. In the prior art, the interface call information is recorded by embedding a code for recording the call information in each interface to be recorded. The main drawback of this method is that it is inefficient to add a record code to each interface. Meanwhile, the record codes added by each interface are difficult to unify, so that the recorded calling information is inconsistent.
Disclosure of Invention
The embodiment of the invention provides a method for recording calling information between program interfaces, electronic equipment and a readable storage medium, which are used for unifying the recording method of the calling information of each program interface under the condition that recording codes are not added to the program interfaces repeatedly so as to keep the recorded calling log information consistent.
In a first aspect, the present invention provides a method for recording call information between program interfaces, wherein a preset hook class is registered in an application program item, and a method before program interface execution and a method after program interface execution are written in the preset hook class, the method comprising:
before a program interface in the application program item is called by a superior program interface, calling information transferred by the superior program interface is extracted from header information of a first http request of the superior program interface through the method before the program interface is executed, first private calling information of the program interface is generated, calling information needing to be transferred to a subordinate program interface is determined, and the calling information needing to be transferred to the subordinate program interface is packaged to the header information of a second http request;
after the program interface is executed, calling the program interface execution method, generating second private calling information of the program interface through the program interface execution method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
Optionally, the method for executing the front method by the program interface includes a method for setting an identifier called by the program interface, and the generating of the first private call information of the program interface includes:
and generating a first identifier called by the program interface by the method for setting the identifier called by the program interface, wherein the first private calling information comprises the first identifier.
Optionally, the calling information transferred by the upper level program interface includes any one or more combinations of an identifier of the application program item, a link identifier of the calling request, and an identifier of the upper level program interface, and the calling information to be transferred to the lower level program interface includes any one or more combinations of an identifier of the application program item, a link identifier of the calling request, and the first identifier.
Optionally, the method before the program interface is executed includes a method of obtaining a time when the program interface starts to be executed, and the generating of the first private call information of the program interface includes:
and acquiring the starting time of the program interface starting execution by the method for acquiring the time of the program interface starting execution, wherein the first private calling information comprises the starting time.
Optionally, the method after the program interface is executed includes a method of obtaining time when the program interface finishes executing, and the generating of the second private call information of the program interface includes:
and acquiring the end time of the program interface end execution by the method for acquiring the time of the program interface end execution, wherein the second private calling information comprises the end time.
Optionally, the splicing out the calling information to be recorded includes:
and determining the calling duration of the program interface based on the starting time and the ending time, wherein the calling information to be recorded comprises the calling information.
Optionally, the call information to be recorded includes any one or more combinations of an identifier of the application program item, a link identifier of a call request, an identifier of the superior program interface, the call duration, and the first identifier.
In a second aspect, an embodiment of the present invention provides an electronic device, where a preset hook class is registered in an application program item in the electronic device, and a method before program interface execution and a method after program interface execution are written in the preset hook class, where the electronic device includes:
the first calling unit is used for calling a method before program interface execution before a program interface in the application program item is called by a superior program interface, extracting calling information transmitted by the superior program interface from header information of a first http request of the superior program interface through the method before program interface execution, generating first private calling information of the program interface, determining calling information required to be transmitted to a subordinate program interface, and packaging the calling information required to be transmitted to the subordinate program interface to header information of a second http request;
the second calling unit is used for calling the program interface execution post method after the program interface is executed, generating second private calling information of the program interface through the program interface execution post method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
Optionally, the method for setting the identifier called by the program interface is included in the front method executed by the program interface, and the first calling unit is configured to:
and generating a first identifier called by the program interface by the method for setting the identifier called by the program interface, wherein the first private calling information comprises the first identifier.
Optionally, the calling information transferred by the upper level program interface includes any one or more combinations of an identifier of the application program item, a link identifier of the calling request, and an identifier of the upper level program interface, and the calling information to be transferred to the lower level program interface includes any one or more combinations of an identifier of the application program item, a link identifier of the calling request, and the first identifier.
Optionally, the method before the execution of the program interface includes a method of acquiring a time when the program interface starts to be executed, and the first call unit is configured to:
and acquiring the starting time of the program interface starting execution by the method for acquiring the time of the program interface starting execution, wherein the first private calling information comprises the starting time.
Optionally, the method after the execution of the program interface includes a method of obtaining time for ending the execution of the program interface, and the second invoking unit is configured to:
and acquiring the end time of the program interface end execution by the method for acquiring the time of the program interface end execution, wherein the second private calling information comprises the end time.
Optionally, the second invoking unit is configured to:
and determining the calling duration of the program interface based on the starting time and the ending time, wherein the calling information to be recorded comprises the calling information.
Optionally, the call information to be recorded includes any one or more combinations of an identifier of the application program item, a link identifier of a call request, an identifier of the superior program interface, the call duration, and the first identifier.
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, when executing a computer program stored in a memory, implement the steps of the method for recording information of inter-program-interface calls described in the foregoing first aspect.
In a fourth aspect, an embodiment of the present invention provides a readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the method for recording information of call between program interfaces as described in the foregoing embodiment of the first aspect.
One or more technical solutions in the embodiments of the present application have at least one or more of the following technical effects:
according to the technical scheme of the embodiment of the invention, when the application program is developed, a preset hook class is registered in an application program project, and a method before program interface execution and a method after program interface execution are compiled in the preset hook class; before the program interface is called by a superior program interface, calling a method before the program interface executes, extracting calling information transmitted by the superior program interface from header information of a first http request of the superior program interface, generating first private calling information of the program interface, and determining calling information required to be transmitted to a subordinate program interface; after the program interface is executed, calling the method after the program interface is executed, generating second private calling information of the program interface, and splicing the calling information to be recorded based on the calling information, the first private information and the second private information transmitted by the superior program interface; and recording the calling information to be recorded into a log file, and packaging the calling information to be transmitted to a lower program interface into header information of the second http request. Since it is not necessary to embed a code for recording call information in each program interface, only a hook class needs to be registered in the program framework, so that it performs specific operations before and after the execution of the program interface. Therefore, the complicated operation of embedding codes in each program interface is omitted, the calling information recording method of each program interface is unified, and the recorded log information is kept consistent, so that the efficiency is greatly improved, and the unified management of the code library is facilitated.
Drawings
FIG. 1 is a flowchart of a method for recording call information between program interfaces according to a first embodiment of the present invention;
FIG. 2 is a diagram of an electronic device according to a second embodiment of the invention;
fig. 3 is a schematic diagram of an electronic device according to a third embodiment of the invention.
Detailed Description
The embodiment of the invention provides a method for recording calling information between program interfaces, electronic equipment and a readable storage medium, which are used for unifying the recording method of the calling information of each program interface under the condition that recording codes are not added to the program interfaces repeatedly so as to keep the recorded calling log information consistent. A preset hook class is registered in an application program item, a method before program interface execution and a method after program interface execution are written in the preset hook class, and the method comprises the following steps: before a program interface in the application program item is called by a superior program interface, calling information transferred by the superior program interface is extracted from header information of a first http request of the superior program interface through the method before the program interface is executed, first private calling information of the program interface is generated, calling information needing to be transferred to a subordinate program interface is determined, and the calling information needing to be transferred to the subordinate program interface is packaged to the header information of a second http request; after the program interface is executed, calling the program interface execution method, generating second private calling information of the program interface through the program interface execution method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
The technical solutions of the present invention are described in detail below with reference to the drawings and specific embodiments, and it should be understood that the specific features in the embodiments and examples of the present invention are described in detail in the technical solutions of the present application, and are not limited to the technical solutions of the present application, and the technical features in the embodiments and examples of the present application may be combined with each other without conflict.
The term "and/or" herein is merely an association describing an associated object, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Examples
Referring to fig. 1, a first embodiment of the present invention provides a method for recording call information between program interfaces, where a preset hook class is registered in an application program item, and a method before program interface execution and a method after program interface execution are written in the preset hook class, the method including the following steps:
s101: before a program interface in the application program item is called by a superior program interface, calling information transferred by the superior program interface is extracted from header information of a first http request of the superior program interface through the method before the program interface is executed, first private calling information of the program interface is generated, calling information needing to be transferred to a subordinate program interface is determined, and the calling information needing to be transferred to the subordinate program interface is packaged to the header information of a second http request;
s102: after the program interface is executed, calling the program interface execution method, generating second private calling information of the program interface through the program interface execution method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
The method for executing the program interface comprises a method for setting an identifier called by the program interface and a method for acquiring the time for starting execution of the program interface, and the method for executing the program interface comprises a method for acquiring the time for finishing execution of the program interface. Generating a first identifier called by the program interface by the method for setting the identifier called by the program interface, acquiring the starting time of starting execution of the program interface by the method for acquiring the time of starting execution of the program interface, and acquiring the ending time of ending execution of the program interface by the method for acquiring the time of ending execution of the program interface. The first private calling information comprises the first identifier and the starting time, and the second private calling information comprises the ending time. Splicing the calling information needing to be recorded, comprising the following steps: and determining the calling duration of the program interface based on the starting time and the ending time.
Further, the calling information transferred by the upper level program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the identifier of the upper level program interface, and the calling information to be transferred to the lower level program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the first identifier. The calling information to be recorded comprises any one or more of the identifier of the application program item, the link identifier of the calling request, the identifier of the superior program interface, the calling duration and the first identifier.
Specifically, in this embodiment, when an application is developed, the recording of the program interface call information is performed by using the interceptor hook in the framework. The present embodiment mainly uses a development framework as a PHP for detailed description. A hook class is registered in the application program item, and a method before program interface execution and a method after program interface execution are written in the hook class. The hook class creation process is as follows:
first, a hook method class is created
In both the PHP and Go frameworks, the interceptor function is implemented first, and a hook method class is created first. Therefore, a hook class is first created in which the program interface execution front method code and the program interface execution back method code are written. The hook method class is registered in the application program item.
Then, by step S101, a call of a method before program interface execution is made.
In this embodiment, the pre-api execution method is called before each api is executed, and is configured to receive header information of a first http request from a higher-level api, and initialize the api call information.
In the created hook class, a new public class is created, the class comprises a start method, and programming of code before program interface execution is carried out in the start, wherein the programming step comprises the following steps:
a) receiving header information of a first http request transmitted by a superior program interface
Obtaining the header information of the first http request through a global variable $ _ SERVER in the PHP, and reading information required by link recording in the header: and the calling information transmitted by the upper program interface, such as the identifier id of the application program item, the link identifier id of the calling request, the identifier id of the upper program interface and the like.
b) Setting unique id of a program interface call
The unique identifier id (namely, the first identifier) called by the program interface at this time is generated through the uniqid () function of the PHP, and the uniqid function can randomly generate the unique identifier id according to the current time at the accurate microsecond level.
c) Request http header information setting
Calling a curl _ setup method of the PHP, filling a CurLEPT _ POSTFIELDS parameter into a second parameter, filling a json character string of a header to be set into a third parameter, and putting a link identifier id of a calling request, an identifier id of an application program item and the first identifier generated in the step b) into a header information header of a second http request to be transmitted to a lower-level program interface.
d) Method for acquiring time for program interface to start execution
And calling a time () method of the PHP to acquire the starting time startTime when the program interface starts to execute.
Then, in step S102, a method after the program interface is executed is called.
By the method before the program interface is executed, the receiving of the header information of the first http request transmitted by the upper program interface is completed, and the unique identifier id called by the program interface is initialized. Calling a method after the program interface is executed, logging calling information, creating a new public class in the created hook class, wherein the class comprises an end method, and writing a program interface execution back method code in the end, wherein the writing steps are as follows:
a) calculating program interface execution time
And calling the time () method in the PHP again, acquiring the ending time after the program interface is executed, and subtracting the passing starting time startTime from the ending time to obtain the calling time value of the program interface.
b) Splicing out call information to be recorded
And storing the application program name and the application program name into an array, wherein the application program name is obtained by executing a front method through a program interface, the identification id of a calling request, the identification id of a superior program interface, the unique identification id of the program interface calling, and the calling time value obtained by executing a back method through the program interface, and the array is converted into a json character string by using a json _ encode function.
c) Recording call information to log file
Obtaining the current day date by using a date (Y-m-d) function, generating or opening a log file of the current day date by using a fopen function, filling a + in a second parameter of the fopen function, writing the character string spliced in the b) into the log file by using a fwrite function, filling a handle of the log file in the first parameter of the fwrite, and filling a json character string in the second parameter of the fwrite.
Through the steps, the call of the hook method is completed. Therefore, in the framework, only the hook class needs to be registered to record the link information.
Specifically, registering the hook method may include the following steps:
1) php file is established, and centralized management is carried out on hook registration.
2) The start method is registered before the controller executes, using $ hook [ 'pre _ controller' ] in the framework. Assigning an array to $ hook [ 'pre _ controller' ], wherein the value of class in the array is the name of a hook class created in the scheme, the value of function is start, the value of filename is the name of a file where a hook class method is located, and the value of filepath is the file path where the class method is located.
3) The start method is registered before the controller executes, using $ hook [ 'post _ controller' ] in the frame. Assigning $ hook [ 'post _ controller' ] to an array whose value is the same as in 2) above except that the function value is end.
Through the process of establishing the hook method in the frame and registering, the method for recording the calling information of the program interfaces is realized, the method does not need to embed codes in each program interface, but can record information of all the program interfaces in the frame, the efficiency is very high, and meanwhile, the method eliminates the tedious labor of repeatedly writing the codes by recording the calling information before, so that the codes are uniform and easy to manage.
Furthermore, the method for extracting the header information of the first http request before the execution of the program interface through the registered hook class comprises the following steps: information such as a link identification id (unique id for identifying each request call chain), an identification id of an application program item, and an identification id of a higher-level program interface is called, and information such as a unique id called by the program interface and a start time called by the program interface is generated. And then, information such as a link identification id of the calling request, an identification id of the application program item, a unique id called by the program interface and the like is put into the header information of the second http request and transmitted to the next interface. After the program interface is executed, the calling information such as the calling time of the program interface is saved in the form of a log.
The method in the embodiment does not need to embed a code for recording the calling information in the interface, and only needs to add a hook in the program frame to enable the hook to perform specific operations before and after the execution of the program interface. Therefore, the complicated operation of embedding codes in each program interface is omitted, and the calling information recording method of each program interface is unified, so that the recorded log information is kept consistent. Therefore, the method greatly improves the efficiency and is beneficial to the unified management of the code base.
Referring to fig. 2, a second embodiment of the present invention provides an electronic device, in which a preset hook class is registered in an application program item, and a method before program interface execution and a method after program interface execution are written in the preset hook class, the electronic device including:
a first calling unit 201, configured to, before a program interface in the application program item is called by a superior program interface, call a method before program interface execution, extract, by the method before program interface execution, calling information transferred by the superior program interface from header information of a first http request of the superior program interface, generate first private calling information of the program interface, determine calling information that needs to be transferred to a subordinate program interface, and package, by the calling information that needs to be transferred to the subordinate program interface, the calling information to be transferred to a second http request;
the second calling unit 202 is configured to call the program interface post-execution method after the program interface is executed, generate second private calling information of the program interface through the program interface post-execution method, splice calling information to be recorded based on the calling information transferred by the superior program interface, the first private information, and the second private information, and record the calling information to be recorded to a log file.
The method for executing the program interface comprises a method for setting an identifier called by the program interface and a method for acquiring the time for starting execution of the program interface, and the method for executing the program interface comprises a method for acquiring the time for finishing execution of the program interface. Generating a first identifier called by the program interface by the method for setting the identifier called by the program interface, acquiring the starting time of starting execution of the program interface by the method for acquiring the time of starting execution of the program interface, and acquiring the ending time of ending execution of the program interface by the method for acquiring the time of ending execution of the program interface. The first private calling information comprises the first identifier and the starting time, and the second private calling information comprises the ending time. Splicing the calling information needing to be recorded, comprising the following steps: and determining the calling duration of the program interface based on the starting time and the ending time.
Further, the calling information transferred by the upper level program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the identifier of the upper level program interface, and the calling information to be transferred to the lower level program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the first identifier. The calling information to be recorded comprises any one or more of the identifier of the application program item, the link identifier of the calling request, the identifier of the superior program interface, the calling duration and the first identifier.
Specifically, in this embodiment, the electronic device is provided with a software development platform, and when an application program is developed by using the software development platform, the recording of the program interface call information is performed by using an interceptor hook in the framework.
The present embodiment mainly uses a development framework as a PHP for detailed description. Specifically, a hook class is registered in the application program item, and a method before program interface execution and a method after program interface execution are written in the hook class. The hook class creation process is as follows:
first, a hook method class is created
In both the PHP and Go frameworks, the interceptor function is implemented first, and a hook method class is created first. Therefore, a hook class is first created in which the program interface execution front method code and the program interface execution back method code are written.
Then, the method before the program interface is executed is written.
In the present embodiment, the pre-api execution method is called before each api is executed by the first calling unit 201, and is configured to receive header information of the first http request from the upper level api, and initialize the api call information.
In the created hook class, a new public class is created, the class comprises a start method, and programming of code before program interface execution is carried out in the start, wherein the programming step comprises the following steps:
a) receiving header information of a first http request transmitted by a superior program interface
Obtaining the header information of the first http request through a global variable $ _ SERVER in the PHP, and reading information required by link recording in the header: and the calling information transmitted by the upper program interface, such as the identifier id of the application program item, the link identifier id of the calling request, the identifier id of the upper program interface and the like.
b) Setting unique id of a program interface call
The unique identifier id (namely, the first identifier) called by the program interface at this time is generated through the uniqid () function of the PHP, and the uniqid function can randomly generate the unique identifier id according to the current time at the accurate microsecond level.
c) Request http header information setting
Calling a curl _ setup method of the PHP, filling a CurLEPT _ POSTFIELDS parameter into a second parameter, filling a json character string of a header to be set into a third parameter, and putting a link identifier id of a calling request, an identifier id of an application program item and the first identifier generated in the step b) into a header information header of a second http request to be transmitted to a lower-level program interface.
d) Method for acquiring time for program interface to start execution
And calling a time () method of the PHP to acquire the starting time startTime when the program interface starts to execute.
Then, the method after the program interface is executed is written.
By the method before the program interface is executed, the receiving of the header information of the first http request transmitted by the upper program interface is completed, and the unique identifier id called by the program interface is initialized. Furthermore, by using the second calling unit 202, calling the method after the program interface is executed, logging the calling information, creating a new public class in the created hook class, where the new public class includes an end method, and performing program interface execution backward method code writing in the end, where the writing steps are as follows:
a) calculating program interface execution time
And calling the time () method in the PHP again, acquiring the ending time after the program interface is executed, and subtracting the passing starting time startTime from the ending time to obtain the calling time value of the program interface.
b) Splicing out call information to be recorded
And storing the application program name and the application program name into an array, wherein the application program name is obtained by executing a front method through a program interface, the identification id of a calling request, the identification id of a superior program interface, the unique identification id of the program interface calling, and the calling time value obtained by executing a back method through the program interface, and the array is converted into a json character string by using a json _ encode function.
c) Recording call information to log file
Obtaining the current day date by using a date (Y-m-d) function, generating or opening a log file of the current day date by using a fopen function, filling a + in a second parameter of the fopen function, writing the character string spliced in the b) into the log file by using a fwrite function, filling a handle of the log file in the first parameter of the fwrite, and filling a json character string in the second parameter of the fwrite.
Through the steps, the writing of the hook method is completed. Therefore, in the framework, only the hook class needs to be registered to record the link information.
Specifically, registering the hook method may include the following steps:
1) php file is established, and centralized management is carried out on hook registration.
2) The start method is registered before the controller executes, using $ hook [ 'pre _ controller' ] in the framework. Assigning an array to $ hook [ 'pre _ controller' ], wherein the value of class in the array is the name of a hook class created in the scheme, the value of function is start, the value of filename is the name of a file where a hook class method is located, and the value of filepath is the file path where the class method is located.
3) The start method is registered before the controller executes, using $ hook [ 'post _ controller' ] in the frame. Assigning $ hook [ 'post _ controller' ] to an array whose value is the same as in 2) above except that the function value is end.
Through the process of establishing the hook method in the frame and registering, the method for recording the calling information of the program interfaces is realized, the method does not need to embed codes in each program interface, but can record information of all the program interfaces in the frame, the efficiency is very high, and meanwhile, the method eliminates the tedious labor of repeatedly writing the codes by recording the calling information before, so that the codes are uniform and easy to manage.
Furthermore, the method for extracting the header information of the first http request before the execution of the program interface through the registered hook class comprises the following steps: information such as a link identification id (unique id for identifying each request call chain), an identification id of an application program item, and an identification id of a higher-level program interface is called, and information such as a unique id called by the program interface and a start time called by the program interface is generated. After the program interface is executed, the calling information such as the calling time of the program interface is saved in a log mode, and then information such as a link identification id of a calling request, an identification id of an application program item, a unique id called by the program interface is put into header information of a second http request and transmitted to a next interface.
In the electronic device in this embodiment, a code for recording call information does not need to be embedded in the interface, and only a hook needs to be added to the program frame, so that the electronic device performs specific operations before and after execution of the program interface. Therefore, the complicated operation of embedding codes in each program interface is omitted, and the calling information recording method of each program interface is unified, so that the recorded log information is kept consistent. Therefore, the efficiency is greatly improved, and the unified management of the code base is facilitated.
Referring to fig. 3, a third embodiment of the present invention provides an electronic device, which includes: a processor 301, a memory 302, and a computer program stored in the memory and operable on the processor, for example, a program corresponding to the method of recording call information between program interfaces in the first embodiment. The processor implements the steps in the detection of each path in the first embodiment described above when executing the computer program. Alternatively, the processor implements the functions of the modules/units in the electronic device of the second embodiment described above when executing the computer program.
Illustratively, the computer program may be partitioned into one or more modules/units that are stored in the memory and executed by the processor to implement the invention. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of the computer program in the computer apparatus. For example, the computer program may be divided into functions of a first call unit and a second call unit, a preset hook class is registered in an application program item in the electronic device, a method before program interface execution and a method after program interface execution are written in the preset hook class, and specific functions of each unit are as follows:
the first calling unit is used for calling a method before program interface execution before a program interface in the application program item is called by a superior program interface, extracting calling information transmitted by the superior program interface from header information of a first http request of the superior program interface through the method before program interface execution, generating first private calling information of the program interface, determining calling information required to be transmitted to a subordinate program interface, and packaging the calling information required to be transmitted to the subordinate program interface to header information of a second http request;
the second calling unit is used for calling the program interface execution post method after the program interface is executed, generating second private calling information of the program interface through the program interface execution post method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
The electronic device may include, but is not limited to, a processor, a memory. It will be appreciated by those skilled in the art that the schematic diagram 3 is merely an example of a computer apparatus and is not intended to limit an electronic device, which may include more or less components than those shown, or some components in combination, or different components, for example, the electronic device may also include input and output devices, network access devices, buses, etc.
The Processor 301 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like which is the control center for the computer device and which connects the various parts of the overall computer device using various interfaces and lines.
The memory 302 may be used to store the computer programs and/or modules, and the processor may implement the various functions of the computer device by running or executing the computer programs and/or modules stored in the memory, as well as by invoking data stored in the memory. 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 program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, video data, etc.) created according to the use of the cellular phone, etc. In addition, the memory may include 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 Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
Further, the processor 301 included in the electronic device also has the following functions:
the program interface execution front method comprises a method for setting an identifier called by the program interface, a first identifier called by the program interface is generated by the method for setting the identifier called by the program interface, and the first private calling information comprises the first identifier.
Further, the calling information transferred by the superior program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the identifier of the superior program interface, and the calling information to be transferred to the subordinate program interface includes any one or more combinations of the identifier of the application program item, the link identifier of the calling request, and the first identifier.
Further, the processor 301 included in the electronic device also has the following functions:
the method comprises the step of acquiring the time for starting the execution of the program interface, the starting time for starting the execution of the program interface is acquired by the method for acquiring the time for starting the execution of the program interface, and the first private calling information comprises the starting time.
Further, the processor 301 included in the electronic device also has the following functions:
the method for obtaining the time for finishing the execution of the program interface comprises a method for obtaining the time for finishing the execution of the program interface, the method for obtaining the time for finishing the execution of the program interface is used for obtaining the finishing time for finishing the execution of the program interface, and the second private calling information comprises the finishing time.
Further, the processor 301 included in the electronic device also has the following functions:
and determining the calling duration of the program interface based on the starting time and the ending time, wherein the calling information to be recorded comprises the calling information.
Further, the call information to be recorded includes any one or a combination of multiple of the identifier of the application program item, the link identifier of the call request, the identifier of the superior program interface, the call duration, and the first identifier.
A fourth embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored, and the electronic device integrated functional unit in the second embodiment of the present invention may be stored in one computer-readable storage medium if it is implemented in the form of a software functional unit and sold or used as a stand-alone product. Based on such understanding, all or part of the flow of the method for recording information called between interfaces according to the first embodiment of the present invention may also be implemented by a computer program that can be stored in a computer-readable storage medium and that, when being executed by a processor, can implement the steps of the above-described method embodiments. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
According to the technical scheme of the embodiment of the invention, when the application program is developed, a preset hook class is registered in an application program project, and a method before program interface execution and a method after program interface execution are compiled in the preset hook class; before the program interface is called by a superior program interface, calling a method before the program interface executes, extracting calling information transmitted by the superior program interface from header information of a first http request of the superior program interface, generating first private calling information of the program interface, and determining calling information required to be transmitted to a subordinate program interface; after the program interface is executed, calling the method after the program interface is executed, generating second private calling information of the program interface, and splicing the calling information to be recorded based on the calling information, the first private information and the second private information transmitted by the superior program interface; and recording the calling information to be recorded into a log file, and packaging the calling information to be transmitted to a lower program interface into header information of the second http request. Since it is not necessary to embed a code for recording call information in each program interface, only a hook class needs to be registered in the program framework, so that it performs specific operations before and after the execution of the program interface. Therefore, the complicated operation of embedding codes in each program interface is omitted, the calling information recording method of each program interface is unified, and the recorded log information is kept consistent, so that the efficiency is greatly improved, and the unified management of the code library is facilitated.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.
Claims (10)
1. A method for recording call information between program interfaces is characterized in that a preset hook class is registered in an application program item, a method before program interface execution and a method after program interface execution are compiled in the preset hook class, and the method comprises the following steps:
the application program project is developed based on a PHP framework or a Go framework, before a program interface in the application program project is called by a superior program interface, a method before the program interface is executed is called, calling information transmitted by the superior program interface is extracted from header information of a first http request of the superior program interface through the method before the program interface is executed, first private calling information of the program interface is generated, calling information required to be transmitted to a subordinate program interface is determined, the calling information required to be transmitted to the subordinate program interface is packaged to the header information of a second http request, wherein the program interface executes a method for setting an identifier called by the program interface in a front method, a first identifier called by the program interface is generated through the method for setting the identifier called by the program interface, and the first private calling information comprises the first identifier, the calling information transferred by the superior program interface comprises any one or more combinations of the identifier of the application program item, the link identifier of the calling request and the identifier of the superior program interface, and the calling information to be transferred to the subordinate program interface comprises any one or more combinations of the identifier of the application program item, the link identifier of the calling request and the first identifier;
after the program interface is executed, calling the program interface execution method, generating second private calling information of the program interface through the program interface execution method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
2. The method of claim 1, wherein the generating the first private call information for the program interface comprises:
and generating a first identifier called by the program interface by the method for setting the identifier called by the program interface, wherein the first private calling information comprises the first identifier.
3. The method as set forth in claim 2, wherein the calling information passed by the upper level program interface comprises any one or more combination of the identification of the application program item, the link identification of the calling request and the identification of the upper level program interface, and the calling information to be passed to the lower level program interface comprises any one or more combination of the identification of the application program item, the link identification of the calling request and the first identification.
4. The method of claim 3, wherein the method before the program interface is executed comprises a method for acquiring time for starting execution of the program interface, and the generating the first private call information of the program interface comprises:
and acquiring the starting time of the program interface starting execution by the method for acquiring the time of the program interface starting execution, wherein the first private calling information comprises the starting time.
5. The method of claim 4, wherein the method after the program interface is executed includes a method for obtaining a time when the program interface finishes executing, and the generating the second private call information of the program interface includes:
and acquiring the end time of the program interface end execution by the method for acquiring the time of the program interface end execution, wherein the second private calling information comprises the end time.
6. The method of claim 5, wherein the splicing out the call information to be recorded comprises:
and determining the calling duration of the program interface based on the starting time and the ending time, wherein the calling information to be recorded comprises the calling information.
7. The method of claim 6, wherein the call information to be recorded comprises any one or more of an identifier of the application program item, a link identifier of a call request, an identifier of the upper level program interface, the call duration, and the first identifier.
8. An electronic device, wherein a preset hook class is registered in an application program item in the electronic device, and a method before program interface execution and a method after program interface execution are written in the preset hook class, the electronic device comprising:
a first calling unit, configured to, before a program interface in the application program item is called by a superior program interface, call a pre-program interface execution method, extract, by the pre-program interface execution method, calling information transferred by the superior program interface from header information of a first http request of the superior program interface, generate first private calling information of the program interface, determine calling information to be transferred to a subordinate program interface, and package the calling information to be transferred to the subordinate program interface to header information of a second http request, where the program interface execution forward method includes a method for setting an identifier called by the program interface, and the first private calling information includes the first identifier called by the program interface, and the method for setting the identifier called by the program interface generates the first identifier called by the program interface, the calling information transferred by the superior program interface comprises any one or more combinations of the identifier of the application program item, the link identifier of the calling request and the identifier of the superior program interface, and the calling information to be transferred to the subordinate program interface comprises any one or more combinations of the identifier of the application program item, the link identifier of the calling request and the first identifier;
the second calling unit is used for calling the program interface execution post method after the program interface is executed, generating second private calling information of the program interface through the program interface execution post method, splicing calling information to be recorded based on the calling information transmitted by the superior program interface, the first private information and the second private information, and recording the calling information to be recorded to a log file.
9. An electronic device, characterized in that the electronic device comprises a processor for implementing the steps of the method of recording information of inter-program interface calls according to any of claims 1-7 when executing a computer program stored in a memory.
10. A readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of recording information of inter-program-interface calls according to any one of claims 1 to 7.
Priority Applications (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 |
PCT/CN2018/082354 WO2019134291A1 (en) | 2018-01-05 | 2018-04-09 | Method for recording call information between program interfaces, and electronic device |
Applications Claiming Priority (1)
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 |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108228165A CN108228165A (en) | 2018-06-29 |
CN108228165B true CN108228165B (en) | 2021-02-02 |
Family
ID=62643071
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810011867.5A Active CN108228165B (en) | 2018-01-05 | 2018-01-05 | Method for recording calling information between program interfaces and electronic equipment |
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 (4)
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 |
CN102831043A (en) * | 2011-06-17 | 2012-12-19 | 阿里巴巴集团控股有限公司 | Monitoring method and device for application program |
CN105607986A (en) * | 2015-01-06 | 2016-05-25 | 北京志翔科技股份有限公司 | Acquisition method and device of user behavior log data |
CN106649120A (en) * | 2016-12-28 | 2017-05-10 | ***股份有限公司 | Data acquisition method, and data analysis method and system |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP3738624B2 (en) * | 1999-10-26 | 2006-01-25 | 日本電気株式会社 | Distributed application control system, control method, and recording medium recording 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 |
CN103716313B (en) * | 2013-12-24 | 2016-07-13 | 中国科学院信息工程研究所 | A kind of user privacy information guard method and system |
CN105095741A (en) * | 2014-05-13 | 2015-11-25 | 北京奇虎测腾科技有限公司 | Behavior monitoring method and behavior monitoring system of application program |
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 |
-
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 (4)
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 |
CN102831043A (en) * | 2011-06-17 | 2012-12-19 | 阿里巴巴集团控股有限公司 | Monitoring method and device for application program |
CN105607986A (en) * | 2015-01-06 | 2016-05-25 | 北京志翔科技股份有限公司 | Acquisition method and device of user behavior log data |
CN106649120A (en) * | 2016-12-28 | 2017-05-10 | ***股份有限公司 | Data acquisition method, and data analysis method and system |
Also Published As
Publication number | Publication date |
---|---|
WO2019134291A1 (en) | 2019-07-11 |
CN108228165A (en) | 2018-06-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109032691B (en) | Applet running method and device and storage medium | |
CN109064334B (en) | Intelligent contract accounting method, computer device and readable storage medium | |
CN110009334B (en) | Meckel tree construction and simple payment verification method and device | |
CN110096685B (en) | Equipment identifier generation method and device | |
CN106990960B (en) | Code deployment method and device | |
CN110011800B (en) | Block chain data reading method and device | |
CN109299015B (en) | Software testing method, device and system | |
CN111124480B (en) | Method and device for generating application program package, electronic equipment and storage medium | |
CN110197445B (en) | Intellectual property state generation method, intellectual property state query method, computer device and storage medium | |
US20140304683A1 (en) | Method, server and computer-readable recording media for managing metastore | |
CN110059002B (en) | Test data generation method, test equipment, storage medium and device | |
CN111273942A (en) | Code generation method, storage medium, electronic device and system | |
CN111897738B (en) | Automatic testing method and device based on atomic service | |
CN108228165B (en) | Method for recording calling information between program interfaces and electronic equipment | |
CN107895289A (en) | A kind of task dissemination method and device | |
CN110944231B (en) | Monitoring method and device of video player | |
CN107888399A (en) | A kind of platform services PaaS platform management method and device | |
CN113935010A (en) | Mobile banking login method and device based on block chain and 5G message | |
CN112015651B (en) | Data processing method and device | |
CN111724206A (en) | Advertisement processing method, responsibility chain object generation method, device, equipment and medium | |
CN111445279A (en) | Information processing method and device, electronic equipment and storage medium | |
KR102324259B1 (en) | Method and apparatus for providing platform-integrated sdk capable of developing multiple platforms with a single source code | |
CN107092601B (en) | Resource file construction method, resource file application method and device | |
CN115776515A (en) | Software service providing method, device and equipment | |
CN111061686A (en) | Resource processing method, device, server and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |