[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN114328088A - Data acquisition method and device and electronic equipment - Google Patents

Data acquisition method and device and electronic equipment Download PDF

Info

Publication number
CN114328088A
CN114328088A CN202111500975.7A CN202111500975A CN114328088A CN 114328088 A CN114328088 A CN 114328088A CN 202111500975 A CN202111500975 A CN 202111500975A CN 114328088 A CN114328088 A CN 114328088A
Authority
CN
China
Prior art keywords
target
application
function
class
bytecode
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
CN202111500975.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.)
Taikang Insurance Group Co Ltd
Taikang Online Property Insurance Co Ltd
Original Assignee
Taikang Insurance Group Co Ltd
Taikang Online Property Insurance 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 Taikang Insurance Group Co Ltd, Taikang Online Property Insurance Co Ltd filed Critical Taikang Insurance Group Co Ltd
Priority to CN202111500975.7A priority Critical patent/CN114328088A/en
Publication of CN114328088A publication Critical patent/CN114328088A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The method comprises the steps of firstly strengthening byte codes of a target class of a Java probe in an APM, adding starting parameters of the Java probe in the target application, then determining the target class of the target application when the target application is started, calling a callback function in the target class through the Java probe, modifying the byte codes in the target class, and acquiring a request body and a return body of an application interface of the target application based on the modified byte codes. Based on the method, the problem that the current APM tool cannot collect the request body and the return body of the application interface is solved, the correlation between the service data and the performance index is realized, the monitoring capability of the APM tool is improved, and the time cost and the human resource which are spent on collecting the request body and the return body by the APM tool are effectively reduced.

Description

