Methods, devices, equipment and storage media for measuring page load time

By using the KVO mode to observe events and record the time when the page is loading, and calculating the time consumption based on the main thread stack information, the problem of complexity and insufficient accuracy of page loading time statistics in the existing technology is solved, and efficient page loading time and accuracy are achieved. Time consuming analysis.

CN112650959BActive Publication Date: 2024-09-27TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910963651.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-10-11
Publication Date
2024-09-27
Estimated Expiration
2039-10-11

AI Technical Summary

Technical Problem

The existing page loading time statistics methods are complicated, inefficient or inaccurate, and cannot effectively count the loading time and time-consuming functions of each page.

Method used

Use a runtime mechanism based on the KVO mode to observe page initialization and page visible events, record the start and end times, locate the main thread stack information through sub-threads, calculate the method execution time, and filter out the most time-consuming period from page initialization to content visible method.

Benefits of technology

It achieves accurate statistics on page loading time and automatic detection of time-consuming functions, provides an efficient and low-intrusion method, and can optimize page loading performance for developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112650959B
    Figure CN112650959B
Patent Text Reader

Abstract

The present application provides a method, device, equipment and storage medium for counting the page loading time; the method includes: based on the received operation instruction of loading the page, using the runtime mechanism to perform key-value observation on the business class instance; when a page initialization event is observed, obtaining the first start time of the page initialization event; when a page visible event is observed, obtaining the first end time of the page visible event; based on the first start time and the first end time, determining the page loading time. Through the present application, the page loading time can be efficiently and accurately counted.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a method, device, equipment and storage medium for counting page loading time. Background Art

[0002] With the development of Internet technology and smart terminals, people's entertainment methods have undergone tremendous changes. People can use smart terminals to check news, watch videos, listen to music, play online games, etc. anytime and anywhere. Whether you check news and watch videos through a browser, or play games and shop through dedicated applications, page loading time is an extremely important indicator of user experience. Therefore, counting page loading time has become an important task for developers to improve application performance indicators.

[0003] At present, the methods for counting page loading time mainly include statistical schemes based on runtime swizzling, screenshot analysis of pure color ratio schemes, etc. The existing statistical schemes are either complex to implement, inefficient, or have low statistical accuracy. Summary of the invention

[0004] The embodiments of the present application provide a method, device and storage medium for counting page loading time, which can efficiently and accurately count the page loading time.

[0005] The technical solution of the embodiment of the present application is implemented as follows:

[0006] The present application provides a method for counting page loading time, including:

[0007] Based on the received operation instruction of the loading page, the runtime mechanism is used to perform key-value observation on the business class instance;

[0008] When a page initialization event is observed, obtaining a first start time of the page initialization event;

[0009] When a page visible event is observed, obtaining a first end time of the page visible event;

[0010] A page loading duration is determined based on the first start time and the first end time.

[0011] The present application provides a device for counting page loading time, including:

[0012] The observation module performs key-value observation on the business class instance using the runtime mechanism based on the received operation instructions of the loading page;

[0013] A first acquisition module, configured to acquire a first start time of a page initialization event when a page initialization event is observed;

[0014] A second acquisition module, configured to acquire a first end time of a page visible event when a page visible event is observed;

[0015] A first determining module is used to determine a page loading duration based on the first start time and the first end time.

[0016] The present application provides a device for counting page loading time, including:

[0017] A memory for storing executable instructions;

[0018] The processor is used to implement the method provided in the embodiment of the present application when executing the executable instructions stored in the memory.

[0019] An embodiment of the present application provides a storage medium storing executable instructions for causing a processor to execute and implement the method provided in the embodiment of the present application.

[0020] The embodiments of the present application have the following beneficial effects:

[0021] In the page loading time statistics method provided in the embodiment of the present application, when an operation instruction to load a page is received, a runtime mechanism is used to perform key-value observation on the business class instance to observe page initialization and page visible events, and record the start time of the page initialization time and the end time of the page visible event respectively, so as to accurately and efficiently count the page loading time. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A schematic diagram of the network architecture of a statistical method for page loading time according to an embodiment of the present application;

[0023] Figure 2 is a schematic diagram of the structure of the user terminal 100 provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram of an implementation flow of a method for counting page loading time provided in an embodiment of the present application;

[0025] Figure 4 A schematic diagram of a method execution time implementation process is provided for an embodiment of the present application;

[0026] Figure 5 A schematic diagram of another implementation flow of the method for counting page loading time provided in an embodiment of the present application;

[0027] Figure 6 This is a schematic diagram of using KVO to observe business class instances in an embodiment of the present application;

[0028] Figure 7 A schematic diagram of rewriting the parent class method in an embodiment of the present application;

[0029] Figure 8 This is a schematic diagram of the main thread stack information of an embodiment of the present application. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0031] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0032] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0034] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0035] 1) Runtime: The runtime environment provided by the iOS system can change the behavior of the program at runtime;

[0036] 2) Key Value Observing (KVO) mechanism: The key value observing mechanism implemented using the observer pattern is used to "capture" changes in object properties;

[0037] 3) Page loading time: the time from when a user clicks to open a new page to when the page content becomes visible.

