Function Elapsed Time Statistics Method, Device, Electronic Device, and Storage Medium

By obtaining the start and end times of the function in the pre-created time queue and calculating its time-consuming, the time interrupt problem caused by frequent call to the system clock in high concurrency scenarios is solved, and the system stability is improved.

CN114595142BActive Publication Date: 2025-06-27BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210146077.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-17
Publication Date
2025-06-27
Estimated Expiration
2042-02-17

AI Technical Summary

Technical Problem

In high concurrency scenarios, frequent call to the system clock in the prior art causes time interruptions, affecting the performance of the application.

Method used

By obtaining the start and end times in a pre-created time queue, the time consumed of the function to be counted is calculated, thereby avoiding frequent call to the system clock.

Benefits of technology

In high concurrency scenarios, by obtaining time from the time queue, time interruption is avoided and the stability of the system is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114595142B_ABST
    Figure CN114595142B_ABST
Patent Text Reader

Abstract

The present application relates to a method, apparatus, electronic device, and storage medium for function time consumption statistics, which are applied to the technical field of software development. The method includes: when it is determined that the function to be statistically analyzed starts to execute, obtaining a first time from a pre-created time queue; when it is determined that the function to be statistically analyzed ends to execute, obtaining a second time from the pre-created time queue; and determining the function time consumption of the function to be statistically analyzed according to the first time and the second time. This is to solve the problem in the prior art that in a high-concurrency scenario, time interruptions may be caused due to frequent calls to the system clock.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of software development, and in particular, to a method, device, electronic device, and storage medium for function time-consuming statistics. Background Art

[0002] Generally speaking, the longer the time-consuming of the functions used during the operation of an application, the greater the possibility of performance problems in the application. Therefore, in order to optimize the performance of the application running on an electronic device and clarify the time-consuming of each function during the operation of the application, it is a necessary means to solve the performance problem.

[0003] In the related art, when statistically calculating the time-consuming of a function, the system clock is usually called. After the function call starts and ends, the system clock is called respectively to obtain the time-consuming of the function. In a high-concurrency scenario, this method may cause a time interruption due to the frequent call of the system clock. Summary of the Invention

[0004] This application provides a method, device, electronic device, and storage medium for function time-consuming statistics, which are used to solve the problem that in the related art, in a high-concurrency scenario, a time interruption may be caused due to the frequent call of the system clock.

[0005] In a first aspect, an embodiment of this application provides a method for function time-consuming statistics, including:

[0006] When it is determined that the function to be statistically calculated starts to execute, obtain a first time from a pre-created time queue;

[0007] When it is determined that the function to be statistically calculated ends its execution, obtain a second time from the pre-created time queue;

[0008] Determine the function time-consuming of the function to be statistically calculated according to the first time and the second time.

[0009] Optionally, the obtaining of the first time from the pre-created time queue includes:

[0010] Based on a local variable in the function to be statistically calculated, call a first time obtaining function, where the first time obtaining function is a function in the target class corresponding to the local variable;

[0011] Access the time queue through the first time obtaining function, and obtain the first time from the time queue.

[0012] Optionally, the determination of the end of the execution of the function to be statistically calculated includes:

[0013] When it is detected that the local variable in the function to be statistically calculated is released, determine that the function to be statistically calculated ends its execution;

[0014] Obtaining the second time from the pre-created time queue includes:

[0015] Invoking a second time acquisition function based on the local variable, where the second time acquisition function is a function in the target class corresponding to the local variable;

[0016] Accessing the time queue through the second time acquisition function to obtain the second time from the time queue.

[0017] Optionally, invoking the first time acquisition function based on the local variable in the function to be statistically analyzed includes:

[0018] Determining the parameter information defined in the local variable;

[0019] Determining and invoking the first time acquisition function according to the parameter information.

[0020] Optionally, the first time acquisition function includes a parameterized constructor and a parameterless constructor;

[0021] The determining and invoking the first time acquisition function according to the parameter information includes:

[0022] If the parameter information includes user-defined parameters, determining and invoking the parameterized constructor;

[0023] If the parameter information does not include user-defined parameters, determining and invoking the parameterless constructor.

[0024] Optionally, obtaining the first time from the pre-created time queue includes:

[0025] Executing the first time acquisition function pre-created in the function to be statistically analyzed;

[0026] Accessing the time queue through the first time acquisition function to obtain the first time from the time queue.

[0027] Optionally, obtaining the second time from the pre-created time queue includes:

