CN110580220B - Method for measuring code segment execution time and terminal equipment - Google Patents

Method for measuring code segment execution time and terminal equipment Download PDF

Info

Publication number
CN110580220B
CN110580220B CN201910739083.9A CN201910739083A CN110580220B CN 110580220 B CN110580220 B CN 110580220B CN 201910739083 A CN201910739083 A CN 201910739083A CN 110580220 B CN110580220 B CN 110580220B
Authority
CN
China
Prior art keywords
measured
position information
code
code segment
instruction
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
CN201910739083.9A
Other languages
Chinese (zh)
Other versions
CN110580220A (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.)
PAX Computer Technology Shenzhen Co Ltd
Original Assignee
PAX Computer 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 PAX Computer Technology Shenzhen Co Ltd filed Critical PAX Computer Technology Shenzhen Co Ltd
Priority to CN201910739083.9A priority Critical patent/CN110580220B/en
Publication of CN110580220A publication Critical patent/CN110580220A/en
Application granted granted Critical
Publication of CN110580220B publication Critical patent/CN110580220B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3628Software debugging of optimised code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3644Software debugging by instrumenting at runtime
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/366Software debugging using diagnostics

Landscapes

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

Abstract

The invention is applicable to the technical field of program optimization, and provides a method for measuring execution time of a code segment and terminal equipment, wherein the method comprises the following steps: analyzing the obtained measurement instruction set to obtain a position information database; replacing code instructions to be measured on all positions corresponding to the position information of the code segment to be measured with preset instructions; when the preset instruction in the code segment to be measured is operated, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured; after the code segment to be measured is operated, the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set is calculated, so that the execution time of any code segment of the program can be measured under the condition that the program code is not modified, the execution efficiency of which code segment of the program is not high can be rapidly diagnosed, the automatic measurement is realized, a measurement result is formed, and further analysis is facilitated.

Description