[0038] 4) Base class: When using inheritance, the original class is called the base class, or the parent class.

[0039] 5) Derived class: A class derived from an existing class using the inheritance mechanism can also be called a subclass.

[0040] In order to better understand the embodiments of the present application, the statistical method of page loading time in the related art and the existing shortcomings are first explained.

[0041] In related technologies, there are several statistical schemes for page loading time:

[0042] The first one: a statistical solution based on runtime swizzling.

[0043] The basic idea of ​​this solution is to use swizzling to save an initial time in the viewDidLoad method, then get the time when the page appears in viewDidAppear, calculate the difference between the two times, and finally get the loading time of the page.

[0044] The second one: KVO-based statistical solution.

[0045] There is a problem in the first solution: the viewDidLoad method of swizzling is actually the method of the parent class UIViewController, and the subclass actually calls the super viewDidLoad method. This processing method cannot process every page, and it is necessary to establish corresponding categories for each, which is complex and inefficient. This solution uses KVO to get the derived subclass to replace the pointer (IMP, Implementation) pointing to the method implementation, thereby solving this problem.

[0046] The third method: screenshot analysis of the pure color ratio.

[0047] Although both the first and second solutions can count the page loading time, the page data sometimes needs to wait for the network request to come back before refreshing the page, that is, the user sees the page with content. If you want to count this period of time, the above two solutions cannot do it. This solution uses the image pure color ratio to determine whether the current page is loaded. Simply put, it is to start a CADisplayLink timer, take a screenshot of the current page, and then use the algorithm for calculating the pure color ratio to calculate the ratio. When the ratio is greater than a certain threshold, it means that the page has been loaded successfully.

[0048] The disadvantages of the above three statistical schemes are:

[0049] The first solution cannot process every type of page and needs to establish corresponding categories for each, which is complex to implement and inefficient. Although the second solution solves the shortcomings of the first solution and accurately counts the length of the page in a simple way, it cannot count the time-consuming function. The third solution uses screenshot analysis to count the proportion of pure colors to count the page loading time. If some pages are deliberately designed to have more white space, the accuracy of the duration statistics will be low and the time-consuming function cannot be counted.

[0050] Based on this, the embodiment of the present application provides a method for calculating the page loading time. First, based on the KVO mode, the runtime mechanism is used to observe the page initialization and page visible events, and the start time and end time are recorded respectively, so as to accurately count the page loading time. At the same time, the stack information of the main thread is located in the child thread at a fixed time interval, and the execution time of a method is calculated by statistically comparing the stack state between the time intervals, and an approximate value is obtained, so as to screen out the most time-consuming methods during the period from page initialization to page content visibility, and then optimize them one by one in combination with the context environment.

[0051] The following describes an exemplary application of the apparatus for implementing the embodiment of the present application. The apparatus provided in the embodiment of the present application can be implemented as a terminal device. The following describes an exemplary application of the terminal device when the apparatus is implemented as a terminal device.

[0052] See also Figure 1 , Figure 1 This is a schematic diagram of the network architecture of the statistical method for page loading time in the embodiment of the present application. Figure 1 As shown, the network architecture includes at least a user terminal 100, a server 200, a network 300 and a developer terminal 400. To support an exemplary application, the user terminal 100 and the developer terminal 400 are connected to the server 200 via the network 300, respectively. The network 300 can be a wide area network or a local area network, or a combination of the two, and a wireless link is used to realize data transmission.

[0053] When a user opens a web page or a page in an application through the user terminal 100, the user terminal 100 observes the page initialization and page visibility events, and records the start time and the end time respectively, so as to accurately count the page loading time, and locate the stack information of the main thread in the child thread at a fixed time interval, and calculate the execution time of a certain method by statistically comparing the stack state between the time intervals, so as to screen out the most time-consuming method during the period from page initialization to page content visibility, and then the user terminal 100 sends the page loading time and the most time-consuming method to the server 200 through the network 300, and the server 200 can then send the page loading time and the most time-consuming method to the development terminal 400, so that the developer can optimize each method one by one in combination with the context environment.

[0054] In the following description, for the sake of convenience, the above-mentioned various possible forms of servers are collectively referred to as servers. Therefore, server 200 should not be simply understood as one or a type of server, but rather as various possible forms of servers deployed in actual applications to support applications or web pages based on the above examples.

[0055] The device provided in the embodiments of the present application may be implemented in the form of hardware or a combination of hardware and software. Various exemplary implementations of the device provided in the embodiments of the present application are described below.

[0056] according to Figure 2 The exemplary structure of the user terminal 100 shown can foresee other exemplary structures of the user terminal 100, so the structure described here should not be regarded as limiting. For example, some components described below can be omitted, or components not described below can be added to meet the special needs of certain applications.

[0057] Figure 2 The user terminal 100 shown includes: at least one processor 110, a memory 140, at least one network interface 120 and a user interface 130. Each component in the user terminal 100 is coupled together via a bus system 150. It is understood that the bus system 150 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 150 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 150 is not described in detail. Figure 2 Various buses are labeled as bus system 150 .

[0058] The user interface 130 may include a display, a keyboard, a mouse, a touch pad, a touch screen, and the like.

