CN113986740A - Method and device for acquiring code execution record of application - Google Patents

Method and device for acquiring code execution record of application Download PDF

Info

Publication number
CN113986740A
CN113986740A CN202111273007.7A CN202111273007A CN113986740A CN 113986740 A CN113986740 A CN 113986740A CN 202111273007 A CN202111273007 A CN 202111273007A CN 113986740 A CN113986740 A CN 113986740A
Authority
CN
China
Prior art keywords
function
application
code execution
information
proxy object
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.)
Pending
Application number
CN202111273007.7A
Other languages
Chinese (zh)
Inventor
方启涵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202111273007.7A priority Critical patent/CN113986740A/en
Publication of CN113986740A publication Critical patent/CN113986740A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3676Test management for coverage analysis

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to the field of financial technology (Fintech), and discloses a method and a device for acquiring code execution records of an application, wherein a proxy object of a function is set aiming at the function meeting the setting requirement in the application; when the function in the application is called, a copy function of the function is obtained through the proxy object; running the copy function, and acquiring a code execution record in the running process of the copy function based on the proxy object; and reporting the code execution record of each function. The code execution records can be obtained in a non-instrumentation mode in an agent-based mode, invasion of a construction link is not needed, access cost is low, in addition, the dimensionality of the code execution records which can be obtained is more, and compared with the product of a code instrumentation technology, the final product is smaller in file size, so that the performance of program execution is better.

Description

