CN110457196B - Method and device for acquiring function execution time - Google Patents

Method and device for acquiring function execution time Download PDF

Info

Publication number
CN110457196B
CN110457196B CN201910757322.3A CN201910757322A CN110457196B CN 110457196 B CN110457196 B CN 110457196B CN 201910757322 A CN201910757322 A CN 201910757322A CN 110457196 B CN110457196 B CN 110457196B
Authority
CN
China
Prior art keywords
detection module
api
time
time detection
function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910757322.3A
Other languages
Chinese (zh)
Other versions
CN110457196A (en
Inventor
柳金山
龚达远
王照江
陆正发
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910757322.3A priority Critical patent/CN110457196B/en
Publication of CN110457196A publication Critical patent/CN110457196A/en
Application granted granted Critical
Publication of CN110457196B publication Critical patent/CN110457196B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
    • G06F11/3419Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3466Performance evaluation by tracing or monitoring
    • G06F11/3476Data logging
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2201/00Indexing scheme relating to error detection, to error correction, and to monitoring
    • G06F2201/865Monitoring of software
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The application provides a method and a device for acquiring function execution time, wherein the method comprises the following steps: acquiring a first call request, wherein the first call request is used for calling a first target application program interface API, the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used for acquiring the execution time of the target function; setting the state of the time detection module to a state allowing execution in response to the first call request; and the execution time detection module and the objective function are used for obtaining the execution time of the objective function. The method solves the technical problem that the use performance of the API application is reduced under the condition that all existing API interfaces need to be opened when the time-consuming data of the API interface is analyzed through the deterministic analyzer cProfile in the related art.

Description

Method and device for acquiring function execution time
Technical Field
The application relates to the field of Application Program Interface (API) performance test, in particular to a method and a device for acquiring function execution time.
Background
In the prior art, time consuming performance data of the application program interface API (Application Programming Interface) is obtained in two ways. Wherein, mode one: time-consuming log mode through printing API interface, mode two: the API interface time consuming data is analyzed by a deterministic analyzer cProfile.
It should be noted that, in the first method, time consuming performance data of the API interface is obtained, as shown in fig. 1, and the time consuming performance data of the API interface is obtained by printing a time consuming log of the API interface. In the first mode, a developer needs to insert a corresponding execution time code into an original API interface, roughly cut the interface code into different modules, obtain time-consuming information of each module, and finally print the information to a log or return the information through the interface. Namely, in the first mode: the code block inserted with datetime needs to be made for a specific interface, so that the purity of the code is guaranteed, and the source code needs to be read.
In the second mode, the API interface time-consuming performance data is analyzed through the cProfile, and as shown in fig. 2, the API interface time-consuming data is analyzed through the cProfile. In the second mode, the time-consuming data of the API interface is analyzed through the cProfile scheme, so that the purposes of ensuring the purity of the API interface code and reducing invasion can be achieved, but in the second mode, if all the API interfaces are opened, the usability of the application can be seriously affected.
From the above description, it can be seen that the present solution mainly has the following problems: the source code needs to be read and modularly segmented, and some evaluation of the source code made, and the relatively long time consuming modules may need to be segmented and analyzed again in depth. 2) The source code is invaded, and the source code is polluted by modifying the code in the API interface to a certain extent. 3) When time-consuming performance data analysis is needed to be performed on one API interface, and time-consuming performance data analysis is not needed to be performed on other API interfaces, switching cannot be performed at any time.
Aiming at the technical problem that the use performance of an API application is reduced because all existing API interfaces need to be opened when time-consuming data of the API interface is analyzed through a deterministic analyzer cProfile in the prior art. There is currently no effective solution.
Disclosure of Invention
The embodiment of the application provides a method and a device for acquiring function execution time, which at least solve the technical problem of reduced use performance of API application caused by the condition that all existing API interfaces need to be opened when time-consuming data of the API interfaces are analyzed through a deterministic analyzer cProfile in the related art.
According to an embodiment of the present application, there is provided a method for acquiring a function execution time, including: acquiring a first call request, wherein the first call request is used for calling a first target application program interface API, the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used for acquiring execution time of the target function; setting a state of the time detection module to a state that allows execution in response to the first call request; and executing the time detection module and the objective function to obtain the execution time of the objective function.
Further, after executing the time detection module and the objective function, the method further comprises: setting a state of the time detection module in the first target API to the disabled state.
Further, before the obtaining the first call request, the method further includes: and adding the time detection module in a first initial API to obtain the first target API, wherein the first initial API comprises the target function to be executed.
Further, executing the time detection module and the objective function, and obtaining the execution time of the objective function includes: and in the process of obtaining the execution time of the objective function, generating a log of the execution time of all the objective functions in the first objective application program interface API, and storing the log in a database.
Further, after storing the log in the database, the method further comprises: acquiring functions with execution time of all target functions exceeding a first threshold value in the first target API and calling relations among the functions exceeding the first threshold value according to the log; and adjusting the function according to the calling relation so as to reduce the execution time of the target function.
According to another embodiment of the present application, there is provided an apparatus for acquiring a function execution time, including: the system comprises an acquisition unit, a first call request, a second call request and a second call request, wherein the first call request is used for calling a first target application program interface API, the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of being forbidden to be executed before the first target API is called, and the time detection module is used for acquiring the execution time of the target function; a response unit for; and the obtaining unit is used for executing the time detection module and the objective function to obtain the execution time of the objective function.
Further, the apparatus further comprises: and a setting unit configured to set a state of the time detection module in the first target API to the state in which execution is prohibited, after the execution of the time detection module and the target function.
Further, the apparatus further comprises: and the adding unit is used for adding the time detection module in a first initial API before the first call request is acquired to obtain the first target API, wherein the first initial API comprises the target function to be executed.
According to a further embodiment of the present application, there is also provided a storage medium having stored therein a computer program, wherein the computer program is arranged to execute the steps of the method embodiment of obtaining the execution time of any one of the functions described above when run.
According to a further embodiment of the application, there is also provided an electronic device comprising a memory, in which a computer program is stored, and a processor arranged to run the computer program to perform the steps of the method embodiment of the acquisition of the execution time of any of the functions described above.
According to the method and the device for obtaining the target function, a first call request is obtained, wherein the first call request is used for calling a first target Application Program Interface (API), the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of being forbidden to be executed before the first target API is called, and the time detection module is used for obtaining the execution time of the target function; setting the state of the time detection module to a state allowing execution in response to the first call request; and the execution time detection module and the objective function are used for obtaining the execution time of the objective function. The method solves the technical problem that the use performance of the API application is reduced because all existing API interfaces need to be opened when the time-consuming data of the API interface is analyzed through a cProfile scheme in the related art.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
FIG. 1 is a schematic diagram of the prior art for obtaining time-consuming performance data of an API interface by printing a time-consuming log of the API interface;
FIG. 2 is a schematic diagram of prior art analysis of API interface time consuming data via cProfile;
FIG. 3 is a block diagram of a hardware configuration of a mobile terminal according to a method for obtaining a function execution time according to an embodiment of the present application;
FIG. 4 is a flow chart of a method for obtaining function execution time according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a structural framework for specifying an API interface for cProfile analysis of time-consuming performance data in accordance with one preferred embodiment of the present application;
FIG. 6 is a schematic diagram of a stored API interface time-consuming file for analysis by a cProfile in accordance with a preferred embodiment of the present application;
FIG. 7 is a flow chart of time consuming performance data for cProfile analysis of a specified API interface provided in accordance with a preferred embodiment of the present application;
fig. 8 is a block diagram of a function execution time acquisition apparatus according to an embodiment of the present application.
Detailed Description
The application will be described in detail hereinafter with reference to the drawings in conjunction with embodiments. It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order.
Example 1
The method for obtaining the execution time of the function according to the first embodiment of the present application may be implemented in a mobile terminal, a computer terminal, or a similar computing device. Taking the mobile terminal as an example, fig. 3 is a block diagram of a hardware structure of the mobile terminal according to a method for obtaining the execution time of the function according to an embodiment of the present application. As shown in fig. 3, the mobile terminal 10 may include one or more (only one is shown in fig. 3) processors 102 (the processor 102 may include, but is not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA) and a memory 104 for storing data, and optionally a transmission device 106 for communication functions and an input-output device 108. It will be appreciated by those skilled in the art that the structure shown in fig. 3 is merely illustrative and not limiting on the structure of the mobile terminal described above. For example, the mobile terminal 10 may also include more or fewer components than shown in FIG. 3 or have a different configuration than shown in FIG. 3.
The memory 104 may be used to store a computer program, for example, a software program of application software and a module, such as a computer program corresponding to a method for obtaining a function execution time in an embodiment of the present application, and the processor 102 executes the computer program stored in the memory 104, thereby performing various functional applications and data processing, that is, implementing the above-mentioned method. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the mobile terminal 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission means 106 is arranged to receive or transmit data via a network. The specific examples of networks described above may include wireless networks provided by the communication provider of the mobile terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, simply referred to as NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet wirelessly.
Fig. 4 is a flowchart of a method for acquiring a function execution time according to an embodiment of the present application, and as shown in fig. 4, the method for acquiring a function execution time includes the following steps:
step S402, obtaining a first call request, where the first call request is used to call a first target application program interface API, the first target API includes a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used to obtain execution time of the target function.
The first call request can be acquired by inputting a command. The time detection module may be a cProfile performance analysis tool.
It should be noted that, before the first call request is acquired, the method may further include: and adding a time detection module in the first initial API to obtain a first target API, wherein the first initial API comprises target functions to be executed.
It should be further noted that, the time detection module is in a state of prohibiting execution before the first target API is called, so that the condition that the API interfaces are all opened is avoided, and further, the use performance of the AIP is reduced.
Step S404, the state of the time detection module is set to a state allowing to be executed in response to the first call request.
Step S406, executing the time detection module and the objective function to obtain the execution time of the objective function.
It should be noted that, the executing time detecting module and the objective function, the obtaining the executing time of the objective function may include: and in the process of obtaining the execution time of the objective function, generating a log of the execution time of all the objective functions in the first objective application program interface API, and storing the log in a database. Therefore, the execution time of the objective function of the API interface can be obtained in real time, and further the function execution time is adjusted according to the real-time data, so that the performance of the API interface is improved.
Wherein, after the log is stored in the database, the method may further comprise: acquiring functions with execution time of all target functions exceeding a first threshold value in a first target API and calling relations among the functions exceeding the first threshold value according to the log; the function is adjusted according to the call relationship so as to reduce the execution time of the objective function.
It should be noted that, as can be seen from step S402 to step S406, when acquiring the execution time of the function in the first target API interface, the state of the time detection module needs to be acquired, and only when the state of the time detection module is the state that allows execution, the time detection module and the target function may be executed, so as to obtain the execution time of the target function. The method for analyzing the API which needs time-consuming performance analysis is realized without reading the source code of the API interface, modifying the source code and performing pluggable control. Furthermore, the problem of the online API interface is solved, the cProfile performance analysis can be immediately started aiming at the appointed API interface, and then the cProfile performance analysis is closed, so that the online user experience is not affected.
Through the steps, a first call request is obtained, wherein the first call request is used for calling a first target application program interface API, the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used for obtaining the execution time of the target function; setting the state of the time detection module to a state allowing execution in response to the first call request; and the execution time detection module and the objective function are used for obtaining the execution time of the objective function. The method solves the technical problem that the use performance of the API application is reduced because all existing API interfaces need to be opened when the time-consuming data of the API interface is analyzed through a cProfile scheme in the related art.
Alternatively, the execution subject of the above steps may be a server, a terminal, or the like, but is not limited thereto.
From the description of the above embodiments, it will be clear to a person skilled in the art that the method according to the above embodiments may be implemented by means of software plus the necessary general hardware platform, but of course also by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method according to the embodiments of the present application.
Example 2
In combination with the above embodiment, a preferred embodiment is also provided in this embodiment, where the preferred embodiment is a method for acquiring API interface performance data on a cProfile-based pluggable positioning line.
The preferred embodiment mainly solves the problem of locating time-consuming performance data of an on-line or off-line API (wherein the APIs processed in the preferred embodiment are all written by Python) interface of a webpage.
In the preferred embodiment, the time-consuming performance data of the API interface to be detected is processed and analyzed through the cProfile tool, and through a set of plug-in interaction flow, not only can the offline analysis of developers be facilitated, but also the time-consuming performance data of a specific interface can be analyzed in a targeted manner through designating the interface through plug-in when the interface takes too long on line, and the problem of positioning of the developer is provided in a performance data flow visualization mode, so that the problem repairing efficiency of the developer is greatly improved, meanwhile, the detection scheme has no influence on the online environment, and normal operation of the online environment is ensured.
As shown in fig. 5, one of the specific API interfaces provided in the preferred embodiment is a structural framework diagram for performing a cdrofile analysis of time-consuming performance data.
In fig. 5, there are a plurality of applications, e.g., application 1, application 2, application 3, etc., at the user layer. The routing layer has a plurality of API interfaces, e.g., API1, API2, API3, etc. And the cache layer Redis, wherein whether the cProfile is started or not is judged in the cache layer Redis. And judging that the cProfile analysis needs to be executed on the appointed API, and asynchronously storing the time-consuming data analysis result of the API interface in a file storage layer. The stored files may also be subjected to API visualization, API2 visualization, etc. at the visualization layer.
The visualization layer is described in detail as follows:
the files stored on the file storage S3 platform may be pulled for further analysis, such as obtaining sub-modules of the top10 before consuming time in the debug API, obtaining call level relationships between each module in the API, and so on. A flow scheme is also provided for the work, the scheme is realized by pstats+gprof2 dots, and a corresponding visual platform is built. As shown in fig. 6, a certain cdrofile analyzes a schematic of saved API interface time-consuming time files. The details are as follows.
As can be seen from fig. 6, the output result of the execution time of a certain API indicates that: there are 34330 function calls in total; ncall: the number of times the function is called, the total running time of the tottime function, the average time of one time of the per call function running is equal to the total running time of the tottime/ncall and the cumtime function, and the total running time of the function contains the called running time of the function and the filename: lineno (function) the file name of the function, the number of rows of the function, and the function number. In the output results shown in fig. 6, the time at which each function is executed can be clearly known. The functions can be ordered according to the execution time, and the functions with longer execution time can be checked for further adjustment.
And carrying out secondary analysis according to the stored file output in the figure 5 to obtain a sub-module function of the time-consuming top10 and a calling level relation among all modules in the API.
In this embodiment, centralized maintenance and management are performed on the API interfaces that need to initiate the cProfile analysis, and an administrator can configure these APIs in the background, and the program synchronizes the configured APIs that need to initiate the cProfile analysis into the Redis cache; and the analysis and demonstration of the later visual layer are facilitated by judging that the cProfile analysis is required to be executed on the appointed API and asynchronously storing the analysis result in the file storage S3 platform. Through the configurable and pluggable scheme, the purpose of performance debugging of the on-line interface is guaranteed, and the purity, pollution-free and safety of the interface are also guaranteed.
As shown in fig. 7, a flow diagram of time consuming performance data for a cdofile analysis of a specified API interface is provided in the preferred embodiment. It should be noted that the implementation of this flow is based on the structural framework diagram in fig. 5.
Step S701, start.
In step S702, the user initiates a URL request, and the background enters a designated API interface after routing.
Step S703, when entering the specified API interface, it needs to be determined whether the interface has a cProfile performance debug started, if the cProfile performance debug is not started, step S804 is entered, and if the cProfile performance debug is started, step S805 is entered.
Step S704, executing the API interface contents.
Step S705, if the cProfile performance debug is turned on, executing the turn-on cProfile.
Step S706, executing API interface contents.
Step S707, finally, closing the cdofile debug is ended.
In step S708, the obtained performance debugging data is saved in the background S3 (here, the built S3 platform is used), and is used for further analysis in the later period.
Step S709 ends.
With this preferred embodiment, a complete set of pluggable and switch-controlled positioning line interface performance bottlenecks is proposed, mainly for the deterministic analyzer cProfile performance analysis tool, which can be achieved if other analysis tools are used, such as APM (application performance management).
Example 3
The embodiment also provides a device for obtaining the function execution time, which is used for implementing the foregoing embodiments and the preferred implementation manner, and is not described in detail. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. While the means described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and contemplated.
Fig. 8 is a block diagram of a function execution time acquisition apparatus according to an embodiment of the present application, as shown in fig. 8, including: an acquisition unit 81, a response unit 83, an acquisition unit 85. The details are as follows.
The obtaining unit 81 is configured to obtain a first call request, where the first call request is used to call a first target application program interface API, the first target API includes a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is configured to obtain execution time of the target function.
And a response unit 83 that sets the state of the time detection module to a state that allows execution in response to the first call request.
A deriving unit 85, configured to set the state of the time detection module to a state that allows execution in response to the first call request.
Through the above device, the obtaining unit 81 obtains a first call request, where the first call request is used to call a first target application program interface API, the first target API includes a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used to obtain execution time of the target function; the response unit 83 sets the state of the time detection module to a state that allows execution in response to the first call request; the obtaining unit 85 sets the state of the time detection module to a state that allows execution in response to the first call request. The method solves the technical problem that the usability of the API application is reduced under the condition that all existing API interfaces need to be opened when the time-consuming data of the API interface is analyzed through a deterministic analyzer cProfile scheme in the related art
It should be noted that each of the above modules may be implemented by software or hardware, and for the latter, it may be implemented by, but not limited to: the modules are all located in the same processor; alternatively, the above modules may be located in different processors in any combination.
Example 4
An embodiment of the application also provides a storage medium having a computer program stored therein, wherein the computer program is arranged to perform the steps of any of the method embodiments described above when run.
Alternatively, in the present embodiment, the above-described storage medium may be configured to store a computer program for performing the steps of:
s1, acquiring a first call request, wherein the first call request is used for calling a first target Application Program Interface (API), the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used for acquiring the execution time of the target function;
s2, setting the state of the time detection module to be a state allowing execution in response to the first call request;
s3, executing the time detection module and the objective function to obtain the execution time of the objective function.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a usb disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing a computer program.
An embodiment of the application also provides an electronic device comprising a memory having stored therein a computer program and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Alternatively, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
s1, acquiring a first call request, wherein the first call request is used for calling a first target Application Program Interface (API), the first target API comprises a time detection module and a target function to be executed, the time detection module is in a state of prohibiting execution before the first target API is called, and the time detection module is used for acquiring the execution time of the target function;
s2, setting the state of the time detection module to be a state allowing execution in response to the first call request;
s3, executing the time detection module and the objective function to obtain the execution time of the objective function.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments and optional implementations, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the application described above may be implemented in a general purpose computing device, they may be concentrated on a single computing device, or distributed across a network of computing devices, they may alternatively be implemented in program code executable by computing devices, so that they may be stored in a memory device for execution by computing devices, and in some cases, the steps shown or described may be performed in a different order than that shown or described, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps within them may be fabricated into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
The above description is only of the preferred embodiments of the present application and is not intended to limit the present application, but various modifications and variations can be made to the present application by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the principle of the present application should be included in the protection scope of the present application.