[0059] The memory 140 may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM). The volatile memory may be a random access memory (RAM). The memory 140 described in the embodiments of the present application is intended to include any suitable type of memory.

[0060] The memory 140 in the embodiment of the present application can store data to support the operation of the user terminal 100. Examples of such data include: any computer program for operating on the user terminal 100, such as an operating system and an application program. Among them, the operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application program can include various application programs.

[0061] As an example of the method provided in the embodiment of the present application being implemented by software, the method provided in the embodiment of the present application can be directly embodied as a combination of software modules executed by the processor 110. The software module can be located in a storage medium, and the storage medium is located in the memory 140. The processor 110 reads the executable instructions included in the software module in the memory 140, and completes the method provided in the embodiment of the present application in combination with the necessary hardware (for example, including the processor 110 and other components connected to the bus 150).

[0062] As an example, the processor 110 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0063] The method for counting the page loading time provided in the embodiment of the present application will be explained in combination with the exemplary application and implementation of the terminal provided in the embodiment of the present application.

[0064] See also Figure 3 , Figure 3 A schematic diagram of an implementation flow of a method for counting page loading time provided in an embodiment of the present application, which is applied to Figure 1 The user terminal shown will be combined with Figure 3 The steps shown are explained.

[0065] Step S101 : the user terminal performs key-value observation on the business class instance using a runtime mechanism based on the received operation instruction for loading a page.

[0066] Here, the user terminal may be a mobile terminal with wireless communication capability, such as a mobile phone (cell phone), a tablet computer, a laptop computer, etc., and may also be implemented as a desktop computer with computing function that is not convenient to move, a desktop computer, etc. Various application clients may be installed in the user terminal, for example, a game application client, a social application client, a shopping application client, a browser application client, etc., and the user may open the corresponding page through the various application clients installed in the user terminal to play games, socialize, shop, browse news, etc.

[0067] The operation instruction to load the page can be triggered by the user clicking on the Uniform Resource Locator (URL) address of the page, or by the user clicking on a button control to load the page; of course, in some embodiments, it can also be triggered by the user uttering a preset voice to load the page or by the user making a preset gesture to load the page.

[0068] In an embodiment of the present application, when the user terminal receives an operation instruction to load a page, the runtime mechanism is used to perform KVO on the business class instance. This can also be understood as registering the KVO function for the business class instance or setting the business class instance to the KVO mode to implement the key-value observation mechanism using the observer mode.

[0069] In some embodiments, when implementing key-value observing of a business class instance using a runtime mechanism, a key-value observing derived class may be created for the business class when the business class instance is initialized, wherein the key-value observing derived class is implemented by calling a method of the business class.

[0070] Step S102: when the user terminal observes a page initialization event, a first start time of the page initialization event is obtained.

[0071] Here, when observing the page initialization event, it can be to observe whether the method (also called function) required for page initialization is called. When it is observed that the method required for page initialization is called, it is considered that the page initialization event is observed, and the first start time of the page initialization event is obtained at this time.

[0072] In the embodiment of the present application, the first start time of the page initialization event may be the execution start time of the method that needs to be called for page initialization. The first start time may be the system time of executing the first instruction of the method that needs to be called for page initialization. In actual implementation, when it is detected that the first instruction of the method that needs to be called for page initialization is executed, a code for obtaining the system time is added to obtain the first start time.

[0073] In some embodiments, when it is detected that the last instruction of the method to be called for page initialization is executed, a code for obtaining the system time may also be added to obtain the second end time.

[0074] Step S103: when the user terminal observes a page visible event, a first end time of the page visible event is obtained.

[0075] Here, when observing the page visible event, it can be to observe whether the method (also called function) needed to be called to represent the page visibility is called. When it is observed that the method needed to be called to represent the page visibility is called, it is considered that the page visible event is observed. When the execution of the method needed to be called to represent the page visibility ends, the first end time of the page visible event is obtained.

[0076] In an embodiment of the present application, the first end time of the page visible event may be the execution end time of the method that needs to be called to indicate that the page is visible. The first end time may be the system time when the method that needs to be called to indicate that the page is visible executes the last instruction. In actual implementation, when it is detected that the last instruction of the method that needs to be called to indicate that the page is visible is executed, a code for obtaining the system time is added to obtain the first end time.

[0077] In some embodiments, when the first instruction of the method that needs to be called to indicate that the page is visible is executed, a code for obtaining the system time may be added to obtain the second start time.

[0078] Step S104: The user terminal determines a page loading duration based on the first start time and the first end time.

[0079] Here, when step S104 is implemented, the first end time is subtracted from the first start time to obtain the page loading time. For example, if the first end time is 10:04:30 on October 9, 2019, and the first start time is 10:04:20 on October 9, 2019, then the first end time is subtracted from the first start time to obtain a page loading time of 10 seconds.

[0080] In the page loading time statistics method provided in the embodiment of the present application, when an operation instruction to load a page is received, a runtime mechanism is used to perform key-value observation on the business class instance to observe page initialization and page visible events, and record the start time of the page initialization time and the end time of the page visible event respectively. In this way, the changes to the existing business code are very small, and only the implementation code for obtaining the first start time and the first end time needs to be added. The intrusion to the business code is almost negligible, and the page loading time can be accurately and efficiently counted.

