CN112732513B - Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment - Google Patents

Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment Download PDF

Info

Publication number
CN112732513B
CN112732513B CN201911028363.5A CN201911028363A CN112732513B CN 112732513 B CN112732513 B CN 112732513B CN 201911028363 A CN201911028363 A CN 201911028363A CN 112732513 B CN112732513 B CN 112732513B
Authority
CN
China
Prior art keywords
interface
message
callback
preset
memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201911028363.5A
Other languages
Chinese (zh)
Other versions
CN112732513A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201911028363.5A priority Critical patent/CN112732513B/en
Publication of CN112732513A publication Critical patent/CN112732513A/en
Application granted granted Critical
Publication of CN112732513B publication Critical patent/CN112732513B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3037Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a memory, e.g. virtual memory, cache
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application relates to a memory monitoring method, a memory monitoring device, a computer readable storage medium and computer equipment, wherein the memory monitoring method comprises the following steps: acquiring a preset message; registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface; the preset message is sent to a client, and the preset message is used for indicating the client to acquire the memory map information of a target JS object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object; and receiving the memory map information through the callback monitoring object. The scheme provided by the application can improve the memory monitoring efficiency of JS class application.

Description

Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a memory monitoring method, a memory monitoring device, a computer readable storage medium, and a computer device.
Background
In JavaScript, whenever we create an object, the application will occupy memory and will automatically release memory when it is no longer used. In practical situations, due to the fact that the memory cannot be released in time caused by the design error or the coding error of the program, the memory which is not released cannot be reused, so that the application running is easy to be caused due to the fact that the application memory is too high in use, and in order to prevent the situation, remote monitoring and analysis of the JS-like application memory of the mobile terminal are needed, and memory optimization is conducted in time.
In the conventional technology, when a JS object is monitored, a developer is usually required to install a DEBUG certificate on an application to be monitored, a computer is connected through a true machine in a debugging stage, a debugging panel is opened on the computer, and the monitoring of the internal memory of the JS application of the mobile terminal is realized, so that the efficiency of internal memory monitoring is low.
Disclosure of Invention
Based on this, it is necessary to provide a memory monitoring method, a device, a computer readable storage medium and a computer apparatus for solving the technical problems raised in the background art.
A memory monitoring method, comprising:
acquiring a preset message;
registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
the preset message is sent to a client, and the preset message is used for indicating the client to acquire the memory map information of the current monitoring object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and receiving the memory map information through the callback monitoring object.
A memory monitoring device, the device comprising:
the message acquisition module is used for acquiring a preset message;
the registration module is used for registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
the sending module is used for sending the preset message to the client, wherein the preset message is used for indicating the client to acquire the memory map information of the current monitoring object and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and the receiving module is used for receiving the memory map information through the callback monitoring object.
A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of:
acquiring a preset message;
registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
the preset message is sent to a client, and the preset message is used for indicating the client to acquire the memory map information of the current monitoring object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and receiving the memory map information through the callback monitoring object.
A computer device comprising a memory and a processor, the memory storing a computer program which, when executed by the processor, causes the processor to perform the steps of:
acquiring a preset message;
registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
the preset message is sent to a client, and the preset message is used for indicating the client to acquire the memory map information of the current monitoring object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and receiving the memory map information through the callback monitoring object.
According to the memory monitoring method, the memory monitoring device, the computer readable storage medium and the computer equipment, at least one callback monitoring object corresponding to the preset message is registered by acquiring the preset message, each callback monitoring object has a corresponding callback interface, the preset message is sent to the client, the client is instructed to acquire the memory map information of the current monitoring object through the preset message, the callback interface corresponding to the callback monitoring object is called to return the memory map information to the callback monitoring object, and finally the memory map information is received through the callback monitoring object. In addition, the on-line user can realize the real-time memory monitoring of JS class application because the on-line user does not need to monitor in the debugging stage.
Drawings
FIG. 1 is a diagram of an application environment of a memory monitoring method in one embodiment;
FIG. 2 is a flow chart of a memory monitoring method according to an embodiment;
FIG. 3 is a flow diagram of memory monitoring in one embodiment;
FIG. 4 is a flowchart of a memory monitoring method according to another embodiment;
FIG. 5 is a flow chart of step S406 in one embodiment;
FIG. 6 is a flowchart of step S406 in another embodiment;
FIG. 7 is a flow diagram of a client processing a message in one embodiment;
FIG. 8 is a flowchart of a memory monitoring method according to another embodiment;
FIG. 9 is a block diagram of a memory monitoring device according to an embodiment;
FIG. 10 is a block diagram of a memory monitoring device according to another embodiment;
FIG. 11 is a block diagram of a computer device in one embodiment.
Description of the embodiments
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
FIG. 1 is a diagram of an application environment of a memory monitoring method in one embodiment. Referring to fig. 1, the memory monitoring method is applied to a mobile terminal 110. The mobile terminal 110 may be at least one of a mobile phone, a tablet computer, a notebook computer, and the like. The mobile terminal 110 is installed with at least one client corresponding to the JS-type application. When the mobile terminal 110 needs to perform memory monitoring on the JS application, a preset message may be first obtained, at least one callback monitoring object corresponding to the preset message is registered, each callback monitoring object registered has a corresponding callback interface, the mobile terminal 110 further sends the preset message to a client of the JS application needing to monitor the memory, after receiving the preset message, the client may obtain the memory map information of the current monitoring object, and then call the callback interfaces of each callback monitoring object to return the obtained memory map information to the callback monitoring object, so that the mobile terminal may receive the memory map information sent by the client through the callback monitoring object, thereby implementing the monitoring on the memory of the JS application.
As shown in fig. 2, in one embodiment, a memory monitoring method is provided. The present embodiment is mainly exemplified by the application of the method to the mobile terminal 110 in fig. 1. Referring to fig. 2, the memory monitoring method specifically includes the following steps:
s202, acquiring a preset message.
The preset message refers to a message that can instruct the client to execute the agreed memory information acquisition operation. For example, the preset message may be a Heap.snapshot message, where the Heap.snapshot message is a JSON string, and may be used to instruct the client to obtain a memory snapshot, and the structure of the memory snapshot is as follows:
{"id":-1,"method":"Heap.snapshot","params":{}}
the preset message may be a message pre-constructed by a developer, and may be obtained locally when the mobile terminal needs to monitor the memory of the JS application.
S204, registering at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface.
The callback monitoring object corresponding to the preset message refers to an object for callback monitoring on a processing result of the preset message. The callback interface corresponding to the callback monitoring object refers to a callback function used for returning a message processing result to the callback monitoring object. The mobile terminal can register one or more callback monitoring objects corresponding to the preset message in advance. Each callback monitoring object has a corresponding callback interface, and the callback monitoring object can acquire a processing result corresponding to the preset message after the preset message is processed through the corresponding callback interface.
S206, sending a preset message to the client, wherein the preset message is used for indicating the client to acquire the memory map information of the current monitoring object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object.
The current monitoring object refers to all active JS objects in the currently monitored JS class application. The memory map information refers to map information for reflecting the memory usage of the JS object.
Specifically, the mobile terminal may send a preset message to the client through an inter-process communication manner, after receiving the preset message, the client obtains the memory map information of the current monitoring object according to the instruction of the preset message, then traverses all callback monitoring objects, sequentially calls a callback interface corresponding to each callback monitoring object, and returns a message processing result, namely the memory map information, to the corresponding callback monitoring object by calling the callback interface.
In one embodiment, the mobile terminal sends the preset message to the client based on a RemoteDebug remote debug protocol. RemoteDebug provides a standard set of interfaces that allow a desktop browser to connect to the client application and take JS debug and analysis. The RemoteDebug nature is similar to defining a set of interprocess communication mechanisms, in that messages are sent to clients in an interprocess communication manner, and after the client receives the messages, the client can perform operations about the message, such as triggering breakpoints or performing JS code injection or performing performance and time-consuming analysis. As shown in fig. 3, when a mobile terminal sends a preset message to a client, the mobile terminal sends the preset message to a remote debugging proxy layer, triggers the remote debugging proxy layer to send the preset message to the client and register a callback monitoring object in advance, after the message processing is finished, the remote debugging proxy layer obtains a message processing result in a callback monitoring mode, and then returns the message processing result to the mobile terminal. It is understood that the message processing result herein refers to the memory map information of the current monitored object.
In one embodiment, when the remote debugging agent layer sends the preset message to the client, the message is first sent to an instructor layer, namely a monitoring agent layer, a callback monitoring object and a message processing object are registered in the monitoring agent layer, and the monitoring agent layer sends the message to the message processing object corresponding to the client. Such as sending a Heap.snapshot message to an instructor agent, the message is forwarded by the instructor agent to the corresponding agent, such as an instructor HeaapAgent, to process the message, and the instructor HeaapAgent actually processes the message and performs the operations specified by the message, and then returns the message processing results.
S208, receiving the memory map information through the callback monitoring object.
Specifically, the mobile terminal can receive the memory map information returned by the client through the registered callback monitoring object, so that the memory monitoring of the JS-like application on the client is realized. Further, after receiving the memory map information, the mobile terminal can calculate the memory size of each class and each instance according to the memory map information, obtain the memory allocation information and report and analyze the memory allocation information.
According to the memory monitoring method, the mobile terminal registers at least one callback monitoring object corresponding to the preset message by acquiring the preset message, each callback monitoring object has a corresponding callback interface, the preset message is sent to the client, the client is instructed to acquire the memory map information of the current monitoring object by the preset message, the callback interface corresponding to the callback monitoring object is called to return the memory map information to the callback monitoring object, and finally the memory map information is received by the callback monitoring object. In addition, the on-line user can realize the real-time memory monitoring of JS class application because the on-line user does not need to monitor in the debugging stage.
In one embodiment, as shown in fig. 4, a memory monitoring method is provided, in this embodiment, the memory monitoring method is implemented based on a webkit's romitedebug protocol, where the webkit refers to a browser engine of an IOS system, and in this embodiment, the memory monitoring method specifically includes the following steps:
s402, acquiring a preset message.
S404, acquiring a global debugging object corresponding to a global debugging class in the current execution environment; the global debugging class comprises a first interface and a second interface.
Wherein the current execution environment is referred to as JSContext. The global debug class refers to the jsglobalobjectdebugable class defined by webkit. The global debug object corresponding to the global debug class refers to an instance corresponding to the jsglobalobjectdebugable class.
The mobile terminal can acquire the JSGlobalobjjectDebuggable instance of the current JSContext object through the JSC:: VM:: vmEntry Globalobject interface of the webkit. The global debugging class comprises a first interface and a second interface. The first interface is used for registering callback monitoring objects. In one embodiment, the first interface is structured as follows:
void connect (Inspector::FrontendChannel&,boolisAutomaticConnection = false, bool immediatelyPause = false) final;
the second interface is used for triggering the sending of the message. In one embodiment, the second interface is structured as follows:
void disconnect(Inspector::FrontendChannel&) final。
it will be appreciated that since the global debug object is an instance of the global debug class, the global debug object also includes a first interface and a second interface.
In one embodiment, the method further comprises a third interface, wherein the third interface is used for removing the corresponding callback listening object. In one embodiment, the third interface is structured as follows:
void disconnect(Inspector::FrontendChannel&) final。
s406, calling a first interface to register at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface.
Specifically, the mobile terminal can register at least one callback monitoring object corresponding to the preset message by calling the first interface, wherein the callback monitoring object is an instance of a preset class, the preset class comprises a callback interface, and when registering the callback monitoring object, the instance of the preset class is transmitted into the first interface.
In one embodiment, the preset class is a front-end channel class (frontendcs channel), which is a virtual base class, and a custom subclass may be built in advance, and when the virtual base class inherits, the virtual base class stores a virtual function table of the subclass. The virtual inheritance object, the corresponding function execution at the runtime is to dynamically find the virtual function table to determine which function address is to be executed. In this embodiment, the parameter type received by the first interface is an instance corresponding to a subclass inherited from the frontenddchannel, that is, each registered callback listening object is an instance corresponding to a subclass inherited from the frontenddchannel.
S408, calling a second interface to send a preset message to the client; the preset message is used for indicating the client to acquire the memory map information of the current monitoring object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object.
Specifically, the mobile terminal calls the second interface to trigger the sending of the preset message, after the preset message is sent to the client, the client obtains the memory map information of the current monitoring object, traverses all callback monitoring objects, and calls the callback interface corresponding to each callback monitoring object in sequence to return the memory map information to the corresponding callback monitoring object.
S410, the memory map information is received through the callback monitoring object.
In this embodiment, the mobile terminal may call the first interface in the global debug class to register the callback listening object by acquiring the global debug object corresponding to the global debug class in the current execution environment, and call the second interface in the global debug class to trigger the sending of the preset message, so that the registration of the callback listening object and the sending of the preset message may be conveniently and rapidly realized.
In one embodiment, as shown in fig. 5, S406 calls the first interface to register at least one callback listening object corresponding to a preset message, and specifically includes the following steps:
S406A, a first loading initial address and a first section offset address corresponding to the first interface are obtained, and a first runtime address corresponding to the first interface is obtained according to the first loading initial address and the first section offset address.
S406B, calling the first interface according to a first runtime address corresponding to the first interface to register at least one callback monitoring object corresponding to the preset message.
Wherein, the loading start address refers to the loading start address of the dynamic library in running; the intra-segment offset address refers to the intra-segment offset value of the function static analysis.
Because the jsglobalobjjectdebugable class and the corresponding first interface and second interface thereof are private and not disclosed, the corresponding interface cannot be directly referenced by the header file for calling. In the application, the running address of the interface is obtained by a certain symbol loading mechanism of the running process in a static analysis mode so as to complete the calling of the interface.
Symbol function symbols and addresses corresponding to the function symbols are stored in a MachO file of the mobile terminal, but the system can hide part of sensitive symbols in some cases during operation, so that mapping relation between the symbols and the function addresses cannot be queried through MachO file related API (Application Programming Interface ) during operation, and during static analysis, a third-party disassembly analysis tool such as MachOView, hopper Dissambler and the like can be directly used for acquiring an intra-segment offset value of the function addresses in the MachO file according to the function symbols. When running, the offset value in the section is added with the loading initial address of the corresponding dynamic library, so that the actual running address of a certain function can be obtained, and then the indirect calling of the interface is realized directly through the mode of calling by a function pointer and transferring the parameter.
In this embodiment, first, by means of a third party disassembly analysis tool such as machooxiew, hopper Dissambler, etc., an intra-segment offset value of a function address of the third party disassembly analysis tool in a MachO file is obtained according to a function symbol of the first interface, and when the mobile terminal runs, the mobile terminal obtains the intra-segment offset value and a loading start address of a dynamic library corresponding to the first interface, and adds the intra-segment offset value and the loading start address of the dynamic library corresponding to the first interface to obtain a first run-time address corresponding to the first interface. For example, the JSGlobal ObjectDebuggable is obtained, namely, the offset address of the connect function on the iOS 12.2 is 0x9CBEE0, then the starting address of the JavascriptCore.frame is obtained through the dynamic related API in the running process, and the starting address are added to obtain the running address of the connect function.
And then, according to the C++ function call and the parameter statement of the first interface, performing parameter transfer to complete the actual first interface call logic so as to register at least one callback monitoring object corresponding to the preset message.
In this embodiment, by acquiring the first loading start address and the first intra-segment offset address corresponding to the first interface, the first runtime address corresponding to the first interface is obtained according to the first loading start address and the first intra-segment offset address, so that dynamic call to the first interface can be implemented during runtime.
In one embodiment, S408 invokes a second interface to send a preset message to the client, including: acquiring a second loading initial address and a second intra-segment offset address corresponding to a second interface, and acquiring a second runtime address corresponding to the second interface according to the second loading initial address and the second intra-segment offset address; and calling the second interface according to a second runtime address corresponding to the second interface so as to send a preset message to the client.
Specifically, the third party disassembly analysis tool such as machooxiew, hopper Dissambler and the like can be used for obtaining the intra-segment offset value of the function address in the MachO file according to the function symbol of the second interface, and when the mobile terminal runs, the mobile terminal obtains the intra-segment offset value and the loading start address of the dynamic library corresponding to the second interface, and the second run-time address corresponding to the second interface is obtained by adding the intra-segment offset value and the loading start address of the dynamic library corresponding to the second interface. And then, according to the C++ function call and the parameter statement of the second interface, carrying out parameter transmission to complete the actual second interface call logic so as to trigger the sending of the preset message.
In this embodiment, by acquiring the second loading start address and the second intra-segment offset address corresponding to the second interface, the second runtime address corresponding to the second interface is obtained according to the second loading start address and the second intra-segment offset address, so that dynamic call to the second interface can be implemented during runtime.
In one embodiment, as shown in fig. 6, in S406, the calling the first interface to register at least one callback listening object corresponding to the preset message includes:
s602, obtaining at least one instance corresponding to a preset front-end channel subclass; presetting a front-end channel subclass as a subclass of the front-end channel class; the front-end channel class is a virtual base class.
S604, calling the first interface by taking the instance corresponding to at least one preset front-end channel subclass as the interface parameter of the first interface respectively so as to register at least one callback monitoring object corresponding to the preset message.
The front-end channel class refers to the frontenddchannel class defined by webkit, and the frontenddchannel class is a virtual base class, and has the following structure:
class FrontendChannel {
public:
enum class ConnectionType {
Remote,
Local
};
virtual ~FrontendChannel() { }
virtual ConnectionType connectionType() const = 0;
virtual void sendMessageToFrontend(const String& message) = 0;
};
the preset front-end channel subclass refers to a pre-built subclass inherited from the frontenddchannel class, and the sendMessageToFrontend interface in the frontenddchannel class is rewritten and implemented in the preset front-end channel subclass.
In the embodiment, the mobile terminal can acquire at least one instance corresponding to a preset front-end channel subclass, and when registering a callback monitoring object, the acquired instances are respectively used as interface parameters of a first interface to call the first interface and register to obtain an Injector. Because the callback monitoring object is an instance corresponding to the preset front-end channel subclass, the sendmessagetofront interface is rewritten in the preset front-end channel subclass, and the sendmessagetofront interface is a callback interface corresponding to the callback monitoring object. Because the preset front-end channel subclass inherits from the virtual base class front channel class, the preset front-end channel subclass is also a virtual base class, the sendmessagetofront interface function corresponding to the preset front-end channel subclass is a virtual function, the first address of the preset front-end channel subclass stores a virtual function table thereof, and the virtual function table stores a function address corresponding to the virtual function. The object of the preset front-end channel subclass, whose corresponding function execution is executed at runtime, determines which function address is to be executed by dynamically searching its virtual function table.
In this embodiment, the mobile terminal invokes the first interface by obtaining at least one instance corresponding to a preset front-end channel subclass, and taking the obtained instance as an interface parameter of the first interface, so as to register at least one callback listening object corresponding to a preset message.
In one embodiment, as shown in fig. 7, the preset message includes a message identifier and a message name; the preset message is further used to instruct the client to perform the following steps S702-S704, and the client processes the preset message by performing these steps:
s702, determining a corresponding first message processor according to the message identifier and the message name, and executing memory acquisition operation corresponding to the preset message through the first message processor to obtain character string data corresponding to the current monitoring object.
In particular, message identification is used to uniquely identify a message. The first message processor may specifically be a webkit defined backhanddistatchaerhandler. When a developer builds a preset message, a corresponding relation between the message and the first message processor can be established. Because different messages correspond to different first message processors, the mobile terminal can determine the corresponding first message processor according to the message identifier and the message name carried in the preset message, send the preset message to the corresponding first message processor through the message distributor dispatcher defined by webkit, and execute the memory acquisition operation corresponding to the preset message through the first message processor to obtain string data, namely character string data.
And S704, the character string data is sent to a corresponding second message processor, and the character string data is converted into JSON format data through the second message processor so as to obtain the memory map information of the current monitoring object.
Specifically, the second message processor may be an m_backanddispatcher defined by webkit, where the second message processor refers to a specific message processor corresponding to the type of message. The mobile terminal sends the obtained string data to the m_backdrop dispatcher by calling the sendResponse interface, and the m_backdrop dispatcher converts the received data into JSON format data so as to obtain the memory map information of the current monitoring object.
Further, the mobile terminal sends the JSON format data to a foreground router m_frontendRouter defined by webkit, the m_frontendRouter traverses all registered callback monitoring objects after receiving the data, and calls a callback interface corresponding to each callback listener respectively, the JSON format data is returned to each callback monitoring object respectively, and the mobile terminal can receive the JSON format memory map information through the callback monitoring objects, so that the memory monitoring of JS applications is realized.
As shown in fig. 8, a flow chart of a memory monitoring method in an embodiment is shown, in which the memory monitoring method specifically includes the following steps:
s802, acquiring a preset message, wherein the preset message carries a message identifier and a message name.
S804, obtaining a JSGlobalObjectDebuggable instance of the current JSContext object.
S806, obtaining a loading start address and an intra-segment offset value of a connect interface and a dispatchMessageFromremote interface corresponding to the JSGlobalobjectdebugable instance, and obtaining runtime addresses of the connect interface and the dispatchMessageFromremote interface respectively according to the loading start address and the intra-segment offset value of the two.
S808, calling the connect interface according to the runtime address of the connect interface, and when calling the cennect interface, introducing a pre-constructed instance corresponding to the sub-class inherited from the virtual base class front channel to register the Insector: front channel object.
S810, calling a dispatcheMessageFromremote interface to forward the preset message to the dispatcher corresponding to the client in an inter-process communication mode.
S812, the dispatcher corresponding to the client finds the corresponding backdrop dispatcher handler according to the message identifier and the message name.
S814, the corresponding windband dispatcher handler of the client processes the message, and after the processing is finished, the processed result String data is sent to the m_windband dispatcher and the sendResponse interface is called to send the message.
S816, the m_backdrop dispatcher corresponding to the client converts the received String data into memory map information in JSON format and sends the memory map information to the m_frontendRouter.
S818, after receiving the data, the m_frontendRouter corresponding to the client traverses all registered callback monitoring objects, acquires callback interfaces corresponding to the callback monitoring objects, searches function addresses corresponding to the callback interfaces from the virtual function table, and returns memory map information to the callback monitoring objects according to the function addresses.
S820, receiving the memory map information through the callback monitoring object.
In this embodiment, the callback monitoring object is registered in advance and the transmission of the preset message is triggered by dynamically calling the connect interface and the dispatchmessage from remote interface, and meanwhile, the callback interface of the callback monitoring object is a virtual function, so that the virtual function table can be dynamically searched to execute the function address during running, and the message processing result is dynamically obtained, thereby dynamically obtaining the memory map information in the JS application, and realizing the real-time monitoring of the memory map information of the JS application. In addition, as the mobile terminal can acquire the memory map information directly by sending the preset message without connecting the computer through the debugging panel, the memory monitoring of JS class application is conveniently and rapidly realized, and thus, the memory monitoring efficiency can be remarkably improved.
It should be understood that, although the steps in the flowcharts of fig. 2-8 are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps of fig. 2-8 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor does the order in which the sub-steps or stages are performed necessarily occur in sequence, but may be performed alternately or alternately with at least a portion of other steps or sub-steps or stages of other steps.
In one embodiment, as shown in fig. 9, there is provided a memory monitoring apparatus 900, referring to fig. 9, the apparatus includes:
a message obtaining module 902, configured to obtain a preset message;
a registration module 904, configured to register at least one callback listening object corresponding to a preset message; the callback monitoring object has a corresponding callback interface;
the sending module 906 is configured to send a preset message to the client, where the preset message is used to instruct the client to obtain the memory map information of the current monitored object, and call a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
the receiving module 908 is configured to receive the memory map information through the callback listening object.
In one embodiment, as shown in fig. 10, the apparatus further comprises: an object obtaining module 910, configured to obtain a global debug object corresponding to a global debug class in a current execution environment; the global debugging class comprises a first interface and a second interface; the registration module is also used for calling the first interface to register at least one callback monitoring object corresponding to the preset message; the sending module is also used for calling the second interface to send a preset message to the client.
In one embodiment, the registration module is further configured to obtain a first loading start address and a first intra-segment offset address corresponding to the first interface, and obtain a first runtime address corresponding to the first interface according to the first loading start address and the first intra-segment offset address; and calling the first interface according to a first runtime address corresponding to the first interface so as to register at least one callback monitoring object corresponding to the preset message.
In one embodiment, the sending module is further configured to obtain a second loading start address and a second intra-segment offset address corresponding to the second interface, and obtain a second runtime address corresponding to the second interface according to the second loading start address and the second intra-segment offset address; and calling the second interface according to a second runtime address corresponding to the second interface so as to send a preset message to the client.
In one embodiment, the registration module is further configured to obtain an instance corresponding to at least one preset front-end channel subclass; presetting a front-end channel subclass as a subclass of the front-end channel class; the front-end channel class is a virtual base class; and respectively calling the first interface by taking the instance corresponding to the at least one preset front-end channel subclass as the interface parameter of the first interface so as to register at least one callback monitoring object corresponding to the preset message.
In one embodiment, the preset message carries a message identifier and a message name; the preset message is further used for instructing the client to execute the following steps: determining a corresponding first message processor according to the message identifier and the message name, and executing memory acquisition operation corresponding to a preset message through the first message processor to obtain character string data corresponding to the current monitoring object; and sending the character string data to a corresponding second message processor, and converting the character string data into JSON format data through the second message processor so as to obtain the memory map information of the current monitoring object.
According to the memory monitoring device, at least one callback monitoring object corresponding to the preset message is registered through obtaining the preset message, each callback monitoring object has a corresponding callback interface, the preset message is sent to the client, the client is instructed to obtain the memory map information of the current monitoring object through the preset message, the callback interface corresponding to the callback monitoring object is called to return the memory map information to the callback monitoring object, finally the memory map information is received through the callback monitoring object, and as the mobile terminal is not required to be connected with a computer through a debugging panel, the memory map information can be obtained through sending the preset message, the memory monitoring of JS applications can be conveniently and rapidly realized, and the memory monitoring efficiency can be remarkably improved. In addition, the on-line user can realize the real-time memory monitoring of JS class application because the on-line user does not need to monitor in the debugging stage.
FIG. 11 illustrates an internal block diagram of a computer device in one embodiment. The computer device may be specifically the mobile terminal 110 of fig. 1. As shown in fig. 11, the computer device includes a processor, a memory, a network interface, an input device, a display screen, a camera, a sound collection device, and a speaker connected by a system bus. The memory includes a nonvolatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system, and may also store a computer program that, when executed by a processor, causes the processor to implement a memory monitoring method. The internal memory may also store a computer program that, when executed by the processor, causes the processor to perform the memory monitoring method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, the input device of the computer equipment can be a touch layer covered on the display screen, can also be keys, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in fig. 11 is merely a block diagram of a portion of the structure associated with the present application and is not limiting of the computer device to which the present application applies, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, the memory monitoring apparatus provided herein may be implemented in the form of a computer program that is executable on a computer device as shown in fig. 11. The memory of the computer device may store various program modules constituting the memory monitoring apparatus, such as a message acquisition module, a registration module, a transmission module, and a reception module shown in fig. 9. The computer program comprising the respective program modules causes the processor to execute the steps in the memory monitoring method according to the embodiments of the present application described in the present specification.
For example, the computer apparatus shown in fig. 11 may execute step S202 through the message acquisition module in the memory monitoring device shown in fig. 9. The computer device may perform step S204 through the registration module. The computer device may perform S206 through the transmission module. The computer device may perform step S208 through the receiving module.
In one embodiment, a computer device is provided that includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the memory monitoring method described above. The steps of the memory monitoring method may be the steps of the memory monitoring method in the foregoing embodiments.
In one embodiment, a computer readable storage medium is provided, storing a computer program which, when executed by a processor, causes the processor to perform the steps of the memory monitoring method described above. The steps of the memory monitoring method may be the steps of the memory monitoring method in the foregoing embodiments.
Those skilled in the art will appreciate that implementing all or part of the above-described methods in accordance with the embodiments may be accomplished by way of a computer program, which may be stored on a non-transitory computer readable storage medium, and which, when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the various embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples only represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the present application. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application is to be determined by the claims appended hereto.