Method and device for acquiring code execution record of application
Technical Field
The embodiment of the application relates to the field of financial technology (Fintech), in particular to a method and a device for acquiring code execution records of an application.
Background
With the development of computer technology, more and more technologies (such as big data, cloud computing or block chain) are applied to the financial field, and the traditional financial industry is gradually changing to financial technology, for example, for some banking businesses, a user can transact through a daily used terminal, so that the offline entity bank transaction is avoided. The user mainly transacts business through the online banking service provided by the bank. Therefore, from the perspective of banks, the online banking service is continuously optimized, the satisfaction degree of users on the online banking service is improved, and the method has profound significance on the sustainable development of banks. The bank can analyze the code coverage rate by acquiring the code execution record, and further provides an idea for the optimization of the online banking service.
Currently, in order to obtain an execution record of a code, a code instrumentation technique is used in many cases. For example, for a section of target code requiring analysis of code coverage, a technician may insert codes, i.e., stub codes, at different positions of the section of target code to complete corresponding work according to actual code detection requirements. Therefore, when the target code is executed, the instrumentation code is also executed, and at this time, the corresponding information can be sent to the background server in an interface request mode, so that the execution record of the code is obtained, and the detection of the code coverage rate is realized.
For the above-mentioned scheme of obtaining code execution record, because it needs to rely on code instrumentation technology, it has several disadvantages:
firstly, the introduction time of instrumentation codes lies in the process of constructing and compiling object codes, so that for different object codes, when the detection of code coverage rate is to be performed on the object codes respectively, the object codes need to be changed or adapted, namely, certain transformation cost exists;
secondly, the implementation of the code instrumentation technology requires secondary processing and injection of instrumentation codes when object codes are constructed, which is invasive and can destroy the purity of the object codes to some extent, so that the codes actually produced by developers are different from the products during compiling, thereby causing some unknown errors which are not under the control of the developers;
thirdly, in the actually produced code, because some instrumented codes are also included, the instrumented codes may be repeated and redundant, which may cause the size of the constructed and packaged code to become large, increase the time for loading and rendering the application, and is not favorable for the user experience.
Therefore, there is a need for a code execution record acquisition scheme with small file size, low access cost and non-intrusive features.
Disclosure of Invention
The application provides a method and a device for acquiring a code execution record of an application, which are used for acquiring the code execution record in a low-cost and non-invasive manner.
In a first aspect, an embodiment of the present application provides a method for obtaining a code execution record of an application, where the method includes: setting a proxy object of a function aiming at the function meeting the setting requirement in the application; when the function in the application is called, a copy function of the function is obtained through the proxy object; running the copy function, and acquiring a code execution record of the running of the copy function based on the proxy object; and reporting the code execution record of each function.
In the scheme, the code execution records can be acquired in a non-instrumentation mode based on an agent mode, the intrusion of a construction link is not needed, the access cost is low, in addition, the dimensionality of the acquired code execution records is more, and the file volume of the final output is smaller than that of the output of a code instrumentation technology, so that the program execution performance is better.
In a possible implementation method, for a function in an application that meets a setting requirement, setting a proxy object of the function includes: introducing a configuration code into a main entry file of the application; and creating a proxy object for the function meeting the set requirement in the construction class of the application based on the factory function in the configuration code.
In the above scheme, the configuration code is introduced into the main entry file of the application, so that functions in the application construction class can be traversed based on the factory function in the configuration code, functions meeting the setting requirement are screened out and proxy objects are created for the functions, and finally, the time and operation information for executing the functions, namely, the code execution records of the functions, can be obtained based on the created proxy objects. This approach avoids the invasiveness of secondary machining and injection operations that would otherwise be required to introduce instrumentation code during source code construction.
In one possible implementation method, obtaining, by the proxy object, a copy function of the function when the function in the application is called includes: when the function in the application is called, acquiring a function context and a function parameter set of the function through the proxy object; and taking the function context and the function parameter set as the input parameters of the binding function of the function to obtain the copy function of the function.
In the above scheme, when the code execution record of the function is obtained through the proxy object, the original function is required to be executed accurately at first, so that the code execution record obtained subsequently is credible; in the process, because the attribute of the primitive function is replaced by the proxy object, in order to implement accurate execution of the primitive function, before the primitive function is called, the function context and the function entry parameter group of the primitive function are acquired by the proxy object, and then the acquired function context and the function entry parameter group can be used as entry parameters of the binding function, so that the copy function of the primitive function can be acquired.
In one possible implementation, obtaining the code execution record in the execution of the copy function based on the proxy object includes: creating a global abnormal object based on the proxy object; stack information corresponding to the copy function running process is obtained through the abnormal object; the stack information comprises a call link of a function; obtaining a code execution record of the copy function based on the stack information; and deleting the abnormal object after the code execution record is obtained.
In the above scheme, after the function is accurately executed, in order to obtain the code execution record corresponding to the function, a global abnormal object may be created based on the proxy object, and the abnormal object may be used to obtain the stack information corresponding to the original function in the running process, so that the code execution record of the original function may be obtained based on the stack information, obviously, compared with the conventional code instrumentation technology, the scheme for obtaining the code execution record may utilize the global abnormal object to post the analysis step from the construction process to the code running without any access of the construction process, thereby saving the additional cost of analyzing the code text in construction; in addition, after the code execution record is acquired, the exception is not thrown outwards by deleting the exception object, so that the phenomenon that feedback is transmitted to an upper layer stack to cause abnormal application blocking due to the fact that exception errors are not captured is avoided, and meanwhile, the memory is optimized.
In one possible implementation method, obtaining a code execution record of the copy function based on the stack information includes: analyzing the stack information to obtain meta-record information of the copy function in the stack information analysis time; the meta recording information includes function information arranged in reverse order in the execution order.
In the above scheme, the stack information obtained correspondingly after the function is executed is analyzed, so that the function information arranged in the reverse order according to the execution sequence, namely the meta-record information, can be obtained, a timestamp of the function analyzed stack information is printed on any piece of meta-record information at the same time, and the timestamp information can provide a condition for rapid processing for subsequent function deduplication processing.
In one possible implementation method, reporting a code execution record of each function includes: arranging the code execution records of each function according to the reverse order of the stack information analysis time of each function; carrying out duplicate removal processing on each function information in the code execution records of each function in the reverse order; and if the function information after the duplication removal meets the requirement of the preset quantity, sending each function information meeting the requirement of the preset quantity to the background server.
In the above scheme, since the functions are executed in the JavaScript from top to bottom, in the process of executing one function, the stack information executed by the last function includes the whole call link, and the function located at the upper layer on the link may be recorded once, which may generate a large amount of redundant data and cause statistical deviation. According to the scheme, the filtering operation can be performed for cleaning the redundant data, so that repeated data can be effectively filtered through the filtering operation in the mode, and a foundation is laid for detecting the code coverage rate of the subsequent background server. In addition, according to the result of processing the stack information, a better feedback mode can be adopted, namely the code execution records corresponding to the functions are sent to the background server after the quantity requirement is met, so that the influence on the application performance caused by frequent network requests in a short time in a code execution record state needing to feed back a large number of functions is avoided.
In one possible implementation, the method of executing the copy function includes: wrapping the copy function through a try cache grammar; storing the abnormal information transmitted in the cache statement through a temporary variable; and after the copy function is finished running, reporting the abnormal information stored in the temporary variable.
In the above scheme, since the copy function may have exception information during the execution process, the uncaptured exception may block the execution process of the function, so that some functions that generate exceptions cannot be recorded. In order to avoid the situation, a try cache grammar is required to wrap an execution statement of the copy function, then the transmitted abnormal information is stored in the cache statement by using a temporary variable, and whether the abnormal information is reported or not is determined according to the situation that the abnormal information exists in the temporary variable after the copy function is finished running, so that real and effective feedback on a user is ensured.
In a second aspect, an embodiment of the present application provides an apparatus for obtaining a code execution record of an application, where the apparatus includes: the proxy object setting unit is used for setting a proxy object of a function aiming at the function meeting the setting requirement in the application; the function obtaining unit is used for obtaining a copy function of the function through the proxy object when the function in the application is called; the function processing unit is used for operating the copy function and acquiring a code execution record of the operation of the copy function based on the proxy object; and the reporting unit is used for reporting the code execution records of the functions.
In a third aspect, an embodiment of the present application provides a computing device, including:
a memory for storing program instructions;
and the processor is used for calling the program instructions stored in the memory and executing the implementation method of the first aspect according to the obtained program.
In a fourth aspect, the present application provides a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the method according to any one of the first aspects.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of a system architecture according to an embodiment of the present application;
fig. 2 is a schematic diagram of a method for obtaining a code execution record of an application according to an embodiment of the present application;
fig. 3 is a schematic diagram of an apparatus for obtaining a code execution record of an application according to an embodiment of the present application;
fig. 4 is a computing device provided in an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be described in further detail with reference to the accompanying drawings, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Aiming at the current scheme of acquiring the code execution record of the function through the code instrumentation technology, because different object codes require continuous adaptation of corresponding instrumentation codes, much time and labor cost are obviously required, and the opportunity of introducing the instrumentation codes mainly lies in the process of constructing the object codes, which is a secondary processing and injection process, is invasive, destroys the purity of the object codes to some extent, and causes some unknown errors which are not under the control of developers, and in addition, because the instrumentation codes are introduced, the volume of the constructed and packaged codes is obviously increased, so that the application loading and rendering time is prolonged, and the user experience is reduced.
In view of the above technical problem, the present application provides a possible system architecture, as shown in fig. 1, which is a schematic diagram of a system architecture provided in an embodiment of the present application, and includes a terminal 110 and a server 120.
The terminal 110 may be a smart phone, a computer, an iPad, or other smart devices, and various applications are installed thereon. In the context of the present application, in order to detect the code coverage rate corresponding to an application itself or a local service of the application, the application may be constructed based on the specification of ECMAScript 6.0(ES 6).
The server 120 is a server corresponding to each application in the terminal 110, and is configured to provide various services for a user, and in the context of the present application, the server 120 supports detecting code coverage of the application. The server 120 may be a physical server or a server cluster constructed by a plurality of physical servers.
ES6 is the next generation standard in JavaScript, and has been promulgated formally in month 6 of 2015. The Proxy is a function newly added in the ES6 standard, and is used to create a Proxy of a target object to implement interception and customization of basic operations, such as attribute lookup, assignment, enumeration, function call, and the like. It will be appreciated that a layer of "interception" is established in front of the target object, and external access to the target object must first pass through the layer of interception, so Proxy provides a mechanism to support filtering and rewriting of external access.
In view of the problems of the background art and the system architecture provided by the present application, an embodiment of the present application provides a method for obtaining a code execution record of an application. As shown in fig. 2, a schematic diagram of a method for obtaining a code execution record of an application according to an embodiment of the present application is provided, where the method may be executed by the terminal 110 shown in fig. 1, and the method includes the following steps:
step 201, aiming at the function meeting the setting requirement in the application, setting the proxy object of the function.
Optionally, a configuration code is introduced into a main entry file of the application; and creating a proxy object for the function meeting the set requirement in the construction class of the application based on the factory function in the configuration code.
For example, a reference to the associated logic code may be added in the main function entry file of the application at the initial execution of the program. Wherein the added logic code provides capabilities for at least three aspects including:
1. providing the capability of configurability. For example, initializing various configuration items, such as interface addresses of the backend server, conditions for code execution records of functions sent to the backend server (i.e., data sending policies), and the like;
2. providing the capability of temporarily storing code execution records and the capability of timely interacting with a background server according to a configured data sending strategy;
3. factory functions that provide agent behavior. The factory function is also a capability which is the most important item in the whole service, a Proxy object can be created inside the factory function by using the Proxy function, and based on the created Proxy object, the timing and operation information of the execution of the proxied function, that is, the code execution record of the function, can be obtained.
After the relevant logic code is introduced, the framework in which the application is located can be adapted and a proxy object can be created. For example, in the context of the present application, proxy objects are created for attributes as a function of the instance method for illustration. Specifically, after the relevant logic code is introduced, a factory function can be injected into the global environment of the currently running program, wherein the input parameter of the factory function is a constructor used for instantiation by a framework where the application is located, and the constructor can be processed through the factory function. The content of the factory function processing the constructor may include:
the factory function can traverse each attribute of the constructor, wherein if the currently traversed attribute is not an example method, the next attribute is continuously judged; if the currently traversed attribute is an instance method, the factory function can store the attribute through a temporary variable; after the plant function finishes traversing all the attributes of the constructor, the plant function can sequentially transfer the attributes stored in the temporary variable into the Proxy function, and through the Proxy function, the attributes in the temporary variable can be created into a Proxy object corresponding to the attributes one by one. This means that after the traversal is completed, all instance methods inside the constructor will be replaced one by the newly created proxy object.
Step 202, when the function in the application is called, a copy function of the function is obtained through the proxy object.
Optionally, when the function in the application is called, the function context and the function parameter set of the function are obtained through the proxy object; and taking the function context and the function parameter set as the input parameters of the binding function of the function to obtain the copy function of the function.
In the specification of ES 6.0, after the Proxy agent interception processing is performed on a function, a user triggers a call to the relevant function corresponding to an action, and actually executes the call, the call is an instance method named Apply in an agent object instantiated based on the function, and the instance method is used for realizing call interception on the proxied function.
For example, for a certain action made by a user to an application program, a function corresponding to the action is set as a function F; further, if the function F belongs to the instance method, the function F creates a Proxy object by using a Proxy function for the configured factory function in the application initialization process; therefore, when the user really sends out the action corresponding to the function F, the method is actually executed based on the example method named appliance in the proxy object instantiated by the function F, namely the function F is intercepted, and the function F is not executed directly. While the function F is intercepted, the application may import three parameters, namely a pointer of the function F, context information of the function F, and an import parameter group of the function F, to the instance method of Apply.
After the function F is intercepted, in order to obtain a code execution record corresponding to the function F in the embodiment of the present application, the function F needs to be accurately executed first. In order to implement accurate execution of the function F, the context and scope of the function must be consistent with those of the proxied function. To this end, the embodiment of the present application employs a bind method on a function prototype chain, which can be used to copy a function and allow manual modification of the orientation of a context. Taking the function F as an example, the bind method may specifically include: firstly, acquiring a first parameter, namely a pointer of a function F, transmitted into an appliance instance method, namely acquiring the function F before being proxied; then, a bind method in the function F is found and executed by searching the prototype chain, and the second parameter and the third parameter in the Apply instance method, that is, the context information of the function F and the parameter set of the function F are used as the input parameters of the bind method, so that the copy function of the function F is obtained.
Step 203, running the copy function, and obtaining the code execution record when the copy function runs based on the proxy object.
Based on step 202, after a function satisfies a proxy condition and is created as a proxy object, when a user issues a corresponding action of the function, the application will not directly execute the function, but execute an instance method named appliance in the created proxy object. The first step of the example method is then to accurately execute the proxied function, i.e., the primitive function. To accurately execute the primitive function, this step may then be performed based on the copy function (of the primitive function) provided in step 202.
Optionally, wrapping the copy function through a try cache syntax; storing the abnormal information transmitted in the cache statement through a temporary variable; and after the copy function is finished running, reporting the abnormal information stored in the temporary variable.
For example, when the step executes a copy function (of an original function), since there may be exception information in the execution process of the function, and an uncaptured exception may block the obtaining behavior of the step, some functions that generate exceptions may not be recorded. In order to avoid this situation, it is necessary to wrap the execution statement of the copy function using the try cache syntax, and then store the incoming exception information in the cache statement with a temporary variable, so as to be used in the subsequent flow, which is specifically described below.
Optionally, obtaining a code execution record in the running of the copy function based on the proxy object includes: creating a global abnormal object based on the proxy object; stack information corresponding to the copy function running process is obtained through the abnormal object; the stack information comprises a call link of a function; obtaining a code execution record of the copy function based on the stack information; and deleting the abnormal object after the code execution record is obtained.
Optionally, obtaining a code execution record of the copy function based on the stack information includes: analyzing the stack information to obtain meta-record information of the copy function in the stack information analysis time; the meta recording information includes function information arranged in reverse order in the execution order.
For example, after a call is performed to a copy function of the primitive function and a temporary variable is used to store exception information that the copy function may throw when called, a code execution record corresponding to the primitive function is generated. For the formed code execution record, in the embodiment of the present application, a completely new exception object can be instantiated through an Error global object, and the exception object is implemented by applying a standard based on ES specification, and there is no problem of compatibility, so that after the exception object is instantiated, the application can automatically assign a value to the stack information field "stack" of the exception object, and the field may include a call link and a sequence of functions. Compared with the traditional code insertion technology, the analysis method and the analysis device have the advantages that the analysis step can be placed from the construction process to the code operation by utilizing the Error global abnormal object, any construction process is not required to be accessed, and therefore the extra cost for analyzing the code text during construction is saved.
Further, for the acquired stack information of "stack", the data structure is a string stored in a specific format, and the content is to connect each stack with the strings "at", "v \" n ". The stack information character string is cut by using the two identifiers of 'at' and 'v' to obtain a stack information array arranged in reverse order according to the execution sequence, each item in the array is a character string, and the content is that the specific information such as function name, function file name, code line number and the like is connected by using a blank space. And performing secondary traversal on the obtained stack information array, cutting each item by using a blank space to obtain information such as a function name, a function file name, a code line number and the like of each execution record respectively, storing the obtained information such as the function name, the function file name, the code line number and the like as an object form, expanding the attribute of the timestamp to obtain a piece of meta-record information, and finally storing the meta-record information in a temporary storage point of a terminal memory, wherein the temporary storage point is used as a record pool. After the stack information is analyzed and the execution record of the code is obtained, the Error global object actively instantiated in the embodiment of the application needs to be destroyed, and it is ensured that the exception is not thrown outwards, so that the abnormal blocking of the program caused by the transmission of feedback to the upper layer stack due to the fact that the exception Error is not captured is avoided, and meanwhile, the memory is optimized.
It is noted that, after the stack information is analyzed, the present application may record one or more pieces of meta-record information regardless of whether the copy function of the original function is executed normally or an exception is generated during the execution. For the exception possibly generated by the copy function of the primary function in the execution process, the embodiment of the application stores the exception possibly generated by using a temporary variable in the process of executing the copy function of the primary function; therefore, after the stack information is analyzed, in order to implement correct response to the user operation, it is necessary to determine whether the information in the temporary variable is a null value, and if the information is a null value, it indicates that no exception is generated in the execution process of the copy function of the original function, so that the subsequent reporting step of the code execution record can be continued; if the exception value is not a null value, the stored exception information can be thrown outwards without being changed by using a throw statement, so that functions and exception capture logic outside the agent can be furthest prevented from being influenced, and then the subsequent reporting step of code execution records is continued.
And step 204, reporting the code execution records of the functions.
Optionally, the code execution records of each function are arranged in reverse order according to the stack information analysis time of each function; carrying out duplicate removal processing on each function information in the code execution records of each function in the reverse order; and if the function information after the duplication removal meets the requirement of the preset quantity, sending each function information meeting the requirement of the preset quantity to the background server.
In the embodiment of the application, for each function of which the attribute in the constructor corresponding to the framework where the application is located is the example method, the Proxy object is created by the Proxy function, and each function currently has the recording and Proxy intercepting capabilities, so that when the application runs, the meta-record information is continuously recorded in the record pool in response to each action of the user on the application. In JavaScript, functions are executed in a top-down order, and in the process of executing a function once, stack information executed by the last function includes information of the entire call link, so that it is easy to cause a situation that a function located at an upper layer on the call link may be recorded once, obviously, a large amount of redundant data may be generated in the process, which causes statistical deviation, and is not favorable for accurately detecting the code coverage rate. Therefore, in order to clean up redundant data in the embodiment of the application, filtering operation may be performed first, and then function information obtained through the filtering operation is sent to the background server, so that the background server can perform detection of the code coverage. The specific method of the filtering operation may be as follows:
firstly, arranging the meta-record information in the record pool according to the reverse order of the time stamps, and then traversing the stack information in sequence, wherein the execution is carried out in the later time. In the traversal process, the function names in the stack information of the current items are temporarily recorded, whether records with the same name as the temporary records exist in the stack information or not is matched, and the current items are removed when the function names are completely consistent.
For example, if an action triggered by the user to the application relates to the function S, where an attribute of the function S is an example method, it indicates that the function S satisfies a condition for creating a Proxy object by a Proxy function, and therefore, when the action issued by the user corresponds to the function S, the action is actually an example method for executing the application in the created Proxy object, where the first step is to correctly execute a copy function of the function S. Wherein, the function S includes 3 subfunctions including a function a, a function B and a function C, and the link calling relationship of the 3 subfunctions is: function a calls function B, which in turn calls function C. Then, the stack information corresponding to when executing the function a only includes the function a, the stack information corresponding to when executing the function B includes the function B and the function a, and the stack information corresponding to when executing the function C includes the function C, the function B, and the function a; then, when the time indicated by the timestamp corresponding to the meta record information obtained by sequentially analyzing the stack information corresponding to the function a, the function B, and the function C is sequentially increased, for example, the time indicated by the timestamp corresponding to the function a, the function B, and the function C is sequentially 10:01, 10:02, and 10:03, when the filtering operation is performed, the stack information corresponding to the function C may be processed first, then the stack information corresponding to the function B may be processed, and finally the stack information corresponding to the function a may be processed, which specifically includes: sequentially recording the function names included in the stack information corresponding to the function C in a temporary record (for example, setting the current temporary record to be empty), that is, after the step, storing the function C, the function B and the function a in the temporary record; then, comparing the function B included in the stack information corresponding to the function B with each record in the temporary record, wherein the temporary record does not need to be added with the function B included in the stack information corresponding to the function B because the function B already exists in the temporary record; similarly, the function a included in the stack information corresponding to the function B is continuously processed according to the same processing logic, and it is determined that it is still not necessary to add the function a included in the stack information corresponding to the function B to the temporary record; similarly, the function a included in the stack information corresponding to the function a is processed according to the same processing logic, and it is determined that it is still not necessary to add the function a included in the stack information corresponding to the function a to the temporary record, so that, in this scenario, the function recorded in the temporary record includes 3 functions, namely, the function a, the function B, and the function C, and the problem of repeatedly recording the same function is avoided.
After the filtering operation, the number of entries in the current recording pool is compared with the maximum number of entries in the configuration items, and when the number of function entries in the recording pool exceeds the maximum number of entries, the records in the recording pool are submitted to a background server in a batch interface mode, so that the influence of the recording operation of a large number of target codes and frequent network requests on the application performance in a short time can be avoided.
Based on the same concept, an apparatus for obtaining a code execution record of an application is provided in an embodiment of the present application, and as shown in fig. 3, the apparatus for obtaining a code execution record of an application provided in an embodiment of the present application is a schematic diagram, and the apparatus includes a proxy object setting unit 301, a function obtaining unit 302, a function processing unit 303, and a reporting unit 304;
a proxy object setting unit 301, configured to set a proxy object of a function that satisfies a setting requirement in an application;
a function obtaining unit 302, configured to obtain, when the function in the application is called, a copy function of the function through the proxy object;
a function processing unit 303, configured to run the copy function, and obtain, based on the proxy object, a code execution record when the copy function runs;
a reporting unit 304, configured to report the code execution record of each function.
Further, for the apparatus, the proxy object setting unit 301 is specifically configured to: introducing a configuration code into a main entry file of the application; and creating a proxy object for the function meeting the set requirement in the construction class of the application based on the factory function in the configuration code.
Further, for the apparatus, the function obtaining unit 302 is specifically configured to: when the function in the application is called, acquiring a function context and a function parameter set of the function through the proxy object; and taking the function context and the function parameter set as the input parameters of the binding function of the function to obtain the copy function of the function.
Further, for the apparatus, the function processing unit 303 is specifically configured to: creating a global abnormal object based on the proxy object; stack information corresponding to the copy function running process is obtained through the abnormal object; the stack information comprises a call link of a function; obtaining a code execution record of the copy function based on the stack information; and deleting the abnormal object after the code execution record is obtained.
Further, for the apparatus, the function processing unit 303 is further configured to: analyzing the stack information to obtain meta-record information of the copy function in the stack information analysis time; the meta recording information includes function information arranged in reverse order in the execution order.
Further, for the apparatus, the reporting unit 304 is specifically configured to: arranging the code execution records of each function according to the reverse order of the stack information analysis time of each function; carrying out duplicate removal processing on each function information in the code execution records of each function in the reverse order; and if the function information after the duplication removal meets the requirement of the preset quantity, sending each function information meeting the requirement of the preset quantity to the background server.
Further, for the apparatus, the function processing unit 303 is specifically configured to: wrapping the copy function through a try cache grammar; storing the abnormal information transmitted in the cache statement through a temporary variable; and after the copy function is finished running, reporting the abnormal information stored in the temporary variable.
The embodiment of the present application further provides a computing device, which may specifically be a desktop computer, a portable computer, a smart phone, a tablet computer, a Personal Digital Assistant (PDA), and the like. The computing device may include a Central Processing Unit (CPU), memory, input/output devices, etc., the input devices may include a keyboard, mouse, touch screen, etc., and the output devices may include a Display device, such as a Liquid Crystal Display (LCD), a Cathode Ray Tube (CRT), etc.
Memory, which may include Read Only Memory (ROM) and Random Access Memory (RAM), provides the processor with program instructions and data stored in the memory. In an embodiment of the application, the memory may be configured to store program instructions of a method of obtaining a code execution record of an application;
and the processor is used for calling the program instructions stored in the memory and executing the method for acquiring the code execution records of the application according to the obtained program.
As shown in fig. 4, a schematic diagram of a computing device provided in an embodiment of the present application includes:
a processor 401, a memory 402, a transceiver 403, a bus interface 404; the processor 401, the memory 402 and the transceiver 403 are connected by a bus 405;
the processor 401 is configured to read a program in the memory 402, and execute the method for obtaining the code execution record of the application;
the processor 401 may be a Central Processing Unit (CPU), a Network Processor (NP), or a combination of a CPU and an NP. But also a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. The PLD may be a Complex Programmable Logic Device (CPLD), a field-programmable gate array (FPGA), a General Array Logic (GAL), or any combination thereof.
The memory 402 is used for storing one or more executable programs, and may store data used by the processor 401 in performing operations.
In particular, the program may include program code including computer operating instructions. The memory 402 may include a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 402 may also include a non-volatile memory (non-volatile memory), such as a flash memory (flash memory), a Hard Disk Drive (HDD) or a solid-state drive (SSD); the memory 402 may also comprise a combination of memories of the kind described above.
The memory 402 stores the following elements, executable modules or data structures, or a subset thereof, or an expanded set thereof:
and (3) operating instructions: including various operational instructions for performing various operations.
Operating the system: including various system programs for implementing various basic services and for handling hardware-based tasks.
The bus 405 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 4, but this does not indicate only one bus or one type of bus.
The bus interface 404 may be a wired communication access port, a wireless bus interface, or a combination thereof, wherein the wired bus interface may be, for example, an ethernet interface. The ethernet interface may be an optical interface, an electrical interface, or a combination thereof. The wireless bus interface may be a WLAN interface.
The embodiment of the application also provides a computer-readable storage medium, which stores computer-executable instructions for causing a computer to execute a method for acquiring the code execution record of the application.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application 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 alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method of obtaining a code execution record of an application, the method comprising:
setting a proxy object of a function aiming at the function meeting the setting requirement in the application;
when the function in the application is called, a copy function of the function is obtained through the proxy object;
running the copy function, and acquiring a code execution record in the running process of the copy function based on the proxy object;
and reporting the code execution record of each function.
2. The method of claim 1,
the setting of the proxy object of the function aiming at the function meeting the setting requirement in the application comprises the following steps:
introducing a configuration code into a main entry file of the application;
and creating a proxy object for the function meeting the set requirement in the construction class of the application based on the factory function in the configuration code.
3. The method of claim 1,
when the function in the application is called, obtaining a copy function of the function through the proxy object includes:
when the function in the application is called, acquiring a function context and a function parameter set of the function through the proxy object;
and taking the function context and the function parameter set as the input parameters of the binding function of the function to obtain the copy function of the function.
4. The method of claim 1,
the obtaining of the code execution record in the copy function operation based on the proxy object includes:
creating a global abnormal object based on the proxy object;
stack information corresponding to the copy function running process is obtained through the abnormal object; the stack information comprises a call link of a function;
obtaining a code execution record of the copy function based on the stack information;
and deleting the abnormal object after the code execution record is obtained.
5. The method of claim 4,
the obtaining, based on the stack information, a code execution record of the copy function includes:
analyzing the stack information to obtain meta-record information of the copy function in the stack information analysis time; the meta recording information includes function information arranged in reverse order in the execution order.
6. The method of claim 5,
reporting the code execution record of each function includes:
arranging the code execution records of each function according to the reverse order of the stack information analysis time of each function;
carrying out duplicate removal processing on each function information in the code execution records of each function in the reverse order;
and if the function information after the duplication removal meets the requirement of the preset quantity, sending each function information meeting the requirement of the preset quantity to the background server.
7. The method of any one of claims 1 to 6,
the executing the copy function includes:
wrapping the copy function through a try cache grammar;
storing the abnormal information transmitted in the cache statement through a temporary variable;
and after the copy function is finished running, reporting the abnormal information stored in the temporary variable.
8. An apparatus for obtaining a code execution record of an application, the apparatus comprising:
the proxy object setting unit is used for setting a proxy object of a function aiming at the function meeting the setting requirement in the application;
the function obtaining unit is used for obtaining a copy function of the function through the proxy object when the function in the application is called;
the function processing unit is used for operating the copy function and acquiring a code execution record of the operation of the copy function based on the proxy object;
and the reporting unit is used for reporting the code execution records of the functions.
9. A computer device, comprising:
a memory for storing a computer program;
a processor for calling a computer program stored in said memory, for executing the method according to any one of claims 1-7 in accordance with the obtained program.
10. A computer-readable storage medium having stored thereon computer-executable instructions for causing a computer to perform the method of any one of claims 1-7.
CN202111273007.7A 2021-10-29 2021-10-29 Method and device for acquiring code execution record of application Pending CN113986740A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111273007.7A CN113986740A (en) 2021-10-29 2021-10-29 Method and device for acquiring code execution record of application

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111273007.7A CN113986740A (en) 2021-10-29 2021-10-29 Method and device for acquiring code execution record of application