[0081] In some embodiments, page initialization may be performed through the following steps to determine whether a page initialization event is observed:

[0082] Step S21, determining whether the view loading method of the key-value observing derived class has a corresponding implementation.

[0083] Here, since the key-value observing derived class is generally implemented by calling the method of the business class, the view loading method of the key-value observing derived class generally has no corresponding implementation. At this time, it is necessary to enter step S23 to initialize the page by calling the base class, that is, the view loading method of the business class; if the view loading method of the key-value observing derived class has a corresponding implementation, then enter step S22 to call the view loading method of the key-value observing derived class to initialize the page.

[0084] Step S22: When it is determined that the view loading method of the key-value observing derived class has a corresponding implementation, the view loading method of the key-value observing derived class is called to initialize the page.

[0085] Here, the view loading method can be used to create a view of a user interface view controller (UIViewController ler), so it can also be considered as a view creation method. In an embodiment of the present application, the view loading method of a key-value observing derived class can be a kvo_loadView method.

[0086] Step S23: When it is determined that the view loading method of the key-value observing derived class has no corresponding implementation, the view loading method of the business class is called to initialize the page.

[0087] Here, when the view loading method of the key-value observing derived class has no corresponding implementation, the parent class of the key-value observing derived class, that is, the view loading method of the business class is called. The view loading method of the business class can be the loadView method.

[0088] In an embodiment of the present application, when it is observed that the view loading method is called, it is determined that a page initialization event is observed. Further, when it is observed that the kvo_loadView method or the loadView method is called, it is considered that page initialization has started. At this time, it is determined that a page initialization event is observed, and step S102 is entered to obtain the first start time of the page initialization event.

[0089] In some embodiments, whether a page visible event is observed may be determined by the following steps:

[0090] Step S31, when a preset page visibility condition is met, it is determined whether the view visibility method of the key-value observing derived class has a corresponding implementation.

[0091] Here, when the user terminal determines that the preset page visibility condition is met, the view visibility method needs to be called. During the page loading process, after the page is initialized, the content to be displayed on the page needs to be rendered and displayed. When it is detected that the proportion of the displayed content to the screen display content is greater than a certain threshold, it is considered that the preset page visibility condition is met; in some embodiments, the displayed graphic controls can also be detected, and when the preset graphic controls are displayed, it is considered that the preset page visibility condition is met.

[0092] Since the key-value observing derived class is generally implemented by calling the method of the business class, similar to the view loading method, in general, the view visible method of the key-value observing derived class has no corresponding implementation. At this time, it is necessary to enter step S33 to call the base class, that is, the view visible method of the business class, to achieve page visibility; if the view visible method of the key-value observing derived class has a corresponding implementation, at this time enter step S32 and call the view visible method of the key-value observing derived class to achieve page visibility.

[0093] Step S32: When it is determined that the view visible method of the key-value observing derived class has a corresponding implementation, the view visible method of the key-value observing derived class is called.

[0094] Here, the view visible method triggers the behavior after the view is fully displayed on the screen, such as any animations. The view visible method of a key-value observing derived class can be the kvo_viewDidAppear method.

[0095] Step S33: When it is determined that the view visible method of the key-value observing derived class has no corresponding implementation, the view visible method of the business class is called.

[0096] Here, when the view visible method of the key-value observing derived class has no corresponding implementation, the parent class of the key-value observing derived class, that is, the view visible method of the business class is called, and the view visible method of the business class can be the viewDidAppear method.

[0097] When it is observed that the view visible method is called, it is determined that the page visible event is observed. Further, when it is observed that the kvo_viewDidAppear method or the viewDidAppear method is called, it is determined that the page visible event is observed.

[0098] In some embodiments, after the page loading duration is determined in step S104, the following steps may also be performed:

[0099] Step S105, obtaining the page identifier of the loaded page.

[0100] Step S106, establishing a corresponding relationship between the page identifier and the page loading duration, and storing the corresponding relationship.

[0101] Here, since a page may be loaded multiple times, in some embodiments, the corresponding relationship may also include a first start time, so that the page loading time consumed when a page is loaded at different times can be determined.

[0102] Step S107, based on the correspondence between the page identifier and the page loading duration, determine the average loading duration corresponding to the page identifier.

[0103] Here, since a page may be loaded multiple times, a page identifier corresponds to multiple page loading times. According to the page identifier, the loading times of each page can be obtained, and the average loading time can be determined based on the loading times of each page, so that the page loading performance can be determined and analyzed based on the average loading time.

[0104] In some embodiments, during the page loading process, Figure 4 Steps 41 to 44 shown further determine the execution time of each method:

[0105] Step S41, after observing the page initialization event, obtaining the stack information of the main thread of the page loading at a preset time interval.

[0106] Here, since the page loading starts after the page initialization event is observed, the stack information of the main thread of the page loading is obtained at a preset time interval, wherein the stack information of the main thread includes the calling status and execution status of each method (function).

