Background
When a client loads a page, data of the page to be loaded needs to be acquired from a server, then a blank page is displayed on a screen according to the acquired data, then content rendering is carried out on the page, and after the content rendering of the page is finished, the page loading is finished.
In the client monitoring technology, detecting the page loading completion time is an important ability, and can help a developer to know the time consumed for jumping from a page to the first screen rendering, the waiting time of a user, the rendering problem caused by server interface data and the like. How to accurately determine the time for completing page loading is a key for improving the time-consuming detection accuracy of page loading.
Disclosure of Invention
The embodiment of the disclosure at least provides a page loading detection method and device.
In a first aspect, an embodiment of the present disclosure provides a page loading detection method, including:
after the target page starts to be loaded, screen capturing is carried out according to a preset time interval, and a screen capturing picture is obtained;
respectively calculating the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture from the captured second screen capture picture;
and determining that the target page is loaded completely after the difference value between the first hash value and the second hash value is smaller than a set threshold value.
In an optional embodiment, the determining that the target page is loaded completely after the difference between the first hash value and the second hash value is smaller than a set threshold includes:
after determining that the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture is smaller than a set threshold value for N times, determining that the target page is completely loaded; n is a positive integer greater than 1.
In an optional implementation manner, after determining that the target page loading is completed, the method further includes:
and determining the loading time of the target page based on the moment when the target page starts to be loaded and the moment corresponding to the currently obtained screenshot picture.
In an optional embodiment, the hash value of the screenshot picture is determined according to the following steps:
converting the screen capture picture into a gray scale image to obtain the gray scale value of each pixel point in the gray scale image;
and determining the hash value of the screen capture picture based on the gray value of each pixel point in the gray map.
In an optional embodiment, the determining the hash value of the screenshot picture based on the gray scale value of each pixel point in the gray scale map includes:
determining the difference value of the gray value between the next pixel point and the previous pixel point in each row of pixel points of the gray map;
and determining the hash value of the screen capture picture based on the difference value of the gray values.
In an optional embodiment, the converting the screenshot picture into a grayscale map includes:
compressing the screen shot picture to a preset size;
and converting the screen capture picture compressed to the preset size into a gray scale image.
In a second aspect, an embodiment of the present disclosure further provides a page loading detection apparatus, including:
the acquisition module is used for carrying out screen capture according to a preset time interval after the target page starts to be loaded, and acquiring a screen capture picture;
the calculation module is used for respectively calculating the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture from the intercepted second screen capture picture;
and the first determining module is used for determining that the target page is loaded completely after the difference value between the first hash value and the second hash value is smaller than a set threshold value.
In an alternative embodiment, the apparatus further comprises:
and the second determining module is used for determining the time consumed by loading the target page based on the moment when the target page starts to be loaded and the moment corresponding to the currently obtained screenshot picture after the target page is determined to be loaded.
In an optional implementation manner, the first determining module is specifically configured to:
after determining that the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture is smaller than a set threshold value for N times, determining that the target page is completely loaded; n is a positive integer greater than 1.
In an optional embodiment, the apparatus further comprises a third determining module configured to:
converting the screen capture picture into a gray scale image to obtain the gray scale value of each pixel point in the gray scale image;
and determining the hash value of the screen capture picture based on the gray value of each pixel point in the gray map.
In an optional implementation manner, when determining the hash value of the screenshot picture based on the gray value of each pixel point in the gray map, the third determining module is specifically configured to:
determining the difference value of the gray value between the next pixel point and the previous pixel point in each row of pixel points of the gray map;
and determining the hash value of the screen capture picture based on the difference value of the gray values.
In an optional implementation manner, when the third determining module converts the screen capture picture into a grayscale map, the third determining module is specifically configured to:
compressing the screen shot picture to a preset size;
and converting the screen capture picture compressed to the preset size into a gray scale image.
In a third aspect, an embodiment of the present disclosure further provides a computer device, including: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating via the bus when the computer device is running, the machine-readable instructions when executed by the processor performing the steps of the first aspect described above, or any possible implementation of the first aspect.
In a fourth aspect, this disclosed embodiment also provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps in the first aspect or any one of the possible implementation manners of the first aspect.
For the description of the effects of the page loading detection apparatus, the computer device, and the computer-readable storage medium, reference is made to the description of the page loading detection method, which is not repeated herein.
According to the page loading detection method and device provided by the embodiment of the disclosure, after a target page is loaded, a screen of the target page being loaded is captured according to a preset time interval, a difference value between a first hash value corresponding to a currently obtained screen capture picture and a second hash value corresponding to a previous screen capture picture is calculated, the difference value between the first hash value and the second hash value can represent a difference degree between the currently obtained screen capture picture and the previous screen capture picture of the target page, and if the difference degree between the two screen capture pictures is smaller, it is indicated that display content of the target page is basically stable, page loading completion can be determined, so that the page can be rapidly and accurately detected to be in a loading completion state, and further, relevant page performances such as time consumption for loading and the like can be evaluated.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
Research shows that when time consumption detection is carried out on page loading, point burying can be carried out on a page display callback port provided by a system, and the time of the page display on a screen is counted.
Based on the research, the disclosure provides a page loading detection method, which can quickly and accurately detect that a page is in a loading completion state, thereby improving the page loading time-consuming detection accuracy.
The above-mentioned drawbacks are the results of the inventor after practical and careful study, and therefore, the discovery process of the above-mentioned problems and the solutions proposed by the present disclosure to the above-mentioned problems should be the contribution of the inventor in the process of the present disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
To facilitate understanding of the present embodiment, first, a page loading test method disclosed in the embodiments of the present disclosure is described in detail, where an execution subject of the page loading test method provided in the embodiments of the present disclosure is generally a computer device with certain computing capability, and the computer device includes, for example: a terminal device, which may be a User Equipment (UE), a mobile device, a User terminal, a cellular phone, a cordless phone, a Personal Digital Assistant (PDA), a handheld device, a computing device, a vehicle mounted device, a wearable device, or a server or other processing device. In some possible implementations, the page load test method may be implemented by a processor calling computer readable instructions stored in a memory.
The following describes a page loading test method provided by the embodiment of the present disclosure by taking an execution subject as a terminal device.
Referring to fig. 1, a flowchart of a page loading test method provided in the embodiment of the present disclosure is shown, where the method includes steps S101 to S103, where:
s101: and after the target page starts to be loaded, screen capture is carried out according to a preset time interval, and a screen capture picture is obtained.
In this step, after the terminal device starts to load the target page, the terminal device may capture a screen of the target page according to a preset time interval, so as to obtain a screen capture picture of the target page.
The operation system of the terminal device may be an IOS system.
Here, since the time consumption of page loading is usually short, usually within several seconds, the preset time interval may be determined according to the expected time consumption of page loading, for example, if the expected time consumption of page loading is within several seconds, the preset time interval may be set to millisecond level.
Further, the length of the preset time interval affects the accuracy of the time-consuming test for page loading and the occupied computing resources, and the shorter the preset time interval is, the more accurate the loading completion time of the detected target page is, and the more computing resources are occupied.
S102: and respectively calculating the difference value between the first hash value corresponding to the currently obtained screen capture picture and the second hash value corresponding to the previous screen capture picture from the captured second screen capture picture.
In this step, each time a screenshot picture is captured, the hash value of the screenshot picture may be calculated, and a difference between a first hash value corresponding to the currently obtained screenshot picture and a second hash value corresponding to the previous screenshot picture is calculated from a captured second screenshot picture.
The algorithm for calculating the hash value can be a perceptual hash algorithm, the perceptual hash algorithm is an algorithm for calculating the hash value of the picture, the fingerprint hash value associated with the content of the picture can be calculated, the similarity comparison between the pictures can be used, the higher the similarity is, the smaller the fingerprint hash difference is, the lower the similarity is, and the larger the fingerprint hash difference is.
Illustratively, the hash value of the screenshot picture may be determined by:
converting the screen capture picture into a gray scale image to obtain the gray scale value of each pixel point in the gray scale image;
and determining the hash value of the screen capture picture based on the gray value of each pixel point in the gray map.
In this step, the screenshot picture can be compressed to a preset size, and then the screenshot picture compressed to the preset size is converted into a gray scale image, so as to obtain the gray scale value of each pixel point in the gray scale image; then, the difference value of the gray value between the next pixel point and the previous pixel point in each row of pixel points of the gray map can be determined; and determining the hash value of the screen capture picture based on the difference value of the gray values.
Specifically, the screenshot picture may be compressed first, and the preset size may be 8 × 8, which is 64 pixels. Therefore, high frequency and details in the screenshot picture can be removed, only the structural brightness and darkness are kept, and after the screenshot picture is compressed, the screenshot picture can be converted into a gray scale image to obtain the gray scale value of each pixel point. Then, in each row of pixel points of a gray scale image of the screenshot picture, subtracting the gray scale value of the previous pixel point from the gray scale value of the next pixel point to obtain a difference value of the gray scale value between the next pixel point and the previous pixel point, and then configuring a corresponding hash value for each difference value according to the numerical value of each difference value, illustratively, if the difference value of the gray scale value between the next pixel point and the migration pixel point is greater than or equal to 0, a hash value of "1" may be assigned to the difference value, and if the difference value of the gray scale value between the next pixel point and the migration pixel point is less than 0, a hash value of "0" may be assigned to the difference value, so that a 7 × 8 matrix may be finally obtained, where elements in the matrix are the hash values corresponding to each difference value, and the matrix is the hash value of the screenshot picture.
S103: and determining that the target page is loaded completely after the difference value between the first hash value and the second hash value is smaller than a set threshold value.
In this step, after it is determined that a difference value between a first hash value corresponding to a currently obtained screenshot picture and a second hash value corresponding to a previous screenshot picture is less than a set threshold value N times continuously, it is determined that the target page is completely loaded; n is a positive integer greater than 1.
When the page is in the loading and rendering processes, the view level of the page is unstable, the content is changed all the time, and when the page rendering loading is completed, the view level is basically in a stable state, and the content is not changed greatly any more. Therefore, when the difference between the first hash value and the second hash value is smaller than the set threshold, it can be shown that the similarity between the page corresponding to the previous screenshot picture and the page corresponding to the next screenshot picture is high, and the difference is small, and if the difference between the first hash value and the second hash value is determined to be smaller than the set threshold for N consecutive times, it can be determined that the view level of the target page is in a stable state, and the page loading is considered to be completed.
In a possible implementation manner, after the target page is determined to be loaded, the time consumed for loading the target page can be determined based on the time when the target page starts to be loaded and the time corresponding to the currently obtained screenshot picture.
For example, the time when the target page starts to be loaded is taken as the starting time, the capturing time of the currently obtained screenshot image is taken as the ending time, and the time length from the starting time to the time within the ending time is taken as the time consumed by loading the target page.
According to the page loading detection method provided by the embodiment of the disclosure, after a target page is loaded, a screen of the target page being loaded is captured according to a preset time interval, and a difference value between a first hash value corresponding to a previously obtained screen capture picture and a second hash value corresponding to a previously obtained screen capture picture is calculated, wherein the difference value between the first hash value and the second hash value can represent a difference degree between the currently obtained screen capture picture and the previously obtained screen capture picture of the target page, and if the difference degree between the two screen capture pictures is smaller, it is indicated that display content of the target page is basically stable, page loading completion can be determined, so that the page can be rapidly and accurately detected to be in a state of being loaded, and thus page loading time consumption detection accuracy is improved.
Referring to fig. 2, a flowchart of another page loading test method provided in the embodiment of the present disclosure is shown, the method comprises the steps of regularly acquiring a screen shot after a page is loaded, compressing the size of the acquired screen shot, converting the compressed screen shot into a gray-scale image, then, calculating the gray difference value between the next pixel point and the previous pixel point in each line of pixel points in the gray map to obtain a fingerprint hash value (hash), comparing the fingerprint hash of the current screen capture with the fingerprint hash of the previous screen capture to obtain the difference value of the fingerprint hash, if the fingerprint hash difference value is less than the set threshold value for N times, then it may be determined that the page is in a stable state, it may be determined that the page loading is complete, the acquisition of the page screenshot may be stopped, and if the page is not in a stable state, the step of acquiring the screen shot can be executed in a timed mode, and a loop is entered until the page loading is determined to be completed.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, the embodiment of the present disclosure further provides a page loading detection apparatus corresponding to the page loading detection method, and since the principle of the apparatus in the embodiment of the present disclosure for solving the problem is similar to the page loading detection method in the embodiment of the present disclosure, the implementation of the apparatus may refer to the implementation of the method, and repeated details are not described again.
Referring to fig. 3, which is a schematic diagram of an architecture of a page loading detection apparatus provided in an embodiment of the present disclosure, the apparatus includes: an acquisition module 310, a calculation module 320, a first determination module 330; wherein the content of the first and second substances,
the obtaining module 310 is configured to capture a screen at a preset time interval after the target page starts to be loaded, and obtain a screen capture picture;
a calculating module 320, configured to calculate, starting from the second captured screenshot picture, differences between a first hash value corresponding to the currently obtained screenshot picture and a second hash value corresponding to the previous screenshot picture;
a first determining module 330, configured to determine that the target page is loaded completely after a difference between the first hash value and the second hash value is smaller than a set threshold.
The page loading detection device provided by the embodiment of the disclosure performs screen capturing on a target page being loaded according to a preset time interval after the target page starts to be loaded, calculates a difference value between a first hash value corresponding to a previously obtained screen capturing picture and a second hash value corresponding to a previously obtained screen capturing picture, and determines that the page loading is completed if the difference value between the first hash value and the second hash value is smaller than the difference value between the currently obtained screen capturing picture and the previously obtained screen capturing picture of the target page.
In an optional implementation manner, the page loading detection apparatus 300 further includes:
the second determining module 340 is configured to determine, after it is determined that the target page is completely loaded, time consumed for loading the target page based on a time when the target page starts to be loaded and a time corresponding to the currently obtained screenshot picture.
In an optional implementation manner, the first determining module 330 is specifically configured to:
after determining that the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture is smaller than a set threshold value for N times, determining that the target page is completely loaded; n is a positive integer greater than 1.
In an optional implementation manner, the page loading detection apparatus 300 further includes a third determining module 350, configured to:
converting the screen capture picture into a gray scale image to obtain the gray scale value of each pixel point in the gray scale image;
and determining the hash value of the screen capture picture based on the gray value of each pixel point in the gray map.
In an optional implementation manner, when determining the hash value of the screenshot picture based on the gray value of each pixel point in the gray map, the third determining module 350 is specifically configured to:
determining the difference value of the gray value between the next pixel point and the previous pixel point in each row of pixel points of the gray map;
and determining the hash value of the screen capture picture based on the difference value of the gray values.
In an optional implementation manner, when the third determining module 350 converts the screen shot into a grayscale map, it is specifically configured to:
compressing the screen shot picture to a preset size;
and converting the screen capture picture compressed to the preset size into a gray scale image.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
Based on the same technical concept, the embodiment of the disclosure also provides computer equipment. Referring to fig. 4, a schematic structural diagram of a computer device 400 provided in the embodiment of the present disclosure includes a processor 401, a memory 402, and a bus 403. The memory 402 is used for storing execution instructions and includes a memory 4021 and an external memory 4022; the memory 4021 is also referred to as an internal memory, and is configured to temporarily store operation data in the processor 401 and data exchanged with an external memory 4022 such as a hard disk, the processor 401 exchanges data with the external memory 4022 through the memory 4021, and when the computer device 400 operates, the processor 401 communicates with the memory 402 through the bus 403, so that the processor 401 executes the following instructions:
after the target page starts to be loaded, screen capturing is carried out according to a preset time interval, and a screen capturing picture is obtained;
respectively calculating the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture from the captured second screen capture picture;
and determining that the target page is loaded completely after the difference value between the first hash value and the second hash value is smaller than a set threshold value.
In a possible implementation manner, the determining that the target page loading is completed after the difference between the first hash value and the second hash value is smaller than a set threshold by the processor 401 includes:
after determining that the difference value between a first hash value corresponding to the currently obtained screen capture picture and a second hash value corresponding to the previous screen capture picture is smaller than a set threshold value for N times, determining that the target page is completely loaded; n is a positive integer greater than 1.
In one possible implementation, after determining that the target page loading is completed, processor 401 is further configured to:
and determining the loading time of the target page based on the moment when the target page starts to be loaded and the moment corresponding to the currently obtained screenshot picture.
In one possible implementation, the processor 401 is further configured to perform:
converting the screen capture picture into a gray scale image to obtain the gray scale value of each pixel point in the gray scale image;
and determining the hash value of the screen capture picture based on the gray value of each pixel point in the gray map.
In a possible embodiment, the instructions executed by the processor 401 for determining the hash value of the screenshot based on the gray scale value of each pixel point in the gray scale map includes:
determining the difference value of the gray value between the next pixel point and the previous pixel point in each row of pixel points of the gray map;
and determining the hash value of the screen capture picture based on the difference value of the gray values.
In a possible implementation, the instructions executed by the processor 401 for converting the screenshot into a grayscale map include:
compressing the screen shot picture to a preset size;
and converting the screen capture picture compressed to the preset size into a gray scale image.
The embodiments of the present disclosure also provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the page load detection method in the foregoing method embodiments are executed. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The computer program product of the page load detection method provided in the embodiments of the present disclosure includes a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the steps of the page load detection method in the above method embodiments, which may be referred to specifically in the above method embodiments, and are not described herein again.
The embodiments of the present disclosure also provide a computer program, which when executed by a processor implements any one of the methods of the foregoing embodiments. The computer program product may be embodied in hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.