Claims (12)

1. A memory monitoring method, comprising:
acquiring a preset message;
acquiring a global debugging object corresponding to a global debugging class defined by webkit in a current execution environment; the global debugging class comprises a first interface and a second interface;
invoking the first interface to register at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
invoking the second interface to send the preset message to the client, wherein the preset message is used for indicating the client to acquire the memory map information of the target JS object, and invoking a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and receiving the memory map information through the callback monitoring object.
2. The method of claim 1, wherein the invoking the first interface to register at least one callback listening object corresponding to the preset message comprises:
acquiring a first loading initial address and a first intra-segment offset address corresponding to the first interface, and acquiring a first runtime address corresponding to the first interface according to the first loading initial address and the first intra-segment offset address;
and calling the first interface according to a first run-time address corresponding to the first interface so as to register at least one callback monitoring object corresponding to the preset message.
3. The method of claim 1, wherein the invoking the second interface to send the preset message to a client comprises:
acquiring a second loading initial address and a second intra-segment offset address corresponding to the second interface, and acquiring a second runtime address corresponding to the second interface according to the second loading initial address and the second intra-segment offset address;
and calling the second interface according to a second runtime address corresponding to the second interface so as to send the preset message to the client.
4. The method of claim 1, wherein the invoking the first interface to register at least one callback listening object corresponding to the preset message comprises:
acquiring at least one instance corresponding to a preset front-end channel subclass; the preset front-end channel subclass is a subclass of the front-end channel class; the front-end channel class is a virtual base class;
and respectively calling the first interface by taking at least one instance corresponding to the preset front-end channel subclass as an interface parameter of the first interface so as to register at least one callback monitoring object corresponding to the preset message.
5. The method according to any one of claims 1 to 4, wherein the preset message carries a message identifier and a message name; the preset message is further used for instructing the client to execute the following steps:
determining a corresponding first message processor according to the message identifier and the message name, and executing memory acquisition operation corresponding to the preset message through the first message processor to obtain character string data corresponding to a target JS object;
and sending the character string data to a corresponding second message processor, and converting the character string data into JSON format data through the second message processor so as to obtain the memory map information of the target JS object.
6. A memory monitoring device, the device comprising:
the message acquisition module is used for acquiring a preset message;
the object acquisition module is used for acquiring a global debugging object corresponding to a global debugging class defined by webkit in the current execution environment; the global debugging class comprises a first interface and a second interface;
the registration module is used for calling the first interface to register at least one callback monitoring object corresponding to the preset message; the callback monitoring object has a corresponding callback interface;
the sending module is used for calling the second interface to send the preset message to the client, wherein the preset message is used for indicating the client to obtain the memory map information of the target JS object, and calling a callback interface corresponding to the callback monitoring object to return the memory map information to the callback monitoring object;
and the receiving module is used for receiving the memory map information through the callback monitoring object.
7. The apparatus of claim 6, wherein the registration module is further configured to:
acquiring a first loading initial address and a first intra-segment offset address corresponding to the first interface, and acquiring a first runtime address corresponding to the first interface according to the first loading initial address and the first intra-segment offset address;
and calling the first interface according to a first run-time address corresponding to the first interface so as to register at least one callback monitoring object corresponding to the preset message.
8. The apparatus of claim 6, wherein the means for transmitting is further configured to:
acquiring a second loading initial address and a second intra-segment offset address corresponding to the second interface, and acquiring a second runtime address corresponding to the second interface according to the second loading initial address and the second intra-segment offset address;
and calling the second interface according to a second runtime address corresponding to the second interface so as to send the preset message to the client.
9. The apparatus of claim 6, wherein the registration module is further configured to:
acquiring at least one instance corresponding to a preset front-end channel subclass; the preset front-end channel subclass is a subclass of the front-end channel class; the front-end channel class is a virtual base class;
and respectively calling the first interface by taking at least one instance corresponding to the preset front-end channel subclass as an interface parameter of the first interface so as to register at least one callback monitoring object corresponding to the preset message.
10. The apparatus according to any one of claims 6 to 9, wherein the preset message carries a message identifier and a message name; the preset message is further used for instructing the client to execute the following steps:
determining a corresponding first message processor according to the message identifier and the message name, and executing memory acquisition operation corresponding to the preset message through the first message processor to obtain character string data corresponding to a target JS object;
and sending the character string data to a corresponding second message processor, and converting the character string data into JSON format data through the second message processor so as to obtain the memory map information of the target JS object.
11. A computer readable storage medium storing a computer program which, when executed by a processor, causes the processor to perform the steps of the method of any one of claims 1 to 5.
12. A computer device comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method of any of claims 1 to 5.
CN201911028363.5A 2019-10-28 2019-10-28 Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment Active CN112732513B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911028363.5A CN112732513B (en) 2019-10-28 2019-10-28 Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911028363.5A CN112732513B (en) 2019-10-28 2019-10-28 Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment

Publications (2)

Publication Number Publication Date
CN112732513A CN112732513A (en) 2021-04-30
CN112732513B true CN112732513B (en) 2023-05-23

Family

ID=75588851

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911028363.5A Active CN112732513B (en) 2019-10-28 2019-10-28 Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment

Country Status (1)

Country Link
CN (1) CN112732513B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113377621B (en) * 2021-07-01 2022-08-02 武汉斗鱼鱼乐网络科技有限公司 Data monitoring method and device, storage medium and electronic equipment
CN113688419B (en) * 2021-07-22 2023-05-19 成都鲁易科技有限公司 Data protection method and device, storage medium and computer equipment

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107277226A (en) * 2017-05-11 2017-10-20 珠海金山网络游戏科技有限公司 A kind of method and device for obtaining mobile phone application memory snapshot and Memory Allocation storehouse
CN107391276A (en) * 2017-07-05 2017-11-24 腾讯科技(深圳)有限公司 Distributed monitor method, interception control device and system
CN107957941A (en) * 2016-10-17 2018-04-24 腾讯科技(深圳)有限公司 Mobile terminal memory overflow treating method and apparatus
CN108197029A (en) * 2018-01-08 2018-06-22 华为技术有限公司 A kind of method and apparatus for obtaining progress information
CN108427622A (en) * 2018-04-08 2018-08-21 平安普惠企业管理有限公司 A kind of EMS memory management process, device, computer equipment and storage medium
CN108664390A (en) * 2017-03-31 2018-10-16 华为技术有限公司 A kind of method for detecting memory leakage and equipment
CN109710425A (en) * 2018-12-19 2019-05-03 北京金山安全软件有限公司 Message monitoring method and device
CN109901916A (en) * 2019-02-26 2019-06-18 北京小米移动软件有限公司 The call back function of event executes method, apparatus, storage medium and mobile terminal
CN110209959A (en) * 2018-02-11 2019-09-06 北京京东尚科信息技术有限公司 Information processing method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010042058A1 (en) * 1998-07-09 2001-11-15 Robert J. Harrington Apparatus and method for managing memory use by software objects
CN101788949B (en) * 2010-03-10 2015-01-28 中兴通讯股份有限公司 Method and device for realizing embedded type system function monitoring
US10095599B2 (en) * 2016-03-31 2018-10-09 International Business Machines Corporation Optimization for application runtime monitoring
CN106991042A (en) * 2017-03-07 2017-07-28 南京航空航天大学 A kind of memory overflow localization method of Web applications
CN108132817B (en) * 2017-12-26 2020-07-10 广州酷狗计算机科技有限公司 Object management method and device

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107957941A (en) * 2016-10-17 2018-04-24 腾讯科技(深圳)有限公司 Mobile terminal memory overflow treating method and apparatus
CN108664390A (en) * 2017-03-31 2018-10-16 华为技术有限公司 A kind of method for detecting memory leakage and equipment
CN107277226A (en) * 2017-05-11 2017-10-20 珠海金山网络游戏科技有限公司 A kind of method and device for obtaining mobile phone application memory snapshot and Memory Allocation storehouse
CN107391276A (en) * 2017-07-05 2017-11-24 腾讯科技(深圳)有限公司 Distributed monitor method, interception control device and system
CN108197029A (en) * 2018-01-08 2018-06-22 华为技术有限公司 A kind of method and apparatus for obtaining progress information
CN110209959A (en) * 2018-02-11 2019-09-06 北京京东尚科信息技术有限公司 Information processing method and device
CN108427622A (en) * 2018-04-08 2018-08-21 平安普惠企业管理有限公司 A kind of EMS memory management process, device, computer equipment and storage medium
CN109710425A (en) * 2018-12-19 2019-05-03 北京金山安全软件有限公司 Message monitoring method and device
CN109901916A (en) * 2019-02-26 2019-06-18 北京小米移动软件有限公司 The call back function of event executes method, apparatus, storage medium and mobile terminal

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
傅建明 ; 刘秀文 ; 汤毅 ; 李鹏伟 ; .内存地址泄漏分析与防御.计算机研究与发展.2016,(第08期),全文. *