Data acquisition method and device and electronic equipment
Technical Field
The present application relates to the field of Java technologies, and in particular, to a method and an apparatus for acquiring data, and an electronic device.
Background
With the popularization of JAVA (computer programming language) Performance optimization tool APM (Application Performance Management), APM can be used to collect Performance data of an Application, and the Performance data can be used as an index for judging the Performance of the Application.
Although APM has better performance data collection capability, APM has a poor capability of collecting business data. Specifically, the APM can only collect the character string request parameter and the interface return code on the application interface path of a certain application, and cannot collect the request body and the return body of the application interface.
Currently, in order to enhance the capability of the APM to collect the request body and the return body of the application interface, a secondary development mode is adopted for the source code of the APM. Specifically, a developer downloads the source code of the APM, modifies the source code in a code hierarchy, and then recompiles and redeploys the modified code.
However, every time the source code of the APM is updated or upgraded periodically, a developer needs to develop the updated source code again, which causes a lot of waste of time cost and human resources.
Disclosure of Invention
The application provides a collection method, a collection device and electronic equipment, which are used for collecting a request body and a return body of an application interface.
In a first aspect, the present application provides a method of collecting data, the method comprising:
when a target application is started, determining a target class of the target application, wherein the target class is a class file registered with a callback function, and the callback function is used for modifying byte codes in the target class;
modifying the byte codes in the target class by calling the callback function in the target class;
and acquiring a request body and a return body of the application interface of the target application based on the modified byte codes.
In one possible design, the determining the target class of the target application when the target application is started includes:
after a Java Virtual Machine (JVM) is started, loading a plug-in related to a target application through a Java probe, wherein the plug-in is used for identifying a target class to be modified;
when the target application is started, loading the class file in the target application through the JVM, and determining whether the currently loaded class file is a target class identified by the plug-in;
if yes, determining the currently loaded class file as the target class;
if not, continuing to load the next class file.
In one possible design, the modifying the bytecode in the target class includes:
determining a target bytecode in the target class, wherein the target bytecode is a bytecode which remains unchanged in the target class;
adding a before function of a listener at the head of the target bytecode, and adding an after function of the listener at the tail of the target bytecode;
modifying the bytecode in the target class based on the before function and the after function.
In one possible design, the adding a before function of a listener to the head and the tail of the target bytecode and adding an after function of the listener to the tail of the target bytecode includes:
when a before function of a listener is added, determining that the before function contains a sub-target class registered with a callback function;
when an after function of a listener is added, determining that the after function contains a sub-target class registered with a callback function;
and calling the callback function in the sub-target class, adding a Filter function of a Filter in the sub-target class, and modifying the byte codes in the sub-target class through the Filter function.
In one possible design, the modifying the bytecode in the target class based on the before function and the after function includes:
according to the before function, adding a request body of an application interface of the target application and a listener character code of a return body at the head end of a target byte code in the target class;
and adding a request body of an application interface of the target application and a listener character code of a return body at the tail end of the target bytecode in the target class according to the after function.
In one possible design, the obtaining the request body and the return body of the application interface of the target application based on the modified bytecode includes:
after the modified bytecode is loaded, continuing to start the target application and executing the modified bytecode;
and acquiring a request body and a return body of the application interface of the target application after the modified bytecode is executed.
In one possible design, after the obtaining the request body and the return body of the application interface of the target application based on the modified bytecode, the method further includes:
and sending the request body and the return body to a front-end interface for visual display.
By the method, the problem that the request body and the return body of the application interface of the target application are difficult to collect by the APM tool can be solved, the business data of the request body and the return body of the application interface can be collected while the performance data of the target application is collected, the performance index and the business data of the target application can be automatically associated, the independence function between the performance index and the business data is realized, and the target application can be monitored more comprehensively by the APM tool.
Furthermore, the circulation condition of the business data in practical application can be truly reflected, the accuracy of performance bottleneck solution and positioning problem analysis is favorably improved, and important data support is provided for later business modeling.
In a second aspect, the present application provides an apparatus for collecting data, the apparatus comprising:
the device comprises a determining module, a judging module and a judging module, wherein the determining module is used for determining a target class of a target application when the target application is started, the target class is a class file registered with a callback function, and the callback function is used for modifying byte codes in the target class;
the modification module modifies the byte codes in the target class by calling the callback function in the target class;
and the acquisition module acquires the request body and the return body of the application interface of the target application based on the modified bytecode.
In one possible design, the determining module is specifically configured to load, through a Java probe, a plug-in related to a target application after a Java virtual machine JVM is started, where the plug-in is used to identify a target class to be modified; when the target application is started, loading the class file in the target application through the JVM, and determining whether the currently loaded class file is a target class identified by the plug-in; if yes, determining the currently loaded class file as the target class; if not, continuing to load the next class file.
In one possible design, the modification module is specifically configured to determine a target bytecode in the target class, where the target bytecode is a bytecode that remains unchanged in the target class; adding a before function of a listener at the head of the target bytecode, and adding an after function of the listener at the tail of the target bytecode; modifying the bytecode in the target class based on the before function and the after function.
In a possible design, the modification module is specifically configured to determine that a before function of a listener includes a sub-target class in which a callback function is registered when the before function is added; when an after function of a listener is added, determining that the after function contains a sub-target class registered with a callback function; and calling the callback function in the sub-target class, adding a Filter function of a Filter in the sub-target class, and modifying the byte codes in the sub-target class through the Filter function.
In a possible design, the modification module is specifically configured to add, according to the before function, a listener character code of a request body and a listener character code of a return body of an application interface of the target application at a head end of a target bytecode in the target class; and adding a request body of an application interface of the target application and a listener character code of a return body at the tail end of the target bytecode in the target class according to the after function.
In one possible design, after the obtaining module, the obtaining module is further configured to continue to start the target application and execute the modified bytecode after the modified bytecode is loaded; and acquiring a request body and a return body of the application interface of the target application after the modified bytecode is executed.
In a third aspect, the present application provides an electronic device, comprising:
a memory for storing a computer program;
the processor is used for realizing the steps of the data acquisition method when executing the computer program stored in the memory.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the above-mentioned method steps of collecting data.
For each of the second to fourth aspects and possible technical effects of each aspect, please refer to the above description of the first aspect or the possible technical effects of each of the possible solutions in the first aspect, and no repeated description is given here.
Drawings
Fig. 1 is a structural diagram of a possible application scenario provided in the present application;
FIG. 2 is a flow chart of a method of collecting data provided herein;
FIG. 3 is a schematic diagram of an apparatus for acquiring data provided herein;
fig. 4 is a schematic diagram of a structure of an electronic device provided in the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more clear, the present application will be further described in detail with reference to the accompanying drawings. The particular methods of operation in the method embodiments may also be applied to apparatus embodiments or system embodiments. It should be noted that "a plurality" is understood as "at least two" in the description of the present application. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. A is connected with B and can represent: a and B are directly connected and A and B are connected through C. In addition, in the description of the present application, the terms "first," "second," and the like are used for descriptive purposes only and are not intended to indicate or imply relative importance nor order to be construed.
The inventor of the application finds that, when monitoring the application, the request body and the return body of the application interface cannot be directly acquired through an APM tool, so that the accuracy of analyzing the application interface is low. Specifically, in an actual application scenario, when an actually started application has a problem, due to lack of a request body and a return body of an application interface, an abnormal interface cannot be located, affected service data cannot be determined, and a flow path of a specific service on a system link cannot be obtained, for example, a specific system, a specific interface, and the like of a link through which a specific service passes when executing the service.
It should be noted that the content of the research findings of the inventors is not prior art, and is essentially part of the present application.
In order to solve the problem that an APM tool cannot collect a request body and a return body of an application interface, the application provides a method and a device for collecting data and electronic equipment. The technical scheme includes that byte codes in an APM tool are modified through an APM enhancement tool, when a target application is started, a target class of a callback function registered in the target application is determined, then the callback function is called through the APM tool, byte codes in the target class are modified, and a request body and a return body of an application interface of the target application are obtained based on the modified byte codes.
Compared with the prior art, the technical scheme provided by the embodiment of the application has the advantages that the request body and the return body can be obtained without carrying out secondary development on the source code in the APM tool every time, so that the time cost and the manpower resource spent on monitoring the target application through the APM tool are effectively saved, and the target application and the APM tool can be conveniently used and maintained in the later period.
It should be noted that, in this embodiment of the present application, the APM enhancement tool is a tool for modifying a bytecode in the APM tool, and the bytecode of the APM tool is modified by the APM enhancement tool to collect a request body and a return body of an application interface, which is a possible implementation manner, and further includes other functions that can be implemented on the premise of not modifying a source code of the APM tool, for example, controlling a trigger condition for the APM tool to collect data, and implementing adjustment of a sampling rate in a process of monitoring a target application by the APM tool.
The technical scheme provided by the embodiment of the application can be applied to performance monitoring of Java applications, and particularly relates to an APM (Java performance optimization tool). In addition, the application scenario described in the embodiment of the present application is to illustrate the technical solution of the embodiment of the present application more clearly, and does not constitute a limitation to the technical solution provided in the embodiment of the present application, and as the ways of monitoring the performance of the Java application increase, the Java performance optimization tool updates and iterates, and the source code in the APM tool is modified and upgraded, the technical solution provided in the embodiment of the present application is also applicable to similar technical solutions.
Referring to fig. 1, an embodiment of the present application provides a structure diagram of an applicable application scenario.
The application scenario shown in fig. 1 is a structural diagram of an application scenario in which a requesting entity and a returning entity of an application interface are collected by an APM tool based on the APM enhancement tool. The application scenario may include a Java enhanced probe module 110, a Java probe module 120, a data module 130, a storage module 140, and a presentation module 150.
In order to more clearly illustrate the application scenario provided by the present application, the application scenario shown in fig. 1 is specifically described below by taking an APM tool, which is Pinpoint, as an example. Herein, Pinpoint does not constitute a limitation to the application scenarios provided in the embodiments of the present application, and those skilled in the art will know that the application scenarios provided in the embodiments of the present application are also applicable to other APM tools.
The Java enhanced probe module 110 specifically includes a Pinpoint enhanced probe (a Java probe), which will be started together with the target application and share a JVM (Java virtual machine) with the target application. The Pinpoint reinforced probe may be used to enhance the collection function of the Pinpoint probe in Java probe module 120 so that the Pinpoint probe may be used to collect the request and return entities of the application interface. In addition, the Pinpoint enhanced probe can also be applied to enhance other functions of the Pinpoint probe, such as enhancing the function of the Pinpoint probe to adjust the sampling rate, increasing the trigger condition of the Pinpoint probe to set the acquisition data, and the like. In practical applications, the Pinpoint-enhanced probe will also be deployed into the target application.
The Java probe module 120 specifically includes a Pinpoint probe (Java probe), which can be used to monitor and collect various data of the target application, and the Pinpoint probe will be started together with the target application and share the JVM with the target application. The Pinpoint probe is used for periodically sending data to the data module 130, for example, configuration data supporting UDP (User data Protocol)/TCP (Transmission Control Protocol) and thread (interface description language and binary communication Protocol). And the Pinpoint probe may also be used to monitor the target application and collect performance data of the target application, and further, based on the Pinpoint enhanced probe in the Java enhanced probe module 110, the Pinpoint probe may also be used to collect performance data of the target application, that is, a request body and a return body of the application interface. In practical applications, the Pinpoint probe will also be deployed into the target application.
And a data module 130 for collecting data transmitted by the Java probe module 120 and storing the data in the storage module 140.
The storage module 140 specifically includes an HBase (distributed, column-oriented open database), and the HBase may be used to store data received by the data module 130.
The presentation module 150 specifically includes a Pinpoint front-end interface (Pinpoint Web UI), where the Pinpoint front-end interface is used to extract data stored in the storage module 140, and the extracted data is used for performing visual presentation on the Pinpoint front-end interface.
The preferred embodiments of the present application will be described below with reference to the accompanying drawings of the specification, it should be understood that the preferred embodiments described herein are merely for illustrating and explaining the present invention, and are not intended to limit the present invention, and that the embodiments of the present application and the technical features of the embodiments of the present application may be combined with each other without conflict.
Referring to fig. 2, an embodiment of the present application provides a method for acquiring data, which includes the following specific processes:
before the steps of the embodiment of the present application are specifically executed, the method further includes configuring a starting environment of Pinpoint, adding a Pinpoint probe and a Pinpoint reinforcement probe in the starting parameters of the application, and then starting the target application, where the target application is the application added with the Pinpoint probe starting parameters and the Pinpoint reinforcement probe starting parameters.
Specifically, after configuring the starting environment of the Pinpoint and before starting the target application, a Java Virtual Machine (JVM) is started, the JVM is used for running the target application, and the Pinpoint probe and the Pinpoint reinforced probe are started following the JVM start.
The Pinpoint probe is specifically used for acquiring data of a target application, and the acquisition mode of the Pinpoint probe can be used for acquiring the data of the target application on the basis of not changing the target application, for example, the performance data of the target application can be acquired by the Pinpoint probe at present.
The Pinpoint reinforced probe is specifically used for reinforcing the acquisition function of the Pinpoint probe, and the reinforcement function of the Pinpoint reinforced probe can enable the Pinpoint probe to acquire more data of a target application on the basis of not changing a Pinpoint tool, for example, acquiring a request body and a return body of an application interface of the target application.
Further, after the Pinpoint probe, the Pinpoint reinforcement probe, is activated, the Pinpoint probe will also load all the plug-ins under the target directory, e.g., the Pinpoint probe loads all the plug-ins under the plugin directory.
During the loading of the plug-in by the Pinpoint probe, the Pinpoint probe calls a preset method, wherein the plug-in presets the target class according to the preset method. Based on a preset method, the class file which needs to be modified in the target application can be determined, whether the class file registers the callback function can also be determined, and the class file which registers the callback function is used as the target class.
For example, each time a Pinpoint probe loads a plug-in, the Pinpoint probe calls the profiler plug-in setup method, based on which the target class that needs to be changed and the transformer callback function registered can be determined.
Based on the method, after the Pinpoint probe finishes loading all the plug-ins in the target directory, the target application is started.
Step 201: when a target application is started, determining a target class of the target application;
and after determining to start the Pinpoint probe and the Pinpoint reinforced probe, starting the target application and loading a class file of the target application. In the process of loading the class file, whether the currently loaded class file is a target class registered with a callback function can be determined based on the plug-in: if so, stopping the current loading operation; if not, completing the loading of the current class file and continuing to load the next class file.
In particular, the target class may be determined from a plug-in that calls a preset method load. The callback function may be used to modify the bytecode in the target class to collect a request body and a return body of the application interface of the target application corresponding to the target class.
Step 202: modifying the byte codes in the target class by calling the callback function in the target class;
after the target class is determined, a calling method corresponding to a callback function on the target class is called through a Pinpoint probe, and the callback function is used for modifying byte codes in the target class, so that the functions of a request body and a return body of an acquisition application interface are realized.
Specifically, a target bytecode that remains unchanged among bytecodes in the target class is determined, a before function is added to the head of the target bytecode, and an after function is added to the tail of the target bytecode. The before function and the after function are functions of a calling method corresponding to the callback function, and a listener can be added to the header of the target bytecode based on the before function, and is used for collecting a request body and a return body of the application interface; a listener can be added at the tail of the target bytecode based on the after function, and the listener is used for collecting a request body and a return body of the application interface.
In the embodiment of the application, the collection of the request body and the return body of the application interface is realized based on the introduction of a Pinpoint reinforced probe through a before function and an after function. Specifically, the bytecodes of the class files in the before function and the after function are modified based on the Pinpoint reinforced probe. The modification of bytecodes in the Pinpoint probe by the Pinpoint enhanced probe is specifically described below by taking the before function as an example, and the after function is modified in the same way as the before function and is not described herein too much.
In particular, the before function is a method provided by the Pinpoint probe for the target application, which is used for realizing the data acquisition function of the target application, and it does not belong to the method in the target application. In practical application, the target application calls the before function to realize the function in the before function. Therefore, in the process of developing a Pinpoint probe, a developer needs to write specific codes of a before function to implement a corresponding data acquisition function, for example, write a class file for implementing the function. In view of the fact that the before function that the Pinpoint probe can provide at present is mainly a method for acquiring performance data of a target application, that is, a request body and a return body of an application interface cannot be acquired. Therefore, in order to avoid secondary development of a developer on a Pinpoint source code and save human resources and time cost, the embodiment of the application provides that the acquisition function of the before function in the Pinpoint probe is enhanced by the Pinpoint enhanced probe.
To facilitate understanding of the embodiments of the present application, the before function in the Pinpoint probe and the before function enhanced by the Pinpoint enhanced probe are specifically described below.
In the embodiment of the application, the before function of the Pinpoint probe includes a class file for collecting performance data of a target application, and after a call method of a callback function of the Pinpoint reinforcement probe is registered on the class file, a reinforced before function is added to a bytecode head in the class file, and a reinforced after function is added to a bytecode tail in the class file. Herein, the enhanced before function and the enhanced after function are methods provided in the Pinpoint enhanced probe, and based on the enhanced before function and the enhanced after function, a request body and a return body of an application interface can be collected on the basis of collecting performance data of a target application.
The service data of a request body and a return body of an application interface can be acquired while acquiring the performance data of the target application through the enhanced before function and the enhanced after function, so that the automatic association of the performance index and the service data in the running process of the target application can be automatically realized, the independence between the performance index and the service data is broken through, and the monitoring on the target application is more comprehensive. By applying the method, the circulation condition of the business data can be truly reflected in practical application, a more accurate basis is further provided for solving the performance bottleneck and analyzing and positioning problems, and the method has very important significance for providing data support for later business modeling.
In one possible embodiment, an interceptor Filter function may also be added to the before function of the Pinpoint probe based on the enhanced before function and the enhanced after function. The Filter function may be used to control whether to collect performance data of the target application or a request body and a return body of the application interface, for example, if an operation parameter of the target application meets a preset operation parameter, no collection is set; and if the operation parameters of the target application do not meet the preset operation parameters, setting acquisition.
The determination conditions for controlling the collection may be set according to actual application conditions or may be set manually, and the determination conditions are not limited to the above-mentioned conditions, and may be set to control the collection of only one kind of data or a plurality of kinds of data, and the types of the collected data are not limited to the above-mentioned data. In addition, the idea of the technical scheme provided above is also applicable to the control of other functions applied to the target.
By adding the Filter function, data in the monitoring process of the target application can be selectively extracted, resource overhead generated in the monitoring process of the target application is effectively saved, and the monitoring capability of the Pinpoint probe for acquiring data and the like is improved.
It should be noted that the enhanced before function and the enhanced after function provided in the Pinpoint enhanced probe are not only suitable for enhancing the monitoring function of the Pinpoint probe for acquiring the application interface request body and the return body, but also suitable for enhancing the monitoring function of the Pinpoint probe for controlling the trigger condition for acquiring the target application data.
In addition, the embodiment of the present application describes that a specific monitoring function is enhanced based on a Pinpoint reinforced probe, so as to more clearly illustrate the technical solution of the embodiment of the present application, and does not limit the technical solution provided by the embodiment of the present application, and it is known to a person skilled in the art that the Pinpoint reinforced probe provided by the embodiment of the present application is also suitable for a monitoring function that is difficult to implement by other Pinpoint probes, such as enhancing a sampling rate of a Pinpoint probe set target application.
Based on the method, the callback function in the target class is called through the Pinpoint probe to modify the bytecode in the target class, so that the subsequent acquisition of the request body and the return body of the application interface of the target application based on the modified bytecode is facilitated.
Step 203: and acquiring a request body and a return body of the application interface of the target application based on the modified byte codes.
And after the modified bytecode is executed, acquiring a request body and a return body of an application interface of the target application.
In the embodiment of the application, after the request body and the return body of the application interface are obtained, the request body and the return body are sent to a Pinpoint front-end interface for visual display.
Specifically, the user can view the performance data of the target application and the request body and the return body of the application interface through the Pinpoint front-end interface. Of course, in some possible embodiments, the user may also view other monitoring data of the target application through the Pinpoint front-end interface, which is not specifically set forth herein.
By the technical scheme provided by the embodiment of the application, the problem that the request body and the return body of the application interface of the target application are difficult to collect by the APM tool can be solved, the service data of the request body and the return body of the application interface can be collected while the performance data of the target application is collected, the performance index and the service data of the target application can be automatically associated, the independence function between the performance index and the service data is realized, and the target application can be monitored more comprehensively by the APM tool.
Furthermore, by the technical scheme provided by the embodiment of the application, the circulation condition of the business data in practical application can be truly reflected, the accuracy of performance bottleneck solution and positioning problem analysis is favorably improved, and important data support is provided for later business modeling.
Based on the same invention concept, the application also provides a device for acquiring data, which is used for acquiring the request body and the return body of the application interface, solving the problem that the request body and the return body of the application interface cannot be acquired by the APM tool at present, realizing the association between the service data and the performance index, improving the monitoring capability of the APM tool, and effectively reducing the time cost and the human resource spent on acquiring the request body and the return body by the APM tool. Referring to fig. 3, the apparatus includes:
the determining module 301 is configured to determine a target class of a target application when the target application is started, where the target class is a class file in which a callback function is registered, and the callback function is used to modify a bytecode in the target class;
a modifying module 302, configured to modify the bytecode in the target class by calling the callback function in the target class;
the obtaining module 303 obtains the request body and the return body of the application interface of the target application based on the modified bytecode.
In one possible design, the determining module 301 is specifically configured to load, after the Java virtual machine JVM is started, a plug-in related to the target application through a Java probe, where the plug-in is used to identify a target class to be modified; when the target application is started, loading the class file in the target application through the JVM, and determining whether the currently loaded class file is a target class identified by the plug-in; if yes, determining the currently loaded class file as the target class; if not, continuing to load the next class file.
In one possible design, the modification module 302 is specifically configured to determine a target bytecode in the target class, where the target bytecode is a bytecode that remains unchanged in the target class; adding a before function of a listener at the head of the target bytecode, and adding an after function of the listener at the tail of the target bytecode; modifying the bytecode in the target class based on the before function and the after function.
In a possible design, the modifying module 302 is specifically configured to determine that a before function of a listener includes a sub-target class in which a callback function is registered when the before function is added; when an after function of a listener is added, determining that the after function contains a sub-target class registered with a callback function; and calling the callback function in the sub-target class, adding a Filter function of a Filter in the sub-target class, and modifying the byte codes in the sub-target class through the Filter function.
In a possible design, the modifying module 302 is specifically configured to add, according to the before function, a listener character code of a request body and a listener character code of a return body of an application interface of the target application at a head end of a target bytecode in the target class; and adding a request body of an application interface of the target application and a listener character code of a return body at the tail end of the target bytecode in the target class according to the after function.
In a possible design, after the obtaining module 303, the method is further configured to continue to start the target application and execute the modified bytecode after the modified bytecode is loaded; and acquiring a request body and a return body of the application interface of the target application after the modified bytecode is executed.
Based on the device, the device can be used for acquiring the request body and the return body of the application interface, the problem that the request body and the return body of the application interface cannot be acquired through an APM tool at present is solved, the association between the service data and the performance index is realized, the monitoring capability of the APM tool is improved, and the time cost and the human resource spent on acquiring the request body and the return body through the APM tool are effectively reduced.
Based on the same inventive concept, an embodiment of the present application further provides an electronic device, where the electronic device can implement the function of the foregoing apparatus for acquiring data, and with reference to fig. 4, the electronic device includes:
at least one processor 401 and a memory 402 connected to the at least one processor 401, in this embodiment, a specific connection medium between the processor 401 and the memory 402 is not limited in this application, and fig. 4 illustrates an example in which the processor 401 and the memory 402 are connected by a bus 400. The bus 400 is shown in fig. 4 by a thick line, and the connection manner between other components is merely illustrative and not limited thereto. The bus 400 may be divided into an address bus, a data bus, a control bus, etc., and is shown with only one thick line in fig. 4 for ease of illustration, but does not represent only one bus or type of bus. Alternatively, processor 401 may also be referred to as a controller, without limitation to name a few.
In an embodiment of the present application, the memory 402 stores instructions executable by the at least one processor 401, and the at least one processor 401 may execute the method for acquiring data discussed above by executing the instructions stored in the memory 402. The processor 401 may implement the functions of the various modules in the apparatus shown in fig. 3.
The processor 401 is a control center of the apparatus, and may connect various parts of the entire control device by using various interfaces and lines, and perform various functions and process data of the apparatus by operating or executing instructions stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the apparatus.
In one possible design, processor 401 may include one or more processing units and processor 401 may integrate an application processor that handles primarily operating systems, user interfaces, application programs, and the like, and a modem processor that handles primarily wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 401. In some embodiments, processor 401 and memory 402 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 401 may be a general-purpose processor, such as a Central Processing Unit (CPU), digital signal processor, application specific integrated circuit, field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or the like, that may implement or perform the methods, steps, and logic blocks disclosed in embodiments of the present application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the data collecting method disclosed in the embodiments of the present application may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
Memory 402, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 402 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and so on. The memory 402 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 402 in the embodiments of the present application may also be circuitry or any other device capable of performing a storage function for storing program instructions and/or data.
By programming the processor 401, the code corresponding to the data collecting method described in the foregoing embodiment may be solidified in the chip, so that the chip can execute the steps of the data collecting method of the embodiment shown in fig. 2 when running. How to program the processor 401 is well known to those skilled in the art and will not be described in detail herein.
Based on the same inventive concept, the present application also provides a storage medium storing computer instructions, which when executed on a computer, cause the computer to perform the data collecting method discussed above.
In some possible embodiments, the various aspects of the method for collecting data provided in the present application may also be implemented in the form of a program product comprising program code means for causing a control device to carry out the steps of the method for collecting data according to various exemplary embodiments of the present application described above in the present specification, when the program product is run on an apparatus.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, apparatus, 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.
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 collecting data, the method comprising:
when a target application is started, determining a target class of the target application, wherein the target class is a class file registered with a callback function, and the callback function is used for modifying byte codes in the target class;
modifying the byte codes in the target class by calling the callback function in the target class;
and acquiring a request body and a return body of the application interface of the target application based on the modified byte codes.
2. The method of claim 1, wherein determining the target class of the target application upon startup of the target application comprises:
after a Java Virtual Machine (JVM) is started, loading a plug-in related to a target application through a Java probe, wherein the plug-in is used for identifying a target class to be modified;
when the target application is started, loading the class file in the target application through the JVM, and determining whether the currently loaded class file is a target class identified by the plug-in;
if yes, determining the currently loaded class file as the target class;
if not, continuing to load the next class file.
3. The method of claim 1, wherein the modifying the bytecode in the target class comprises:
determining a target bytecode in the target class, wherein the target bytecode is a bytecode which remains unchanged in the target class;
adding a before function of a listener at the head of the target bytecode, and adding an after function of the listener at the tail of the target bytecode;
modifying the bytecode in the target class based on the before function and the after function.
4. The method of claim 3, wherein adding a before function of a listener at the head and the tail of the target bytecode and adding an after function of a listener at the tail of the target bytecode includes:
when a before function of a listener is added, determining that the before function contains a sub-target class registered with a callback function;
when an after function of a listener is added, determining that the after function contains a sub-target class registered with a callback function;
and calling the callback function in the sub-target class, adding a Filter function of a Filter in the sub-target class, and modifying the byte codes in the sub-target class through the Filter function.
5. The method of claim 3, wherein modifying the bytecode in the target class based on the before function and the after function comprises:
according to the before function, adding a request body of an application interface of the target application and a listener character code of a return body at the head end of a target byte code in the target class;
and adding a request body of an application interface of the target application and a listener character code of a return body at the tail end of the target bytecode in the target class according to the after function.
6. The method of any of claims 1-5, wherein the obtaining the requestor and the reflector of the application interface of the target application based on the modified bytecode comprises:
after the modified bytecode is loaded, continuing to start the target application and executing the modified bytecode;
and acquiring a request body and a return body of the application interface of the target application after the modified bytecode is executed.
7. The method of claim 1, wherein after the obtaining the requestor and the returner of the application interface of the target application based on the modified bytecode, further comprising:
and sending the request body and the return body to a front-end interface for visual display.
8. An apparatus for collecting data, the apparatus comprising;
the device comprises a determining module, a judging module and a judging module, wherein the determining module is used for determining a target class of a target application when the target application is started, the target class is a class file registered with a callback function, and the callback function is used for modifying byte codes in the target class;
the modification module modifies the byte codes in the target class by calling the callback function in the target class;
and the acquisition module acquires the request body and the return body of the application interface of the target application based on the modified bytecode.
9. An electronic device, comprising:
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1-7 when executing the computer program stored on the memory.
10. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1 to 7.
CN202111500975.7A 2021-12-09 2021-12-09 Data acquisition method and device and electronic equipment Pending CN114328088A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111500975.7A CN114328088A (en) 2021-12-09 2021-12-09 Data acquisition method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111500975.7A CN114328088A (en) 2021-12-09 2021-12-09 Data acquisition method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN114328088A true CN114328088A (en) 2022-04-12