[0107] For example, after observing the page initialization event, the stack information of the main thread is obtained once, and then the timer is started again for timing. When the timing duration of the timer reaches the preset time interval, the stack information of the main thread is obtained again, and the timer is reset to zero and continues to time. When the timing duration of the timer reaches the preset time interval, the stack information of the main thread is obtained again until the page loading is completed. In some embodiments, it is also possible that after observing the page initialization event, the stack information of the main thread is obtained once, and the timer is started to start timing. When the timing duration of the timer reaches an integer multiple of the preset time interval, the stack information of the main thread is obtained again.

[0108] Step S42: When the page is loaded, the number of occurrences of each method is determined based on the acquired stack information.

[0109] Here, since the stack information includes the calling situation and execution status of each method, the number of occurrences of each method can be determined by obtaining the stack information multiple times.

[0110] In actual implementation, since the stack information stores the binary representation of the method identifier of each method, when counting the number of occurrences of each method, the method identifier in the stack information can be symbolized first, that is, through the binary representation of the method identifier, the correspondence between the binary representation and the character representation of the method identifier can be queried, the character representation of the method identifier can be determined, and the number of occurrences of each method can be determined.

[0111] In some embodiments, the number of occurrences of each method may be determined directly based on the binary representation of the method identifier, and then the method identifier may be symbolized to obtain a character identifier of the method identifier.

[0112] Step S43, determining the execution time of each method based on the number of occurrences of each method and the preset time interval.

[0113] Here, when step S43 is implemented, the execution time of each method can be obtained by multiplying the number of occurrences of each method by the preset time interval T. For example, func1 appears in the stack information obtained for the third time and the fourth time, that is, func1 appears twice, starts to execute when the stack information is obtained for the third time, is also executed when the stack information is obtained for the fourth time, and is completed when the stack information is obtained for the fifth time, then it can be approximately considered that func1 is executed in the fourth time when the stack information is obtained, and therefore, the execution time of func1 is 2*T.

[0114] Step S44, sorting the execution time of each method, and determining the target method based on the sorting result.

[0115] Here, when implementing step S44, the execution time of each method may be sorted in order from large to small or from small to large, so as to determine one or more methods with the longest execution time according to the sorting result and determine them as the target method.

[0116] In some embodiments, after the page loading time and the target method are determined, the following steps may be performed:

[0117] Step S45, determining whether the page loading time and / or the average loading time both exceed a time threshold.

[0118] Here, when implementing step S45, it can be to only determine whether the current page loading time exceeds the time threshold. When the current page loading time exceeds the time threshold, step S46 is entered. When the current page loading time does not exceed the time threshold, the sending operation is not performed; it can also be to only determine whether the average loading time exceeds the time threshold. When the average loading time exceeds the time threshold, step S46 is entered. When the average loading time does not exceed the time threshold, the sending operation is not performed; of course, it can also be to determine whether both the page loading time and the average loading time exceed the time threshold. When the page loading time and the average loading time exceed the time threshold, step S46 is entered to send the page loading time and the method identifier of the target method to the developer terminal; when the page loading time does not exceed the time threshold, or the average loading time does not exceed the time threshold, the sending operation is not performed.

[0119] Step S46, sending the page loading time and the method identifier of the target method to the development terminal, so that the development terminal performs optimization processing based on the method identifier of the target method.

[0120] Here, when implementing step S46, the page loading time and the method identification of the target method may be sent to the server, and then sent to the development terminal by the server, or the page loading time and the method identification of the target method may be actively obtained by the development terminal. In some embodiments, if a direct communication connection is established between the user terminal and the development terminal, the page loading time and the method identification of the target method may also be directly sent to the development terminal by the user terminal, so that the developer can timely understand the time-consuming methods, and optimize each method one by one in combination with the context, thereby improving the page loading performance.

[0121] Based on the above embodiments, the present application further provides a method for calculating the page loading time, which is applied to Figure 1 In the network architecture shown, Figure 5 FIG. 1 is a schematic diagram of another implementation flow of the method for counting the page loading time according to an embodiment of the present application. Figure 5 As shown, the method includes:

[0122] Step S501: The user terminal performs key-value observation on the business class instance using a runtime mechanism based on the received operation instruction for loading the page.

[0123] Here, in an embodiment of the present application, when the user terminal receives an operation instruction to load a page, KVO is performed on the business class instance using the runtime mechanism. This can also be understood as registering the KVO function for the business class instance or setting the business class instance to the KVO mode to implement the key-value observation mechanism using the observer mode.

[0124] In some embodiments, when implementing key-value observing of a business class instance using a runtime mechanism, a key-value observing derived class may be created for the business class when the business class instance is initialized, wherein the key-value observing derived class is implemented by calling a method of the business class.

[0125] Step S502: the user terminal calls a view loading method to initialize the page, and obtains stack information of the page loading main thread at a preset time interval.

[0126] Here, since the key-value observing derived class is implemented by calling the method of the base class, that is, the business class, generally, the view loading method of the key-value observing derived class has no corresponding implementation, so it is necessary to call the view loading method of the business class to initialize the page. And in the embodiment of the present application, when the page loading starts, the stack information of the main thread of the page loading is obtained once at a preset time interval, and the stack information includes at least the calling status and execution status of each method.

[0127] Step S503: the user terminal obtains the first start time of calling the view loading method.