Claims (9)

1. A method for obtaining execution time of a function, comprising:
before a first target application program interface API is called, configuring a time detection module into a state of prohibiting execution, wherein the time detection module is used for acquiring the execution time of a target function to be executed by the first target application program interface API, and the first target application program interface API comprises the time detection module and the target function;
acquiring a first call request, wherein the first call request is used for calling the first target application program interface API;
setting the state of the time detection module to be allowed to be executed in response to the first call request, and starting the time detection module and executing the objective function to obtain the execution time of the objective function;
and asynchronously storing the log generated based on the execution time of the objective function in a file storage layer, and displaying the log in a visualization layer.
2. The method of claim 1, wherein after executing the objective function, the method further comprises:
setting the state of the time detection module in the first target application program interface API to the disabled state.
3. The method of claim 1, wherein prior to the obtaining the first call request, the method further comprises:
and adding the time detection module in a first initial API to obtain the first target application program interface API, wherein the first initial API comprises the target function.
4. The method of claim 1, wherein after asynchronously saving the log generated based on the execution time of the objective function in a file storage layer, the method further comprises:
acquiring functions with execution time of all target functions exceeding a first threshold value in the first target application program interface API and calling relations among the functions exceeding the first threshold value according to the log;
and adjusting the function according to the calling relation so as to reduce the execution time of the target function.
5. An apparatus for acquiring a function execution time, comprising:
the method comprises the steps of obtaining a first call request, wherein the first call request is used for calling a first target application program interface API;
a response unit, configured to set a state of the time detection module to a state that allows execution in response to the first call request;
the obtaining unit is used for starting the time detection module and executing the objective function to obtain the execution time of the objective function;
the device is further configured to configure a time detection module to be in a state of prohibiting execution before a first target application program interface API is called, where the time detection module is configured to obtain execution time of an objective function to be executed by the first target application program interface API, and the first target application program interface API includes the time detection module and the objective function; and asynchronously storing the log generated based on the execution time of the objective function in a file storage layer, and displaying the log in a visualization layer.
6. The apparatus of claim 5, wherein the apparatus further comprises:
and a setting unit, configured to set a state of the time detection module in the first target application program interface API to the state in which execution is prohibited.
7. The apparatus of claim 5, wherein the apparatus further comprises:
and the adding unit is used for adding the time detection module into a first initial API to obtain the first target application program interface API, wherein the first initial API comprises the target function.
8. A storage medium having a computer program stored therein, wherein the computer program is arranged to perform the method of any of claims 1 to 4 when run.
9. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to run the computer program to perform the method of any of the claims 1 to 4.
CN201910757322.3A 2019-08-16 2019-08-16 Method and device for acquiring function execution time Active CN110457196B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910757322.3A CN110457196B (en) 2019-08-16 2019-08-16 Method and device for acquiring function execution time

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910757322.3A CN110457196B (en) 2019-08-16 2019-08-16 Method and device for acquiring function execution time