Family

ID=81051393

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111500975.7A Pending CN114328088A (en) 2021-12-09 2021-12-09 Data acquisition method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN114328088A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228147A (en) * 2016-12-15 2018-06-29 中国移动通信集团公司 A kind of performance data journal obtaining method and device
CN109471778A (en) * 2018-11-19 2019-03-15 国网安徽省电力有限公司信息通信分公司 A kind of monitoring method of electric system, device and equipment
CN109726016A (en) * 2017-10-30 2019-05-07 阿里巴巴集团控股有限公司 A kind of link tracing methods, devices and systems for distributed system
CN109992454A (en) * 2017-12-31 2019-07-09 中国移动通信集团江西有限公司 The method, apparatus and storage medium of fault location
CN110888780A (en) * 2019-11-19 2020-03-17 泰康保险集团股份有限公司 Application monitoring method, device, equipment and storage medium
CN113076253A (en) * 2021-04-16 2021-07-06 北京京东拓先科技有限公司 Test method and test device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108228147A (en) * 2016-12-15 2018-06-29 中国移动通信集团公司 A kind of performance data journal obtaining method and device
CN109726016A (en) * 2017-10-30 2019-05-07 阿里巴巴集团控股有限公司 A kind of link tracing methods, devices and systems for distributed system
CN109992454A (en) * 2017-12-31 2019-07-09 中国移动通信集团江西有限公司 The method, apparatus and storage medium of fault location
CN109471778A (en) * 2018-11-19 2019-03-15 国网安徽省电力有限公司信息通信分公司 A kind of monitoring method of electric system, device and equipment
CN110888780A (en) * 2019-11-19 2020-03-17 泰康保险集团股份有限公司 Application monitoring method, device, equipment and storage medium
CN113076253A (en) * 2021-04-16 2021-07-06 北京京东拓先科技有限公司 Test method and test device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
WANG_WPW: "《Pinpoint字节码增强技术》", 《HTTPS://BLOG.CSDN.NET/WANG_WPW/ARTICLE/DETAILS/80917012》, 3 August 2018 (2018-08-03), pages 1 - 3 *