[0128] Here, when a call to the view loading method is observed, it is considered that a page initialization event is observed, and the system time when the view loading method executes the first instruction is obtained, and the system time is determined as the first start time.

[0129] Step S504: the user terminal determines whether it is the first time to load the view.

[0130] Here, when it is determined that it is the first time to load the view, it is necessary to enter step S505 and call the viewDidLoad method to load the view; when it is not the first time to load the view, the step of calling the viewDidLoad method can be skipped and enter step S506 to call the viewWillAppear method.

[0131] Step S505: the user terminal calls the viewDidLoad method to load the view.

[0132] Here, the viewDidLoad method is called when the view is loaded for the first time and will not be used afterwards, while viewDidAppear is called every time you switch to the view. If the view loader is created in code, the viewDidLoad method will be called after the loadView method. If it is output from a nib view page, the viewDidLoad method will be called after the view is set.

[0133] Step S506: The user terminal calls the viewWillAppear method.

[0134] Here, the viewWillAppear method is called when the view is about to be visible. By default, no action is performed. The viewWillAppear method is called to update the information of the view that is ready to be displayed. When the viewWill Appear method is called, the view may not have been loaded yet.

[0135] Step S507: the user terminal calls the viewDidAppear method.

[0136] Here, the viewDidAppear method is called when the view has been fully transitioned to the screen, which is used to indicate that the page is visible, that is, the page loading is complete. Calling the viewDidAppear method can trigger the behavior after the view is fully displayed on the screen, such as displaying an animation.

[0137] Step S508: The user terminal obtains the first end time of calling the viewDidAppear method.

[0138] Here, when the viewDidAppear method is executed, it can be considered that the page loading is completed, so the execution time of the last instruction of the viewDidAppear method can be determined as the first end time.

[0139] Step S509: The user terminal determines a page loading duration based on the first start time and the first end time.

[0140] Here, when implementing step S509, the first end time is subtracted from the first start time to obtain the page loading duration.

[0141] Step S510: the user terminal determines the number of occurrences of each method based on the acquired stack information when the page is loaded.

[0142] Here, since the stack information includes the calling situation and execution status of each method, the number of occurrences of each method can be determined by obtaining the stack information multiple times.

[0143] In actual implementation, since the stack information stores the binary representation of the method identifier of each method, when counting the number of occurrences of each method, the method identifier in the stack information can be symbolized first, and then the number of occurrences of each method can be obtained.

[0144] Step S511: the user terminal determines the execution time of each method based on the number of occurrences of each method and a preset time interval.

[0145] Here, when implementing step S511, the number of occurrences of each method is multiplied by the preset time interval T to obtain the execution time of each method.

[0146] Step S512: the user terminal sorts the execution time of each method and determines the target method based on the sorting result.

[0147] Here, the execution time of each method may be sorted in order from large to small or from small to large, so as to determine one or more methods with the longest execution time according to the sorting result and determine them as target methods.

[0148] Step S513: the user terminal determines whether the page loading time exceeds a time threshold.

[0149] Here, when the page loading time exceeds the time threshold, the process proceeds to step S514; when the page loading time does not exceed the time threshold, the process ends.

[0150] Step S514: the user terminal sends the page loading time and the method identifier of the target method to the server.

[0151] Step S515: The server sends the page loading time and the method identifier of the target method to the development terminal.

[0152] Step S516: The development terminal optimizes each method one by one based on the received page loading time and the method identifier of the target method in combination with the context.

[0153] In the page duration statistics method provided in the embodiment of the present application, after the user terminal receives the operation instruction of loading the page, firstly based on the KVO mode, the runtime mechanism is used to observe the view loading method representing the page initialization time, and the first start time is recorded, and then the view visible method representing the page visible event is observed, and the first end time is recorded, so as to accurately count the page loading time, and the intrusion into the existing business code is almost negligible. At the same time, the stack information of the main thread is located at a fixed time interval, and the execution time of a certain method is calculated by counting the number of occurrences of the method in each stack information, and an approximate value is obtained, so as to screen out the most time-consuming method during the period from page initialization to page content visibility, realize automatic detection of page loading time-consuming functions and send them to developers to analyze the reasons, count key functions, and perform special optimization, so as to finally achieve the purpose of shortening the page loading time and improving the user's page browsing experience.

[0154] The following is an explanation of an exemplary application of the embodiments of the present application in a practical application scenario.

[0155] The embodiment of the present application provides a method for counting the page loading time, which is applied to a user terminal. When the user terminal receives an operation instruction to load a page, the runtime mechanism is first used to perform KVO on the business class instance. When the business class instance is initialized, the system automatically creates a derived class for the business class, and the created derived class is implemented by calling the corresponding function of the base class. Figure 6 This is a schematic diagram of using KVO to observe business class instances in an embodiment of the present application, such as Figure 6As shown, when the page is initialized, the kvo_loadView method 601 of the KVO subclass will be executed first. If the kvo_loadView method of the KVO subclass has no corresponding implementation, the loadView method 602 of the business base class will be directly called to initialize the page.

[0156] Secondly, implement the key callback methods of the page life cycle in the subclass NSKVONotifying_ClassXXX: loadView and viewDidAppear. Figure 7 This is a schematic diagram of rewriting the parent class method in the embodiment of the present application, such as Figure 7 As shown, the loadView method 701 is called when the page instance is initialized, and the viewDidAppear method 702 is called when the page is visible.

