CN111694747B - Thread detection method, device, equipment and computer readable medium - Google Patents

Thread detection method, device, equipment and computer readable medium Download PDF

Info

Publication number
CN111694747B
CN111694747B CN202010555035.7A CN202010555035A CN111694747B CN 111694747 B CN111694747 B CN 111694747B CN 202010555035 A CN202010555035 A CN 202010555035A CN 111694747 B CN111694747 B CN 111694747B
Authority
CN
China
Prior art keywords
thread
function
shared
library
shared library
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010555035.7A
Other languages
Chinese (zh)
Other versions
CN111694747A (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.)
Douyin Vision Co Ltd
Original Assignee
Douyin Vision 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 Douyin Vision Co Ltd filed Critical Douyin Vision Co Ltd
Priority to CN202010555035.7A priority Critical patent/CN111694747B/en
Publication of CN111694747A publication Critical patent/CN111694747A/en
Application granted granted Critical
Publication of CN111694747B publication Critical patent/CN111694747B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics

Landscapes

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

Abstract

The embodiment of the disclosure provides a thread detection method, a thread detection device, an electronic device and a computer readable medium, wherein the method comprises the following steps: acquiring a plurality of shared libraries called when compiling the application package; scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library; when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function; when the second function is detected, it is determined that there is no thread leak for the thread running the application package. The method realizes accurate positioning of thread leakage, enables a user to find and solve the problem of thread leakage in advance in the program development and test stages, avoids the problem that the thread leakage occurs after the program is issued and causes various programs to crash, and improves user experience.

Description

