CN107291619B - Memory occupation analysis method and device - Google Patents

Memory occupation analysis method and device Download PDF

Info

Publication number
CN107291619B
CN107291619B CN201710476798.0A CN201710476798A CN107291619B CN 107291619 B CN107291619 B CN 107291619B CN 201710476798 A CN201710476798 A CN 201710476798A CN 107291619 B CN107291619 B CN 107291619B
Authority
CN
China
Prior art keywords
stack
creating
value
class
bytes
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.)
Expired - Fee Related
Application number
CN201710476798.0A
Other languages
Chinese (zh)
Other versions
CN107291619A (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 Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo 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 Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201710476798.0A priority Critical patent/CN107291619B/en
Publication of CN107291619A publication Critical patent/CN107291619A/en
Application granted granted Critical
Publication of CN107291619B publication Critical patent/CN107291619B/en
Expired - Fee Related 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/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs

Landscapes

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

Abstract

The invention discloses a memory occupation analysis method and device, relates to the technical field of information processing, and aims to analyze the memory occupation condition of an object in a fine-grained manner so as to improve the memory occupation analysis precision of application software. The method comprises the following steps: acquiring a memory object dump file corresponding to software test; analyzing the memory object dump file to obtain different classes of objects; and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object. The invention is suitable for software memory occupation analysis.

Description

Memory occupation analysis method and device
Technical Field
The present invention relates to the field of information processing technologies, and in particular, to a method and an apparatus for analyzing memory usage.
Background
With the development of mobile communication technology, mobile terminal devices such as mobile phones are becoming more and more popular, a large amount of application software is produced accordingly, and users usually install a lot of application software in the mobile terminal devices to meet various service requirements. In order to enable the application software to fully utilize resources and stably run on the mobile terminal, the performance test needs to be performed after the application software is developed.
At present, when testing the memory occupation performance of application software, the memory occupation situation of the application software is judged by using the memory occupation value of the corresponding starting process of the application software, however, the application software may include a plurality of classes of objects, for example, JAVA objects, Native objects, ROOT objects, etc., the memory occupation situation of the application software can only be obtained by overall analysis through the above analysis mode, the memory occupation situation of a certain object cannot be analyzed in a fine-grained manner, and further the accuracy of the memory occupation analysis of the application software may be low.
Disclosure of Invention
In view of this, the present invention provides a method, an apparatus, and a system for analyzing memory usage, and mainly aims to analyze the memory usage of an object at a fine granularity, so as to improve the accuracy of memory usage analysis of application software.
According to an aspect of the present invention, there is provided a memory usage analysis method, including:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
According to another aspect of the present invention, there is provided a memory usage analyzing apparatus, including:
the acquisition unit is used for acquiring a memory object dump file corresponding to the software test;
the analysis unit is used for analyzing the memory object dump file acquired by the acquisition unit to obtain different classes of objects;
and the monitoring unit is used for monitoring the memory occupation of the object analyzed by the analysis unit to obtain the memory occupation information corresponding to the object. .
According to yet another aspect of the invention, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
According to another aspect of the present invention, there is provided a memory usage analysis apparatus, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
By means of the technical scheme, compared with the method and the device for analyzing the memory occupation, which are used for judging the memory occupation condition of the application software through the memory occupation value of the corresponding starting process of the application software at present, the method and the device can analyze the memory object dump file corresponding to the software test to obtain different types of objects, further can monitor the memory occupation based on the different types of objects to obtain the memory occupation information corresponding to different objects respectively, can analyze the memory occupation condition of a certain object in a fine-grained manner, can improve the precision of the memory occupation analysis of the application software, are convenient for developers to directly adjust the objects with problems based on the memory occupation conditions of different objects, do not need to analyze each object of the software respectively, and further can improve the software development efficiency.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention 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 invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flow chart illustrating a method for analyzing memory usage according to an embodiment of the present invention;
fig. 2 is a schematic flow chart illustrating another memory usage analysis method according to an embodiment of the present invention;
fig. 3 is a schematic diagram illustrating an example of memory usage analysis based on an object according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram illustrating a memory usage analysis apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram illustrating another memory usage analysis apparatus according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a physical device for memory footprint analysis according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure 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.
As described in the background art, currently, when testing the memory usage performance of the application software, the memory usage of the application software is determined by the memory usage value of the corresponding starting process of the application software, and the memory usage of the application software can only be obtained by overall analysis, but the memory usage of an object of the application software cannot be analyzed in a fine-grained manner, which may cause a problem of low accuracy in analyzing the memory usage of the application software.
In order to solve the above problem, an embodiment of the present invention provides a memory usage analysis method, which can analyze a memory usage situation of a certain object at a fine granularity, and further can improve the precision of memory usage analysis of application software, as shown in fig. 1, the method includes:
101. and acquiring a memory object dump file corresponding to the software test.
The memory use condition in the software testing process is recorded in the memory object dump file. The memory object dump file can be generated by the existing software development tool according to the software test result.
The execution main body of the embodiment of the invention can be a device for analyzing the software memory occupation, and in the process of testing the software memory occupation performance, the device can obtain a corresponding memory object dump file through a specific interface function; then, by analyzing the memory object dump file, the memory occupation status of different objects with finer granularity is monitored, and the process from step 102 to step 103 may be specifically executed.
102. And analyzing the acquired memory object dump file to obtain different types of objects.
For example, according to the memory usage in the software testing process recorded in the memory object dump file, different JAVA objects, Native objects, ROOT objects, and the like are obtained by parsing from the memory object dump file, and may specifically be different picture objects, video objects, database objects, text objects, and the like.
103. And monitoring the memory occupation of the object obtained by analysis to obtain the memory occupation information corresponding to the object.
For example, the memory occupied size corresponding to different JAVA objects, Native objects, ROOT objects and the like is counted based on the memory object dump file, the objects with more memory occupied are marked and sent to the software developer for viewing, the developer can conveniently and directly adjust the objects with more memory occupied based on the memory occupied conditions of the different objects, and the objects with more memory occupied need not to be analyzed respectively, so that the software development efficiency can be improved.
Compared with the method for analyzing the memory occupation provided by the embodiment of the invention, the method for analyzing the memory occupation can analyze memory object dump files corresponding to software testing to obtain different types of objects, further monitor the memory occupation based on the different types of objects to obtain the memory occupation information respectively corresponding to the different objects, analyze the memory occupation condition of a certain object in a fine-grained manner and further improve the precision of the memory occupation analysis of the application software.
Further, to better describe the process of the processing method, as a refinement and an extension of the above embodiment, an embodiment of the present invention provides another memory usage analysis method, taking an Android system as an example, as shown in fig. 2, but not limited thereto, which is specifically shown as follows:
201. in the android system, a memory object dump hardware file is obtained through a predetermined dump hardware data interface function of a Debug class.
202. And respectively creating objects of respective corresponding classes according to different TAG TAG values recorded in the memory object dump hprof file.
For example, after obtaining a memory object dump hardware file, reading TAG values recorded in the hardware object dump hardware file, where possible values are 0x01 to 0x23, and 35 values in total, respectively creating objects of respective corresponding classes according to the TAG values, so as to perform memory occupancy monitoring according to the objects obtained through analysis, obtain memory occupancy information corresponding to the objects, and implement fine-grained analysis of memory occupancy of a certain object.
Specifically, for the embodiment of the present invention, before creating an object, a different set needs to be created so as to be called when creating the object, where a specific implementation process for creating the different set may include: analyzing the dump hardware hprof file of the memory object, and if the TAG value is analyzed to be the value of the preset character string information, establishing a character string set according to the next integer value of the current reading bit and the length of the next byte; if the TAG value is analyzed to be the value of the preset loaded type information, a loaded type set is created according to the next integer value of the current reading position and the created character string set; if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the created character string set; and if the value of the TAG is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number behind the current reading position and the created calling stack object set.
The step of creating a string set according to the next integer value of the current read bit and the length of the next byte may specifically include: determining the next integer value of the current reading bit and the length of the next byte, and determining the integer value as an identification number; continuously reading bytes taking the length as the number; and creating a character string set according to the content of the bytes with the length as the number and the identification number.
For example, if the value of the predetermined character string information is 0x01, parsing the dump hprof file, and if the parsed TAG value is 0x01, reading the next integer int value as the identification number ID thereof; reading the next byte, wherein the content stored in the byte is the length of the character string; then reading length bytes, wherein the content of the length bytes is the character string content value; and finally, storing the ID and the value into a character string set mStrings of the map object in the form of key value pairs key and value, wherein the ID value and the value of the character string content obtained by repeating the process when the TAG value analyzed each time is 0x01 are stored in the character string set.
The creating a loaded class set according to the next integer value of the current read bit and the created string set may specifically include: determining the next integer value of the current reading position as an identification number; inquiring a corresponding character string value from the created character string set according to the identification number; determining the inquired character string value as the class name of the class; and creating a loaded class set according to the class name and the identification number.
For example, when the value of the predetermined loaded class information is 0x02, parsing the memory object dump pump hprof file, and if the parsed TAG value is 0x02, reading the next integer int value as the identification number ID thereof; then, with the ID value as a key, finding a corresponding character string value from the created character string set mStrings as a class name className of the class; and finally, storing the ID and className into a loaded class set mClass of the map object according to the key value pair key and value, wherein the ID value and className value obtained by repeating the above process when the TAG value analyzed each time is 0x02 are stored in the loaded class set.
The creating of the call stack object set according to the integer values of the preset number after the current read bit and the created string set may specifically include: determining the next integer value of the current reading position as an identification number; continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier; inquiring in the established character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier; creating function call stack information according to the query result; and creating a call stack object set according to the function call stack information and the identification number.
For example, the value of the predetermined function call stack information is 0x04, the preset number is 5, the dump hprof file is analyzed, and if the analyzed TAG value is 0x04, the next integer int value is read as the identification number ID of the memory dump hprof file; continuing to read the next 5 integer values as a method name identifier (methodname ID), a method signature identifier (methodSignatureID), a source file identifier (sourceFileID), a serial number identifier (serial ID) and a line number identifier (lineNumberID); then using the 5 IDs as keys, finding out respective corresponding character string values from the created character string set mStrings, and respectively using the respective corresponding character string values as a method name, a method signature, a source file sourceFile, a serial number serial and a line number lineNumber; then, a function call stack information frame is created by the 5 values of the methodName, the methodSignature, the sourceFile, the serial and the lineNumber; and finally, storing the ID and the frame of the identification number into a call stack object set mFrames in the form of key value pairs of key and value, wherein the ID value and the frame value obtained by repeating the process are stored in the call stack object set when the TAG value analyzed each time is 0x 04.
The creating of the call stack frame set according to the preset number of bytes after the current read bit and the created call stack object set may specifically include: continuously reading bytes with preset number after the current reading bit, and respectively taking the bytes as a sequence number, a thread sequence number and a function call stack number; continuing to read bytes taking the number of the function call stack as the number of the bytes, and taking the bytes as the identifier of the function call stack information; acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set; and creating a calling stack frame set according to the formed calling stack set, the sequence number and the line program column number.
For example, if the value of the predetermined stack frame information is 0x05 and the preset number is 5, parsing the memory object dump hprof file, and if the parsed TAG value is 0x05, reading the next three bytes as a serial number, a thread serial number threadedsialnumber, and a function call stack number numFrames, respectively; continuing reading numFrames bytes as ID of function call stack information frame, finding out corresponding function call stack information frame from created call stack object set mFrames according to the ID, and forming call stack set frames; and finally, creating a call stack frame stackTrace by using the values of the servicenumber, the readSerialNumber and the frames, storing the stackTrace and a call stack sequence number corresponding to the stackTrace in a call stack frame set mTraces, and repeating the process to obtain a stackTrace value and a call stack sequence number corresponding to the stackTrace when the analyzed TAG value is 0x05 in each call stack frame set mTraces.
Further, after the above sets are created, if the TAG value is analyzed to be the value of the predetermined heap dump information, the TAG value is continuously read by taking the length of the next byte of the current reading bit as the number, and the object of the corresponding class is created according to the read TAG value.
For example, the value of the predetermined heap dump information is 0x0c or 0x1c, after the above sets are created, the dump file of the memory object hprof is parsed, and if the parsed TAG value is 0x0c or 0x1c, the next byte is read as the length of the length; and circularly reading the TAG values of the length number, and creating the object of the corresponding class according to the read TAG values.
Specifically, if the read TAG value is a first predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: a corresponding ROOT object is created.
For example, the first predetermined value may be one of oxff, 0x01, 0x05, 0x07, 0x89, 0x8a, 0x8b, 0x8c, and 0x90, and if the read TAG value is the one, a corresponding ROOT object is created and stored in the member mRoots set of the current heap object mhepap.
If the read TAG value is the second predetermined value, creating an object of the corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack frame number; inquiring a thread object corresponding to the line program column number from the created thread object set; inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the created calling stack frame set; and creating a corresponding original state Native object, or JAVA object, or original state Stack object, or thread block ThreadLock object according to calling Stack frame information, identification number and line program column number.
For example, the second predetermined value may be one of 0x02, 0x03, 0x04 and 0x06, the preset number may be 3, and if the read TAG value is 0x02, the next three bytes are read as the identification number ID, the thread column number threadserial number and the stack frame number stackFrameNumber, respectively; according to the threadSerialNumber, finding the corresponding thread object threadObj from the created thread object set mThreads; then according to the calling stack sequence number traceSerialNumber value of the current thread object threadObj, inquiring corresponding calling stack frame information trace from the created calling stack frame set mTrays; and finally, creating a Native object Native Obj according to the three values of the ID, the threedisSerialNumber and the trace, and storing the Native object Native Obj into an mRoots set.
If the read TAG value is 0x03, repeating the process, and finally creating a JAVA object javaObj according to the three values of the ID, the readSerialNumber and the trace and storing the JAVA object javaObj in an mRoots set; if the read TAG value is 0x04, repeating the process, and finally creating a native stack object native StackObj according to three values of ID, threadSerialNumber and trace, and storing the native stack object native StackObj in a mRoots set; if the read TAG value is 0x06, repeating the above process, and finally creating a ThreadLock object threedBlockObj according to the three values of ID, threadSerialNumber and trace, and storing the ThreadLock object threadBlockObj in a mRoots set.
If the read TAG value is a third predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack frame number; and creating a Thread Object according to the identification number and the stack frame number.
For example, the third predetermined value may be 0x08, the preset number may be 3, and if the read TAG value is 0x08, the next three bytes are read as the identification number ID, the line program column number thadsiralnummber, and the stack sequence number stackserialnummber, respectively; creating a Thread Object threeadObj according to the ID and the stackFrameNumber value; and finally, storing the stackFrameNumber and the threadObj as key-value pairs key and value into a thread set object set mThreads respectively.
If the read TAG value is a fourth predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading a preset number of bytes after the current reading position, and respectively using the bytes as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item and position information; inquiring a thread object corresponding to the line program column number from the created thread object set; inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the created calling stack frame set; querying a class name corresponding to the identification number from the created loaded class set; and creating a class object ClassObj object according to the identification number, calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
For example, the fourth predetermined value may be 0x20, the predetermined number may be 7, and if the read TAG value is 0x20, the next 7 bytes are read as an identification number ID, a line program column number threadSerialNumber, a superClassId, a class loader number classloaderld, an object instance size instanceSize, a number item numEntries, and a location information position, respectively; according to the threadSerialNumber, inquiring a corresponding thread object thredObj from the created thread object set mThreads; inquiring corresponding calling stack frame information trace from the created calling stack frame set mTrays according to the calling stack sequence number traceSerialNumber value of the current thread object threeadObj; according to the ID value, the name className of the current class is inquired from the created loaded class set mClass; then creating a ClassObj object ClassObj according to the ID, trace, className and position, and configuring the values of subclassId and classLoaderId of the ClassObj as the analyzed subclassId and classLoaderId; and finally, respectively taking the ID and classObj as key-value pairs key and value, and storing the key-value pairs key and value into the mClassById of the class set.
If the read TAG value is a fifth predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, a class number, a residual amount and position information; inquiring calling stack frame information corresponding to the stack number from the created calling stack frame set; and creating a class instance ClassInstance object according to the identification number, calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
For example, the fifth predetermined value may be 0x21, the preset number may be 5, and if the read TAG value is 0x21, the next 5 bytes are read as the identification number ID, the stack number stackId, the class number classId, the remaining amount remaining, and the position information position, respectively; according to the stackId, inquiring corresponding calling stack frame information stack from the created calling stack frame set mTraches; creating an instance of the ClassInstance object according to the three values of the ID, the stack and the position, and configuring the classId value of the instance as classId; and finally, storing the ID and the instance as key values and values into an instance set mInstance of the heap object.
If the read TAG value is a sixth predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number and position information; inquiring calling stack frame information corresponding to the stack number from the created calling stack frame set; and creating an array instance ArrayInstance object according to the identification number, calling stack frame information, position information and element number, and configuring the ArrayInstance object according to the class number.
For example, the sixth predetermined value may be 0x22, the preset number may be 5, and if the read TAG value is 0x22, the next 5 bytes are read as the identification number ID, the stack number stackId, the element number numElements, the class number classId, and the position information position, respectively; inquiring corresponding calling stack frame information stack from the created calling stack frame set mTraches according to the stack Id; then creating an array object array according to the four values of ID, stack, position and numElements, and configuring the classId value of the array as classId; and finally, storing the ID and the array as key value pairs key and value into an instance set mInstance of the heap object.
If the read TAG value is a seventh predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with specific number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number, a type and position information; inquiring calling stack frame information corresponding to the stack number from the created calling stack frame set; and creating an array instance ArrayInstance object according to the identification number, calling stack frame information, position information and element number, and configuring the ArrayInstance object according to the class number.
For example, the seventh predetermined value may be 0x23 or 0xc3, the specific number may be 6, and if the read TAG value is 0x23 or 0xc3, the next 6 bytes are read as the identification number ID, the stack number stackId, the number of elements numElements, the class number classId, the type, and the position information position, respectively; then according to the stack Id, inquiring corresponding calling stack frame information stack from the created calling stack frame set; then creating an array instance object array according to five values of ID, stack, type, numElements and position, and configuring the class value of the array as class ID; and finally, storing the ID and the array as key value pairs key and value into an instance set mInstance of the heap object.
If the read TAG value is an eighth predetermined value, creating an object of a corresponding class according to the read TAG value, which may specifically include: continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack depth; inquiring a thread object corresponding to the line program column number from a preset thread object set; inquiring corresponding calling stack frame information from a calling stack frame set according to the calling stack sequence number and the stack depth of the thread object; and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
For example, the eighth predetermined value may be 0x8e, the preset number may be 3, and if the read TAG value is 0x8e, the next three bytes are read as the identification number ID, the line program column number threadedserialnumber, and the stack depth stackDepth, respectively; then inquiring the current thread object threadObj from the created thread object set mTheaders according to the threadSerialNumber; then inquiring current calling stack frame information trace from the created mTrachs set according to the traceSerialNumber member and the stackDepth of the threadObj; and finally, creating a root object root according to the three values of the ID, the threadesSerialNumber and the trace, and adding the root object to the mRoots set.
Further, when the TAG value of the heap is read, processing of heap aggregation may be performed, for example, if the read TAG value is 0xfe, the next two bytes are read and respectively used as a heap identifier heapId and a heap name identifier heapnamid id; according to the heapNameId, inquiring the current heap heapHeapName from the created mStrings set of the character string set; and finally, respectively taking the heapId and the heapName as key-value pairs key and value, and storing the key-value pairs key and value into the heap set mHeaps.
203. And monitoring the memory occupation of the object obtained by analysis to obtain the memory occupation information corresponding to the object.
For example, memory occupation monitoring can be performed on a ROOT Object, an original state Native Object, a JAVA Object, an original state Stack Native Stack Object, a Thread Block Object, a Thread Object, a class Object classsobj, and the like in the above example to obtain memory occupation conditions of different objects, and send the memory occupation conditions to a software developer for viewing, as shown in fig. 3, the memory occupation conditions of different objects in the software a are convenient for the developer to directly adjust the Object with larger memory occupation based on the memory occupation conditions of the different objects.
Compared with the current method for analyzing the memory occupation by starting the process corresponding to the application software to judge the memory occupation condition of the application software, the method for analyzing the memory occupation can monitor the memory occupation based on different objects, obtain the memory occupation information corresponding to different objects respectively, and further analyze the memory occupation condition of a certain object in a fine-grained manner, thereby improving the accuracy of the memory occupation analysis of the application software.
Further, as a specific implementation of the method shown in fig. 1 and fig. 2, an embodiment of the present invention provides a memory usage analysis apparatus, and as shown in fig. 4, the server includes: an acquisition unit 31, an analysis unit 32, and a monitoring unit 33.
The obtaining unit 31 may be configured to obtain a memory object dump file corresponding to a software test; the obtaining unit 31 is a main functional module for obtaining a memory object dump file in the present apparatus.
The analysis unit 32 is configured to analyze the memory object dump file acquired by the acquisition unit 31 to obtain different classes of objects; the parsing unit 32 is a main function module in the apparatus for parsing the memory object dump file, and is a core unit module in the apparatus.
The monitoring unit 33 may be configured to perform memory usage monitoring on the object analyzed by the analyzing unit 32, so as to obtain memory usage information corresponding to the object. The monitoring unit 33 is a main function module of the present apparatus for monitoring memory usage information of different objects.
In a specific application scenario, the parsing unit 32 may be specifically configured to create objects of respective corresponding classes according to different TAG values recorded in the memory object dump file.
In a specific application scenario, as shown in fig. 5, the parsing unit 32 may specifically include: a parsing module 321 and a creating module 322.
The parsing module 321 may be configured to parse the memory object dump file.
A creating module 322, configured to create a string set according to a next integer value of a current read bit and a length of a next byte if the TAG value is analyzed by the analyzing module 321 as a value of predetermined string information; if the TAG value is analyzed to be the value of the preset loaded class information, a loaded class set is created according to the next integer value of the current reading position and the character string set; if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the character string set; if the TAG value is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number after the current reading position and the calling stack object set; and if the TAG value is analyzed to be the value of the preset heap dump information, continuously reading the TAG value by taking the length of the next byte of the current reading position as the number, and creating the object of the corresponding class according to the read TAG value.
In a specific application scenario, the creating module 322 may be specifically configured to create a corresponding ROOT object if the read TAG value is a first predetermined value.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a second predetermined value, continue to read a preset number of bytes after the current read bit, where the preset number of bytes is respectively used as an identification number, a thread sequence number, and a stack frame number; inquiring a thread object corresponding to the line program column number from a preset thread object set; inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set; and creating a corresponding original state Native object, or a JAVA object, or an original state Stack object, or a thread block threadlock object according to the calling Stack frame information, the identification number and the line program column number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a third predetermined value, continue to read a preset number of bytes after the current read bit, where the preset number of bytes is respectively used as an identification number, a thread sequence number, and a stack sequence number; and creating a Thread Object according to the identification number and the stack sequence number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a fourth predetermined value, continue to read a predetermined number of bytes after the current reading position, where the bytes are respectively used as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item, and location information; inquiring a thread object corresponding to the line program column number from a preset thread object set; inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set; querying a class name corresponding to the identification number from the loaded class set; creating a class object ClassObj object according to the identification number, the calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a fifth predetermined value, continue to read bytes of a preset number after the current reading position, where the bytes are respectively used as an identification number, a stack number, a class number, a remaining amount, and position information; inquiring calling stack frame information corresponding to the stack number from the calling stack frame set; creating a class instance ClassInstance object according to the identification number, the calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a sixth predetermined value, continue to read bytes of a preset number after the current reading position, where the bytes are respectively used as an identification number, a stack number, an element number, a class number, and position information; inquiring calling stack frame information corresponding to the stack number from the calling stack frame set; and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is a seventh predetermined value, continue to read a specific number of bytes after the current reading position, where the bytes are respectively used as an identification number, a stack number, an element number, a class number, a type, and location information; inquiring calling stack frame information corresponding to the stack number from the calling stack frame set; and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
In a specific application scenario, the creating module 322 may be further configured to, if the read TAG value is an eighth predetermined value, continue to read a preset number of bytes after the current read bit, where the preset number of bytes is respectively used as an identification number, a thread sequence number, and a stack depth; inquiring a thread object corresponding to the line program column number from a preset thread object set; inquiring corresponding calling stack frame information from the calling stack frame set according to the calling stack sequence number and the stack depth of the thread object; and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
In a specific application scenario, the creating module 322 may be further configured to determine a next integer value of a current read bit and a length of a next byte, and determine the integer value as an identification number; continuing to read the bytes taking the length as the number; and creating a character string set according to the content of the bytes with the length as the number and the identification number.
In a specific application scenario, the creating module 322 may be further configured to determine a next integer value of the current reading bit as an identification number; inquiring a corresponding character string value from the character string set according to the identification number; determining the string value as a class name of a class; and creating a loaded class set according to the class name and the identification number.
In a specific application scenario, the creating module 322 may be further configured to determine a next integer value of the current reading bit as an identification number; continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier; inquiring in the character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier; creating function call stack information according to the query result; and creating a call stack object set according to the function call stack information and the identification number.
In a specific application scenario, the creating module 322 may be further configured to continue to read bytes of a preset number after the current read bit, where the bytes are respectively used as a sequence number, a thread sequence number, and a function call stack number; continuing to read bytes taking the number of the function call stack as the number, and taking the bytes as the identifier of the function call stack information; acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set; and creating a calling stack frame set according to the calling stack set, the sequence number and the line program column number.
It should be noted that other corresponding descriptions of the functional units related to the memory usage analysis device provided in the embodiment of the present invention may refer to the corresponding descriptions in fig. 1 and fig. 2, and are not described herein again.
Based on the method shown in fig. 1, correspondingly, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the following steps: acquiring a memory object dump file corresponding to software test; analyzing the memory object dump file to obtain different classes of objects; and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
Based on the foregoing embodiments of the method shown in fig. 1 and the apparatuses shown in fig. 4 and fig. 5, an embodiment of the present invention further provides a physical apparatus for memory usage analysis, as shown in fig. 6, the apparatus includes: a processor 41, a memory 42, and a computer program stored on the memory 42 and executable on the processor, the processor 41 implementing the following steps when executing the program: acquiring a memory object dump file corresponding to software test; analyzing the memory object dump file to obtain different classes of objects; monitoring the memory occupation of the object to obtain memory occupation information corresponding to the object; the device also includes: a bus 43 configured to couple the processor 41 and the memory 42.
By applying the technical scheme of the invention, the memory occupation condition of a certain object can be analyzed in a fine-grained manner, and the memory occupation analysis precision of application software can be further improved.
A1, a memory usage analysis method, comprising:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
A2, the method as in a1, where the parsing the memory object dump file to obtain different types of objects specifically includes:
and respectively creating objects of respective corresponding classes according to different TAG TAG values recorded in the memory object dump file.
A3, the method according to a2, wherein the creating objects of respective corresponding classes according to different TAG values recorded in the memory object dump file includes:
analyzing the memory object dump file, and if the TAG value is analyzed to be the value of the preset character string information, establishing a character string set according to the next integer value of the current reading bit and the length of the next byte;
if the TAG value is analyzed to be the value of the preset loaded class information, a loaded class set is created according to the next integer value of the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number after the current reading position and the calling stack object set;
and if the TAG value is analyzed to be the value of the preset heap dump information, continuously reading the TAG value by taking the length of the next byte of the current reading position as the number, and creating the object of the corresponding class according to the read TAG value.
A4, the method as in A3, if the read TAG value is a first predetermined value, creating an object of a corresponding class according to the read TAG value, specifically including:
a corresponding ROOT object is created.
A5, the method according to A3, if the read TAG value is a second predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack frame number;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
and creating a corresponding original state Native object, or a JAVA object, or an original state Stack object, or a thread block threadlock object according to the calling Stack frame information, the identification number and the line program column number.
A6, the method according to A3, if the read TAG value is a third predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack sequence number;
and creating a Thread Object according to the identification number and the stack sequence number.
A7, the method according to A3, if the read TAG value is a fourth predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading a preset number of bytes after the current reading position, and respectively using the bytes as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item and position information;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
querying a class name corresponding to the identification number from the loaded class set;
creating a class object ClassObj object according to the identification number, the calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
A8, the method according to A3, if the read TAG value is a fifth predetermined value, creating an object of the corresponding class according to the read TAG value, which specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, a class number, a residual amount and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
creating a class instance ClassInstance object according to the identification number, the calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
A9, the method according to A3, if the read TAG value is a sixth predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
A10, the method as in A3, if the read TAG value is a seventh predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading the bytes with specific number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number, a type and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
A11, the method according to A3, if the read TAG value is an eighth predetermined value, creating an object of the corresponding class according to the read TAG value, specifically including:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack depth;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring corresponding calling stack frame information from the calling stack frame set according to the calling stack sequence number and the stack depth of the thread object;
and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
A12, the method as in A3, wherein the creating a string set according to the next integer value of the current read bit and the length of the next byte specifically includes:
determining the next integer value and the length of the next byte of the current reading bit, and determining the integer value as an identification number;
continuing to read the bytes taking the length as the number;
and creating a character string set according to the content of the bytes with the length as the number and the identification number.
13. The method according to claim 12, wherein creating a call stack object set according to a preset number of integer values after the current read bit and the character string set specifically includes:
determining the next integer value of the current reading position as an identification number;
inquiring a corresponding character string value from the character string set according to the identification number;
determining the string value as a class name of a class;
and creating a loaded class set according to the class name and the identification number.
14. The method according to claim 12, wherein creating a call stack object set according to a preset number of integer values after the current read bit and the character string set specifically includes:
determining the next integer value of the current reading position as an identification number;
continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier;
inquiring in the character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier;
creating function call stack information according to the query result;
and creating a call stack object set according to the function call stack information and the identification number.
15. The method according to claim 14, wherein creating a call stack frame set according to a preset number of bytes after the current read bit and the call stack object set specifically includes:
continuously reading bytes with preset number after the current reading bit, and respectively taking the bytes as a sequence number, a thread sequence number and a function call stack number;
continuing to read bytes taking the number of the function call stack as the number, and taking the bytes as the identifier of the function call stack information;
acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set;
and creating a calling stack frame set according to the calling stack set, the sequence number and the line program column number.
B16, a memory usage analysis device, comprising:
the acquisition unit is used for acquiring a memory object dump file corresponding to the software test;
the analysis unit is used for analyzing the memory object dump file acquired by the acquisition unit to obtain different classes of objects;
and the monitoring unit is used for monitoring the memory occupation of the object analyzed by the analysis unit to obtain the memory occupation information corresponding to the object.
B17, device according to B16,
the parsing unit is specifically configured to create objects of respective corresponding classes according to different TAG values recorded in the memory object dump file.
B18, the apparatus as defined in B17, wherein the parsing unit specifically comprises:
the analysis module is used for analyzing the memory object dump file;
the creation module is used for creating a character string set according to the next integer value of the current reading bit and the length of the next byte if the TAG value analyzed by the analysis module is the value of the preset character string information;
if the TAG value is analyzed to be the value of the preset loaded class information, a loaded class set is created according to the next integer value of the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number after the current reading position and the calling stack object set;
and if the TAG value is analyzed to be the value of the preset heap dump information, continuously reading the TAG value by taking the length of the next byte of the current reading position as the number, and creating the object of the corresponding class according to the read TAG value.
B19, device according to B18,
the creating module is specifically configured to create a corresponding ROOT object if the read TAG value is a first predetermined value.
B20, device according to B18,
the creation module is specifically configured to continue reading bytes with a preset number after the current reading position if the read TAG value is a second predetermined value, and the bytes are respectively used as an identification number, a thread sequence number and a stack frame number;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
and creating a corresponding original state Native object, or a JAVA object, or an original state Stack object, or a thread block threadlock object according to the calling Stack frame information, the identification number and the line program column number.
B21, device according to B18,
the creation module is specifically configured to, if the read TAG value is a third predetermined value, continue to read a preset number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, and a stack sequence number;
and creating a Thread Object according to the identification number and the stack sequence number.
B22, device according to B18,
the creation module is specifically configured to, if the read TAG value is a fourth predetermined value, continue to read a predetermined number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item, and location information;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
querying a class name corresponding to the identification number from the loaded class set;
creating a class object ClassObj object according to the identification number, the calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
B23, device according to B18,
the creation module is specifically configured to, if the read TAG value is a fifth predetermined value, continue to read a preset number of bytes after the current reading position, where the preset number of bytes is used as an identification number, a stack number, a class number, a residual amount, and position information, respectively;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
creating a class instance ClassInstance object according to the identification number, the calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
B24, device according to B18,
the creation module is specifically configured to, if the read TAG value is a sixth predetermined value, continue to read a preset number of bytes after the current reading position, where the bytes are respectively used as an identification number, a stack number, an element number, a class number, and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
B25, device according to B18,
the creation module is specifically configured to, if the read TAG value is a seventh predetermined value, continue to read a specific number of bytes after the current reading position, which are respectively used as an identification number, a stack number, an element number, a class number, a type, and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
B26, device according to B18,
the creation module is specifically configured to, if the read TAG value is an eighth predetermined value, continue to read a preset number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, and a stack depth;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring corresponding calling stack frame information from the calling stack frame set according to the calling stack sequence number and the stack depth of the thread object;
and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
B27, device according to B18,
the creating module is specifically configured to determine a next integer value of a current read bit and a length of a next byte, and determine the integer value as an identification number;
continuing to read the bytes taking the length as the number;
and creating a character string set according to the content of the bytes with the length as the number and the identification number.
B28, device according to B27,
the creation module is specifically further configured to determine a next integer value of the current read bit as an identification number;
inquiring a corresponding character string value from the character string set according to the identification number;
determining the string value as a class name of a class;
and creating a loaded class set according to the class name and the identification number.
B29, device according to B27,
the creation module is specifically further configured to determine a next integer value of the current read bit as an identification number;
continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier;
inquiring in the character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier;
creating function call stack information according to the query result;
and creating a call stack object set according to the function call stack information and the identification number.
B30, device according to B29,
the creating module is specifically further configured to continue reading bytes of a preset number after the current read bit, and the bytes are respectively used as a sequence number, a thread sequence number, and a function call stack number;
continuing to read bytes taking the number of the function call stack as the number, and taking the bytes as the identifier of the function call stack information;
acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set;
and creating a calling stack frame set according to the calling stack set, the sequence number and the line program column number.
C31, a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
D32, a memory usage analysis device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
and monitoring the memory occupation of the object to obtain the memory occupation information corresponding to the object.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
It will be appreciated that the relevant features of the method and apparatus described above are referred to one another. In addition, "first", "second", and the like in the above embodiments are for distinguishing the embodiments, and do not represent merits of the embodiments.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention 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 invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure 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: that the invention as claimed requires more features than are expressly recited in each claim. 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 invention.
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 invention 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 invention 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 a memory footprint analysis method, apparatus and system in accordance with embodiments of the present invention. The present invention 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 invention may be stored on computer-readable media 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.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, 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 invention 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 (28)

1. A memory usage analysis method is characterized by comprising the following steps:
acquiring a memory object dump file corresponding to software test;
analyzing the memory object dump file to obtain different classes of objects;
monitoring the memory occupation of the object to obtain memory occupation information corresponding to the object;
analyzing the memory object dump file to obtain different types of objects, specifically comprising:
respectively creating objects of respective corresponding classes according to different TAG TAG values recorded in the memory object dump file, which specifically comprises:
analyzing the memory object dump file, and if the TAG value is analyzed to be the value of the preset character string information, establishing a character string set according to the next integer value of the current reading bit and the length of the next byte;
if the TAG value is analyzed to be the value of the preset loaded class information, a loaded class set is created according to the next integer value of the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number after the current reading position and the calling stack object set;
and if the TAG value is analyzed to be the value of the preset heap dump information, continuously reading the TAG value by taking the length of the next byte of the current reading position as the number, and creating the object of the corresponding class according to the read TAG value.
2. The method according to claim 1, wherein if the read TAG value is a first predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
a corresponding ROOT object is created.
3. The method according to claim 1, wherein if the read TAG value is a second predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack frame number;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
and creating a corresponding original state Native object, or a JAVA object, or an original state Stack object, or a Thread Block object according to the calling Stack frame information, the identification number and the line program column number.
4. The method according to claim 1, wherein if the read TAG value is a third predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack sequence number;
and creating a Thread Object according to the identification number and the stack sequence number.
5. The method according to claim 1, wherein if the read TAG value is a fourth predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading a preset number of bytes after the current reading position, and respectively using the bytes as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item and position information;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
querying a class name corresponding to the identification number from the loaded class set;
creating a class object ClassObj object according to the identification number, the calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
6. The method according to claim 1, wherein if the read TAG value is a fifth predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, a class number, a residual amount and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
creating a class instance ClassInstance object according to the identification number, the calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
7. The method according to claim 1, wherein if the read TAG value is a sixth predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
8. The method according to claim 1, wherein if the read TAG value is a seventh predetermined value, the creating an object of a corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with specific number after the current reading position, and respectively using the bytes as an identification number, a stack number, an element number, a class number, a type and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
9. The method according to claim 1, wherein if the read TAG value is an eighth predetermined value, the creating of the object of the corresponding class according to the read TAG value specifically includes:
continuously reading the bytes with the preset number after the current reading position, and respectively using the bytes as an identification number, a thread sequence number and a stack depth;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring corresponding calling stack frame information from the calling stack frame set according to the calling stack sequence number and the stack depth of the thread object;
and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
10. The method of claim 1, wherein creating a string set according to a next integer value of a current read bit and a length of a next byte comprises:
determining the next integer value and the length of the next byte of the current reading bit, and determining the integer value as an identification number;
continuing to read the bytes taking the length as the number;
and creating a character string set according to the content of the bytes with the length as the number and the identification number.
11. The method according to claim 10, wherein the creating a call stack object set according to the integer value of the preset number after the current read bit and the string set specifically includes:
determining the next integer value of the current reading position as an identification number;
inquiring a corresponding character string value from the character string set according to the identification number;
determining the string value as a class name of a class;
and creating a loaded class set according to the class name and the identification number.
12. The method according to claim 10, wherein the creating a call stack object set according to the integer value of the preset number after the current read bit and the string set specifically includes:
determining the next integer value of the current reading position as an identification number;
continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier;
inquiring in the character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier;
creating function call stack information according to the query result;
and creating a call stack object set according to the function call stack information and the identification number.
13. The method according to claim 12, wherein creating a call stack frame set according to a preset number of bytes after the current read bit and the call stack object set specifically includes:
continuously reading bytes with preset number after the current reading bit, and respectively taking the bytes as a sequence number, a thread sequence number and a function call stack number;
continuing to read bytes taking the number of the function call stack as the number, and taking the bytes as the identifier of the function call stack information;
acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set;
and creating a calling stack frame set according to the calling stack set, the sequence number and the line program column number.
14. A memory usage analysis apparatus, comprising:
the acquisition unit is used for acquiring a memory object dump file corresponding to the software test;
the analysis unit is used for analyzing the memory object dump file acquired by the acquisition unit to obtain different classes of objects;
the monitoring unit is used for monitoring the memory occupation of the object analyzed by the analyzing unit to obtain the memory occupation information corresponding to the object;
the parsing unit is specifically configured to create objects of respective corresponding classes according to different TAG values recorded in the memory object dump file, and the parsing unit specifically includes:
the analysis module is used for analyzing the memory object dump file;
the creation module is used for creating a character string set according to the next integer value of the current reading bit and the length of the next byte if the TAG value analyzed by the analysis module is the value of the preset character string information;
if the TAG value is analyzed to be the value of the preset loaded class information, a loaded class set is created according to the next integer value of the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset function call stack information, creating a call stack object set according to the integer values with the preset number after the current reading position and the character string set;
if the TAG value is analyzed to be the value of the preset stack frame information, creating a calling stack frame set according to the bytes with the preset number after the current reading position and the calling stack object set;
and if the TAG value is analyzed to be the value of the preset heap dump information, continuously reading the TAG value by taking the length of the next byte of the current reading position as the number, and creating the object of the corresponding class according to the read TAG value.
15. The apparatus of claim 14,
the creating module is specifically configured to create a corresponding ROOT object if the read TAG value is a first predetermined value.
16. The apparatus of claim 14,
the creation module is specifically configured to continue reading bytes with a preset number after the current reading position if the read TAG value is a second predetermined value, and the bytes are respectively used as an identification number, a thread sequence number and a stack frame number;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
and creating a corresponding original state Native object, or a JAVA object, or an original state Stack object, or a Thread Block object according to the calling Stack frame information, the identification number and the line program column number.
17. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is a third predetermined value, continue to read a preset number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, and a stack sequence number;
and creating a Thread Object according to the identification number and the stack sequence number.
18. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is a fourth predetermined value, continue to read a predetermined number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, a super class number, a class loader number, an object instance size, a number item, and location information;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring calling stack frame information corresponding to the calling stack sequence number of the thread object from the calling stack frame set;
querying a class name corresponding to the identification number from the loaded class set;
creating a class object ClassObj object according to the identification number, the calling stack frame information, the class name and the position information, and configuring the ClassObj object according to the super class number and the class loader number.
19. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is a fifth predetermined value, continue to read a preset number of bytes after the current reading position, where the preset number of bytes is used as an identification number, a stack number, a class number, a residual amount, and position information, respectively;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
creating a class instance ClassInstance object according to the identification number, the calling stack frame information and the position information, and configuring the ClassInstance object according to the class number.
20. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is a sixth predetermined value, continue to read a preset number of bytes after the current reading position, where the bytes are respectively used as an identification number, a stack number, an element number, a class number, and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
21. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is a seventh predetermined value, continue to read a specific number of bytes after the current reading position, which are respectively used as an identification number, a stack number, an element number, a class number, a type, and position information;
inquiring calling stack frame information corresponding to the stack number from the calling stack frame set;
and creating an array instance ArrayInstance object according to the identification number, the calling stack frame information, the position information and the element number, and configuring the ArrayInstance object according to the class number.
22. The apparatus of claim 14,
the creation module is specifically configured to, if the read TAG value is an eighth predetermined value, continue to read a preset number of bytes after the current read bit, where the bytes are respectively used as an identification number, a thread sequence number, and a stack depth;
inquiring a thread object corresponding to the line program column number from a preset thread object set;
inquiring corresponding calling stack frame information from the calling stack frame set according to the calling stack sequence number and the stack depth of the thread object;
and creating a root object rootObj object according to the identification number, the thread sequence number and the calling stack frame information.
23. The apparatus of claim 14,
the creating module is specifically configured to determine a next integer value of a current read bit and a length of a next byte, and determine the integer value as an identification number;
continuing to read the bytes taking the length as the number;
and creating a character string set according to the content of the bytes with the length as the number and the identification number.
24. The apparatus of claim 23,
the creation module is specifically further configured to determine a next integer value of the current read bit as an identification number;
inquiring a corresponding character string value from the character string set according to the identification number;
determining the string value as a class name of a class;
and creating a loaded class set according to the class name and the identification number.
25. The apparatus of claim 23,
the creation module is specifically further configured to determine a next integer value of the current read bit as an identification number;
continuously reading a preset number of integer values after the next integer value, and respectively using the preset number of integer values as a method name identifier, a method signature identifier, a source file identifier, a serial number identifier and a line number identifier;
inquiring in the character string set according to the method name identifier, the method signature identifier, the source file identifier, the serial number identifier and the line number identifier;
creating function call stack information according to the query result;
and creating a call stack object set according to the function call stack information and the identification number.
26. The apparatus of claim 25,
the creating module is specifically further configured to continue reading bytes of a preset number after the current read bit, and the bytes are respectively used as a sequence number, a thread sequence number, and a function call stack number;
continuing to read bytes taking the number of the function call stack as the number, and taking the bytes as the identifier of the function call stack information;
acquiring function call stack information corresponding to the identifier of the function call stack information from the call stack object set, and forming a call stack set;
and creating a calling stack frame set according to the calling stack set, the sequence number and the line program column number.
27. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of a memory footprint analysis method as claimed in claim 1.
28. A memory footprint analysis device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of a memory footprint analysis method as claimed in claim 1 when executing said program.
CN201710476798.0A 2017-06-21 2017-06-21 Memory occupation analysis method and device Expired - Fee Related CN107291619B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710476798.0A CN107291619B (en) 2017-06-21 2017-06-21 Memory occupation analysis method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710476798.0A CN107291619B (en) 2017-06-21 2017-06-21 Memory occupation analysis method and device

Publications (2)

Publication Number Publication Date
CN107291619A CN107291619A (en) 2017-10-24
CN107291619B true CN107291619B (en) 2021-04-02

Family

ID=60098049

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710476798.0A Expired - Fee Related CN107291619B (en) 2017-06-21 2017-06-21 Memory occupation analysis method and device

Country Status (1)

Country Link
CN (1) CN107291619B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109240773B (en) * 2018-08-20 2022-08-16 武汉斗鱼网络科技有限公司 Method, device, terminal and readable storage medium for solving room string data
CN111966472B (en) * 2020-07-02 2023-09-26 佛山科学技术学院 Process scheduling method and system of industrial real-time operating system
CN114546590B (en) * 2022-02-18 2023-03-14 北京基调网络股份有限公司 Java virtual machine heap memory set object monitoring method and memory overflow analysis method

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102662850A (en) * 2012-03-30 2012-09-12 杭州华三通信技术有限公司 Memory management method and system
CN105490876A (en) * 2015-11-26 2016-04-13 上海斐讯数据通信技术有限公司 Method for automatic testing of server performance through packet sending linkage and concurrent monitoring

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104133761A (en) * 2013-11-28 2014-11-05 腾讯科技(成都)有限公司 Memory usage analysis method, device and system of mobile terminal
US9514025B2 (en) * 2015-04-15 2016-12-06 International Business Machines Corporation Modeling memory use of applications
CN105260294A (en) * 2015-11-16 2016-01-20 曙光信息产业(北京)有限公司 Monitoring method and device for memory occupied by application program
CN105511963B (en) * 2015-11-30 2019-12-10 Tcl集团股份有限公司 memory optimization method and system based on Android system

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102662850A (en) * 2012-03-30 2012-09-12 杭州华三通信技术有限公司 Memory management method and system
CN105490876A (en) * 2015-11-26 2016-04-13 上海斐讯数据通信技术有限公司 Method for automatic testing of server performance through packet sending linkage and concurrent monitoring

Also Published As

Publication number Publication date
CN107291619A (en) 2017-10-24

Similar Documents

Publication Publication Date Title
US8336029B1 (en) Debugger connection
CN105589805B (en) Method and device for generating code coverage rate report
CN107291619B (en) Memory occupation analysis method and device
CN107066519B (en) Task detection method and device
CN111190825A (en) Automatic test method, system and robot
CN109344066B (en) Method, system and terminal for testing browser page
CN111831542B (en) API application debugging method and device and storage medium
CN111273891A (en) Business decision method and device based on rule engine and terminal equipment
CN108023905B (en) Internet of things application system and method
CN112671878B (en) Block chain information subscription method, device, server and storage medium
CN114116509A (en) Program analysis method, program analysis device, electronic device, and storage medium
CN113806216A (en) Interface test method, device, medium and equipment
CN110609666B (en) Printer configuration method and device, electronic equipment and readable storage medium
CN112612460A (en) Interface packaging and calling method, electronic device and storage medium
CN112181479A (en) Method and device for determining difference between code file versions and electronic equipment
CN107506299B (en) Code analysis method and terminal equipment
CN107767434B (en) Method for acquiring texture mapping configuration information in virtual reality technology and storage medium
CN112631949B (en) Debugging method and device, computer equipment and storage medium
CN110262912B (en) Calling method and device for procedure call gRPC
AU2013206622B2 (en) Download management method and device based on Android browser
CN112764761A (en) Program interruption file analysis method, storage medium, electronic device and system
CN108848398B (en) Method, device, terminal and storage medium for distributing local barrage messages
CN106713902A (en) Camera module fault detection method and apparatus, and terminal
CN113741878A (en) GraphQL-based interface construction method and system, electronic equipment and storage medium
CN105955991A (en) Method and device for aggregation and positioning of search results

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
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20210402