[0157] like Figure 7 As shown, the implementation logic of the loadView method 701 and the viewDidAppear method 702 is generally consistent, both of which record the start time first, then call the corresponding method of the parent class, and finally record the end time. When the loadView and viewDidAppear methods are executed, four time values ​​will be obtained, namely the start time T1 of the loadView method, the end time T2 of the loadView method, the start time T3 of the viewDidAppear method, and the end time T4 of the viewDidAppear method, so as to accurately count the loading time of the page, that is, (T4-T1).

[0158] In an embodiment of the present application, the execution time of the method can also be counted. In the related art, the stack information of each thread can be located at a fixed time interval, and the stack state between the time intervals can be counted and compared to calculate how long a method has been executed, and an approximate value can be obtained. According to this idea, in an embodiment of the present application, during the page loading process, the stack information of the main thread is obtained every time T, and when the page loading is completed, the number of times each method appears in all stacks is counted, so that the execution time of each method can be calculated. The interval time T is dynamically set according to the performance test data.

[0159] In the technical solution for counting the execution time of each method, first, when the page instance is initialized, the child thread is started, and the stack information of the main thread is obtained every time interval T. Since the stack frame is represented by a binary address in the memory, and a specific function name is required in the embodiment of the present application, it is necessary to symbolize the stack information first to obtain the specific function name, and then save the specific function name in the memory array, such as Figure 8 shown. Figure 8This is a schematic diagram of the main thread stack information of the embodiment of the present application, such as Figure 3 As shown, func1, func2 and func3 appear once in stack1, func1 and func2 appear once in stack2, ..., and func4 and func5 appear once in stackn.

[0160] Secondly, when the page is loaded, that is, after the page is visible to the user, a HashMap is used to count the number of times each method appears in all stacks, for example, Figure 8 In the example, func1 and func2 appear twice, and func3 appears once. Based on the interval time parameter T, we can roughly estimate that the execution time of func1 and func2 is 2T, and the execution time of func3 is T.

[0161] Finally, all methods are sorted from large to small by execution time, and the most time-consuming methods are screened out. The user terminal sends the most time-consuming methods to the server, and the server can further send them to the development terminal, so that the developer can optimize the methods one by one in combination with the current context of the business, thereby shortening the page loading time. The statistical solution for method execution time provided in the embodiment of the present application not only has no intrusion on the existing business code, but is also transparent to developers and fully supports subsequent business expansion.

[0162] In the page loading time statistics method provided in the embodiment of the present application, the page loading time can be accurately counted by recording the start time of the loadView method and the end time of the viewDidAppear method, and the time-consuming functions of page loading can be automatically detected and the reasons can be analyzed through the stack information of the main thread, and the key functions can be counted to guide developers to perform special optimization, ultimately shortening the page loading time, thereby improving the user's page browsing experience.

[0163] The following is a description of an exemplary structure of a page loading duration statistics device 80 (hereinafter referred to as a statistics device) provided in an embodiment of the present application implemented as a software module. In some embodiments, for example, Figure 2 As shown, the software modules stored in the statistical device 80 of the memory 140 may include:

[0164] The observation module 81 performs key-value observation on the business class instance using a runtime mechanism based on the received operation instruction of the loading page;

[0165] A first acquisition module 82, configured to acquire a first start time of a page initialization event when a page initialization event is observed;

[0166] A second acquisition module 83 is used to acquire a first end time of the page visible event when a page visible event is observed;

[0167] The first determining module 84 is configured to determine a page loading duration based on the first start time and the first end time.

[0168] In some embodiments, the observation module 81 includes:

[0169] The creation unit is used to create a key-value observing derived class for the business class when the business class instance is initialized, wherein the key-value observing derived class is implemented by calling a method of the business class.

[0170] In some embodiments, the statistical device further comprises:

[0171] A second determination module is used to determine whether the view loading method of the key-value observation derived class has a corresponding implementation;

[0172] A first calling module is used to call the view loading method of the key-value observing derived class to initialize the page when it is determined that the view loading method of the key-value observing derived class has a corresponding implementation;

[0173] A second calling module is used to call the view loading method of the business class to perform page initialization when it is determined that the view loading method of the key-value observation derived class has no corresponding implementation;

[0174] When it is observed that the view loading method is called, it is determined that a page initialization event is observed.

[0175] In some embodiments, the statistical device further comprises:

[0176] A third determination module is used to determine whether the view visible method of the key-value observation derived class has a corresponding implementation when a preset page visible condition is met;

[0177] A third calling module, configured to call the view visible method of the key-value observing derived class when it is determined that the view visible method of the key-value observing derived class has no corresponding implementation;

[0178] The fourth calling module is used to call the view visible method of the business class when it is determined that the view visible method of the key-value observation derived class has no corresponding implementation, wherein when the view visible method is observed to be called, it is determined that a page visible event is observed.

[0179] In some embodiments, the statistical device further comprises:

[0180] A third acquisition module is used to acquire the page identifier of the loaded page;

