CN110333993B - Memory snapshot generation method and device, electronic equipment and storage medium - Google Patents

Memory snapshot generation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110333993B
CN110333993B CN201910548851.2A CN201910548851A CN110333993B CN 110333993 B CN110333993 B CN 110333993B CN 201910548851 A CN201910548851 A CN 201910548851A CN 110333993 B CN110333993 B CN 110333993B
Authority
CN
China
Prior art keywords
function
memory snapshot
byte stream
memory
address
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
CN201910548851.2A
Other languages
Chinese (zh)
Other versions
CN110333993A (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.)
Beijing Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online Technology 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 Beijing Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN201910548851.2A priority Critical patent/CN110333993B/en
Publication of CN110333993A publication Critical patent/CN110333993A/en
Application granted granted Critical
Publication of CN110333993B publication Critical patent/CN110333993B/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/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Retry When Errors Occur (AREA)

Abstract

The application discloses a memory snapshot generating method and device, electronic equipment and a storage medium. The method comprises the following steps: if the memory snapshot generating condition is met, acquiring the address of a memory snapshot file based on an initialization function, and assigning a proxy function of a native layer to a target function in a Java layer system function; calling a system function to generate a byte stream of the memory snapshot; intercepting the byte stream based on an agent function, and generating a memory snapshot file according to the intercepted byte stream and the address. The technical scheme has the beneficial effects that the advantage that the IO efficiency of the native layer is higher than that of the Java layer is utilized, the memory snapshot file is generated after the byte stream is obtained according to the proxy function of the native layer, and the efficiency is remarkably improved.

Description