[0028] Executing the second time acquisition function pre-created in the function to be statistically analyzed;

[0029] Accessing the time queue through the second time acquisition function to obtain the second time from the time queue.

[0030] Optionally, the creation process of the time queue includes:

[0031] Create an initial circular queue, where the initial circular queue includes at least two time storage nodes, and the times stored in each storage node are different;

[0032] Create a time acquisition thread, and collect the system time at intervals of a preset duration through the time acquisition thread;

[0033] Update the time stored in the target storage node in the initial circular queue at intervals of a preset duration based on the time acquisition thread, where the target storage node is the storage node in the initial circular queue at a preset access interface;

[0034] Determine that the initial circular queue updated based on the time acquisition thread is the time queue.

[0035] In a second aspect, an embodiment of the present application provides a function elapsed time statistics device, including:

[0036] A first acquisition module, configured to obtain a first time from a pre-created time queue when it is determined that a function to be statistically analyzed starts to execute;

[0037] A second acquisition module, configured to obtain a second time from the pre-created time queue when it is determined that the function to be statistically analyzed ends to execute;

[0038] A determination module, configured to determine the elapsed time of the function to be statistically analyzed according to the first time and the second time.

[0039] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;

[0040] The memory is used to store a computer program;

[0041] The processor is configured to execute the program stored in the memory to implement the function elapsed time statistics method described in the first aspect.

[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, storing a computer program, where the computer program, when executed by a processor, implements the function elapsed time statistics method described in the first aspect.

[0043] The above technical solution provided by the embodiments of the present application has the following advantages compared with the prior art: In the method provided by the embodiments of the present application, when it is determined that the function to be statistically analyzed starts to execute, the first time is obtained from the pre-created time queue; when it is determined that the function to be statistically analyzed ends to execute, the second time is obtained from the pre-created time queue; and according to the first time and the second time, the function execution time of the function to be statistically analyzed is determined. In this way, if you want to statistically analyze the execution duration of the function to be statistically analyzed, when it is determined that the function to be statistically analyzed starts to execute and when it is determined that the function to be statistically analyzed ends to execute, the time is obtained from the pre-created time queue, thereby avoiding the invocation of the system time. Especially in a high-concurrency scenario, obtaining the time from the pre-created time queue avoids frequent invocation of the system time and avoids time interruptions, improving the stability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present invention and, together with the specification, are used to explain the principles of the present invention.

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0046] Figure 1 It is a diagram of the application scenario of the function execution time statistical method provided by an embodiment of the present application;

[0047] Figure 2 It is a flowchart of the function execution time statistical method provided by an embodiment of the present application;

[0048] Figure 3 It is a schematic diagram of the time queue in the function execution time statistical method provided by an embodiment of the present application;

[0049] Figure 4 It is a structural diagram of the function execution time statistical device provided by an embodiment of the present application;

[0050] Figure 5 It is a structural diagram of the electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0051] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this application. Apparently, the described embodiments are some but not all of the embodiments of this application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts shall fall within the scope of protection of this application.

[0052] Before further elaborating on the embodiments of the present invention, the nouns and terms involved in the embodiments of the present invention are explained, and the nouns and terms involved in the embodiments of the present invention are applicable to the following explanations.

[0053] Class and object: Class and object are the most basic concepts in object-oriented programming technology. Class and object are the collective names of two computer languages carried by a computer. An object is an abstraction of an objective thing, and a class is an abstraction of an object. A class is an abstract data type. Their relationship is that an object is an instance of a class, and a class is a template for an object. An object is created through new classname and is used to call the methods of the class; the constructor method of the class.

[0054] Local variable: It refers to a variable defined inside a function or a compound statement. The scope of a local variable is the function or compound statement in which the variable is defined. The lifetime of a local variable starts from the moment the function is called and ends when the function returns to the calling place.

[0055] Constructor: It is a special method. It is mainly used to initialize an object when creating an object, that is, to assign initial values to the object member variables, and is always used together with the new operator in the statement for creating an object. In particular, a class can have multiple constructors, which can be distinguished according to the different numbers or types of their parameters, that is, the overloading of the constructor. The constructor of a local static object is called only when the program first executes the corresponding statement.

[0056] Destructor: Contrary to the constructor, when an object ends its life cycle, such as when the function where the object is located has been called, the system automatically executes the destructor. The destructor is often used to do "clean-up" work (for example, when new is used to allocate a piece of memory space when creating an object, delete will automatically call the destructor and then release the memory).