[0181] An establishing module, used to establish a corresponding relationship between the page identifier and the page loading time, and store the corresponding relationship;

[0182] The fourth determination module is used to determine the average loading time corresponding to the page identifier based on the correspondence between the page identifier and the page loading time.

[0183] In some embodiments, the statistical device further comprises:

[0184] A fourth acquisition module is used to acquire the stack information of the main thread of the page loading at a preset time interval after observing the page initialization event;

[0185] A fifth determination module, used to determine the number of occurrences of each method that appears based on the acquired stack information when the page is loaded;

[0186] A sixth determination module, used to determine the execution time of each method based on the number of occurrences of each method and a preset time interval;

[0187] The sorting module is used to sort the execution time of each method and determine the target method based on the sorting result.

[0188] In some embodiments, the statistical device further comprises:

[0189] A sending module is used to send the page loading time and the method identification of the target method to the development terminal when the page loading time and / or the average loading time exceeds a time threshold, so that the development terminal performs optimization processing based on the method identification of the target method.

[0190] The present application embodiment provides a storage medium storing executable instructions, wherein the executable instructions are stored. When the executable instructions are executed by a processor, the processor will execute the method provided by the present application embodiment, for example, Figure 3 , Figure 4 and Figure 5 The method shown.

[0191] In some embodiments, the storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EE PROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.

[0192] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0193] As an example, executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions).

[0194] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0195] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims

1. A method for calculating the length of page loading time, characterized in that: include: Based on the received operation instruction of loading the page, when the business class instance is initialized, creating a key-value observing derived class for the business class, wherein the key-value observing derived class is implemented by calling a method of the business class; When it is determined that the view loading method of the key-value observing derived class has a corresponding implementation, calling the view loading method of the key-value observing derived class to initialize the page; When it is determined that the view loading method of the key-value observation derived class has no corresponding implementation, calling the view loading method of the business class to initialize the page; wherein, when it is observed that the view loading method is called, it is determined that a page initialization event is observed; When the page initialization event is observed, obtaining a first start time of the page initialization event; When a page visible event is observed, obtaining a first end time of the page visible event; Determine a page loading duration based on the first start time and the first end time; After observing the page initialization event, the stack information of the main thread of the page loading is obtained at a preset time interval; the stack information of the main thread includes the calling status and execution status of each method; When the page is loaded, the number of occurrences of each method is determined based on the acquired stack information; the execution time of each method is determined based on the number of occurrences of each method and the preset time interval; the execution time of each method is sorted, and the target method is determined based on the sorting result; When the page loading time exceeds a time threshold, the page loading time and the method identifier of the target method are sent to a development terminal, so that the development terminal performs optimization processing based on the method identifier of the target method.

2. The method according to claim 1, characterized in that The method further comprises: When a preset page visibility condition is met, determining whether a view visibility method of the key-value observing derived class has a corresponding implementation; When it is determined that the view visible method of the key-value observing derived class has no corresponding implementation, calling the view visible method of the key-value observing derived class; When it is determined that the view visible method of the key-value observing derived class has no corresponding implementation, the view visible method of the business class is called, wherein when it is observed that the view visible method is called, it is determined that a page visible event is observed.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: Get the page ID of the loaded page; Establishing a correspondence between the page identifier and the page loading duration, and storing the correspondence; Based on the correspondence between the page identifier and the page loading duration, the average loading duration corresponding to the page identifier is determined.

4. A device for counting page loading time, characterized in that: include: An observation module, configured to create a key-value observation derived class for the business class based on the received operation instruction of loading the page when the business class instance is initialized, wherein the key-value observation derived class is implemented by calling a method of the business class; A first calling module is used to call the view loading method of the key-value observing derived class to initialize the page when it is determined that the view loading method of the key-value observing derived class has a corresponding implementation; A second calling module is used to call the view loading method of the business class to perform page initialization when it is determined that the view loading method of the key-value observation derived class has no corresponding implementation; wherein, when it is observed that the view loading method is called, it is determined that a page initialization event is observed; A first acquisition module, configured to acquire a first start time of a page initialization event when a page initialization event is observed; A second acquisition module, configured to acquire a first end time of a page visible event when a page visible event is observed; A first determining module, configured to determine a page loading duration based on the first start time and the first end time; A fourth acquisition module is used to acquire the stack information of the main thread of the page loading at a preset time interval after observing the page initialization event; the stack information of the main thread includes the calling status and execution status of each method; A fifth determination module, configured to determine the number of occurrences of each of the methods based on the acquired stack information when the page is loaded; A sixth determination module, used to determine the execution time of each method based on the number of occurrences of each method and the preset time interval; A sorting module is used to sort the execution time of each method and determine the target method based on the sorting result. The sending module is used to send the page loading time and the method identification of the target method to the development terminal when the page loading time exceeds the time threshold, so that the development terminal performs optimization processing based on the method identification of the target method.

5. A device for counting page loading time, characterized in that: include: A memory for storing executable instructions; A processor, configured to implement the method according to any one of claims 1 to 3 when executing the executable instructions stored in the memory.

6. A storage medium, characterized in that: Executable instructions are stored, which are used to cause a processor to execute and implement the method described in any one of claims 1 to 3.