Thread detection method, device, equipment and computer readable medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a thread detection method, apparatus, electronic device, and computer readable medium.
Background
In the prior art, through a programming language such as C or C + +, a written application program may create and use a thread during running, and perform concurrent execution operations of multiple threads, and sometimes a stack space memory corresponding to the thread may not be released, thereby causing thread leakage. When the thread leakage is not serious, a user is not easy to perceive the existence of the thread leakage; when the number of times of thread leakage exceeds a preset threshold, a program crash is caused, but a user usually cannot locate which thread is leaked, so that the user needs to spend a lot of time to locate which thread is leaked, and the accuracy of location is often low, thereby reducing the working efficiency.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
The present disclosure provides a thread detection method, a thread detection device, an electronic apparatus, and a computer-readable medium to solve the problem of how to accurately locate thread leakage.
In a first aspect, the present disclosure provides a method for detecting a thread, including:
acquiring a plurality of shared libraries called when compiling the application package;
scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library;
when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function;
when the second function is detected, it is determined that there is no thread leak for the thread running the application package.
In a second aspect, the present disclosure provides an apparatus for detecting a thread, including:
the first processing module is used for acquiring a plurality of shared libraries called when the application package is compiled;
the second processing module is used for scanning the shared libraries called by any one of the shared libraries except any one of the shared libraries so as to detect first functions included in the shared libraries except any one of the shared libraries;
the third processing module is used for scanning a shared library comprising the first function when the first function is detected so as to detect a second function paired with the first function;
and the fourth processing module is used for determining that the thread for running the application program package has no thread leakage when the second function is detected.
In a third aspect, the present disclosure provides an electronic device, comprising: a processor, memory, and a bus;
a bus for connecting the processor and the memory;
a memory for storing operating instructions;
and the processor is used for executing the thread detection method of the first aspect of the disclosure by calling the operation instruction.
In a fourth aspect, the present disclosure provides a computer-readable medium storing a computer program for performing the method for detecting a thread of the first aspect of the present disclosure.
The technical scheme provided by the embodiment of the disclosure has at least the following beneficial effects:
acquiring a plurality of shared libraries called when compiling the application package; scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library; when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function; when the first function is used for creating the thread, the second function is called to recover the thread, so that leakage cannot be caused, whether the thread for running the application program package has thread leakage or not is determined by detecting whether the second function used in pair with the first function is detected or not, thread leakage is accurately positioned, a user can find and solve the problem of thread leakage in advance in the program development and test stages, the problem that the thread leakage occurs after the program is issued and various programs are crashed is avoided, and user experience is improved.
Additional aspects and advantages of the disclosure will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the disclosure.
Drawings
The above and other features, advantages, and aspects of embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure, the drawings used in the description of the embodiments of the present disclosure will be briefly described below.
Fig. 1 is a schematic flowchart of a thread detection method according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of another thread detection method according to an embodiment of the present disclosure;
fig. 3 is a schematic structural diagram of a thread detection apparatus according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it is to be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing the devices, modules, or units, and are not used for limiting the devices, modules, or units to be determined as different devices, modules, or units, and are not used for limiting the sequence or interdependence of the functions performed by the devices, modules, or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
The embodiment of the present disclosure provides a method for detecting a thread, a flow diagram of the method is shown in fig. 1, and the method includes:
s101, a plurality of shared libraries called when the application package is compiled are obtained.
In the embodiment of the disclosure, the so (shared object) library is a shared library, and in Android development, a common code is developed and packaged into a so library by using a java language generally for other module calls, so that the reuse rate of the common code is improved. Compiling the application package requires preprocessing, compiling, assembling, and linking. Some public codes need to be used repeatedly, the public codes can be compiled into library files, namely a so library, the so library is used for dynamic connection and is compiled out of C or C + +, and the so library can save system resources, accelerate the running speed and simplify code upgrading. The functions in the library file may be linked to the application package through a linker, thereby eliminating the need to compile the functions in the library file each time the application is developed.
In the embodiment of the disclosure, all the so libraries used by the application package are scanned out by calling the plug-in program in the process of starting and compiling the application package.
S102, scanning the shared libraries called by any one of the shared libraries except any one of the shared libraries to detect first functions included in the shared libraries except any one of the shared libraries.
In the embodiment of the present disclosure, the so libraries called by any one of the so libraries other than any one of the so libraries are scanned for detecting the first functions included in the so libraries other than any one of the so libraries.
In the embodiment of the present disclosure, the first function includes a function pthread _ create created by the thread.
In the embodiment of the present disclosure, pthread _ create is a function of thread creation of the operating system, pthread _ create is a function of creating a thread, and after the thread is created, the relevant thread function starts to run.
S103, when the first function is detected, scanning the shared library including the first function for detecting a second function paired with the first function.
In the embodiment of the present disclosure, when the first function is detected, the so library including the first function is scanned for detecting the second function paired with the first function.
In an embodiment of the present disclosure, the second function includes at least one of:
a function pthread _ attr _ setdachstate of thread separation state and a thread recycle function phtread _ join.
In the embodiment of the present disclosure, the PTHREAD _ attr _ setdachstate includes a split thread parameter PTHREAD _ CREATE _ DETACHED, and when a thread is created using PTHREAD _ CREATE, the PTHREAD _ CREATE _ DETACHED state is set by PTHREAD _ attr _ setdachsate, so that the stack space memory corresponding to the thread is released, thereby avoiding thread leakage.
In the embodiment of the present disclosure, the thread recycling function pthread _ join is used to wait for the completion of a thread and the operation of synchronization between threads. The main thread is blocked by pthread _ join waiting for other threads to exit so that the main thread can clear the context of other threads.
And S104, when the second function is detected, determining that the thread for running the application program package has no thread leakage.
In the embodiment of the disclosure, when the second function is not detected, determining that thread leakage exists in a thread running the application package, and determining information of any so library; and repairing the thread leakage according to the information of any so library.
In the embodiment of the present disclosure, the information of any so library includes at least one of the following:
name of any so library, binary archive file aar package, symbol of thread.
In the embodiment of the present disclosure, the so library has a file name containing real library code, called the name realname of the so library, and the naming format is usually libxxx. The aar (Android Archive) package is a binary Archive file of Android library items. The notation of a thread includes a thread identification ID, which is represented by a pthread _ t data type.
In the embodiment of the present disclosure, after determining that there is thread leakage in a thread running an application package, and determining information of any so library, the method further includes:
and generating prompt information aiming at the thread leakage according to the thread leakage, wherein the prompt information comprises information of any so library.
In the embodiment of the disclosure, a plurality of shared libraries so called when an application package is compiled are obtained; scanning so as to detect a first function included in a so library except any so library called by any so library in the plurality of so libraries; when the first function is detected, scanning a so library comprising the first function for detecting a second function paired with the first function; when the first function is used for creating the thread, the second function is called to recover the thread, so that leakage cannot be caused, whether the thread for running the application program package has thread leakage or not is determined by detecting whether the second function used in pair with the first function is detected or not, thread leakage is accurately positioned, a user can find and solve the problem of thread leakage in advance in the program development and test stages, the problem that the thread leakage occurs after the program is issued and various programs are crashed is avoided, and user experience is improved.
Another thread detection method is provided in the embodiments of the present disclosure, and a flowchart of the method is shown in fig. 2, where the method includes:
s201, writing a plug-in program.
In the embodiment of the present disclosure, the plug-in is configured to perform thread leakage detection on a thread running an APK (Android application package).
S202, compiling the APK.
In the embodiment of the disclosure, in the process of compiling the APK, the plug-in program is used for detecting thread leakage of the thread running the APK.
S203, calling the plug-in program to scan out all so libraries used by the APK.
S204, traversing each so library through the plug-in program, and inquiring the external symbols called by each so library of dump.
In the embodiment of the present disclosure, the external symbol called by the dump first so library is queried by the plug-in, and the external symbol is a so library other than the first so library, for example, the so library other than the first so library includes a second so library, and the external symbol includes a function implemented in the second so library, and the second so library is called by the first so.
S205, detecting whether the external symbol of each so library includes pthread _ create, and if it is determined that the external symbol includes pthread _ create, going to step S206.
In the embodiment of the present disclosure, it is detected whether the external symbol of the first so repository includes pthread _ create, for example, whether the second so repository includes pthread _ create, and when it is determined that the second so repository includes pthread _ create, the process goes to step S206.
S206, judging whether pthread _ attr _ setdachstat or phtread _ join used for pairing with pthread _ create exists, and turning to the step S207 to process when determining that pthread _ attr _ setdachstat or phtread _ join used for pairing with pthread _ create exists; when it is determined that there is no pthread _ attr _ setdachstat or phtread _ join used as a pair with pthread _ create, processing proceeds to step S208.
In the embodiment of the present disclosure, pthread _ attr _ setdatchstate is used to set the thread state, for example, active recycle. phtread _ join is used to recycle threads.
And S207, determining that no thread leakage exists in the thread running the APK.
And S208, determining that thread leakage exists in the thread running the APK, and collecting the information of the so library.
In the embodiment of the disclosure, it is determined that there is thread leakage in the thread running the APK, and information of the first so library is collected.
In the embodiment of the present disclosure, the information of the first so repository includes a name of the first so repository, a binary archive file aar package, and a symbol of the thread.
S209, triggering a compiling error and printing the information of the so library.
In the embodiment of the disclosure, according to the thread leakage, a compiling error is triggered, that is, prompt information for the thread leakage is generated, where the prompt information includes information of the first so library, and the information of the first so library is printed.
And S210, the user repairs the thread leakage according to the information of the so library.
In the embodiment of the disclosure, the user repairs the thread leakage according to the information of the first so library; when the thread leakage repair is completed, the APK is normally issued and executed.
The application of the embodiment of the disclosure has at least the following beneficial effects:
whether the thread leakage exists in the thread running the application program package APK is determined by detecting whether phtread _ join or pthread _ attr _ setdachstat paired with pthread _ create exists, so that the thread leakage is accurately positioned, a user can find and solve the problem of thread leakage in advance in the program development and test stage, the problem of thread leakage after the program is issued and various programs are crashed is avoided, and the user experience is improved.
Based on the same inventive concept, the embodiment of the present disclosure further provides a thread detection apparatus, a schematic structural diagram of the apparatus is shown in fig. 3, and the thread detection apparatus 30 includes a first processing module 301, a second processing module 302, a third processing module 303, and a fourth processing module 304.
A first processing module 301, configured to obtain multiple shared libraries called when compiling an application package;
a second processing module 302, configured to scan shared libraries called by any shared library of the multiple shared libraries, except for any shared library, so as to detect a first function included in the shared libraries except for any shared library;
a third processing module 303, configured to, when the first function is detected, scan a shared library including the first function for detecting a second function paired with the first function;
a fourth processing module 304, configured to determine that there is no thread leak in the thread running the application package when the second function is detected.
In an embodiment of the disclosure, the first function includes a thread-created function, and the second function includes at least one of:
a thread separation state function and a thread recycle function.
In this embodiment of the present disclosure, the fourth processing module 304 is specifically configured to determine that there is thread leakage in a thread running an application package and determine information of any shared library when the second function is not detected; and repairing the thread leakage according to the information of any shared library.
In the embodiment of the present disclosure, the information of any shared library includes at least one of the following:
name of any shared library, binary archive file, symbol of thread.
In this embodiment of the present disclosure, the fourth processing module 304 is specifically configured to, after determining that there is thread leakage in a thread running an application package and determining information of any shared library, generate prompt information for the thread leakage according to the thread leakage, where the prompt information includes information of any shared library.
The application of the embodiment of the disclosure has at least the following beneficial effects:
acquiring a plurality of shared libraries called when compiling an application package; scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library; when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function; when the first function is used for creating the thread, the second function is called to recover the thread, so that leakage cannot be caused, whether the thread for running the application program package has thread leakage or not is determined by detecting whether the second function used in pair with the first function is detected or not, thread leakage is accurately positioned, a user can find and solve the problem of thread leakage in advance in the program development and test stages, the problem that the thread leakage occurs after the program is issued and various programs are crashed is avoided, and user experience is improved.
For the content that is not described in detail in the thread detection apparatus provided in the embodiment of the present disclosure, reference may be made to the thread detection method provided in the above embodiment, and the beneficial effects that can be achieved by the thread detection apparatus provided in the embodiment of the present disclosure are the same as the thread detection method provided in the above embodiment, and are not described again here.
Referring now to FIG. 4, a block diagram of an electronic device 800 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
The electronic device includes: a memory and a processor, wherein the processor may be referred to as the processing device 801 described below, and the memory may include at least one of a Read Only Memory (ROM) 802, a Random Access Memory (RAM) 803, and a storage device 808, as shown in fig. 4:
the electronic device 800 may include a processing means (e.g., a central processing unit, a graphics processor, etc.) 801 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 802 or a program loaded from a storage means 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data necessary for the operation of the electronic apparatus 800 are also stored. The processing apparatus 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
Generally, the following devices may be connected to the I/O interface 805: input devices 806 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 807 including, for example, a Liquid Crystal Display (LCD), speakers, vibrators, and the like; storage 808 including, for example, magnetic tape, hard disk, etc.; and a communication device 809. The communication means 809 may allow the electronic device 800 to communicate wirelessly or by wire with other devices to exchange data. While fig. 4 illustrates an electronic device 800 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, the processes described above with reference to the flow diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 809, or installed from the storage means 808, or installed from the ROM 802. The computer program, when executed by the processing apparatus 801, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may be separate and not incorporated into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring a plurality of shared libraries called when compiling the application package; scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library; when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function; when the second function is detected, it is determined that there is no thread leak for the thread running the application package.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules or units described in the embodiments of the present disclosure may be implemented by software or hardware. Wherein the designation of a module or unit does not in some cases constitute a limitation of the unit itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, an embodiment provides a thread detection method, including:
acquiring a plurality of shared libraries called when compiling an application package;
scanning shared libraries called by any shared library in the plurality of shared libraries except any shared library, so as to detect a first function included in the shared libraries except any shared library;
when a first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function;
when the second function is detected, it is determined that there is no thread leak for the thread running the application package.
In an embodiment of the disclosure, the first function includes a thread-created function, and the second function includes at least one of:
a thread separation state function and a thread recycle function.
In the embodiment of the disclosure, when the second function is not detected, determining that thread leakage exists in a thread running the application package, and determining information of any shared library; and repairing the thread leakage according to the information of any shared library.
In the embodiment of the present disclosure, the information of any shared library includes at least one of the following:
name of any shared library, binary archive file, symbol of thread.
In the embodiment of the present disclosure, after determining that there is thread leakage in a thread running an application package and determining information of any shared library, the method further includes:
and generating prompt information aiming at the thread leakage according to the thread leakage, wherein the prompt information comprises information of any shared library.
According to one or more embodiments of the present disclosure, an embodiment provides an apparatus for detecting a thread, including:
the first processing module is used for acquiring a plurality of shared libraries called when the application package is compiled;
the second processing module is used for scanning the shared libraries called by any one of the shared libraries except any one of the shared libraries so as to detect first functions included in the shared libraries except any one of the shared libraries;
the third processing module is used for scanning a shared library comprising the first function when the first function is detected so as to detect a second function paired with the first function;
and the fourth processing module is used for determining that the thread for running the application program package has no thread leakage when the second function is detected.
In an embodiment of the disclosure, the first function includes a thread-created function, and the second function includes at least one of:
a thread separation state function and a thread recycle function.
In the embodiment of the present disclosure, the fourth processing module is specifically configured to determine that there is thread leakage in a thread running an application package and determine information of any shared library when the second function is not detected; and repairing the thread leakage according to the information of any shared library.
In the embodiment of the present disclosure, the information of any shared library includes at least one of the following:
name of any shared library, binary archive file, symbol of thread.
In an embodiment of the present disclosure, the fourth processing module is specifically configured to generate, according to the thread leakage, prompt information for the thread leakage after determining that the thread running the application package has the thread leakage and determining information of any shared library, where the prompt information includes information of any shared library.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other combinations of features described above or equivalents thereof without departing from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (8)

1. A method for detecting a thread, comprising:
acquiring a plurality of shared libraries called when compiling the application package;
scanning a shared library, except any shared library, called by any shared library in the plurality of shared libraries for detecting a first function included in the shared library except the any shared library;
when the first function is detected, scanning a shared library comprising the first function for detecting a second function paired with the first function;
when the second function is detected, determining that no thread leakage exists in the thread running the application program package;
wherein the scanning the shared libraries called by any one of the plurality of shared libraries except for any one of the shared libraries comprises:
traversing the shared libraries except any one shared library through a plug-in program, and inquiring external symbols called by the shared libraries except any one shared library;
wherein the first function comprises a thread-created function and the second function comprises at least one of:
a thread separation state function and a thread recycle function.
2. The method of claim 1, further comprising:
when the second function is not detected, determining that thread leakage exists in the thread running the application program package, and determining information of any shared library;
and repairing the thread leakage according to the information of any shared library.
3. The method of claim 2, after determining that there is a thread leak in a thread running the application package and determining information of any shared library, further comprising:
and generating prompt information aiming at the thread leakage according to the thread leakage, wherein the prompt information comprises the information of any shared library.
4. The method of claim 2, wherein the information of any one of the shared libraries comprises at least one of:
the name of any shared library, a binary archive file, the symbol of the thread.
5. An apparatus for detecting a thread, comprising:
the first processing module is used for acquiring a plurality of shared libraries called when the application package is compiled;
the second processing module is used for scanning the shared libraries called by any one of the plurality of shared libraries except for any one of the shared libraries so as to detect first functions included in the shared libraries except for any one of the shared libraries;
a third processing module, configured to, when the first function is detected, scan a shared library including the first function, so as to detect a second function paired with the first function;
the fourth processing module is used for determining that no thread leakage exists in the thread running the application program package when the second function is detected;
wherein the scanning the shared libraries called by any one of the plurality of shared libraries except for any one of the shared libraries comprises:
traversing the shared libraries except any shared library through a plug-in program, and inquiring external symbols called by the shared libraries except any shared library;
wherein the first function comprises a thread-created function and the second function comprises at least one of:
a thread separation state function and a thread recycle function.
6. The apparatus of claim 5, comprising:
a fourth processing module, configured to determine that a thread leakage exists in a thread running the application package and determine information of any shared library when the second function is not detected; and repairing the thread leakage according to the information of any shared library.
7. An electronic device, comprising: a processor, a memory;
the memory for storing a computer program;
the processor, configured to execute the method for detecting a thread according to any one of claims 1 to 4 by calling the computer program.
8. A computer-readable medium, in which a computer program is stored which, when being executed by a processor, is adapted to carry out the method of detecting a thread according to any one of claims 1 to 4.
CN202010555035.7A 2020-06-17 2020-06-17 Thread detection method, device, equipment and computer readable medium Active CN111694747B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010555035.7A CN111694747B (en) 2020-06-17 2020-06-17 Thread detection method, device, equipment and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010555035.7A CN111694747B (en) 2020-06-17 2020-06-17 Thread detection method, device, equipment and computer readable medium