[0057] According to an embodiment of the present application, a method for statistical function time-consuming is provided. Optionally, in the embodiment of the present application, the above method for statistical function time-consuming can be applied to a hardware environment composed of a terminal 101 and a server 102 as shown in Figure 1 the following figure. As shown in Figure 1As shown in the figure, the server 102 is connected to the terminal 101 through a network and can be used to provide services (such as video services, application services, etc.) for the terminal or the client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for the server 102. The above network includes but is not limited to: wide area network, metropolitan area network or local area network. The terminal 101 is not limited to PCs, mobile phones, tablet computers, etc.

[0058] The function elapsed time statistics method of the embodiments of the present application can be executed by the server 102, or by the terminal 101, or jointly executed by the server 102 and the terminal 101. Among them, when the terminal 101 executes the function elapsed time statistics method of the embodiments of the present application, it can also be executed by the client installed on it.

[0059] Taking the server executing the function elapsed time statistics method of the embodiments of the present application as an example, Figure 2 is a schematic flowchart of an optional function elapsed time statistics method according to the embodiments of the present application, as Figure 2 shown, the process of this method can include the following steps:

[0060] Step 201, when it is determined that the function to be statistically analyzed starts to execute, obtain the first time from the pre-created time queue.

[0061] In some embodiments, the function to be statistically analyzed refers to the functions corresponding to various types in the code. Exemplarily, the function to be statistically analyzed can be a code segment in a certain application program that can implement a specific function.

[0062] In software development, to ensure software quality, it is often necessary to perform performance testing on the developed software, and based on the performance test results, the software can be improved. For example, the elapsed time of functions in the software can be statistically analyzed to find out the reasons for page freezing. When developers are testing, they often need to process the functions to be statistically analyzed in the software so that when the function to be executed starts to execute, the elapsed time of the function to be executed can be statistically analyzed.

[0063] Exemplarily, a first time acquisition function can be written at the position where the function to be statistically analyzed starts to execute, and a second time acquisition function can be written at the position where the function to be statistically analyzed ends to execute. It is also possible to pre-create a target class including the first time acquisition function and the second time acquisition function, define an object of the target class in the function to be statistically analyzed, and define the class name and local variables of the target class in the object, so that when the function to be statistically analyzed starts to execute, the function in the target class can be called to obtain the time.

[0064] Correspondingly, determining that the function to be statistically analyzed starts to execute can be when the first time acquisition function written in the function to be statistically analyzed is executed, determining that the function to be statistically analyzed starts to execute; or when the object of the target class is executed, determining that the function to be statistically analyzed starts to execute.

[0065] In an alternative embodiment, obtaining a first time from a pre-created time queue includes:

[0066] Executing a first time acquisition function pre-created in the function to be statistically analyzed; accessing the time queue through the first time acquisition function to obtain the first time from the time queue.

[0067] Specifically, when the first time acquisition function is written into the function to be statistically analyzed, when the function to be executed starts to execute, since the first time acquisition function is set at the start position of the function to be executed, the first time acquisition function will be executed first, and the first time acquisition function accesses the time queue to obtain the first time.

[0068] In another alternative embodiment, obtaining a first time from a pre-created time queue includes:

[0069] Based on a local variable in the function to be statistically analyzed, calling a first time acquisition function, where the first time acquisition function is a function in a target class corresponding to the local variable; accessing the time queue through the first time acquisition function to obtain the first time from the time queue.

[0070] Specifically, when the first time acquisition function is written into the target class, when starting to execute the function to be statistically analyzed, by determining the class name in the object defined in the function to be statistically analyzed, the target class is determined, and the first time acquisition function in the target class is called by the local variable in the object, so as to obtain the first time from the time queue through the first time acquisition function.

[0071] Among them, the first time acquisition function can be but is not limited to a constructor function. It can be understood that the constructor function includes a parameterized constructor function and a non-parameterized constructor function.

[0072] Furthermore, a parameterized constructor function and a non-parameterized constructor function are created in the target class. When executing the function to be statistically analyzed, the constructor function to be called can be determined according to the parameter information in the local variable of the function to be statistically analyzed.

[0073] In an alternative embodiment, determining and calling the first time acquisition function according to the parameter information includes:

[0074] If the parameter information includes a user-defined parameter, determine and call the parameterized constructor function; if the parameter information does not include a user-defined parameter, determine and call the non-parameterized constructor function.