Publications (2)

Publication Number Publication Date
CN110457196A CN110457196A (en) 2019-11-15
CN110457196B true CN110457196B (en) 2023-10-24

Family

ID=68486993

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910757322.3A Active CN110457196B (en) 2019-08-16 2019-08-16 Method and device for acquiring function execution time

Country Status (1)

Country Link
CN (1) CN110457196B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111625302A (en) * 2020-05-29 2020-09-04 北京字节跳动网络技术有限公司 Function time consumption tracking method, device and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014222384A (en) * 2013-05-13 2014-11-27 日本電気株式会社 Function execution time measuring device, function execution time measuring method, and function execution time measuring program
CN104866416A (en) * 2014-02-25 2015-08-26 腾讯科技(深圳)有限公司 Method and device for performance analysis of application program
CN107957931A (en) * 2017-11-23 2018-04-24 泰康保险集团股份有限公司 A kind of method and device for monitoring run time
CN108037926A (en) * 2017-12-26 2018-05-15 网易(杭州)网络有限公司 Optimization method, device, storage medium, processor and the terminal of bytecode
CN109783161A (en) * 2018-12-11 2019-05-21 北京三快在线科技有限公司 The operation information of application program determines method, apparatus in iOS system
CN109947624A (en) * 2019-03-25 2019-06-28 深圳市腾讯信息技术有限公司 Method for monitoring state and device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7895579B2 (en) * 2006-06-16 2011-02-22 Microsoft Corporation Automated method and system for collecting and reporting API performance profiles
US9934122B2 (en) * 2014-07-09 2018-04-03 Microsoft Technology Licensing, Llc Extracting rich performance analysis from simple time measurements
US9569288B2 (en) * 2014-07-15 2017-02-14 International Business Machines Corporation Application pattern discovery
EP3104278A1 (en) * 2015-06-12 2016-12-14 dSPACE digital signal processing and control engineering GmbH Method for the realistic estimation of function runtimes in pil simulation

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2014222384A (en) * 2013-05-13 2014-11-27 日本電気株式会社 Function execution time measuring device, function execution time measuring method, and function execution time measuring program
CN104866416A (en) * 2014-02-25 2015-08-26 腾讯科技(深圳)有限公司 Method and device for performance analysis of application program
CN107957931A (en) * 2017-11-23 2018-04-24 泰康保险集团股份有限公司 A kind of method and device for monitoring run time
CN108037926A (en) * 2017-12-26 2018-05-15 网易(杭州)网络有限公司 Optimization method, device, storage medium, processor and the terminal of bytecode
CN109783161A (en) * 2018-12-11 2019-05-21 北京三快在线科技有限公司 The operation information of application program determines method, apparatus in iOS system
CN109947624A (en) * 2019-03-25 2019-06-28 深圳市腾讯信息技术有限公司 Method for monitoring state and device