Method for measuring code segment execution time and terminal equipment
Technical Field
The invention belongs to the technical field of program optimization, and particularly relates to a method for measuring execution time of a code segment and terminal equipment.
Background
In the process of program operation, the problem of low program operation efficiency often exists, so that various experiences of users are affected. At present, codes corresponding to programs can be manually reviewed, the codes are subjected to logic analysis, codes which are possibly excessively time-consuming are found out, then debug information is added by modifying the codes which are correspondingly excessively time-consuming, then actual running debug verification is carried out, and software codes and debug verification are repeatedly modified, so that the workload is high. In addition, the software codes need to be modified for many times, various debugging information is added to diagnose that the code fragments are excessively time-consuming to execute, and therefore the work efficiency of searching codes with lower running efficiency is extremely low.
Disclosure of Invention
In view of the above, the embodiments of the present invention provide a method and a terminal device for measuring execution time of a code segment, so as to solve the problems of excessive workload and low efficiency of modifying software codes when excessive time consuming code may exist in searching by modifying the software codes in the prior art.
A first aspect of an embodiment of the present invention provides a method for measuring execution time of a code segment, including:
analyzing the obtained measurement instruction set to obtain a position information database, wherein the position information database comprises a plurality of position information records, and each position information record comprises position information of a code segment to be measured, a backup code instruction to be measured and access time of the code segment to be measured;
replacing code instructions to be measured on positions corresponding to all position information of the code segments to be measured with preset instructions;
when the preset instruction in the code segment to be measured is operated, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured;
and after the code segment to be measured is operated, calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result.
In an embodiment, before said parsing the acquired measurement instruction set, further comprises:
acquiring a code segment to be measured;
and obtaining a measurement instruction set according to the code segment to be measured, wherein the measurement instruction set comprises a plurality of instructions, and each instruction comprises the position information of the code segment to be measured.
In an embodiment, the position information of the code segment to be measured includes a start position and an end position of the code segment to be measured.
In an embodiment, the analyzing the obtained measurement instruction set to obtain the location information database includes:
analyzing the acquired measurement instruction set to acquire all position information of the code segment to be measured;
obtaining code instructions to be measured at corresponding positions according to the position information, and carrying out backup processing to obtain backup code instructions to be measured;
setting access time corresponding to all the position information as a preset value;
obtaining a position information record corresponding to each position information according to all the position information, the backup code instruction to be measured and the set access time of the code segment to be measured;
and forming a position information database comprising all position information records according to the position information records corresponding to each position information.
In an embodiment, before the acquiring the code segment to be measured, the method further includes:
stopping the operation of the measured program;
after replacing the code instruction to be measured on the corresponding position of all the position information with the preset instruction, the method further comprises the following steps:
the operation of the measured program is started.
In an embodiment, when the preset instruction in the code segment to be measured is executed, replacing the preset instruction with the backed up code instruction to be measured, and saving the current time to the access time of the code segment to be measured, including:
when the preset instructions in the code segment to be measured are operated, jumping to preset programs corresponding to the preset instructions, and executing the preset programs;
the preset program obtains detection position information of the preset instruction;
searching a corresponding position information record in the position information database according to the detected position information, replacing the preset instruction with a code instruction to be measured, which is backed up in the position information record, and updating the access time of the code segment to be measured in the position information record according to the current time.
In an embodiment, before calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result, the method further includes:
detecting whether all the access time of all the code segments to be measured in the position information database are valid;
when the access time of all the code segments to be measured is all effective, calculating the execution time of the code segments to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result, and returning to the position corresponding to the detection position information to continue executing the measured program;
after detecting whether all the access times of all the code segments to be measured in the location information database are valid, the method further comprises:
and when the access time of all the code segments to be measured is not all valid, directly returning to the position corresponding to the detection position information to continue to execute the measured program.
In an embodiment, the detecting whether the access time of all the code segments to be measured in the location information database is all valid includes:
and detecting whether all the access time of all the code segments to be measured in the position information database are not the preset value.
A second aspect of an embodiment of the present invention provides an apparatus for measuring execution time of a code segment, including:
the analysis module is used for analyzing the acquired measurement instruction set to obtain a position information database, wherein the position information database comprises a plurality of position information records, and each position information record comprises position information of a code segment to be measured, a backup code instruction to be measured and access time of the code segment to be measured;
the processing module is used for replacing code instructions to be measured on positions corresponding to all position information of the code segments to be measured by preset instructions;
the processing module is further configured to replace the preset instruction with the backed-up code instruction to be measured when the preset instruction is run into the code segment to be measured, and save the current time into the access time of the code segment to be measured;
and the calculation module is used for calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set after the code segment to be measured runs, so as to obtain a measurement result.
A third aspect of an embodiment of the present invention provides a terminal device, including: a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the computer program, realizes the steps as described in the method for measuring the execution time of a code segment.
Compared with the prior art, the embodiment of the invention has the beneficial effects that: replacing code instructions to be measured on all positions corresponding to the position information of the code segment to be measured with preset instructions; when the preset instruction in the code segment to be measured is operated, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured; after the code segment to be measured is operated, the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set is calculated, so that the execution time of any code segment of the program can be measured under the condition that the program code is not modified, the execution efficiency of which code segment of the program is not high can be rapidly diagnosed, the automatic measurement is realized, a measurement result is formed, and further analysis is facilitated.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings that are needed in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a method for measuring execution time of a code segment according to an embodiment of the present invention;
FIG. 2 is a flow chart of obtaining a measurement instruction set according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of replacing preset instructions and saving a current time to an access time according to an embodiment of the present invention;
FIG. 4 is an exemplary diagram of an apparatus for measuring execution time of a code segment provided by an embodiment of the present invention;
FIG. 5 is a schematic diagram of a system for measuring execution time of a code segment provided by an embodiment of the present invention;
fig. 6 is a schematic diagram of a terminal device according to an embodiment of the present invention.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as the particular system architecture, techniques, etc., in order to provide a thorough understanding of the embodiments of the present invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to illustrate the technical scheme of the invention, the following description is made by specific examples.
Fig. 1 is a schematic implementation flow chart of a method for measuring execution time of a code segment according to an embodiment of the present invention, which is described in detail below.
And step 101, analyzing the acquired measurement instruction set to obtain a position information database.
The position information database comprises a plurality of position information records, and each position information record comprises position information of a code segment to be measured, a backup code instruction to be measured and access time of the code segment to be measured.
Optionally, as shown in fig. 2, before this step, the following steps may be further included:
in step 201, a code segment to be measured is obtained.
Optionally, before step 201, the method may further include: and stopping the running of the measured program, and then setting the code segment to be measured, namely acquiring the code segment to be measured.
Step 202, obtaining a measurement instruction set according to the code segment to be measured, wherein the measurement instruction set comprises a plurality of instructions, and each instruction comprises position information of the code segment to be measured.
Alternatively, the position information of the code segment to be measured may include a start position and an end position of the code segment to be measured. For example, the start position is a and the end position is B. It will be appreciated that the location herein is the memory address where the code is located in the running space, and the start location may also be referred to as a start memory address, and the end location may be referred to as an end memory address.
Alternatively, the execution entity that obtains the measurement instruction set may be a control unit, and the control unit may send the measurement instruction set to the measurement unit, so that the measurement unit may further process the measurement instruction set, i.e. perform the operation of step 101.
Optionally, step 101 may include: analyzing the acquired measurement instruction set to acquire all position information of the code segment to be measured; obtaining code instructions to be measured at corresponding positions according to the position information, and carrying out backup processing to obtain backup code instructions to be measured; setting access time corresponding to all the position information as a preset value; obtaining a position information record corresponding to each position information according to all the position information, the backup code instruction to be measured and the set access time of the code segment to be measured; and forming a position information database comprising all position information records according to the position information records corresponding to each position information.
Alternatively, the access time, i.e., the preset value, may be set to be empty, or the access time may be set to 0.
And 102, replacing the code instruction to be measured on the corresponding position of all the position information of the code segment to be measured with a preset instruction.
Alternatively, the preset instruction may be a probe instruction, and the probe instruction may be generally implemented by various abnormal instructions supported by the CPU.
After the replacement work of the code instruction to be measured on the corresponding position of all the position information is completed, the measuring unit informs the control unit to start the operation of the measured program. After receiving the instruction, the control unit starts the running of the measured program.
Step 103, when the preset instruction in the code segment to be measured is run, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured.
Optionally, as shown in fig. 3, step 103 includes the following steps.
Step 301, when the preset instruction in the code segment to be measured is executed, jumping to a preset program corresponding to the preset instruction, and executing the preset program.
Optionally, when the measured program runs to the program instruction where a certain position information item is located, the instruction at this time is not the original program instruction, but the replaced preset instruction is the detection instruction, so that the measured program jumps to the preset program corresponding to the measuring unit, and the execution of the preset program is started. The preset program may be a probing program.
Step 302, the preset program obtains the detection position information where the preset instruction is located.
The detection program acquires the position information of the detection instruction when the trigger detection program is called, and the position information is simply detected.
Step 303, searching for a corresponding location information record in the location information database according to the detected location information, replacing the preset instruction with a code instruction to be measured, which is backed up in the location information record, and updating the access time of the code segment to be measured in the location information record according to the current time.
Step 303 is to restore the original code instruction to be measured to the original code to be measured, so the embodiment can detect the execution time of each code segment of the program without modifying the program code.
The current time may be Real-time clock (RTC) time, i.e. the preset value of the access time is updated to the RTC time.
And 104, after the code segment to be measured is operated, calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result.
Optionally, after the code segments to be measured are run, the detection program detects whether all the access times of all the code segments to be measured in the location information database are valid, that is, detects whether all the access times of all the code segments to be measured in the location information database are not preset values. If the preset value is set to be null or 0, since the RTC time cannot be 0, it is possible to detect whether the access time is valid as long as it is detected whether the access time in the location information database is 0 or null.
When all the access times of the code segments to be measured are valid, calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set, for example, by inquiring a position information database, acquiring the access time of the starting position and the ending position, calculating the difference value to obtain the execution time of the code segment to be measured, forming a measurement result, informing a control unit of the completion of measurement, and returning to the position corresponding to the detection position information to continue executing the measured program.
Optionally, when the access time of all the code segments to be measured is not all valid, directly returning to the position corresponding to the detection position information to continue executing the measured program.
Optionally, after the control unit receives the notification of the completion of the measurement, the measurement result can be actively read by the measurement unit to confirm the time-consuming execution of each code segment of the measured program, or the time-consuming execution is transmitted to the cloud processing.
According to the method for measuring the execution time of the code segment, the code instruction to be measured on the corresponding positions of all the position information of the code segment to be measured is replaced by the preset instruction; when the code instruction to be measured is operated to a preset instruction, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured; and after the code segment to be measured is operated, calculating the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result. The embodiment can realize measurement of the execution time of any code segment of the program under the condition of not modifying the program code, thereby being capable of rapidly diagnosing which code segment of the program has low execution efficiency, realizing automatic measurement, forming a measurement result and being convenient for further analysis.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present invention.
Corresponding to the method for measuring the execution time of the code segment described in the above embodiments, fig. 4 is an exemplary diagram of an apparatus for measuring the execution time of the code segment according to an embodiment of the present invention. As shown in fig. 4, the apparatus may include: a parsing module 401, a processing module 402 and a computing module 403.
The analyzing module 401 is configured to analyze the obtained measurement instruction set to obtain a location information database, where the location information database includes a plurality of location information records, and each location information record includes location information of a code segment to be measured, a backup code instruction to be measured, and access time of the code segment to be measured;
a processing module 402, configured to replace code instructions to be measured on positions corresponding to all position information of the code segment to be measured with preset instructions;
the processing module 402 is further configured to replace the preset instruction with the backed-up code instruction to be measured when the preset instruction is run into the code segment to be measured, and save the current time to the access time of the code segment to be measured;
and the calculating module 403 is configured to calculate an execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set after the code segment to be measured runs, so as to obtain a measurement result.
Alternatively, an example diagram of a system for measuring the execution time of a code segment is shown in fig. 5, which system comprises a control unit 501, a measurement unit 502 and a timing unit 503. It should be noted that the code segment to be measured must run in the same code executable address space as the system that measures the execution time of the code segment.
Optionally, the control unit 501 is configured to control the running or stopping of the measured program, determine which code segments need to be measured, obtain a measurement result, further process the measurement result, and so on.
The measurement unit 502 is responsible for measuring all code segments to be measured and outputting measurement results.
A timing unit 503 for providing time-related information.
Alternatively, the measuring unit 502 may include any one of the modules of the apparatus for measuring the execution time of the code segments.
Optionally, the control unit 501 is configured to obtain a code segment to be measured; obtaining a measurement instruction set according to the code segment to be measured, wherein the measurement instruction set comprises a plurality of instructions, and each instruction comprises the position information of the code segment to be measured; and transmitting the code segment to be measured to the measurement unit 502.
Optionally, the position information of the code segment to be measured includes a start position and an end position of the code segment to be measured.
When the measuring unit 502 receives the code segment to be measured, the analyzing module 401 analyzes the obtained measurement instruction set to obtain a location information database. Optionally, the analyzing module 401 is configured to analyze the obtained measurement instruction set to obtain all the location information of the code segment to be measured; obtaining code instructions to be measured at corresponding positions according to the position information, and carrying out backup processing to obtain backup code instructions to be measured; setting access time corresponding to all the position information as a preset value; obtaining a position information record corresponding to each position information according to all the position information, the backup code instruction to be measured and the set access time of the code segment to be measured; and forming a position information database comprising all position information records according to the position information records corresponding to each position information.
After the parsing module 401 parses the code segment, the processing module 402 is configured to replace the code instruction to be measured in the position corresponding to all the position information of the code segment to be measured with a preset instruction. The measurement unit 502 then sends a notification to the control unit 501 to start the measured program running. Upon receiving this notification, the control unit 501 starts the operation of the measured program.
Optionally, the processing module 402 in the measurement unit 502 is configured to jump to a preset program corresponding to the preset instruction and execute the preset program when running to the preset instruction in the code segment to be measured; the preset program obtains detection position information of the preset instruction; searching a corresponding position information record in the position information database according to the detected position information, replacing the preset instruction with a code instruction to be measured, which is backed up in the position information record, and acquiring the current time from the timing unit 503, and updating the access time of the code segment to be measured in the position information record according to the current time.
Optionally, before the calculating module 403 calculates the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set, the processing module 402 is further configured to detect whether all access times of all code segments to be measured in the location information database are valid, that is, detect whether all access times of all code segments to be measured in the location information database are not preset values.
When the access time of all the code segments to be measured is all valid, the calculation module 403 calculates the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result, and the processing module 402 returns the position corresponding to the detection position information to continue executing the measured program;
when the access time of all the code segments to be measured is not all valid, the processing module 402 directly returns to the position corresponding to the detection position information to continue to execute the measured program.
After receiving the notification of the completion of the measurement, the control unit 501 confirms the time-consuming condition of executing each code segment of the measured program by the main reading measurement result of the measurement unit 502, or transmits the time-consuming condition to the cloud processing.
The device for measuring the execution time of the code segment replaces the code instruction to be measured on the corresponding position of all the position information of the code segment to be measured with the preset instruction through the processing module; when the code instruction to be measured is operated to a preset instruction, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code section to be measured; and after the code segment to be measured is operated, the calculation module calculates the execution time of the code segment to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result. The embodiment can realize measurement of the execution time of any code segment of the program under the condition of not modifying the program code, thereby being capable of rapidly diagnosing which code segment of the program has low execution efficiency, realizing automatic measurement, forming a measurement result and being convenient for further analysis.
Fig. 6 is a schematic diagram of a terminal device according to an embodiment of the present invention. As shown in fig. 6, the terminal device 600 of this embodiment includes: a processor 601, a memory 602 and a computer program 603 stored in said memory 602 and executable on said processor 601, for example a program for measuring the execution time of a code segment. The steps of the method embodiment for measuring the execution time of the code segments, such as steps 101 to 104 shown in fig. 1, or steps 201 to 202 shown in fig. 2, or steps 301 to 303 shown in fig. 3, are implemented when the processor 601 executes the computer program 603, and the functions of the modules of the device embodiments, such as the functions of the modules 401 to 403 shown in fig. 4, are implemented when the processor 601 executes the computer program 603.
By way of example, the computer program 603 may be partitioned into one or more program modules that are stored in the memory 602 and executed by the processor 601 to implement the present invention. The one or more program modules may be a series of computer program instruction segments capable of performing the specified functions, describing the execution of the computer program 603 in the means for measuring the execution time of the code segments or in the terminal device 600. For example, the computer program 603 may be divided into a parsing module 401, a processing module 402 and a calculating module 403, where specific functions of each module are shown in fig. 4, and are not described herein.
The terminal device 600 may be a computing device such as a desktop computer, a notebook computer, a palm computer, and a cloud server. The terminal device may include, but is not limited to, a processor 601, a memory 602. It will be appreciated by those skilled in the art that fig. 6 is merely an example of a terminal device 600 and is not limiting of the terminal device 600, and may include more or fewer components than shown, or may combine certain components, or different components, e.g., the terminal device may also include input and output devices, network access devices, buses, etc.
The processor 601 may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), off-the-shelf programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 602 may be an internal storage unit of the terminal device 600, for example, a hard disk or a memory of the terminal device 600. The memory 602 may also be an external storage device of the terminal device 600, for example, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the terminal device 600. Further, the memory 602 may also include both an internal storage unit and an external storage device of the terminal device 600. The memory 602 is used for storing the computer program and other programs and data required by the terminal device 600. The memory 602 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other manners. For example, the apparatus/terminal device embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical function division, and there may be additional divisions in actual implementation, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via interfaces, devices or units, which may be in electrical, mechanical or other forms.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated modules/units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present invention may implement all or part of the flow of the method of the above embodiment, or may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, and when the computer program is executed by a processor, the computer program may implement the steps of each of the method embodiments described above. . Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunications signal, a software distribution medium, and so forth. It should be noted that the computer readable medium contains content that can be appropriately scaled according to the requirements of jurisdictions in which such content is subject to legislation and patent practice, such as in certain jurisdictions in which such content is subject to legislation and patent practice, the computer readable medium does not include electrical carrier signals and telecommunication signals.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention, and are intended to be included in the scope of the present invention.