[0075] Specifically, if the parameter information is defined in the local variable, the parameterized constructor function will be called during execution to record the user-defined parameter. When the parameter information is not defined in the local variable, the non-parameterized constructor function is called.

[0076] The target class T created above has variables including: start time (starttime), end time (endtime), and a string pointer (char* str) (used to record the parameters passed in by the application). The target class includes a default constructor, a parameterized constructor, and a destructor.

[0077] Exemplarily, the default constructor can be:

[0078] T(){

[0079] Record the start execution time of the function and record it with the variable starttime;

[0080] Call the interface of the time queue;

[0081] }

[0082] The parameterized constructor can be:

[0083] T(char*strp){

[0084] Record the start execution time of the function and record it with the variable starttime;

[0085] Call the interface of the time queue;

[0086] Str = strp; Record the user-defined parameter;

[0087] }

[0088] The destructor can be:

[0089] ~T(){

[0090] Record the end execution time of the function and record it with the variable endtime;

[0091] Call the interface of the time queue;

[0092] }

[0093] Exemplarily, the original function to be statistically analyzed is:

[0094] int funTest(){ ..

[0096] }

[0097] After defining variables in the original function to be statistically analyzed, it can be: int funTest(){

[0098] T t; ..

[0100] }

[0101] Alternatively, after defining variables in the original function to be counted, it can be: int funTest(){

[0102] T t("flag"); ..

[0104] }

[0105] Wherein, T represents the class name of the target class, t represents a local variable, and flag represents a user-defined parameter.

[0106] In an alternative embodiment, the creation process of the pre-created time queue includes:

[0107] Create an initial circular queue, which includes at least two time storage nodes, and the times stored in each storage node are different; create a time acquisition thread, and through the time acquisition thread, collect the system time every preset time interval and store it in the storage node; based on the time acquisition thread, update the time stored in the target storage node in the initial circular queue every preset time interval, where the target storage node is the storage node in the initial circular queue at the preset access interface; determine that the initial circular queue updated based on the time acquisition thread is the time queue.

[0108] Specifically, the initial circular queue can be, but is not limited to, a lock-free circular queue. The time acquisition thread can be, but is not limited to, an independent thread. The preset time interval can be set according to the actual situation. For example, it can be 5 - 10 microseconds. Preferably, the preset time interval is 5 microseconds.

[0109] Exemplarily, based on the independent thread, the time is collected once every 5 microseconds, and the collected time is stored in the lock-free circular queue, and an access structure is provided for the first time acquisition function and the second time acquisition function described above to access the lock-free circular queue.

[0110] See Figure 3 , taking the number of storage nodes in the lock-free circular queue as 3 as an example, the system time is stored in the lock-free circular queue, that is, the three storage nodes A, B, and C store the time, and the external structure accesses a fixed preset access interface. The independent thread updates the lock-free circular queue every 5 microseconds. In the lock-free circular queue, A, B, and C rotate in sequence, are continuously updated, with a 5-microsecond interval, and the function execution time difference is 5 microseconds.

[0111] In this embodiment, if the execution time of the function to be counted is less than 5 microseconds, then the function consumption time is counted as 0. This function is mainly to find out functions with long execution times, and the 5-microsecond error can be ignored. Thus, by sacrificing the time precision, the system performance is improved.

[0112] Among them, the access interface information of the time queue can be written into the first-time acquisition function and the second-time acquisition function to read the latest time.

[0113] Step 202, when it is determined that the function to be counted has finished executing, obtain the second time from the pre-created time queue.

[0114] In some embodiments, if it is determined by executing the first-time acquisition function written into the function to be counted when the function to be counted starts to execute, correspondingly, to determine that the function to be counted has finished executing, it can be to determine that the second-time acquisition function written into the function to be counted is executed.

[0115] Further, obtaining the second time from the pre-created time queue includes:

[0116] Execute the second-time acquisition function pre-created in the function to be counted; access the time queue through the second-time acquisition function to obtain the second time from the time queue.

[0117] Specifically, when the second-time acquisition function is written into the function to be counted, during the execution of the function to be counted, since the second-time acquisition function is written at the end of the function to be counted, therefore, after executing the second-time acquisition function, it is determined that the function to be counted has finished executing, and thus the time queue is accessed through the second-time acquisition function to obtain the second time.