Also Published As

Publication number Publication date
CN110457196A (en) 2019-11-15

Similar Documents

Publication Publication Date Title
EP3471344B1 (en) System and method for selecting proxy computer
CN108845930B (en) Interface operation test method and device, storage medium and electronic device
US20170168885A1 (en) System and Method for Testing Internet of Things Network
CA3137748A1 (en) Method and apparatus for determining configuration knob of database
CN109614325B (en) Method and device for determining control attribute, electronic equipment and storage medium
CN112702225B (en) Cloud platform performance testing device and method, computer terminal and readable storage medium
EP3413149B1 (en) Field device commissioning system and field device commissioning method
CN112035344A (en) Multi-scenario test method, device, equipment and computer readable storage medium
CN110457196B (en) Method and device for acquiring function execution time
CN107621963B (en) Software deployment method, software deployment system and electronic equipment
CN116166525A (en) Method and device for generating test script
CN111859139A (en) Application program recommendation method and device, computing equipment and medium
CN114416451A (en) Server testing method and device, computer equipment and storage medium
EP4142238A1 (en) Pico base station configuration method and apparatus, and storage medium and electronic apparatus
CN112732556B (en) Automatic testing method, device, equipment and storage medium of distributed system
CN109783837A (en) Emulator, analogue system, emulation mode and simulated program
CN113448844A (en) Method and device for regression testing and electronic equipment
CN110990381B (en) Processing method and device of server, storage medium and electronic device
CN111459796B (en) Automated testing method, apparatus, computer device and storage medium
CN114880157B (en) Fault injection method and device
CN111651350A (en) Test case processing method, device and equipment and computer readable storage medium
CN114944942B (en) Data reporting method and device based on effective buried points, computer equipment and medium
CN116303320A (en) Real-time task management method, device, equipment and medium based on log file
CN105868957A (en) Continuous integration method and device
CN112817816B (en) Embedded point processing method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant