CN117762676A - Method and device for detecting abnormal memory allocation, storage medium and electronic equipment - Google Patents
Method and device for detecting abnormal memory allocation, storage medium and electronic equipment Download PDFInfo
- Publication number
- CN117762676A CN117762676A CN202311867786.2A CN202311867786A CN117762676A CN 117762676 A CN117762676 A CN 117762676A CN 202311867786 A CN202311867786 A CN 202311867786A CN 117762676 A CN117762676 A CN 117762676A
- Authority
- CN
- China
- Prior art keywords
- sampling
- initial
- memory allocation
- detected
- results
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 230000002159 abnormal effect Effects 0.000 title claims abstract description 92
- 238000000034 method Methods 0.000 title claims abstract description 68
- 238000003860 storage Methods 0.000 title claims abstract description 21
- 238000005070 sampling Methods 0.000 claims abstract description 425
- 238000001514 detection method Methods 0.000 claims abstract description 33
- 230000006870 function Effects 0.000 claims description 21
- 230000005856 abnormality Effects 0.000 claims description 11
- 238000005516 engineering process Methods 0.000 abstract description 9
- 238000004883 computer application Methods 0.000 abstract description 2
- 238000009826 distribution Methods 0.000 description 19
- 238000010586 diagram Methods 0.000 description 14
- 230000008569 process Effects 0.000 description 10
- 238000004364 calculation method Methods 0.000 description 9
- 238000004590 computer program Methods 0.000 description 8
- 230000000875 corresponding effect Effects 0.000 description 7
- 238000012544 monitoring process Methods 0.000 description 7
- 238000012545 processing Methods 0.000 description 7
- 230000003068 static effect Effects 0.000 description 6
- 230000002596 correlated effect Effects 0.000 description 4
- 238000004458 analytical method Methods 0.000 description 3
- 230000007547 defect Effects 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 2
- 238000007689 inspection Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000009467 reduction Effects 0.000 description 2
- 230000026676 system process Effects 0.000 description 2
- 238000012360 testing method Methods 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 230000001276 controlling effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 238000004806 packaging method and process Methods 0.000 description 1
- 230000002085 persistent effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The application discloses a method and device for detecting abnormal memory allocation, a storage medium and electronic equipment. To the field of computer applications or other related fields, the method includes: obtaining a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules; calculating an initial sampling result of each program module in the M program modules to obtain M initial sampling results, executing the program codes to be detected to obtain a first operation result of the program codes to be detected, and adjusting the M initial sampling results according to the first operation result to obtain M target sampling results; and acquiring N target sampling results with sampling result types of memory allocation failure types, and determining a program module associated with the N target sampling results as an abnormal module. By the method and the device, the problem of low detection efficiency when the problem positioning detection is carried out on the memory allocation failure of the program code to be detected in the related technology is solved.
Description
Technical Field
The present invention relates to the field of computer applications or other related fields, and in particular, to a method and apparatus for detecting abnormal memory allocation, a storage medium, and an electronic device.
Background
With the development of computer hardware and software, memory allocation technology is evolving and perfecting, and memory allocation is a technology that provides necessary memory space for application programs and system processes by managing memory resources in a computer system. The existing memory allocation technology comprises two main modes of static allocation and dynamic allocation, wherein a specific program is executed to apply for a certain size of memory space from an operating system to store data and variables, and the static allocation refers to determining the memory space required by each variable or object before the program runs and then keeping unchanged during the execution of the program; the dynamic allocation is to dynamically allocate and release the memory space according to the actual running condition of the program.
However, during the running process of the program, a memory allocation failure may occur, and the memory allocation failure may cause a program crash, especially when the operating system cannot allocate the required memory, which easily causes an unpredictable result, for example, the memory allocation failure may cause the program crash, and at this time, the program may attempt to access the unallocated memory or the unallocated memory, so that the operating system terminates the execution of the program; memory leakage may result from a memory allocation failure; memory allocation failure can lead to data loss, which can result in data loss if the memory allocation failure results in the data in the program being incorrectly saved or loaded, such that serious problems can result for applications requiring persistent storage (e.g., database systems), and system stability anomalies can result, particularly at the operating system level, where multiple programs competing for limited memory resources can cause the system to crash or become unstable.
In order to solve the problem of memory allocation failure, the prior art generally adopts some methods to detect and analyze the failure cause so as to find and solve the problem in time, and can monitor and analyze the memory allocation condition of the program by using a static code detection tool to locate the problems of memory leakage, memory overflow and the like, and can also check the log record of the memory allocation failure, including the position, size, cause and the like of the allocation failure so as to facilitate the subsequent analysis and location of the problem. However, the methods have the defects of high performance cost, long scanning time, inaccurate positioning, easy generation of false alarm and missing alarm, need of manual inspection, analysis and monitoring results, difficulty in finding problems generated by cross-file and cross-module interaction and the like.
When the problem location detection is performed on the memory allocation failure of the program code to be detected in the related art, the problem of low detection efficiency exists, and no effective solution is proposed at present.
Disclosure of Invention
The main purpose of the present application is to provide a method, an apparatus, a storage medium, and an electronic device for detecting abnormal memory allocation, so as to solve the problem of low detection efficiency when performing problem location detection on memory allocation failure of a program code to be detected in the related art.
In order to achieve the above object, according to one aspect of the present application, a method for detecting a memory allocation abnormality is provided. The method comprises the following steps: obtaining a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying memory allocation, and M is a positive integer; calculating initial sampling results of each of the M program modules to obtain M initial sampling results, executing program codes to be detected to obtain first operation results of the program codes to be detected, and adjusting the M initial sampling results according to the first operation results to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type; and acquiring N target sampling results with the sampling result type being the memory allocation failure type, and determining a program module associated with the N target sampling results as an abnormal module, wherein N is a positive integer.
Further, obtaining the program code to be detected, and dividing the program code to be detected into modules, wherein obtaining M program modules includes: calling a code detection tool to extract target codes in the program codes to be detected to obtain M target codes; and identifying task types of memory allocation tasks associated with the M target codes to obtain M task types, and marking the M target codes by using the M task types to obtain M program modules.
Further, adjusting the M initial sampling results according to the first operation result, and obtaining M target sampling results includes: under the condition that the first operation result represents that the operation of the program code to be detected is abnormal, obtaining the result number of the initial sampling result with the sampling result type being the memory allocation failure type; judging whether the ratio of the number of results to M is smaller than or equal to a preset ratio; under the condition that the ratio of the number of results to M is larger than a preset ratio, executing the step of adjusting M initial sampling results according to the first operation result to obtain M target sampling results; the method further comprises the steps of: and under the condition that the ratio of the number of results to M is smaller than or equal to a preset ratio, N initial sampling results are obtained from the M initial sampling results, and program modules related to the N initial sampling results are determined to be abnormal modules, wherein the N initial sampling results refer to sampling results with the sampling result type of memory allocation failure type.
Further, calculating the initial sampling result for each of the M program modules includes: calculating to obtain a beta function value according to the first initial probability parameter and the second initial probability parameter, and calculating sampling probability values according to the beta function value and initial values of M program modules to obtain M sampling probability values; determining M initial sampling results according to the M sampling probability values, wherein when the mth sampling probability value is a first preset value, the sampling result type of the mth initial sampling result is a memory allocation success type; when the M-th sampling probability value is a second preset value, the sampling result type of the M-th initial sampling result is determined to be a memory allocation failure type, M is a positive integer less than or equal to M, and the first preset value is greater than the second preset value.
Further, adjusting the M initial sampling results according to the first operation result, and obtaining M target sampling results includes: under the condition that the first operation result represents that the operation of the program code to be detected is abnormal, carrying out parameter adjustment on the first initial probability parameter and the second initial probability parameter to obtain an adjusted first probability parameter and an adjusted second probability parameter; and calculating sampling probability values of target program modules in the M program modules according to the adjusted first probability parameters and the adjusted second probability parameters to obtain M target sampling probability values, and determining M target sampling results according to the M target sampling probability values, wherein the target program modules are program modules which enable the program codes to be detected to run abnormally.
Further, performing parameter adjustment on the first initial probability parameter and the second initial probability parameter to obtain an adjusted first probability parameter and an adjusted second probability parameter, wherein the steps of: obtaining Z initial sampling results with sampling result types of memory allocation failure types, and obtaining X initial sampling results with sampling result types of memory allocation success types, wherein Z, X is a positive integer, and Z+X=M; reducing the first initial probability parameters associated with the Z initial sampling results, and raising or keeping the second initial probability parameters associated with the Z initial sampling results unchanged to obtain Z adjusted first probability parameters and Z adjusted second probability parameters; and reducing second initial probability parameters associated with the X initial sampling results, and raising or keeping the first initial probability parameters associated with the X initial sampling results unchanged to obtain X adjusted first probability parameters and X adjusted second probability parameters.
Further, before determining the program module associated with the N target sampling results as the abnormal module, the method further includes: acquiring a second operation result of the program code to be detected, wherein the second operation result refers to a result of operating the program code to be detected after M target sampling results are obtained; under the condition that the second operation result represents that the operation of the program code to be detected is abnormal, executing the step of acquiring N target sampling results with sampling result types of memory allocation failure types; and under the condition that the second operation result represents that the operation of the program code to be detected is normal, executing the program code to be detected until the operation of the program code to be detected is abnormal, and executing the step of acquiring N target sampling results with the sampling result type of the memory allocation failure type.
In order to achieve the above object, according to another aspect of the present application, a device for detecting abnormal memory allocation is provided. The device comprises: the first acquisition unit is used for acquiring a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying memory allocation, and M is a positive integer; the computing unit is used for computing an initial sampling result of each program module in the M program modules to obtain M initial sampling results, executing the program code to be detected to obtain a first operation result of the program code to be detected, and adjusting the M initial sampling results according to the first operation result to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and the sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type; the second obtaining unit is used for obtaining N target sampling results with sampling result types of memory allocation failure types, and determining program modules related to the N target sampling results as abnormal modules, wherein N is a positive integer.
According to another aspect of the embodiment of the present invention, there is further provided a computer storage medium, where the computer storage medium is configured to store a program, and when the program runs, control a device in which the computer storage medium is located to execute a method for detecting an abnormal memory allocation.
According to another aspect of embodiments of the present invention, there is also provided an electronic device including one or more processors and a memory; the memory stores computer readable instructions, and the processor is configured to execute the computer readable instructions, where the computer readable instructions execute a method for detecting an abnormal memory allocation when executed.
Through the application, the following steps are adopted: obtaining a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying memory allocation, and M is a positive integer; calculating initial sampling results of each of the M program modules to obtain M initial sampling results, executing program codes to be detected to obtain first operation results of the program codes to be detected, and adjusting the M initial sampling results according to the first operation results to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type; n target sampling results with sampling result types of memory allocation failure types are obtained, program modules related to the N target sampling results are determined to be abnormal modules, N is a positive integer, the problem of low detection efficiency in the process of problem location detection of memory allocation failure of the program codes to be detected in the related technology is solved, the program codes to be detected are obtained, the program codes to be detected are divided into a plurality of program modules, the sampling result of each program module is calculated, the sampling result is adjusted according to the running result of the program codes to be detected, the target sampling results with the sampling result types of the memory allocation failure types are obtained from the target sampling results, and the program modules related to the target sampling results are determined to be the abnormal modules, so that the effect of improving the efficiency of problem location detection of the memory allocation failure of the program codes to be detected is achieved.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application, illustrate and explain the application and are not to be construed as limiting the application. In the drawings:
FIG. 1 is a flowchart of a method for detecting memory allocation anomalies according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a system for detecting memory allocation anomalies according to an embodiment of the present application;
FIG. 3 is a schematic diagram of an alternative method for detecting memory allocation anomalies according to an embodiment of the present application;
fig. 4 is a schematic diagram of a device for detecting abnormal memory allocation according to an embodiment of the present application;
fig. 5 is a schematic diagram of an electronic device provided according to an embodiment of the present application.
Detailed Description
It should be noted that, in the case of no conflict, the embodiments and features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate in order to describe the embodiments of the present application described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that, related information (including, but not limited to, user equipment information, user personal information, etc.) and data (including, but not limited to, data for presentation, analyzed data, etc.) related to the present disclosure are information and data authorized by a user or sufficiently authorized by each party.
The present invention is described below with reference to preferred implementation steps, and fig. 1 is a flowchart of a method for detecting a memory allocation abnormality according to an embodiment of the present application, as shown in fig. 1, where the method includes the following steps:
Step S101, obtaining a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying for memory allocation, and M is a positive integer.
In particular, memory allocation tasks are a technique by which memory resources in a computer system are managed to provide the necessary memory space for applications and system processes. Memory allocation tasks may apply for a certain amount of memory space from the operating system to store data and variables by executing a particular program. When the memory allocation is realized based on the program codes, the memory allocation failure is easy to occur, and when the static code detection tool is used for detecting defects in the program codes, the defects of high performance cost, inaccurate positioning, easy generation of false alarm and missing report, the need of manual inspection, analysis and monitoring results, difficulty in finding problems generated by cross-file and cross-module interaction and the like exist.
Step S102, calculating an initial sampling result of each program module in M program modules to obtain M initial sampling results, executing program codes to be detected to obtain a first operation result of the program codes to be detected, and adjusting the M initial sampling results according to the first operation result to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and the sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type.
It should be noted that, in this embodiment, each initial sampling result is used to represent whether the memory of the program module associated with each initial sampling result is allocated successfully, and if a first initial sampling result in the multiple initial sampling results is an initial sampling result of a first program module in the multiple program modules, the first program module is the program module associated with the first initial sampling result.
In some examples, after the program code to be detected is divided into modules and a plurality of program modules are obtained, the probability of occurrence of a memory allocation failure condition of each program module can be calculated by using the beta distribution, and the sampling probability value is used as an initial sampling result of each program module.
In some examples, when calculating the initial sampling result associated with each program module, the historical memory allocation result of each program module in the historical time period may be counted first, calculation of statistical distribution is performed based on the historical memory allocation results and the set probability parameters, and then random sampling is performed on the statistical distribution of each program module, so as to obtain the initial sampling result of each program module, where the statistical distribution in this embodiment is not limited to a specific probability distribution, and the statistical distribution may be a normal distribution or a beta distribution, and the statistical distribution in this embodiment may be a probability density distribution capable of reflecting the probability that the memory allocation is successful or failed.
In some examples, after the program code to be detected is executed in the real environment, an operation result of the program code is obtained, and a program module in which a memory allocation failure condition may occur is judged according to the operation result, and at this time, parameter adjustment of beta distribution may be performed according to the operation result and the initial sampling result, so that the sampling result is adjusted based on the parameter, thereby obtaining a corresponding target sampling result. It should be noted that, the initial sampling result calculated according to the beta distribution may be a set of initial sampling results calculated by different variables corresponding to each program module, where each initial sampling result in each set of initial sampling results is a different result calculated by different variables and the same parameter.
Step S103, N target sampling results with sampling result types of memory allocation failure types are obtained, and program modules associated with the N target sampling results are determined to be abnormal modules, wherein N is a positive integer.
In some examples, after the initial sampling result is adjusted by the running result to obtain a plurality of target sampling results, the situation that the memory allocation fails in the program code to be detected occurs can be determined according to the target sampling results, when the target sampling results represent the sent abnormal phenomena such as program crash and memory leakage, that is, when the sampling result type of the target sampling results is the memory allocation failure type, the program module associated with the target sampling results can be determined to be the abnormal module of the program code to be detected, so that code maintenance can be performed on the abnormal module.
According to the method for detecting the memory allocation abnormality, the program codes to be detected are obtained, and are subjected to module division to obtain M program modules, wherein the program codes to be detected are codes for applying memory allocation, and M is a positive integer; calculating initial sampling results of each of the M program modules to obtain M initial sampling results, executing program codes to be detected to obtain first operation results of the program codes to be detected, and adjusting the M initial sampling results according to the first operation results to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type; n target sampling results with sampling result types of memory allocation failure types are obtained, program modules related to the N target sampling results are determined to be abnormal modules, N is a positive integer, the problem of low detection efficiency in the process of problem location detection of memory allocation failure of the program codes to be detected in the related technology is solved, the program codes to be detected are obtained, the program codes to be detected are divided into a plurality of program modules, the sampling result of each program module is calculated, the sampling result is adjusted according to the running result of the program codes to be detected, the target sampling results with the sampling result types of the memory allocation failure types are obtained from the target sampling results, and the program modules related to the target sampling results are determined to be the abnormal modules, so that the effect of improving the efficiency of problem location detection of the memory allocation failure of the program codes to be detected is achieved.
In some examples, when the program code to be detected is divided into modules, the division may be performed according to a code applied for memory allocation in the program code to be detected, and optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, obtaining the program code to be detected, and performing the module division on the program code to be detected, where obtaining M program modules includes: calling a code detection tool to extract target codes in the program codes to be detected to obtain M target codes; and identifying task types of memory allocation tasks associated with the M target codes to obtain M task types, and marking the M target codes by using the M task types to obtain M program modules.
In particular, the code detection tool may be a static code detection tool that may identify codes of the codes for which memory allocation is being applied and codes that involve possible memory leaks and unsafe operations. When the program code to be detected is divided into modules, the code to be detected can be scanned and detected based on the code detection tool, so that the target code for executing the memory allocation task is obtained.
Further, in order to facilitate the subsequent identification and test processing of the object codes, the task type of the memory allocation task executed by each object code can be obtained, and the task type is marked on the corresponding object code, so that the marked object code is determined as a program module. The embodiment lays a foundation for the subsequent judgment of the abnormal reason of the failure of memory allocation of the program code to be detected by dividing and marking the program code to be detected.
In some examples, before adjusting the initial sampling result and obtaining the target sampling result, a first operation result of the program code to be detected needs to be determined, and optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, adjusting M initial sampling results according to the first operation result, to obtain M target sampling results includes: under the condition that the first operation result represents that the operation of the program code to be detected is abnormal, obtaining the result number of the initial sampling result with the sampling result type being the memory allocation failure type; judging whether the ratio of the number of results to M is smaller than or equal to a preset ratio; and under the condition that the ratio of the number of results to M is larger than a preset ratio, executing the step of adjusting M initial sampling results according to the first operation result to obtain M target sampling results.
In some examples, the method further comprises: and under the condition that the ratio of the number of results to M is smaller than or equal to a preset ratio, N initial sampling results are obtained from the M initial sampling results, and program modules related to the N initial sampling results are determined to be abnormal modules, wherein the N initial sampling results refer to sampling results with the sampling result type of memory allocation failure type.
When the operation result indicates that the program code to be detected is normal, the first initial probability parameter α and the second initial probability parameter β need to be adjusted, and the program code to be detected is executed for multiple times until the operation result indicates that the program code to be detected is abnormal.
In some examples, when the running result indicates that the program code to be detected is abnormal in running, the number of results of which the types of sampling results are the types of memory allocation failure needs to be obtained, and whether the proportion of the number of the results to the total number of the sampling results is smaller than a preset proportion is judged, if the proportion of the number of the results to the total number of the sampling results is greater than or equal to the preset proportion, a target sampling result needs to be determined by adjusting a first initial probability parameter alpha and a second initial probability parameter beta, a plurality of sampling results are further selected from the target sampling results, and a program module associated with the sampling results is determined to be an abnormal module, wherein the preset proportion can be 10%.
Alternatively, when the ratio of the number of results to the total number of sampling results is smaller than the preset ratio, a part of initial sampling results may be obtained from the obtained initial sampling results, and the program module associated with the selected initial sampling result may be determined as the abnormal module. According to the embodiment, the first operation result is utilized to adjust the initial sampling result, so that abnormal program modules can be judged more accurately, and the detection efficiency is improved.
Optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, calculating the initial sampling result of each of the M program modules includes: calculating to obtain a beta function value according to the first initial probability parameter and the second initial probability parameter, and calculating sampling probability values according to the beta function value and initial values of M program modules to obtain M sampling probability values; determining M initial sampling results according to the M sampling probability values, wherein when the mth sampling probability value is a first preset value, the sampling result type of the mth initial sampling result is a memory allocation success type; when the M-th sampling probability value is a second preset value, the sampling result type of the M-th initial sampling result is determined to be a memory allocation failure type, M is a positive integer less than or equal to M, and the first preset value is greater than the second preset value.
In some examples, since the memory allocation failure occurs randomly when the program code to be executed runs in the real environment, when the memory allocation failure occurs, the variable of the current application memory cannot acquire the required memory space, and then the function using the variable cannot run normally. To simulate such a scenario, the program modules that perform memory allocation tasks for the tag are sampled using random probabilities, the sampled results corresponding to the sampled results. In sampling each program module, the sampling may be performed using a beta distribution, and the sampling results of the program modules may be determined by the sampling probability of the beta distribution.
For example, the first initial probability parameter α and the second initial probability parameter β may be determined, and then the beta function value may be obtained by performing calculation using the initial value of each program module and the first initial probability parameter α and the second initial probability parameter β, and the beta function value B (α, β) may be obtained by performing calculation according to the following formula:
further, the sampling probability value is calculated according to the beta function value and the initial value of each program module, and the sampling probability value can be calculated by the following formula:
where x represents the initial value of each program module and B (α, β) is the beta function value.
After the sampling probability value is obtained through calculation, determining the type of the sampling result according to the sampling probability value, determining the sampling result type of the sampling result correlated with the sampling probability value of 1 as the memory allocation success type, and determining the sampling result type of the sampling result correlated with the sampling probability value of 0 as the memory allocation failure type, wherein the first preset value in the embodiment can be 1, and the second preset value can be 0.
Optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, adjusting M initial sampling results according to a first operation result, to obtain M target sampling results includes: under the condition that the first operation result represents that the operation of the program code to be detected is abnormal, carrying out parameter adjustment on the first initial probability parameter and the second initial probability parameter to obtain an adjusted first probability parameter and an adjusted second probability parameter; and calculating sampling probability values of target program modules in the M program modules according to the adjusted first probability parameters and the adjusted second probability parameters to obtain M target sampling probability values, and determining M target sampling results according to the M target sampling probability values, wherein the target program modules are program modules which enable the program codes to be detected to run abnormally.
Specifically, when the first operation result represents that the operation of the program code to be detected is abnormal, and the ratio of the number of results to the total number of sampling results is greater than or equal to a preset ratio, the first initial probability parameter alpha and the second initial probability parameter beta need to be adjusted, the adjusted first probability parameter and the adjusted second probability parameter are obtained, the target sampling result is calculated based on the adjusted first probability parameter and the adjusted second probability parameter, the number of sampling results, of which the sampling result type is the memory allocation failure type, of the target sampling result is determined, the ratio of the total number of sampling results of the number of sampling results is smaller than the preset ratio, a plurality of sampling results are selected from the target sampling results, and the program module related to the sampling result is determined to be an abnormal module.
It should be noted that, if the first operation result indicates that the to-be-detected program code is operating normally, parameter adjustment is not required for the first initial probability parameter and the second initial probability parameter, and the to-be-detected program code needs to be operated for multiple times until the obtained operation result indicates that the to-be-detected program code is operating abnormally, and at this time, parameter adjustment can be performed for the first initial probability parameter and the second initial probability parameter, and the above operation steps are executed. According to the method and the device for detecting the abnormal program module, the first initial probability parameter and the second initial probability parameter are adjusted, so that a target sampling result can be obtained, the abnormal program module can be judged more accurately, and the detection efficiency is improved.
The means for adjusting probability parameters of beta distribution includes multiple ways, optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, performing parameter adjustment on the first initial probability parameter and the second initial probability parameter, where obtaining the adjusted first probability parameter and the adjusted second probability parameter includes: obtaining Z initial sampling results with sampling result types of memory allocation failure types, and obtaining X initial sampling results with sampling result types of memory allocation success types, wherein Z, X is a positive integer, and Z+X=M; reducing the first initial probability parameters associated with the Z initial sampling results, and raising or keeping the second initial probability parameters associated with the Z initial sampling results unchanged to obtain Z adjusted first probability parameters and Z adjusted second probability parameters; and reducing second initial probability parameters associated with the X initial sampling results, and raising or keeping the first initial probability parameters associated with the X initial sampling results unchanged to obtain X adjusted first probability parameters and X adjusted second probability parameters.
It should be noted that, by adjusting the first initial probability parameter and the second initial probability parameter, the shape of the beta distribution may be controlled, for example, when α and β are smaller, the beta distribution tends to approach 0 and 1, which means that uncertainty is larger, where the smaller α is, the closer α is to 0, the smaller β is, and the closer β is to 1; when α, β is larger, the beta distribution is more concentrated near the mean, indicating higher certainty.
Specifically, when the initial probability parameters are adjusted, the sampling result types of the sampling results need to be judged, so as to obtain initial sampling results with a plurality of sampling result types being memory allocation failure types, and obtain initial sampling results with a plurality of sampling result types being memory allocation success types. Further, the parameter value of the first initial probability parameter associated with the initial sampling result with the sampling result type being the memory allocation failure type can be reduced, for example, the first initial probability parameter can be reduced from 0.5 to 0.3, so that the probability of allocation failure is improved, and the second initial probability parameter is raised or kept unchanged; and the parameter value of the second initial probability parameter associated with the initial sampling result with the sampling result type being the memory allocation success type is reduced, and the first initial probability parameter is raised or kept unchanged, for example, the second initial probability parameter can be reduced from 0.5 to 0.3, so that the probability of allocation failure is reduced.
Further, after the first initial probability parameter and the second initial probability parameter are adjusted, a sampling probability value may be obtained based on the adjusted first probability parameter, the adjusted second probability parameter, and a module value of each program module, specifically, the beta function value B (α, β) may be obtained by calculating the following formula:
Further calculating a sampling probability value by using the beta function value, the adjusted first probability parameter, the adjusted second probability parameter and the module value of each program module:
and after the sampling probability value is obtained by calculation, determining the type of the sampling result according to the sampling probability value, determining the sampling result type of the sampling result correlated with the sampling probability value of 1 as the memory allocation success type, and determining the sampling result type of the sampling result correlated with the sampling probability value of 0 as the memory allocation failure type, wherein the first preset value in the embodiment can be 1, and the second preset value can be 0.
For example, as shown in table 1, after the calculation of the sampling results for 8 program modules, it is determined that the parameter value of the first initial probability parameter associated with the program module D, G needs to be reduced, the parameter value of the first initial probability parameter associated with the program module B, D, G, H needs to be reduced, and the parameter value of the second initial probability parameter associated with the program module A, C, E, F needs to be reduced. According to the method, the first initial probability parameter and the second initial probability parameter are adjusted, so that the probability of memory allocation failure of different program modules is increased, abnormal program modules are judged more accurately, and the detection efficiency is improved.
TABLE 1
In order to improve the detection accuracy, optionally, in the method for detecting abnormal memory allocation provided in the embodiment of the present application, before determining the program module associated with the N target sampling results as the abnormal module, the method further includes: acquiring a second operation result of the program code to be detected, wherein the second operation result refers to a result of operating the program code to be detected after M target sampling results are obtained; under the condition that the second operation result represents that the operation of the program code to be detected is abnormal, executing the step of acquiring N target sampling results with sampling result types of memory allocation failure types; and under the condition that the second operation result represents that the operation of the program code to be detected is normal, executing the program code to be detected until the operation of the program code to be detected is abnormal, and executing the step of acquiring N target sampling results with the sampling result type of the memory allocation failure type.
Specifically, after the initial sampling result is adjusted and a target sampling result is obtained, the program code to be detected needs to be executed again, whether the running result obtained after the execution is completed represents the running abnormality of the program code to be detected or not is judged, when the running result represents the running abnormality of the program code to be detected or not, the target sampling result with the sampling result type of the preset proportion being the memory allocation failure type can be obtained from the running result, and the program module related to the target sampling result is determined to be an abnormal module; when the running result indicates whether the running of the program code to be detected is normal, the program code to be detected needs to be executed again until the obtained running result indicates that the running of the program code to be detected is abnormal, the related sampling results are obtained, then the target sampling result with the sampling result type of the preset proportion being the memory allocation failure type is obtained from the sampling results, and the program module related to the target sampling result is determined to be an abnormal module. According to the embodiment, the running result of the program code to be detected is judged, so that the range of the program module with hidden danger of memory allocation failure is further reduced, and the detection precision is further improved.
It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that illustrated herein.
The embodiment of the application also provides a system for detecting abnormal memory allocation, and fig. 2 is a schematic diagram of the system for detecting abnormal memory allocation provided according to the embodiment of the application, as shown in fig. 2, the system is installed under the condition that a Web server deploys a firewall, and the protection function operation equipment is started under the real flow environment to monitor the operation condition of the equipment. When the equipment is abnormal, the equipment is recorded on a hard disk of the equipment and is stored, and the system comprises: sampling module, monitoring module, firewall and client used by developer.
Specifically, the sampling module is responsible for acquiring a program module and updating a sampling result, namely acquiring the sampling result according to the sampling probability, and adjusting the sampling probability by means of the running result of the program code to be detected monitored by the monitoring module after the program runs; the monitoring module is used for monitoring the running result of the program code to be detected in the actual running environment, tracking the sampling result of each program module, recording the information of the program module with the sampling result type of the memory allocation failure type in the program module when the abnormal condition occurs in the running of the program code to be detected, packaging and archiving the records to ensure that the information is not lost, and facilitating the positioning of a developer. It should be noted that, the sampling module and the monitoring module act on the firewall together to find out possible program holes and return information to the client used by the developer.
The embodiment of the application also provides a method for detecting abnormal memory allocation, which is operated in the system for detecting abnormal memory allocation, and fig. 3 is a schematic diagram of an alternative method for detecting abnormal memory allocation according to the embodiment of the application, as shown in fig. 3, and the method includes:
when the memory allocation task is executed, the situation that the memory allocation fails easily occurs, at this time, the variable of the application memory cannot get the desired memory space, and normal operation is affected, in order to identify the scene of occurrence of the memory allocation abnormality, the program code to be detected for applying the memory allocation can be divided into modules, and when the module division is performed, the program code to be detected can be scanned and detected based on the code detection tool, so that a plurality of target codes are obtained. Further, in order to facilitate the subsequent identification and test processing of the object codes, the task type of the memory allocation task executed by each object code may be obtained, and the task type may be marked on the corresponding object code, so that the marked object code may be determined as a program module.
Further, in order to determine whether each program module applies for memory successfully, the program modules may be sampled, at this time, a sampling probability value may be calculated by using a probability distribution, and then a sampling result may be determined by the sampling probability value, so as to perform a determination based on the sampling result. Further, running the program code to be detected under the real environment to obtain a running result, after the running result and the sampling result are recorded, continuing to monitor the running condition of the program code to be detected, if the running result of the program code is abnormal, recording the sampling result and the process call stack information of the program module with the sampling result type of the memory allocation failure type in the program module, storing the information in a database, simultaneously obtaining the result number of which the sampling result type of all initial sampling results is the memory allocation failure type, and judging whether the ratio of the number to the total number of the sampling results is smaller than a preset ratio (for example, the preset ratio is 10%).
When the ratio of the number of results to the total number of sampling results is smaller than a preset ratio, a plurality of initial sampling results can be obtained from the initial sampling results, and the program module associated with the selected initial sampling results is determined to be an abnormal module.
If the ratio of the number of the results to the total number of the sampling results is greater than or equal to a preset ratio, the first initial probability parameter alpha and the second initial probability parameter beta which are related when the sampling probability value is calculated are required to be adjusted, the sampling probability value is obtained based on the adjusted first probability parameter, the adjusted second probability parameter and the module value of each program module, the target sampling result is determined according to the sampling probability value, a plurality of sampling results are selected from the target sampling results, and the program module related to the sampling result is determined to be an abnormal module.
If the running result of the program code is normal running, the program code to be detected needs to be re-executed until the running result of the program code is abnormal running, the related sampling result is obtained, then the target sampling result with the sampling result type of the preset proportion being the memory allocation failure type is obtained from the sampling results, the program module related to the target sampling result is determined to be an abnormal module, and finally the program code to be detected is optimized and adjusted according to the related information of the abnormal module.
According to the method, the device and the system, the program code to be detected is obtained, the program code to be detected is divided into modules, the sampling result of each program module is calculated, the sampling result is adjusted according to the operation result of the program code to be detected, a plurality of target sampling results are obtained, the target sampling result with the sampling result type being the memory allocation failure type is obtained from the plurality of target sampling results, the program module associated with the target sampling results is determined to be an abnormal module, and the effect of improving the efficiency of problem location detection on the memory allocation failure of the program code to be detected is achieved.
The embodiment of the application also provides a device for detecting the memory allocation abnormality, and it should be noted that the device for detecting the memory allocation abnormality of the embodiment of the application can be used for executing the method for detecting the memory allocation abnormality provided by the embodiment of the application. The following describes a device for detecting abnormal memory allocation provided in the embodiments of the present application.
Fig. 4 is a schematic diagram of a device for detecting abnormal memory allocation according to an embodiment of the present application, as shown in fig. 4, where the device includes: a first acquisition unit 40, a calculation unit 41, a second acquisition unit 42.
The first obtaining unit 40 is configured to obtain a program code to be detected, and divide the program code to be detected into M program modules, where the program code to be detected is a code for applying for memory allocation, and M is a positive integer;
the calculating unit 41 is configured to calculate an initial sampling result of each of the M program modules, obtain M initial sampling results, execute a program code to be detected, obtain a first operation result of the program code to be detected, and adjust the M initial sampling results according to the first operation result, so as to obtain M target sampling results, where the M initial sampling results are results of success or failure in memory allocation of the M program modules, and sampling result types of the M initial sampling results and the M target sampling results include a memory allocation failure type and a memory allocation success type;
the second obtaining unit 42 is configured to obtain N target sampling results with a sampling result type being a memory allocation failure type, and determine a program module associated with the N target sampling results as an abnormal module, where N is a positive integer.
Optionally, in the apparatus for detecting abnormal memory allocation provided in the embodiment of the present application, the first obtaining unit 40 includes: the calling module is used for calling the code detection tool to extract target codes in the program codes to be detected to obtain M target codes; the identification module is used for identifying task types of memory allocation tasks associated with M target codes to obtain M task types, and marking the M target codes by using the M task types to obtain M program modules.
Optionally, in the apparatus for detecting abnormal memory allocation provided in the embodiment of the present application, the calculating unit 41 includes: the first acquisition module is used for acquiring the result number of the initial sampling result with the sampling result type of the memory allocation failure type under the condition that the first operation result represents that the program code to be detected is abnormal in operation; the judging module is used for judging whether the ratio of the number of results to M is smaller than or equal to a preset ratio; the execution module is used for executing the step of adjusting M initial sampling results according to the first operation result to obtain M target sampling results when the ratio of the number of results to M is larger than a preset ratio; the apparatus further comprises: the first determining module is configured to obtain N initial sampling results from M initial sampling results when a ratio of the number of results to M is less than or equal to a preset ratio, and determine a program module associated with the N initial sampling results as an abnormal module, where the N initial sampling results are sampling results with a sampling result type that is a memory allocation failure type.
Optionally, in the apparatus for detecting abnormal memory allocation provided in the embodiment of the present application, the calculating unit 41 includes: the first calculation module is used for calculating to obtain a beta function value according to the first initial probability parameter and the second initial probability parameter, and calculating sampling probability values according to the beta function value and initial values of the M program modules to obtain M sampling probability values; the second determining module is used for determining M initial sampling results according to the M sampling probability values, wherein when the M-th sampling probability value is a first preset value, the sampling result type of the M-th initial sampling result is a memory allocation success type; when the M-th sampling probability value is a second preset value, the sampling result type of the M-th initial sampling result is determined to be a memory allocation failure type, M is a positive integer less than or equal to M, and the first preset value is greater than the second preset value.
Optionally, in the apparatus for detecting abnormal memory allocation provided in the embodiment of the present application, the calculating unit 41 includes: the adjustment module is used for carrying out parameter adjustment on the first initial probability parameter and the second initial probability parameter under the condition that the first operation result represents that the operation of the program code to be detected is abnormal, so as to obtain an adjusted first probability parameter and an adjusted second probability parameter; and the second calculation module is used for calculating sampling probability values of target program modules in the M program modules according to the adjusted first probability parameters and the adjusted second probability parameters to obtain M target sampling probability values, and determining M target sampling results according to the M target sampling probability values, wherein the target program modules are program modules which enable the program codes to be detected to run abnormally.
Optionally, in the apparatus for detecting abnormal memory allocation provided in the embodiment of the present application, the calculating unit 41 includes: the second acquisition module is used for acquiring Z initial sampling results with sampling result types of memory allocation failure types and acquiring X initial sampling results with sampling result types of memory allocation success types, wherein Z, X is a positive integer, and Z+X=M; the first reduction module is used for reducing the first initial probability parameters associated with the Z initial sampling results, and increasing or keeping the second initial probability parameters associated with the Z initial sampling results unchanged to obtain Z adjusted first probability parameters and Z adjusted second probability parameters; the second reduction module is used for reducing second initial probability parameters associated with the X initial sampling results, and increasing or keeping the first initial probability parameters associated with the X initial sampling results unchanged to obtain X adjusted first probability parameters and X adjusted second probability parameters.
Optionally, in the device for detecting abnormal memory allocation provided in the embodiment of the present application, the device further includes: the third obtaining unit is used for obtaining a second operation result of the program code to be detected before the program module related to the N target sampling results is determined to be an abnormal module, wherein the second operation result refers to a result of operating the program code to be detected after the M target sampling results are obtained; the first execution unit is used for executing the step of acquiring N target sampling results with sampling result types of memory allocation failure types under the condition that the second operation result represents that the program code to be detected is abnormal in operation; and the second execution unit is used for executing the program code to be detected until the program code to be detected runs abnormally under the condition that the second running result represents that the program code to be detected runs normally, and executing the step of acquiring N target sampling results with the sampling result type of the memory allocation failure type.
According to the detecting device for the abnormal memory allocation provided by the embodiment of the application, the first obtaining unit 40 is used for obtaining the program codes to be detected, and the program codes to be detected are subjected to module division to obtain M program modules, wherein the program codes to be detected are codes for applying for memory allocation, and M is a positive integer; the calculating unit 41 calculates an initial sampling result of each of the M program modules to obtain M initial sampling results, executes a program code to be detected to obtain a first operation result of the program code to be detected, and adjusts the M initial sampling results according to the first operation result to obtain M target sampling results, where the M initial sampling results are results of success or failure in memory allocation of the M program modules, and sampling result types of the M initial sampling results and the M target sampling results include a memory allocation failure type and a memory allocation success type; the second obtaining unit 42 obtains N target sampling results with sampling result types being memory allocation failure types, and determines the program modules associated with the N target sampling results as abnormal modules, where N is a positive integer, so as to solve the problem of low detection efficiency when performing problem location detection on memory allocation failure of the program code to be detected in the related art.
The detecting device for abnormal memory allocation includes a processor and a memory, wherein the first acquiring unit 40, the calculating unit 41, the second acquiring unit 42, etc. are stored in the memory as program units, and the processor executes the program units stored in the memory to realize corresponding functions.
The processor includes a kernel, and the kernel fetches the corresponding program unit from the memory. The kernel can be provided with one or more than one kernel, and the problem of low detection efficiency when the problem positioning detection is carried out on the memory allocation failure of the program code to be detected in the related technology is solved by adjusting the kernel parameters.
The memory may include volatile memory, random Access Memory (RAM), and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM), among other forms in computer readable media, the memory including at least one memory chip.
The embodiment of the invention provides a computer storage medium which is used for storing a program, wherein the program is used for controlling equipment where the computer storage medium is located to execute a method for detecting abnormal memory allocation when running.
Fig. 5 is a schematic diagram of an electronic device according to an embodiment of the present application, and as shown in fig. 5, an embodiment of the present invention provides an electronic device, where an electronic device 50 includes a processor, a memory, and a program stored on the memory and executable on the processor, and the processor is configured to execute computer readable instructions, where the computer readable instructions execute a method for detecting a memory allocation abnormality when running. The device herein may be a server, PC, PAD, cell phone, etc.
The present application also provides a computer program product adapted to perform a method of detecting a memory allocation exception when executed on a data processing apparatus.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, etc., such as Read Only Memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises an element.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and changes may be made to the present application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. which are within the spirit and principles of the present application are intended to be included within the scope of the claims of the present application.
Claims (10)
1. The method for detecting the abnormal memory allocation is characterized by comprising the following steps:
obtaining a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying memory allocation, and M is a positive integer;
calculating initial sampling results of each of the M program modules to obtain M initial sampling results, executing the program code to be detected to obtain a first operation result of the program code to be detected, and adjusting the M initial sampling results according to the first operation result to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and the sampling result types of the M initial sampling results and the M target sampling results both comprise a memory allocation failure type and a memory allocation success type;
And acquiring N target sampling results with the sampling result type being the memory allocation failure type, and determining a program module associated with the N target sampling results as an abnormal module, wherein N is a positive integer.
2. The method of claim 1, wherein obtaining program code to be detected, and performing module division on the program code to be detected, obtaining M program modules comprises:
calling a code detection tool to extract target codes in the program codes to be detected to obtain M target codes;
and identifying task types of memory allocation tasks associated with the M target codes to obtain M task types, and marking the M target codes by utilizing the M task types to obtain the M program modules.
3. The method of claim 1, wherein adjusting the M initial sampling results based on the first operation result to obtain M target sampling results comprises:
under the condition that the first operation result represents that the program code to be detected is abnormal in operation, obtaining the result number of the initial sampling result with the sampling result type being the memory allocation failure type;
judging whether the ratio of the number of results to the M is smaller than or equal to a preset ratio;
Executing the step of adjusting the M initial sampling results according to the first operation result to obtain M target sampling results under the condition that the ratio of the result number to the M is larger than the preset ratio;
the method further comprises the steps of:
and under the condition that the ratio of the number of results to the M is smaller than or equal to the preset ratio, acquiring N initial sampling results from the M initial sampling results, and determining a program module associated with the N initial sampling results as the abnormal module, wherein the N initial sampling results refer to sampling results with sampling result types of the memory allocation failure types.
4. The method of claim 1, wherein calculating an initial sampling result for each of the M program modules comprises:
calculating to obtain a beta function value according to the first initial probability parameter and the second initial probability parameter, and calculating sampling probability values according to the beta function value and initial values of the M program modules to obtain M sampling probability values;
determining the M initial sampling results according to the M sampling probability values, wherein when the M-th sampling probability value is a first preset value, the sampling result type of the M-th initial sampling result is the memory allocation success type; when the mth sampling probability value is a second preset value, determining the sampling result type of the mth initial sampling result as the memory allocation failure type, wherein M is a positive integer less than or equal to M, and the first preset value is greater than the second preset value.
5. The method of claim 4, wherein adjusting the M initial sampling results based on the first operation result to obtain M target sampling results comprises:
under the condition that the first operation result represents that the to-be-detected program code is abnormal in operation, carrying out parameter adjustment on the first initial probability parameter and the second initial probability parameter to obtain an adjusted first probability parameter and an adjusted second probability parameter;
calculating sampling probability values of target program modules in the M program modules according to the adjusted first probability parameters and the adjusted second probability parameters to obtain M target sampling probability values, and determining M target sampling results according to the M target sampling probability values, wherein the target program modules are program modules which enable the program codes to be detected to run abnormally.
6. The method of claim 5, wherein performing parameter adjustment on the first initial probability parameter and the second initial probability parameter to obtain an adjusted first probability parameter and an adjusted second probability parameter comprises:
obtaining Z initial sampling results with the sampling result type being the memory allocation failure type, and obtaining X initial sampling results with the sampling result type being the memory allocation success type, wherein Z, X is a positive integer, and Z+X=M;
Reducing the first initial probability parameters associated with the Z initial sampling results, and raising or keeping the second initial probability parameters associated with the Z initial sampling results unchanged to obtain Z adjusted first probability parameters and Z adjusted second probability parameters;
and reducing second initial probability parameters associated with the X initial sampling results, and raising or keeping the first initial probability parameters associated with the X initial sampling results unchanged to obtain X adjusted first probability parameters and X adjusted second probability parameters.
7. The method of claim 1, wherein prior to determining the program module associated with the N target sampling results as an anomaly module, the method further comprises:
acquiring a second operation result of the program code to be detected, wherein the second operation result refers to a result of operating the program code to be detected after the M target sampling results are obtained;
executing the step of acquiring N target sampling results with the sampling result type being the memory allocation failure type under the condition that the second operation result represents that the program code to be detected is abnormal in operation;
and under the condition that the second operation result represents that the operation of the program code to be detected is normal, executing the program code to be detected until the operation of the program code to be detected is abnormal, and executing the step of acquiring N target sampling results with the sampling result type of the memory allocation failure type.
8. The utility model provides a detection device of memory allocation exception which characterized in that includes:
the first acquisition unit is used for acquiring a program code to be detected, and carrying out module division on the program code to be detected to obtain M program modules, wherein the program code to be detected is a code for applying memory allocation, and M is a positive integer;
the computing unit is used for computing initial sampling results of each of the M program modules to obtain M initial sampling results, executing the program code to be detected to obtain a first operation result of the program code to be detected, and adjusting the M initial sampling results according to the first operation result to obtain M target sampling results, wherein the M initial sampling results are results of success or failure of memory allocation of the M program modules, and the sampling result types of the M initial sampling results and the M target sampling results comprise a memory allocation failure type and a memory allocation success type;
the second obtaining unit is used for obtaining N target sampling results with sampling result types of the memory allocation failure types, and determining program modules related to the N target sampling results as abnormal modules, wherein N is a positive integer.
9. A computer storage medium for storing a program, wherein the program when executed controls an apparatus in which the computer storage medium is located to execute the method for detecting a memory allocation abnormality according to any one of claims 1 to 7.
10. An electronic device comprising one or more processors and a memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of detecting a memory allocation exception of any of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311867786.2A CN117762676A (en) | 2023-12-29 | 2023-12-29 | Method and device for detecting abnormal memory allocation, storage medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311867786.2A CN117762676A (en) | 2023-12-29 | 2023-12-29 | Method and device for detecting abnormal memory allocation, storage medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117762676A true CN117762676A (en) | 2024-03-26 |
Family
ID=90310524
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311867786.2A Pending CN117762676A (en) | 2023-12-29 | 2023-12-29 | Method and device for detecting abnormal memory allocation, storage medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117762676A (en) |
-
2023
- 2023-12-29 CN CN202311867786.2A patent/CN117762676A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106201829A (en) | Monitoring Threshold and device, monitoring alarm method, Apparatus and system | |
CN111026080A (en) | Hardware-in-loop test method and device for controller | |
CN113641526A (en) | Alarm root cause positioning method and device, electronic equipment and computer storage medium | |
CN113468384B (en) | Processing method, device, storage medium and processor for network information source information | |
CN104298589B (en) | A kind of performance test methods and equipment | |
CN112749035B (en) | Abnormality detection method, abnormality detection device, and computer-readable medium | |
CN110928941B (en) | Data fragment extraction method and device | |
CN117762676A (en) | Method and device for detecting abnormal memory allocation, storage medium and electronic equipment | |
CN115757138A (en) | Method and device for determining script abnormal reason, storage medium and electronic equipment | |
CN116185706A (en) | Data backup method and device, computing and storage medium and electronic equipment | |
CN107908516B (en) | Data display method and device | |
CN107797915B (en) | Fault repairing method, device and system | |
EP3556084B1 (en) | Application-sensitive strategy for server decommissioning | |
CN116124218B (en) | Transformer fault diagnosis method and device, storage medium and electronic equipment | |
CN110717131A (en) | Page revising monitoring method and related system | |
CN116244204A (en) | Program test coverage rate determining method, device and storage medium | |
CN115718672B (en) | Application abnormality detection method and device | |
CN118295346B (en) | Equipment management method and system based on vibration detector | |
CN107291613B (en) | Functional node abnormity simulation method and device | |
CN115098373A (en) | Processing method and device for test question list, electronic equipment and storage medium | |
CN113489740B (en) | Processing method, device, storage medium and processor for network threat information | |
CN113282304B (en) | System for identifying virtual machine based on app installation list | |
CN117632007A (en) | Data storage method and device, storage medium and electronic equipment | |
CN116881036A (en) | Method and device for determining abnormal operation data of server and nonvolatile storage medium | |
CN114048476A (en) | Malicious command interception method and device, storage medium and processor |
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 |