[0118] In some embodiments, if an object of the target class is written in the function to be counted, since the object includes local variables, the life cycle of the local variables is from the start of the execution of the function to be counted to the end of the execution of the function to be counted, and the local variables will be released when the function to be counted finishes executing. Therefore, it can be determined that the function to be counted has finished executing by detecting that the local variables in the function to be counted are released.

[0119] Further, obtaining the second time from the pre-created time queue includes:

[0120] Call the second-time acquisition function based on the local variables, and the second-time acquisition function is a function in the target class corresponding to the local variables; access the time queue through the second-time acquisition function to obtain the second time from the time queue.

[0121] Specifically, after the local variables are released, the second-time acquisition function of the local variables will be called, so as to access the time queue through the second-time acquisition function to obtain the second time from the time queue.

[0122] Among them, the second-time acquisition function can be but is not limited to a destructor.

[0123] Step 203, determine the function execution time of the function to be counted according to the first time and the second time.

[0124] In some embodiments, after obtaining the first time and the second time, the time difference between the first time and the second time can be calculated, and this time difference can be used as the function execution time of the function to be statistically analyzed. In this way, if you want to statistically analyze the execution duration of the function to be statistically analyzed, when determining the start of the execution of the function to be statistically analyzed and when determining the end of the execution of the function to be statistically analyzed, obtain the time from the pre-created time queue, thus avoiding calling the system time. Especially in a high-concurrency scenario, obtaining the time from the pre-created time queue can avoid frequent calls to the system time and avoid time interruptions, improving the stability of the system.

[0125] In the function execution time statistical method of the present application, an object is created inside the function to be statistically analyzed, and the start time and end time of the execution of the function to be statistically analyzed are recorded through the constructor and the destructor. Thus, the time difference is recorded from the destructor. Through the features of C++, the development is simplified.

[0126] Moreover, three storage times are saved through a lock-free storage queue, and the three storage times are cyclically updated. The application thread does not directly call the system time, but indirectly obtains the time from the time queue, reducing the frequency of obtaining the time and saving CPU resources.

[0127] Based on the same concept, in an embodiment of the present application, a function execution time statistical device is provided. For the specific implementation of this device, reference can be made to the description in the method embodiment part, and repeated parts will not be elaborated. As Figure 4 shown, this device mainly includes:

[0128] A first acquisition module 401, configured to obtain the first time from a pre-created time queue when determining the start of the execution of the function to be statistically analyzed;

[0129] A second acquisition module 402, configured to obtain the second time from a pre-created time queue when determining the end of the execution of the function to be statistically analyzed;

[0130] A determination module 403, configured to determine the function execution time of the function to be statistically analyzed according to the first time and the second time.

[0131] Based on the same concept, in an embodiment of the present application, an electronic device is further provided. As Figure 5 shown, this electronic device mainly includes: a processor 501, a memory 502, and a communication bus 503. Among them, the processor 501 and the memory 502 communicate with each other through the communication bus 503. Among them, a program executable by the processor 501 is stored in the memory 502, and the processor 501 executes the program stored in the memory 502 to implement the following steps:

[0132] When determining the start of the execution of the function to be statistically analyzed, obtain the first time from a pre-created time queue;

[0133] When it is determined that the function to be counted ends its execution, obtain a second time from a pre-created time queue.

[0134] Determine the function execution time of the function to be counted according to the first time and the second time.

[0135] The communication bus 503 mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus 503 can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 5 only a thick line is used to represent it in the figure, but it does not mean that there is only one bus or one type of bus.

[0136] The memory 502 may include a Random Access Memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located far from the aforementioned processor 501.

[0137] The aforementioned processor 501 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc., and may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0138] In another embodiment of the present application, a computer-readable storage medium is further provided. A computer program is stored in the computer-readable storage medium. When the computer program runs on a computer, the computer is enabled to execute the function execution time statistical method described in the above embodiment.

[0139] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions are transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape, etc.), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state drive), etc.

[0140] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise", or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article, or device that includes a series of elements not only includes those elements, but also includes other elements that are not explicitly listed, or further includes elements that are inherent to such process, method, article, or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of another identical element in the process, method, article, or device that includes the said element.