Publications (1)

Publication Number Publication Date
CN113986740A true CN113986740A (en) 2022-01-28

Family

ID=79744481

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111273007.7A Pending CN113986740A (en) 2021-10-29 2021-10-29 Method and device for acquiring code execution record of application

Country Status (1)

Country Link
CN (1) CN113986740A (en)

Similar Documents

Publication Publication Date Title
US10489283B2 (en) Software defect reporting
US9152796B2 (en) Dynamic analysis interpreter modification for application dataflow
US9251011B2 (en) Backup of in-memory databases
US11216342B2 (en) Methods for improved auditing of web sites and devices thereof
US9129058B2 (en) Application monitoring through continuous record and replay
Hunt et al. Java performance
WO2022016847A1 (en) Automatic test method and device applied to cloud platform
CN110474900B (en) Game protocol testing method and device
CN108460068B (en) Method, device, storage medium and terminal for importing and exporting report
US10705949B2 (en) Evaluation of library test suites using mutation testing
CN112559525B (en) Data checking system, method, device and server
US10635724B2 (en) Analysis of data utilization
CN111414402A (en) Log threat analysis rule generation method and device
CN106021054A (en) Method and apparatus for testing upgrading and downgrading stability of BMC
CN110554998A (en) hook method, device, terminal and storage medium for replacing function internal instruction
CN106547658A (en) A kind of automated testing method and device
CN111159040A (en) Test data generation method, device, equipment and storage medium
CN107832446A (en) A kind of searching method and computing device of configuration item information
CN114385722A (en) Interface attribute consistency checking method and device, electronic equipment and storage medium
US11221862B2 (en) Capturing data from a live web application to populate a demo application
CN115357590A (en) Recording method and device for data change, electronic device and storage medium
CN115858487A (en) Data migration method and device
US20070150866A1 (en) Displaying parameters associated with call statements
US20200294057A1 (en) Business processing method, apparatus, and equipment
CN111552648A (en) Automatic verification method and system for application

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