Similar Documents

Publication Publication Date Title
US8601469B2 (en) Method and system for customizing allocation statistics
US6381735B1 (en) Dynamic classification of sections of software
US8583783B1 (en) Method and system for adaptive recovery of heap memory
AU2018310287A1 (en) Smart contract processing method and apparatus
US20080244537A1 (en) Method and system for customizing profiling sessions
US8799889B2 (en) Application downloading
CN109842610B (en) Interface request processing method and device, computer equipment and storage medium
CN110308999B (en) Method for dynamically sharing dependency package between applications, storage medium and mobile terminal
CN106648755B (en) Method and device for dynamically loading dex in android art environment
CN108255708B (en) Method, device, storage medium and equipment for accessing production file in test environment
US20030200530A1 (en) Measuring the exact memory requirement of an application through intensive use of garbage collector
CN113127314B (en) Method and device for detecting program performance bottleneck and computer equipment
EP3113019A1 (en) Policy-based compression of machine code generated by a virtual machine
CN112219196B (en) Method and apparatus for representing active frames for non-suspended garbage collection
US10467027B1 (en) Dynamic script loading resource files
CN111221869B (en) Method and device for tracking database transaction time and analyzing database lock
CN112860507B (en) Control method and device for sampling rate of distributed link tracking system
CN109783284A (en) Information acquisition method, system and server, computer readable storage medium
CN115934199A (en) Service performance monitoring tool, method, device and medium
US7178140B2 (en) Speeding up application downloading from a remote server
CN107656849B (en) Method and device for positioning performance problem of software system
CN114328088A (en) Data acquisition method and device and electronic equipment
US11216352B2 (en) Method for automatically analyzing bottleneck in real time and an apparatus for performing the method
CN111400135A (en) Method and device for extracting service data
CN111240728A (en) Application program updating method, device, equipment 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