[0141] The above are only specific embodiments of the present invention, enabling those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to these embodiments shown herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for statistical analysis of function execution time, characterized in that, Including: When it is determined that the function to be counted starts to execute, obtain the first time from a pre-created time queue; When it is determined that the function to be counted ends its execution, obtain the second time from the pre-created time queue; Determine the function execution time of the function to be counted according to the first time and the second time; Among them, the obtaining the first time from the pre-created time queue includes: based on the local variable in the function to be counted, call a first time obtaining function, and the first time obtaining function is a function in the target class corresponding to the local variable; access the time queue through the first time obtaining function, and obtain the first time from the time queue; Among them, when it is determined that the function to be counted ends its execution, it includes: detecting that the local variable in the function to be counted is released, and determining that the function to be counted ends its execution; the obtaining the second time from the pre-created time queue includes: based on the local variable, call a second time obtaining function, and the second time obtaining function is a function in the target class corresponding to the local variable; access the time queue through the second time obtaining function, and obtain the second time from the time queue; Among them, the creation process of the time queue includes: creating an initial circular queue, where the initial circular queue includes at least two time storage nodes, and the times stored in each storage node are different; creating a time obtaining thread, and collecting the system time every preset time interval through the time obtaining thread; based on the time obtaining thread, update the time stored in the target storage node in the initial circular queue every preset time interval, and the target storage node is the storage node in the initial circular queue at the preset access interface; determine that the initial circular queue updated based on the time obtaining thread is the time queue; Among them, the first time obtaining function and the second time obtaining function are functions in the target class, and the access interface information of the time queue is written in the first time obtaining function and the second time obtaining function to read the latest time.

2. The function time-consuming statistical method according to claim 1, wherein The calling the first time obtaining function based on the local variable in the function to be counted includes: Determine the parameter information defined in the local variable; Determine and call the first time obtaining function according to the parameter information.

3. The function elapsed time statistical method according to claim 2, wherein The first time obtaining function includes a parameterized constructor and a non-parameterized constructor; The determining and calling the first time obtaining function according to the parameter information includes: If the parameter information includes user-defined parameters, determine and call the parameterized constructor; If the parameter information does not include user-defined parameters, determine and call the non-parameterized constructor.

4. The function time-consuming statistics method according to claim 1, wherein The obtaining the first time from the pre-created time queue includes: Execute the first time obtaining function pre-created in the function to be counted; Access the time queue through the first time obtaining function, and obtain the first time from the time queue.

5. The function time-consuming statistical method according to claim 1, characterized in that, The obtaining the second time from the pre-created time queue includes: Execute the second time obtaining function pre-created in the function to be counted; Access the time queue through the second time acquisition function, and acquire the second time from the time queue.

6. A function time-consuming statistics device, characterized in that It includes: A first acquisition module, configured to acquire a first time from a pre-created time queue when it is determined that the function to be statistically analyzed starts to execute; A second acquisition module, configured to acquire a second time from the pre-created time queue when it is determined that the function to be statistically analyzed ends its execution; A determination module, configured to determine the function execution time of the function to be statistically analyzed according to the first time and the second time; Among them, acquiring the first time from the pre-created time queue includes: based on a local variable in the function to be statistically analyzed, calling a first time acquisition function, where the first time acquisition function is a function in the target class corresponding to the local variable; accessing the time queue through the first time acquisition function, and acquiring the first time from the time queue; Among them, when it is determined that the function to be statistically analyzed ends its execution, it includes: detecting that a local variable in the function to be statistically analyzed is released, and determining that the function to be statistically analyzed ends its execution; acquiring the second time from the pre-created time queue includes: based on the local variable, calling a second time acquisition function, where the second time acquisition function is a function in the target class corresponding to the local variable; accessing the time queue through the second time acquisition function, and acquiring the second time from the time queue; Among them, the creation process of the time queue includes: creating an initial circular queue, where the initial circular queue includes at least two time storage nodes, and the times stored in each storage node are different; creating a time acquisition thread, and collecting the system time at intervals of a preset duration through the time acquisition thread; based on the time acquisition thread, updating the time stored in a target storage node in the initial circular queue at intervals of a preset duration, where the target storage node is a storage node in the initial circular queue at a preset access interface; determining that the initial circular queue updated based on the time acquisition thread is the time queue; Among them, the first time acquisition function and the second time acquisition function are functions in the target class, and the access interface information for writing to the time queue is written in the first time acquisition function and the second time acquisition function to read the latest time.

7. An electronic device, characterized in that, It includes: A processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete mutual communication through the communication bus; The memory is used to store a computer program; The processor is configured to execute the program stored in the memory to implement the function execution time statistical method according to any one of claims 1-5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the function execution time statistical method according to any one of claims 1-5.

Citation Information

Patent Citations

  • Mass farmland data monitoring method and system

    CN103886508A