Publications (2)

Publication Number Publication Date
CN111694747A CN111694747A (en) 2020-09-22
CN111694747B true CN111694747B (en) 2023-03-28

Family

ID=72481793

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010555035.7A Active CN111694747B (en) 2020-06-17 2020-06-17 Thread detection method, device, equipment and computer readable medium

Country Status (1)

Country Link
CN (1) CN111694747B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5432932A (en) * 1992-10-23 1995-07-11 International Business Machines Corporation System and method for dynamically controlling remote processes from a performance monitor
US7802257B1 (en) * 2005-06-20 2010-09-21 Oracle America, Inc. Mechanism for bridging a thread-oriented computing paradigm and a job-oriented computing paradigm
CN102662825A (en) * 2012-02-22 2012-09-12 中国人民解放军国防科学技术大学 Method for detecting memory leakage of heap operational program
CN102831068A (en) * 2011-06-13 2012-12-19 阿里巴巴集团控股有限公司 Memory operating record processing method and device
CN103761479A (en) * 2014-01-09 2014-04-30 北京奇虎科技有限公司 Scanning method and scanning device for malicious programs
JP2016224506A (en) * 2015-05-27 2016-12-28 西日本電信電話株式会社 Information leak detection device, information leak detection system, and information leak detection program
CN106598858A (en) * 2016-12-14 2017-04-26 合网络技术(北京)有限公司 Resource calling analysis method and resource calling analysis device
CN107967155A (en) * 2016-10-18 2018-04-27 腾讯科技(深圳)有限公司 Method, apparatus, the server of program operation are realized based on Hook shared libraries
CN110457150A (en) * 2019-07-10 2019-11-15 锐捷网络股份有限公司 A kind of memory failure detection method and device
CN111090536A (en) * 2019-11-19 2020-05-01 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for acquiring memory leakage information

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8793662B2 (en) * 2008-03-25 2014-07-29 Microsoft Corporation Runtime code hooking for print driver and functionality testing
KR101649925B1 (en) * 2010-10-13 2016-08-31 삼성전자주식회사 Analysis for Single Thread Access of variable in Multi-threaded program

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5432932A (en) * 1992-10-23 1995-07-11 International Business Machines Corporation System and method for dynamically controlling remote processes from a performance monitor
US7802257B1 (en) * 2005-06-20 2010-09-21 Oracle America, Inc. Mechanism for bridging a thread-oriented computing paradigm and a job-oriented computing paradigm
CN102831068A (en) * 2011-06-13 2012-12-19 阿里巴巴集团控股有限公司 Memory operating record processing method and device
CN102662825A (en) * 2012-02-22 2012-09-12 中国人民解放军国防科学技术大学 Method for detecting memory leakage of heap operational program
CN103761479A (en) * 2014-01-09 2014-04-30 北京奇虎科技有限公司 Scanning method and scanning device for malicious programs
JP2016224506A (en) * 2015-05-27 2016-12-28 西日本電信電話株式会社 Information leak detection device, information leak detection system, and information leak detection program
CN107967155A (en) * 2016-10-18 2018-04-27 腾讯科技(深圳)有限公司 Method, apparatus, the server of program operation are realized based on Hook shared libraries
CN106598858A (en) * 2016-12-14 2017-04-26 合网络技术(北京)有限公司 Resource calling analysis method and resource calling analysis device
CN110457150A (en) * 2019-07-10 2019-11-15 锐捷网络股份有限公司 A kind of memory failure detection method and device
CN111090536A (en) * 2019-11-19 2020-05-01 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for acquiring memory leakage information

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
傅建明 ; 汤毅 ; 刘秀文 ; 张旭 ; .一种基于动态污点的内存越界访问检测框架.武汉大学学报(理学版).(05),全文. *
张鹏 ; 杨秋辉 ; 李海怒 ; .嵌入式软件内存泄露检测方法研究.计算机工程与应用.(第14期),全文. *
王让定 ; 李霏 ; 徐霁 ; .基于嵌入式系统的线程池研究.宁波大学学报(理工版).2008,(01),全文. *
蔡志强 ; 丁丽萍 ; 贺也平 ; .一种基于虚拟机的动态内存泄露检测方法.计算机应用与软件.2012,(09),全文. *
高海昌 ; 冯博琴 ; 卫鹏 ; 何杭军 ; .Linux下可执行文件的动态内存检测设计与实现.计算机工程.2007,(01),全文. *