Claims (10)

1. A method of measuring execution time of a code segment, comprising:
analyzing the obtained measurement instruction set to obtain a position information database, wherein the position information database comprises a plurality of position information records, and each position information record comprises position information of a code segment to be measured, a backup code instruction to be measured and access time of the code segment to be measured;
replacing code instructions to be measured on positions corresponding to all position information of the code segments to be measured with preset instructions;
when the preset instruction in the code segment to be measured is operated, replacing the preset instruction with the backed-up code instruction to be measured, and storing the current time into the access time of the code segment to be measured;
after the code segments to be measured are run, detecting whether all the access time of all the code segments to be measured in the position information database are valid; when the access time of all the code segments to be measured is all effective, calculating the execution time of the code segments to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result, and returning to the position corresponding to the detection position information to continue executing the program to be measured.
2. The method of measuring code segment execution time of claim 1, further comprising, prior to said resolving the acquired measurement instruction set:
acquiring a code segment to be measured;
and obtaining a measurement instruction set according to the code segment to be measured, wherein the measurement instruction set comprises a plurality of instructions, and each instruction comprises the position information of the code segment to be measured.
3. The method of measuring execution time of a code segment according to claim 2, wherein the position information of the code segment to be measured includes a start position and an end position of the code segment to be measured.
4. The method of measuring execution time of a code segment of claim 1, wherein said parsing the acquired measurement instruction set to obtain a location information database comprises:
analyzing the acquired measurement instruction set to acquire all position information of the code segment to be measured;
obtaining code instructions to be measured at corresponding positions according to the position information, and carrying out backup processing to obtain backup code instructions to be measured;
setting access time corresponding to all the position information as a preset value;
obtaining a position information record corresponding to each position information according to all the position information, the backup code instruction to be measured and the set access time of the code segment to be measured;
and forming a position information database comprising all position information records according to the position information records corresponding to each position information.
5. The method of measuring code segment execution time of claim 2, further comprising, prior to said acquiring the code segment to be measured:
stopping the operation of the measured program;
after replacing the code instruction to be measured on the corresponding position of all the position information with the preset instruction, the method further comprises the following steps:
the operation of the measured program is started.
6. The method of measuring execution time of a code segment according to any one of claims 1 to 5, wherein the replacing the preset instruction with the backed up code instruction to be measured when the preset instruction in the code segment to be measured is executed, and saving the current time into the access time of the code segment to be measured, comprises:
when the preset instructions in the code segment to be measured are operated, jumping to preset programs corresponding to the preset instructions, and executing the preset programs;
the preset program obtains detection position information of the preset instruction;
searching a corresponding position information record in the position information database according to the detected position information, replacing the preset instruction with a code instruction to be measured, which is backed up in the position information record, and updating the access time of the code segment to be measured in the position information record according to the current time.
7. The method of measuring execution time of code segments according to claim 6, further comprising, after said detecting whether access time of all code segments to be measured in said location information database is all valid:
and when the access time of all the code segments to be measured is not all valid, directly returning to the position corresponding to the detection position information to continue to execute the measured program.
8. The method for measuring execution time of code segments according to claim 7, wherein said detecting whether access time of all code segments to be measured in said location information database is all valid comprises:
and detecting whether all the access time of all the code segments to be measured in the position information database are not the preset value.
9. An apparatus for measuring execution time of a code segment, comprising:
the analysis module is used for analyzing the acquired measurement instruction set to obtain a position information database, wherein the position information database comprises a plurality of position information records, and each position information record comprises position information of a code segment to be measured, a backup code instruction to be measured and access time of the code segment to be measured;
the processing module is used for replacing code instructions to be measured on positions corresponding to all position information of the code segments to be measured by preset instructions;
the processing module is further configured to replace the preset instruction with the backed-up code instruction to be measured when the preset instruction is run into the code segment to be measured, and save the current time into the access time of the code segment to be measured;
the computing module is used for detecting whether all the access time of all the code segments to be measured in the position information database are valid or not after the code segments to be measured are run; when the access time of all the code segments to be measured is all effective, calculating the execution time of the code segments to be measured corresponding to each instruction in the measurement instruction set to obtain a measurement result, and returning to the position corresponding to the detection position information to continue executing the program to be measured.
10. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1 to 8 when the computer program is executed.
CN201910739083.9A 2019-08-12 2019-08-12 Method for measuring code segment execution time and terminal equipment Active CN110580220B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910739083.9A CN110580220B (en) 2019-08-12 2019-08-12 Method for measuring code segment execution time and terminal equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910739083.9A CN110580220B (en) 2019-08-12 2019-08-12 Method for measuring code segment execution time and terminal equipment