Also Published As

Publication number Publication date
CN112732513A (en) 2021-04-30

Similar Documents

Publication Publication Date Title
CN108984388B (en) Method and terminal equipment for generating automatic test case
CN110209652B (en) Data table migration method, device, computer equipment and storage medium
WO2019085073A1 (en) Interface test method and apparatus, computer device, and storage medium
CN109814854B (en) Project framework generation method, device, computer equipment and storage medium
CN111209122B (en) Interface calling method and device, electronic equipment and storage medium
CN112565443A (en) Internet of things data analysis method, device, equipment and storage medium
CN112910945A (en) Request link tracking method and service request processing method
CN112732513B (en) Memory monitoring method, memory monitoring device, computer readable storage medium and computer equipment
CN111858296B (en) Interface testing method, device, equipment and storage medium
CN111475376A (en) Method and device for processing test data, computer equipment and storage medium
CN110765001A (en) Modularized automatic test method and device for application system
CN109343983B (en) Information interaction method, device, equipment and storage medium between function modules
CN111865978B (en) Method, device, equipment and medium for updating request identifier of micro-service
CN110597709A (en) Interactive debugging method and device for mixed-mode mobile application and computer equipment
CN111046312A (en) Page sharing method and device, electronic equipment and storage medium
CN108810633B (en) Barrage message transmission method, device, equipment and storage medium
CN108667919B (en) Data processing method, data processing device, computer equipment and storage medium
CN106557411B (en) Method and system for testing Hybrid application in Android system
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN107908565B (en) Test method and test equipment
US10191844B2 (en) Automatic garbage collection thrashing monitoring
CN109254858B (en) Data sharing method, device and equipment of active window and storage medium
EP4044542A1 (en) Method and apparatus for subscribing to resource
CN111901383A (en) Data request processing method and device, computer equipment and storage medium
CN110865943A (en) Interface testing method and device, computer 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
GR01 Patent grant
GR01 Patent grant