Memory snapshot generation method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for generating a memory snapshot, an electronic device, and a storage medium.
Background
The operation of the application program usually depends on the use of the memory, and the problem of insufficient memory may be generated in the operation process due to reasons such as carelessness in development and the like. For the convenience of reason investigation, when the conditions such as insufficient memory occur, it is a better way to generate and provide memory snapshots to developers.
However, in the prior art, the method has a problem for android application. Because the android system depends on a Java environment, the generation of the memory snapshot in the prior art is mainly performed on a Java layer, the read-write (I/O) efficiency of the Java layer is low, the size of a memory snapshot file generated by a large amount of android application can reach 200M or more, the memory snapshot is directly generated on the Java layer, and the consumption of resources and time is high.
Disclosure of Invention
In view of the above, the present application is proposed to provide a method, an apparatus, an electronic device and a storage medium for generating a memory snapshot, which overcome the above problems or at least partially solve the above problems.
According to an aspect of the present application, a method for generating a memory snapshot is provided, which is applied to an android application, and includes:
if the memory snapshot generating condition is met, acquiring the address of a memory snapshot file based on an initialization function, and assigning a proxy function of a native layer to a target function in a Java layer system function;
calling a system function to generate a byte stream of the memory snapshot;
intercepting the byte stream based on an agent function, and generating a memory snapshot file according to the intercepted byte stream and the address.
Optionally, the memory snapshot generating condition includes:
and the memory used by the android application reaches a preset threshold value, and/or the android application has an out-of-memory (OOM) error.
Optionally, the specifying a proxy function of a native layer for a target function in a system function of a Java layer includes:
and assigning a proxy function of a native layer to the target function based on got apparent hook technology.
Optionally, the generating a memory snapshot file according to the intercepted byte stream and the address includes:
and performing address verification according to the intercepted write address of the byte stream and the address of the memory snapshot file.
Optionally, the generating a memory snapshot file according to the intercepted byte stream and the address includes:
after the specified type of processing is carried out on the byte stream, the byte stream is written into a memory snapshot file according to the address; the specified type of processing includes: cutting off preset type information in the byte stream, and/or writing the byte stream into a cache region, and when the length of the cache region reaches a preset threshold value, performing compression operation on the content of the cache region.
Optionally, the generating a memory snapshot file according to the intercepted byte stream and the address includes: determining the name of the memory snapshot file according to the processing result;
the method further comprises the following steps: and uploading the generated memory snapshot file to a server so that the memory snapshot file can be converted into a memory snapshot file meeting a preset standard according to the name of the memory snapshot file.
Optionally, the proxy function includes a proxy function of a Java layer open function and a proxy function of a Java layer write function; the generating the memory snapshot file according to the intercepted byte stream and the address further comprises:
and recording a file handle fd returned by the proxy function of the Java layer open function, and judging whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
Optionally, the generating the memory snapshot file according to the intercepted byte stream and the address includes:
and confirming the generation result of the memory snapshot file by the proxy function of the Java layer end function and reporting the result to the Java layer end function.
According to another aspect of the present application, there is provided a device for generating a memory snapshot, which is applied to an android application, and includes:
the initialization unit is used for acquiring the address of the memory snapshot file based on an initialization function if the memory snapshot generating condition is met, and appointing a proxy function of a native layer for a target function in a system function of a Java layer;
and the memory snapshot generating unit is used for calling a system function to generate a byte stream of the memory snapshot, intercepting the byte stream based on the proxy function, and generating a memory snapshot file according to the intercepted byte stream and the address.
Optionally, the memory snapshot generating condition includes:
and the memory used by the android application reaches a preset threshold value, and/or the android application has an out-of-memory (OOM) error.
Optionally, the initialization unit is configured to assign a proxy function of a native layer to the target function based on got secure hook technology.
Optionally, the memory snapshot generating unit is configured to perform address verification according to a write address of the intercepted byte stream and an address of the memory snapshot file.
Optionally, the memory snapshot generating unit is configured to write a memory snapshot file according to the address after performing specified type processing on the byte stream; the specified type of processing includes: cutting off preset type information in the byte stream, and/or writing the byte stream into a cache region, and when the length of the cache region reaches a preset threshold value, performing compression operation on the content of the cache region.
Optionally, the memory snapshot generating unit is configured to determine a name of the memory snapshot file according to a processing result;
the device also includes: and the uploading unit is used for uploading the generated memory snapshot file to the server so that the memory snapshot file can be converted into a memory snapshot file meeting a preset standard according to the name of the memory snapshot file.
Optionally, the proxy function includes a proxy function of a Java layer open function and a proxy function of a Java layer write function;
the memory snapshot generating unit is used for recording a file handle fd returned by the proxy function of the Java layer open function, and judging whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
Optionally, the proxy function includes a proxy function of a Java layer end function;
and the memory snapshot generating unit is used for confirming the generation result of the memory snapshot file by the proxy function of the Java layer end function and reporting the generation result to the Java layer end function.
In accordance with yet another aspect of the present application, there is provided an electronic device including: a processor; and a memory arranged to store computer executable instructions that, when executed, cause the processor to perform a method as any one of the above.
According to a further aspect of the application, there is provided a computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement a method as in any above.
According to the technical scheme, under the condition that the memory snapshot generating condition is met, the address of the memory snapshot file is obtained based on the initialization function, the proxy function of a native layer is appointed for the target function in the Java layer system function, the system function is called to generate the byte stream of the memory snapshot, the byte stream is intercepted based on the proxy function, and the memory snapshot file is generated according to the intercepted byte stream according to the address. The technical scheme has the beneficial effects that the advantage that the IO efficiency of the native layer is higher than that of the Java layer is utilized, the memory snapshot file is generated after the byte stream is obtained according to the proxy function of the native layer, and the efficiency is remarkably improved.
The foregoing description is only an overview of the technical solutions of the present application, and the present application can be implemented according to the content of the description in order to make the technical means of the present application more clearly understood, and the following detailed description of the present application is given in order to make the above and other objects, features, and advantages of the present application more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flowchart illustrating a method for generating a memory snapshot according to an embodiment of the present application;
fig. 2 is a schematic structural diagram illustrating an apparatus for generating a memory snapshot according to an embodiment of the present application;
FIG. 3 shows a schematic structural diagram of an electronic device according to an embodiment of the present application;
FIG. 4 shows a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Fig. 1 is a schematic flowchart illustrating a method for generating a memory snapshot according to an embodiment of the present application, where the method is applied to an android application. As shown in fig. 1, the method includes:
step S110, if the memory snapshot generating condition is satisfied, acquiring an address of the memory snapshot file based on the initialization function, and assigning a proxy function of a native layer to a target function in the Java layer system function.
The Java layer of the android system actually provides a means for generating a snapshot, i.e., there are multiple related functions that can perform memory dump. In the technical scheme of the application, the functions are not abandoned comprehensively, and partial functions are proxied at a native layer, so that each function in the dump process is not required to be realized again, and parts with relatively low efficiency can be optimized.
For example, in step S120, a system function is called to generate a byte stream of the memory snapshot. In this step, the system function dump can be directly called to the memory snapshot byte stream, and the IO stage is processed at the native layer.
Step S130, intercepting the byte stream based on the proxy function, and generating a memory snapshot file according to the intercepted byte stream and the address.
Therefore, the method shown in fig. 1 utilizes the advantage that the IO efficiency of the native layer is higher than that of the Java layer, and generates the memory snapshot file after the byte stream is acquired according to the proxy function of the native layer, so that the efficiency is remarkably improved.
In an embodiment of the present application, in the method, the memory snapshot generating condition includes: and when the memory used by the android application reaches a preset threshold value, and/or the android application generates an OOM error of memory overflow.
Since the memory snapshot is mainly used for analyzing the application exception, the present application provides two examples of the memory snapshot generating conditions, which can be used alternatively or together. The memory OOM error indicates that insufficient memory resources are available for the android application, and the android application generally crashes. The preset threshold value can be preset to prevent the occurrence of the OOM error to a certain extent, but at this time, the problem of causing excessive use of the memory generally exists, and further analysis is also needed.
Specifically, Java exception exit monitoring may be registered, a memory occupancy condition of the android application may be analyzed in real time by an asynchronous thread, and when the memory occupancy is abnormal or an OOM error occurs, a memory snapshot may be generated.
In an embodiment of the present application, in the method, specifying a proxy function of a native layer for a target function in a system function of a Java layer includes: and assigning a proxy function of a native layer to the target function based on got apparent technology.
The use of functions in the android system is usually dependent on the symbol table, and the got table is a kind of symbol table, and the addresses of the functions are stored inside. Therefore, the got hook technology can realize the hook of the function by modifying the address, when the target function in the system function is called, the address of the target function is modified into the address of the proxy function of the native layer, so that the proxy function of the native layer is actually called, and the purpose is also realized.
In an embodiment of the present application, the generating a memory snapshot file according to an address of the intercepted byte stream in the method includes: and performing address verification according to the intercepted write address of the byte stream and the address of the memory snapshot file.
The native memory snapshot process of the android system is approximately: firstly, determining the address of a memory snapshot file, then outputting a byte stream from a dump in a memory, and writing the byte stream into the memory snapshot file of the address; specifically, the method can be realized by an init function, a debug.dump function and an end function of a Java layer.
In the embodiment of the application, the address of the memory snapshot file can also be determined by the system function, and the native layer function is called in the writing process to realize the efficiency improvement. In order to ensure the accuracy of writing the file, the method can be realized by an address check mode. Specifically, a system function of the Java layer determines an address of a memory snapshot file first, and at this time, the address of the memory snapshot file is obtained based on an initialization function and is used as a destination address for writing a byte stream; and during actual writing, a writing address of the intercepted byte stream is also obtained, and if the address is consistent with the address of the previously obtained memory snapshot file, the whole process is normally carried out, and the verification is successful.
In an embodiment of the present application, in the above method, the proxy function includes a proxy function of a Java layer open function and a proxy function of a Java layer write function; generating the memory snapshot file according to the intercepted byte stream and the address further comprises: and recording a file handle fd returned by the proxy function of the Java layer open function, and judging whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
Comparing the address transmitted by the proxy function of the Java layer open function with the address of the initialization function is a specific implementation manner of performing address check according to the write address of the intercepted byte stream and the address of the memory snapshot file in the foregoing embodiment. If the verification is successful, the file handle fd returned by the proxy function of the Java layer open function can be recorded, and the proxy function of the write function judges whether the fd returned by the proxy function is the same as the fd returned by the write function, so that another verification is realized, and the file written by the byte stream is the opened memory snapshot file.
In an embodiment of the present application, the generating a memory snapshot file according to an address of the intercepted byte stream in the method includes: after the specified type of processing is carried out on the byte stream, the byte stream is written into a memory snapshot file according to the address; the specified types of processing include: cutting off preset type information in the byte stream, and/or writing the byte stream into a cache region, and when the length of the cache region reaches a preset threshold value, performing compression operation on the content of the cache region.
Some information useless for subsequent analysis processing actually exists in the memory, and the memory snapshot file needs to be returned to a developer, so that a user using the android application needs to upload the information (certainly, the information can also be uploaded automatically by the android application without perception when the user needs to upload the information subsequently in advance through user permission), the storage resource and the network resource of a user terminal need to be consumed, in order to bring better experience and save resources to the user, some processing and discarding can be performed on the byte stream, and the information which is not needed is simplified to obtain useful information.
Specifically, a preset type of information in the byte stream may be cut, where the preset type of information may include: time stamping, since subsequent analysis may not require the use of time-dependent content; values of all basic type arrays, because in subsequent analysis, only the length of one array and its reference chain need to be known, and the content is the content that developers do not need to care about; the memory information of the system, because it is not manipulated and does not need to intervene by the developer. About 60% of data can be removed through the clipping, and the volume of the memory snapshot file is greatly reduced.
In addition, the volume of the memory snapshot file can be reduced through a compression mode, the effect of combining the two modes is relatively better, but the two modes can be alternatively implemented. And the generated memory snapshot file also retains necessary information required for subsequent analysis, for example, sending a memory leak, searching Activity information in a stack, generating an OOM, checking an object with a high memory ratio, checking a reference chain thereof, and the like.
In an embodiment of the present application, the generating a memory snapshot file according to an address of the intercepted byte stream in the method includes: determining the name of the memory snapshot file according to the processing result; the method further comprises the following steps: and uploading the generated memory snapshot file to a server so that the memory snapshot file can be converted into a memory snapshot file meeting a preset standard according to the name of the memory snapshot file.
The result of the processing may be success or failure, and for some reason, some or all of the processing in the clipping or compression may fail. Because the data content of the memory snapshot file is different through different processing, and the subsequent analysis mode is also different, the name of the memory snapshot file is determined according to the processing result, so that the server can convert the memory snapshot file into the memory snapshot file meeting the preset standard according to the name of the memory snapshot file, and the subsequent analysis processing is facilitated.
The specific uploading opportunity may be when the corresponding android application is started next time. By pulling the configuration information, whether the memory snapshot file is stored locally or not can be detected, and if the uploaded configuration switch is in an open state, the locally stored memory snapshot file can be uploaded to the server. The server can identify whether the clipping and compression processing is performed according to the file name, and perform corresponding reverse processing to obtain a complete memory snapshot file.
For example, for a memory snapshot file with the array value being cut off, the type and the length of the array are reserved, and then bytes with a value of 0 can be supplemented at corresponding positions according to the length and the type during recovery, so that a complete memory snapshot file is obtained.
In an embodiment of the present application, in the method, the proxy function includes a proxy function of a Java layer end function, and generating the memory snapshot file according to the intercepted byte stream by address further includes: and confirming the generation result of the memory snapshot file by the proxy function of the Java layer end function and reporting the result to the Java layer end function.
The android memory snapshot file is formally generated after the byte stream is completely written in, and an end function is needed for confirmation. Under the condition of a cache region, the proxy function of the Java layer end function can also carry out operations such as cache region clearing and the like.
Fig. 2 is a schematic structural diagram of a memory snapshot generating apparatus according to an embodiment of the present application, where the apparatus is applied to an android application. As shown in fig. 2, the memory snapshot generating apparatus 200 includes:
the initialization unit 210 is configured to, if the memory snapshot generating condition is met, obtain an address of a memory snapshot file based on an initialization function, and specify a proxy function of a native layer for a target function in a system function of a Java layer.
The Java layer of the android system actually provides a means for generating a snapshot, i.e., there are multiple related functions that can perform memory dump. In the technical scheme of the application, the functions are not abandoned comprehensively, and partial functions are proxied at a native layer, so that each function in the dump process is not required to be realized again, and parts with relatively low efficiency can be optimized.
The memory snapshot generating unit 220 is configured to call a system function to generate a byte stream of a memory snapshot, intercept the byte stream based on a proxy function, and generate a memory snapshot file according to the intercepted byte stream by address. The system function dump can be directly called to the memory snapshot byte stream, and the IO stage is processed at a native layer.
Therefore, the device shown in fig. 2 utilizes the advantage that the IO efficiency of the native layer is higher than that of the Java layer by the mutual cooperation of the units, and generates the memory snapshot file after the byte stream is acquired according to the proxy function of the native layer, so that the efficiency is significantly improved.
In an embodiment of the present application, in the apparatus, the memory snapshot generating condition includes: and when the memory used by the android application reaches a preset threshold value, and/or the android application generates an OOM error of memory overflow.
In an embodiment of the present application, in the apparatus, the initialization unit 210 is configured to assign a proxy function of a native layer to the target function based on got spreadsheet technology.
In an embodiment of the present application, in the above apparatus, the memory snapshot generating unit 220 is configured to perform address verification according to a write address of the intercepted byte stream and an address of the memory snapshot file.
In an embodiment of the present application, in the above apparatus, the memory snapshot generating unit 220 is configured to write a memory snapshot file according to an address after performing specified type processing on a byte stream; the specified types of processing include: cutting off preset type information in the byte stream, and/or writing the byte stream into a cache region, and when the length of the cache region reaches a preset threshold value, performing compression operation on the content of the cache region.
In an embodiment of the present application, in the above apparatus, the memory snapshot generating unit 220 is configured to determine a name of a memory snapshot file according to a processing result; the device also includes: and the uploading unit is used for uploading the generated memory snapshot file to the server so that the memory snapshot file can be converted into a memory snapshot file meeting a preset standard according to the name of the memory snapshot file.
In an embodiment of the present application, in the above apparatus, the proxy function includes a proxy function of a Java layer open function and a proxy function of a Java layer write function; the memory snapshot generating unit 220 is configured to record a file handle fd returned by the proxy function of the Java layer open function, and determine whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
In an embodiment of the present application, in the above apparatus, the proxy function includes a proxy function of a Java layer end function; the memory snapshot generating unit 220 is configured to determine a generation result of the memory snapshot file by using the proxy function of the Java layer end function, and report the generation result to the Java layer end function.
It should be noted that, for the specific implementation of each apparatus embodiment, reference may be made to the specific implementation of the corresponding method embodiment, which is not described herein again.
In summary, according to the technical scheme of the application, under the condition that a memory snapshot generating condition is met, an address of a memory snapshot file is obtained based on an initialization function, a proxy function of a native layer is designated for a target function in a Java layer system function, the system function is called to generate a byte stream of the memory snapshot, the byte stream is intercepted based on the proxy function, and the memory snapshot file is generated according to the intercepted byte stream and the address. The technical scheme has the beneficial effects that the advantage that the IO efficiency of the native layer is higher than that of the Java layer is utilized, the memory snapshot file is generated after the byte stream is obtained according to the proxy function of the native layer, and the efficiency is remarkably improved.
It should be noted that:
the algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose devices may be used with the teachings herein. The required structure for constructing such a device will be apparent from the description above. In addition, this application is not directed to any particular programming language. It will be appreciated that a variety of programming languages may be used to implement the teachings of the present application as described herein, and any descriptions of specific languages are provided above to disclose the best modes of the present application.
In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the application may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the application, various features of the application are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the application and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: this application is intended to cover such departures from the present disclosure as come within known or customary practice in the art to which this invention pertains. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this application.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the application and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the present application may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components of the memory snapshot generating apparatus according to the embodiments of the present application. The present application may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present application may be stored on a computer readable medium or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
For example, fig. 3 shows a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device 300 comprises a processor 310 and a memory 320 arranged to store computer executable instructions (computer readable program code). The memory 320 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. The memory 320 has a storage space 330 storing computer readable program code 331 for performing any of the method steps described above. For example, the storage space 330 for storing the computer readable program code may comprise respective computer readable program codes 331 for respectively implementing various steps in the above method. The computer readable program code 331 may be read from or written to one or more computer program products. These computer program products comprise a program code carrier such as a hard disk, a Compact Disc (CD), a memory card or a floppy disk. Such a computer program product is typically a computer readable storage medium such as described in fig. 4. FIG. 4 shows a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present application. The computer readable storage medium 400 has stored thereon a computer readable program code 331 for performing the steps of the method according to the application, readable by a processor 310 of an electronic device 300, which computer readable program code 331, when executed by the electronic device 300, causes the electronic device 300 to perform the steps of the method described above, in particular the computer readable program code 331 stored on the computer readable storage medium may perform the method shown in any of the embodiments described above. The computer readable program code 331 may be compressed in a suitable form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the application, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The application may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (10)