Also Published As

Publication number Publication date
CN111694747A (en) 2020-09-22

Similar Documents

Publication Publication Date Title
CN113835992B (en) Memory leakage processing method and device, electronic equipment and computer storage medium
CN111897740A (en) User interface testing method and device, electronic equipment and computer readable medium
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN110727566A (en) Method, device, medium and electronic equipment for acquiring process crash information
CN112214408A (en) Dependency conflict detection method and device, electronic equipment and computer readable medium
CN110960855A (en) Communication protocol code updating method and device, electronic equipment and storage medium
CN111240801A (en) Method, device, medium and electronic equipment for generating heap memory snapshot file
CN111459822A (en) Method, device and equipment for extracting system component data and readable medium
CN113407165B (en) SDK generation and self-upgrade method, device, readable medium and equipment
CN111338666A (en) Method, device, medium and electronic equipment for realizing application program upgrading
CN114721656A (en) Interface structure extraction method, device, medium and electronic equipment
CN111414308B (en) Application package processing method and application running method and device
CN111506904B (en) Method and device for online bug repair
CN112084024A (en) Memory monitoring method, device, medium and electronic equipment
CN111796865A (en) Byte code file modification method and device, terminal equipment and medium
CN110704050B (en) Module initializing method and device, electronic equipment and computer readable storage medium
CN111694747B (en) Thread detection method, device, equipment and computer readable medium
CN111273982A (en) Method, device, electronic equipment and medium for confirming default font of operating system
CN113138883A (en) Message processing method and device, storage medium and electronic equipment
CN111538717A (en) Data processing method and device, electronic equipment and computer readable medium
CN111399902A (en) Client source file processing method and device, readable medium and electronic equipment
CN110764995A (en) Method, device, medium and electronic equipment for detecting file access abnormity
CN111309323A (en) Parameter initialization method and device and electronic equipment
CN111562913B (en) Method, device and equipment for pre-creating view component and computer readable medium
CN111209042B (en) Method, device, medium and electronic equipment for establishing function stack

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Tiktok vision (Beijing) Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd.

Address after: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant after: Douyin Vision Co.,Ltd.

Address before: 100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing.

Applicant before: Tiktok vision (Beijing) Co.,Ltd.

GR01 Patent grant
GR01 Patent grant