Publications (2)

Publication Number Publication Date
CN110580220A CN110580220A (en) 2019-12-17
CN110580220B true CN110580220B (en) 2023-05-23

Family

ID=68810726

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910739083.9A Active CN110580220B (en) 2019-08-12 2019-08-12 Method for measuring code segment execution time and terminal equipment

Country Status (1)

Country Link
CN (1) CN110580220B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113268242A (en) * 2020-02-17 2021-08-17 北京达佳互联信息技术有限公司 Code compiling time length determining method and device, electronic equipment and storage medium
CN111414295B (en) * 2020-03-09 2023-06-30 浙江大华技术股份有限公司 Statistical method, device, equipment and medium for CPU occupancy rate
CN116820568B (en) * 2023-06-09 2024-01-05 北京市合芯数字科技有限公司 Instruction translation method and device, storage medium and terminal

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102144222A (en) * 2008-07-02 2011-08-03 国立大学法人东京工业大学 Execution time estimation method, execution time estimation program, and execution time estimation device
CN104169886A (en) * 2012-03-16 2014-11-26 国际商业机器公司 Run-time detection indirect sampling by address
CN109739824A (en) * 2018-12-28 2019-05-10 斑马网络技术有限公司 Journal obtaining method and equipment
CN110008107A (en) * 2018-01-04 2019-07-12 北京奇虎科技有限公司 Test method, device and the computer readable storage medium of application

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101067798A (en) * 2007-06-14 2007-11-07 华南理工大学 Dynamic probe method and application in embedded system thereof
US8112249B2 (en) * 2008-12-22 2012-02-07 Optimaltest Ltd. System and methods for parametric test time reduction
US20150278078A1 (en) * 2014-03-25 2015-10-01 Akiyoshi Kawamura Method and computer program for identifying performance tuning opportunities in parallel programs
CN106055462A (en) * 2016-05-20 2016-10-26 腾讯科技(深圳)有限公司 Method and device for duration acquisition
CN107506293B (en) * 2016-06-14 2022-04-22 中兴通讯股份有限公司 Software performance data acquisition method and device
CN106126431A (en) * 2016-08-23 2016-11-16 腾讯科技(深圳)有限公司 Performance test methods and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102144222A (en) * 2008-07-02 2011-08-03 国立大学法人东京工业大学 Execution time estimation method, execution time estimation program, and execution time estimation device
CN104169886A (en) * 2012-03-16 2014-11-26 国际商业机器公司 Run-time detection indirect sampling by address
CN110008107A (en) * 2018-01-04 2019-07-12 北京奇虎科技有限公司 Test method, device and the computer readable storage medium of application
CN109739824A (en) * 2018-12-28 2019-05-10 斑马网络技术有限公司 Journal obtaining method and equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
An experimental evaluation of data dependence analysis techniques;K. Psarris 等;《IEEE Transactions on Parallel and Distributed Systems》;第15卷(第3期);第196-213页 *
基于逆向工程和插桩技术的软件性能分析;宋元凤;《中国优秀硕士学位论文全文数据库信息科技辑》(第1期);第I138-669页 *