1. A memory snapshot generation method is applied to android applications, and comprises the following steps:
if the memory snapshot generating condition is met, acquiring the address of a memory snapshot file based on an initialization function, and assigning a proxy function of a native layer to a target function in a Java layer system function;
calling a system function to generate a byte stream of the memory snapshot;
intercepting the byte stream based on an agent function, and generating a memory snapshot file according to the intercepted byte stream and the address;
the proxy function comprises a proxy function of a Java layer open function and a proxy function of a Java layer write function; the generating the memory snapshot file according to the intercepted byte stream and the address further comprises:
and recording a file handle fd returned by the proxy function of the Java layer open function, and judging whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
2. The method of claim 1, wherein the memory snapshot generating conditions comprise:
and the memory used by the android application reaches a preset threshold value, and/or the android application has an out-of-memory (OOM) error.
3. The method of claim 1, wherein the specifying a proxy function of a native layer for a target function in system functions of a Java layer comprises:
and assigning a proxy function of a native layer to the target function based on got apparent hook technology.
4. The method of claim 1, wherein generating the memory snapshot file according to the address from the intercepted byte stream comprises:
and performing address verification according to the intercepted write address of the byte stream and the address of the memory snapshot file.
5. The method of claim 1, wherein generating the memory snapshot file according to the address from the intercepted byte stream comprises:
after the specified type of processing is carried out on the byte stream, the byte stream is written into a memory snapshot file according to the address; the specified type of processing includes: cutting off preset type information in the byte stream, and/or writing the byte stream into a cache region, and when the length of the cache region reaches a preset threshold value, performing compression operation on the content of the cache region.
6. The method of claim 5, wherein generating the memory snapshot file according to the address from the intercepted byte stream comprises: determining the name of the memory snapshot file according to the processing result;
the method further comprises the following steps: and uploading the generated memory snapshot file to a server so that the memory snapshot file can be converted into a memory snapshot file meeting a preset standard according to the name of the memory snapshot file.
7. The method of claim 1, wherein the proxy function comprises a proxy function of a Java layer end function, and wherein generating the memory snapshot file according to the address from the intercepted byte stream further comprises:
and confirming the generation result of the memory snapshot file by the proxy function of the Java layer end function and reporting the result to the Java layer end function.
8. An apparatus for generating a memory snapshot, applied to an android application, the apparatus comprising:
the initialization unit is used for acquiring the address of the memory snapshot file based on an initialization function if the memory snapshot generating condition is met, and appointing a proxy function of a native layer for a target function in a system function of a Java layer;
the memory snapshot generating unit is used for calling a system function to generate a byte stream of a memory snapshot, intercepting the byte stream based on an agent function, and generating a memory snapshot file according to the intercepted byte stream and the address;
the proxy function comprises a proxy function of a Java layer open function and a proxy function of a Java layer write function;
the memory snapshot generating unit is used for recording a file handle fd returned by the proxy function of the Java layer open function, and judging whether the fd returned by the proxy function of the Java layer write function is the same as the fd returned by the proxy function of the Java layer write function.
9. An electronic device, wherein the electronic device comprises: a processor; and a memory arranged to store computer-executable instructions that, when executed, cause the processor to perform the method of any one of claims 1-7.
10. A computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the method of any of claims 1-7.
CN201910548851.2A 2019-06-24 2019-06-24 Memory snapshot generation method and device, electronic equipment and storage medium Active CN110333993B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910548851.2A CN110333993B (en) 2019-06-24 2019-06-24 Memory snapshot generation method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910548851.2A CN110333993B (en) 2019-06-24 2019-06-24 Memory snapshot generation method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110333993A CN110333993A (en) 2019-10-15
CN110333993B true CN110333993B (en) 2021-01-29

Family

ID=68142725

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910548851.2A Active CN110333993B (en) 2019-06-24 2019-06-24 Memory snapshot generation method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110333993B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111240801A (en) * 2020-01-06 2020-06-05 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for generating heap memory snapshot file
CN113360454B (en) * 2021-06-30 2024-03-01 广州虎牙科技有限公司 Memory snapshot file compression and decompression method and related device

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105224433B (en) * 2014-06-23 2018-04-10 阿里巴巴集团控股有限公司 A kind of internal memory monitoring method and server
CN106528430B (en) * 2016-12-01 2019-03-26 北京金山安全软件有限公司 Application program detection method and device and electronic 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
US10534687B2 (en) * 2017-06-30 2020-01-14 Intel Corporation Method and system for cache agent trace and capture
CN108632657B (en) * 2018-07-06 2020-12-01 深圳创维-Rgb电子有限公司 Subtitle display method, storage medium and smart television
CN109558308A (en) * 2018-09-29 2019-04-02 中国平安人寿保险股份有限公司 Application program method for detecting memory leakage, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN110333993A (en) 2019-10-15

Similar Documents

Publication Publication Date Title
CN108427613B (en) Abnormal interface positioning method and device, computer equipment and storage medium
CN110333993B (en) Memory snapshot generation method and device, electronic equipment and storage medium
CN104077328B (en) The operation diagnostic method and equipment of MapReduce distributed system
KR102545765B1 (en) Method and system for detecting memory errors
CN114880159B (en) Data processing method, device, equipment and storage medium
CN112256551A (en) Remote log capturing method and device, electronic equipment and storage medium
CN109992511B (en) Device and method for obtaining code test coverage rate
CN109542341B (en) Read-write IO monitoring method, device, terminal and computer readable storage medium
CN110955434A (en) Software development kit processing method and device, computer equipment and storage medium
CN110674145A (en) Data consistency detection method and device, computer equipment and storage medium
CN114817187A (en) Log processing method and device
US11467896B2 (en) Sections in crash dump files
CN114500348B (en) CDN gateway testing method and system
CN108062224B (en) Data reading and writing method and device based on file handle and computing equipment
CN112486824B (en) Case code generation method, device, computer equipment and storage medium
JP4897359B2 (en) MEMORY MANAGEMENT DEVICE, MEMORY MANAGEMENT METHOD, AND PROGRAM
CN113535580A (en) CTS (clear to send) testing method, device and testing equipment
CN111176568B (en) Data analysis method and device
CN113900893A (en) Log obtaining method and related equipment thereof
CN113806119A (en) Memory card processing method, device, equipment and storage medium
CN111444057A (en) Page performance data acquisition method and device and computing equipment
CN112000386A (en) Application implementation method and device
CN111090578A (en) Project development joint debugging method and device, computer equipment and storage medium
CN108664293B (en) Application control method and device in android system
JPWO2020065778A1 (en) Information processing equipment, control methods, and programs

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