Also Published As

Publication number Publication date
CN110580220A (en) 2019-12-17

Similar Documents

Publication Publication Date Title
CN110580220B (en) Method for measuring code segment execution time and terminal equipment
US20100275062A1 (en) Functional Coverage Using Combinatorial Test Design
CN109669798B (en) Crash analysis method, crash analysis device, electronic equipment and storage medium
CN111211929A (en) Fault positioning method, fault positioning device, control equipment and intelligent equipment
US20210042216A1 (en) Detecting problematic code changes
CN114201408A (en) Regression testing method, device, computer equipment and storage medium
CN113535538A (en) Application full-link automatic testing method and device, electronic equipment and storage medium
CN106557419B (en) Program testing method and device
CN115686961A (en) Processor testing method and device and electronic equipment
KR102165747B1 (en) Lightweight crash report based debugging method considering security
CN111338864B (en) Memory problem detection method, device, computer equipment and storage medium
CN111654405B (en) Method, device, equipment and storage medium for fault node of communication link
CN111506455A (en) Checking method and device for service release result
CN116738091A (en) Page monitoring method and device, electronic equipment and storage medium
CN115587048A (en) Regression testing method, terminal device and computer readable storage medium
CN110716747B (en) Program operation efficiency optimization method based on function parameter statistics and terminal equipment
CN113656318A (en) Software version testing method and device and computer equipment
CN113920428B (en) Test method and device for metering field operation terminal and test terminal
CN111310172B (en) Method and control unit for verifying processor execution traces by disassembling
CN113868085B (en) Hard disk monitoring method, device and system
CN118689717A (en) Intelligent electronic equipment problem positioning method and device, electronic equipment and storage medium
CN117992350A (en) Method and device for monitoring code test coverage rate and electronic equipment
CN112256515A (en) Method for checking integrity of storage server link and alarm device
CN117193798A (en) Application deployment method, apparatus, device, readable storage medium and program product
CN115373923A (en) 0x7c error positioning method, device and 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