Code time consumption statistical method and system based on IDEA plug-in
By building a plug-in-based code time-consuming statistics method on the IDEA platform, and automatically recording the code execution time using the breakpoint monitoring function, it solves the problems of strong invasiveness and cumbersome operations in the existing technology, and realizes intrusion-free, fast and simple code time-consuming statistics, improving development efficiency and flexibility.
Patent Information
- Application Number
- CN202510165411.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-14
- Publication Date
- 2025-05-27
AI Technical Summary
The time-consuming statistics of the interface response time in the prior art in back-end development of the interface are problematic, complicated operations and lack of universality, making it difficult to accurately count the code without intruding the source code.
By building a code time-consuming statistics method based on IDEA plug-in, using the breakpoint monitoring function of the IDEA platform, it automatically records the start and end time of code execution, calculates the code time-consuming, and outputs the results in the IDEA console to achieve intrusion-free code time-consuming statistics.
It realizes that without intruding the source code, it takes time to calculate the code quickly and easily, improves development efficiency, reduces operational complexity, and has high flexibility and accuracy.
Smart Images

Figure CN120045431A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of software development, and particularly relates to a method and system for code time-consuming statistics based on an IDEA plug-in. Background Art
[0002] In back-end development, the interface response time is an important indicator to measure the performance of back-end services. To improve the performance of back-end services, developers will identify interfaces with long response times from relevant log files and perform targeted optimizations.
[0003] To find out the reasons for long interface response times, developers need to split the code into multiple code segments according to experience, insert code for timing and printing logs between each code segment, and after compiling and executing the code, find out the code segments with long response times based on the printed logs. This process often needs to be repeated multiple times to accurately identify the code that needs to be optimized, and the operation is very inconvenient. At the same time, after the optimization is completed, the timing code needs to be manually deleted, which poses a risk of accidentally deleting other code.
[0004] The prior art Chinese patent application CN202411043853.3 discloses a method for calculating the time-consuming of a code segment, including: obtaining the execution type of the target code segment to be calculated for time-consuming currently, where the execution type includes single execution and multiple executions; determining the time-consuming calculation strategy corresponding to the execution type based on the correspondence between the preset execution type and the preset time-consuming calculation strategy; determining the execution time period of the scope corresponding to the target code segment according to the execution type; calculating the time-consuming of the execution time period based on the time-consuming calculation strategy to obtain the time-consuming result of the target code segment.
[0005] The above prior art is a time-consuming statistics tool customized for hardware, which is implemented by hard-coding embedded in the project and lacks generality. And after the time-consuming statistics tool is placed, it will invade the original code and form additional system overhead. Summary of the Invention
[0006] The purpose of the present invention is to provide a method and system for code time-consuming statistics based on an IDEA plug-in, which can partially solve or alleviate the above deficiencies in the prior art and can statistically calculate the code time-consuming without invading the source code.
[0007] To solve the above-mentioned technical problems, the present invention specifically adopts the following technical solutions: A method for code time-consuming statistics based on an IDEA plug-in, characterized by including: Build an IDEA time-consuming statistics plugin. The IDEA time-consuming statistics plugin can listen for termination events when the code execution reaches a breakpoint and listen for execution events when the code continues to execute; when an execution event is listened for, the IDEA time-consuming statistics plugin records the system time time1; when a termination event is listened for, the IDEA time-consuming statistics plugin records the system time time2; Load the IDEA time-consuming statistics plugin on the IDEA platform and start the program containing the code to be statistically analyzed on the IDEA platform; Set breakpoints before and after the code to be statistically analyzed; When the code execution stops at the breakpoint, the IDEA time-consuming statistics plugin listens for the termination event and ignores it; When the code resumes execution, the IEDA time-consuming statistics plugin listens for the execution event and records the system time time1; When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin listens for the termination event and records the system time time2; The IDEA time-consuming statistics plugin outputs the code execution time time = time2 - time1.
[0008] As an improvement, the method for building the IDEA time-consuming statistics plugin includes: Create a Java class to implement the XDebuggerManagerListener interface as a listener for listening for termination events and execution events when the code execution reaches a breakpoint; Override the processStarted() method so that when the listener listens for an execution event when the code execution reaches a breakpoint, the processStarted() method can be called to record the system time time1; Override the processStopped() method so that when the listener listens for a termination event when the code execution reaches a breakpoint, the processStopped() method can be called to record the system time time2; Subtract the system time time1 from the system time time2 to obtain the code execution time time and output the code execution time time on the IDEA platform console.
[0009] As an improvement, the method for statistically analyzing the time consumption of multiple consecutive code segments includes: S101. Set breakpoints before and after each code segment to be statistically analyzed; S102. When the code execution stops at the breakpoint, the IDEA time-consuming statistics plugin listens for the termination event and ignores it; S103. When the code resumes execution, the IEDA time-consuming statistics plugin listens for the execution event and records the system time time1; S104. When the code execution stops at the next breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and records the system time time2; S105. The IDEA time-consuming statistics plugin outputs the code execution time time = time2 - time1; S106. Repeat steps S103 to S105 until all the codes to be statistically analyzed are completed.
[0010] As an improvement, a method for statistically analyzing the execution time of multiple non - continuous code segments includes: S201. Set breakpoints before and after each code segment to be statistically analyzed; S202. When the code execution stops at the breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S203. When the code resumes execution, the IDEA time-consuming statistics plugin monitors the execution event and records the system time time1; S204. When the code execution stops at the next breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and records the system time time2; S205. The IDEA time-consuming statistics plugin outputs the code execution time time_1 = time2 - time1; S206. When the code resumes execution, the IDEA time-consuming statistics plugin monitors the execution event and ignores it; S207. When the code execution stops at the breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S208. When the code resumes execution, the IDEA time-consuming statistics plugin monitors the execution event and records the system time time1; S209. When the code execution stops at the next breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and records the system time time2; S210. The IDEA time-consuming statistics plugin outputs the code execution time time = time2 - time1; S211. Repeat steps S206 to S210 until all the codes to be statistically analyzed are completed.
[0011] As an improvement, the execution times of multiple code segments to be statistically analyzed are output in the form of a table or a bar chart on the IDEA platform console.
[0012] The present invention also provides a code execution time statistics system based on an IDEA plugin, including: A listener, which is used to listen for termination events when the code execution reaches a breakpoint and listen for execution events when the code continues to execute; when an execution event is listened, the IDEA time-consuming statistics plugin records the system time time1; when a termination event is listened, the IDEA time-consuming statistics plugin records the system time time2; An output interface, which is used to output the code execution time time = time2 - time1.
[0013] As an improvement, the output interface is a graphical output interface, which is used to output the code execution time in the form of a table or a bar chart.
[0014] As an improvement, the listener includes a single-segment statistics module for performing time-consuming statistics on a single segment of code and a multi-segment statistics module for performing time-consuming statistics on multiple segments of code.
[0015] As an improvement, the method for the single-segment statistics module to perform time-consuming statistics on a single segment of code includes: Set breakpoints before and after the code to be statistically analyzed; When the code execution stops at the breakpoint, a termination event is listened and ignored; When the code resumes execution, an execution event is listened and the system time time1 is recorded; When the code execution stops at the next breakpoint, a termination event is listened and the system time time2 is recorded; Pass time1 and time2 to the output interface.
[0016] As an improvement, the method for the multi-segment statistics module to perform time-consuming statistics on multiple segments of consecutive code includes: S101. Set breakpoints before and after each segment of code to be statistically analyzed; S102. When the code execution stops at the breakpoint, the IDEA time-consuming statistics plugin listens for a termination event and ignores it; S103. When the code resumes execution, the IEDA time-consuming statistics plugin listens for an execution event and records the system time time1; S104. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin listens for a termination event and records the system time time2; S105. Pass time1 and time2 to the output interface; S106. Repeat steps S103 to S105 until all the code to be statistically analyzed is completed.
[0017] The method for the multi-segment statistics module to perform time-consuming statistics on multiple segments of non-consecutive code includes: S201. Set breakpoints before and after each segment of code to be statistically analyzed; S202. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S203. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1; S204. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2; S205. The IDEA time-consuming statistics plugin outputs the code execution time time_1 = time2 - time1; S206. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and ignores it; S207. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S208. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1; S209. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2; S210. Pass time1 and time2 to the output interface; S211. Repeat steps S206 to S210 until all the code to be statistically analyzed is completed.
[0018] Beneficial effects: This solution realizes the code execution time statistics through the IDEA plugin. Developers do not need to write any timing code in the business code. The plugin will automatically monitor the execution and termination events of the debug breakpoints, record the start time and end time of the code execution, and calculate the execution time. This method has no intrusion into the business code, and the business code remains pure and will not become complex due to the execution time statistics. Developers can focus on the implementation of the business logic without worrying about the impact of the timing code on the business code.
[0019] In traditional code execution time statistics, if developers need to count the execution time of multiple code segments, they need to add timing code before and after each code segment and ensure the correct execution of the timing code. When the code structure changes or different code segments need to be counted, the timing code needs to be modified accordingly, which is very cumbersome. Moreover, each time the timing code is modified, the program needs to be recompiled and run, increasing the development cost. This solution utilizes the debugging breakpoint function of IDEA. Developers only need to set breakpoints before and after the code to be counted and then start the program in debug mode. The plugin will automatically monitor the execution and termination events of the breakpoints to complete time recording and elapsed time calculation. No additional code needs to be written throughout the process, and the operation is very simple. For example, if a developer wants to count the execution time of a certain loop code segment, they only need to set breakpoints at the start and end lines of the loop code, start debugging, and the plugin will automatically output the execution time of this code segment.
[0020] This solution has extremely high flexibility. Developers can set or cancel breakpoints at any time according to their needs to count the execution time of different code segments. Whether it is continuous code segments or discontinuous code segments, accurate execution time statistics can be achieved by setting breakpoints. For example, developers can set multiple breakpoints in a large method to separately count the execution time of different parts to identify performance bottlenecks. Moreover, during the debugging process, if it is found that the execution time of other code segments needs to be counted, only new breakpoints need to be added and debugging can continue without rewriting the code or restarting the program.
[0021] In traditional code execution time statistics methods, each time the timing code is modified or the statistical scope is adjusted, the program needs to be recompiled and run, which not only wastes time but also may cause the loss of some environmental states due to restarting the program. However, this solution performs execution time statistics through debugging breakpoints. During the debugging process, the position of the breakpoints can be adjusted at any time, and the plugin will record and calculate the elapsed time in real-time without the need to frequently restart the program. Developers can complete the execution time statistics of multiple code segments during a single debugging process, greatly improving the development efficiency.
[0022] In summary, this solution avoids intruding into the business code by eliminating the need to write timing code and using debugging breakpoints to divide the code into blocks. It is simple to operate, highly flexible, and does not require frequent program restarts, providing developers with an efficient and convenient code execution time statistics solution. Brief Description of the Drawings
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts do not necessarily draw according to the actual scale. Obviously, the following-described drawings are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0024] Figure 1 It is a flowchart of the present invention.
[0025] Figure 2 It is a structural diagram of the present invention. Detailed implementation manners
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are some but not all of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0027] In this article, suffixes such as "module", "component", or "unit" used to represent elements are only for the convenience of the description of the present invention, and they have no specific meaning in themselves. Therefore, "module", "component", or "unit" can be used interchangeably.
[0028] In this article, terms such as "upper", "lower", "inner", "outer", "front", "rear", "one end", "the other end", etc. indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation to the present invention. In addition, the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0029] In this article, unless otherwise clearly defined and limited, terms such as "installation", "provided with", "connection", etc. should be understood in a broad sense. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection, a direct connection, or an indirect connection through an intermediate medium, and it can be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0030] As used herein, "and / or" includes any and all combinations of one or more of the listed related items.
[0031] As used herein, "a plurality of" means two or more, i.e., it includes two, three, four, five, etc.
[0032] Example 1: As Figure 1 shown, the present invention provides a method for counting the code execution time based on an IDEA plugin, which can count the code execution time without invading the source code. The specific steps include: S1. Build an IDEA execution time statistics plugin. The IDEA execution time statistics plugin can listen for termination events when the code execution reaches a breakpoint and listen for execution events when the code continues to execute; when an execution event is listened for, the IDEA execution time statistics plugin records the system time time1; when a termination event is listened for, the IDEA execution time statistics plugin records the system time time2.
[0033] The IDEA platform is a development tool for the Java programming language. Developers can write, debug, and run Java code in the IDEA development tool. The IDEA plugin is a tool developed to extend the functionality of the IDEA platform.
[0034] In this embodiment, the code execution time is counted by loading the IDEA plugin on the IDEA platform without adding code for counting the execution time in the source code. More specifically, the method for building the IDEA execution time statistics plugin in this embodiment includes: S11. Create a Java class to implement the XDebuggerManagerListener interface as a listener for listening for termination events and execution events when the code execution reaches a breakpoint.
[0035] The XDebuggerManagerListener interface is a listener provided by IDEA for listening for breakpoint execution and termination events during code debugging. When the developer's code execution reaches a breakpoint, a breakpoint termination event is triggered, and when the developer continues to execute the code, a breakpoint execution event is triggered. Through these two events, the start time and end time of the code execution between two breakpoints can be known.
[0036] S12. Override the processStarted() method so that when the code execution reaches a breakpoint and the listener listens for an execution event, the processStarted() method can be called to record the system time time1.
[0037] When the code at the breakpoint starts to execute, a breakpoint execution event is triggered. After the listener detects this event, it will call the processStarted() method. In this method, the current system time time1 is recorded as the start time of the code execution.
[0038] S13. Rewrite the processStopped() method so that when the code execution reaches the termination event detected by the listener at the breakpoint, the processStopped() method can be called to record the system time time2.
[0039] When the code execution pauses at the breakpoint, a breakpoint termination event is triggered. When the listener detects this event, it will call the processStopped() method. In this method, the current time time2 is recorded as the end time of the code execution.
[0040] S14. Subtract the system time time1 from the system time time2 to obtain the code execution time time, and output the code execution time time on the IDEA platform console.
[0041] Subtract time1 from time2, and the resulting difference is the execution time of the code between the breakpoints. Print this elapsed time to the console and output it to the plugin statistics result interface for developers to view conveniently.
[0042] S2. Load the IDEA Elapsed Time Statistics Plugin on the IDEA platform and start the program containing the code to be statistically analyzed on the IDEA platform.
[0043] After the IDEA Elapsed Time Statistics Plugin is encapsulated, it needs to be loaded on the IDEA platform so that the plugin can work properly in the IDEA development environment. At the same time, start the program containing the code to be statistically analyzed on the IDEA platform to prepare for subsequent code execution time statistics.
[0044] S3. Set breakpoints before and after the code to be statistically analyzed.
[0045] Breakpoints are key elements in the debugging process. They can pause the program execution at the specified code line. Set breakpoints before and after the code to be statistically analyzed to enclose the code segment to be statistically analyzed between two breakpoints for accurate statistical analysis of the execution time of this code segment.
[0046] For example, if you need to statistically analyze the running time of lines 10 to 43 of the code, you need to add a breakpoint before line 10 and after line 43. The breakpoint function is provided by the IDEA platform.
[0047] S4. When the code execution stops at the breakpoint, the IDEA Elapsed Time Statistics Plugin detects the termination event and ignores it.
[0048] At each breakpoint, two events may be triggered. One is the termination event, that is, the code stops executing, and the other is the execution event, that is, the code continues to execute. When the code stops executing at the first breakpoint, the plugin listens for the termination event, but this event is ignored because the execution time of the code snippet has not started to be officially counted yet.
[0049] Continuing with the above example, when the code stops executing at the breakpoint before line 10, it will first stop. At this time, the listener will listen for a termination event. However, the code that actually needs to be counted has not been executed, so this termination event needs to be ignored.
[0050] S5. When the code resumes execution, the IEDA execution time statistics plugin listens for the execution event and records the system time time1.
[0051] When the code resumes execution from the first breakpoint, the plugin listens for the execution event. At this time, the system time time1 is recorded as the start time of the execution of the code snippet to be counted.
[0052] For example, after manually resuming the execution of the code, the code starts to execute from line 10, and the system time when it starts to execute is recorded as time1.
[0053] S6. When the code stops executing at the next breakpoint, the IEDA execution time statistics plugin listens for the termination event and records the system time time2; When the code stops executing at the second breakpoint, the plugin listens for the termination event and records the system time time2 as the end time of the execution of the code snippet to be counted.
[0054] For example, when reaching the second breakpoint, the code on line 43 has been executed and the system time when it stops executing is recorded as time2.
[0055] S7. The IDEA execution time statistics plugin outputs the code execution time time = time2 - time1.
[0056] The plugin calculates the execution time time of the code snippet to be counted by computing time2 - time1 and prints it out to the IDEA console for developers to view.
[0057] Embodiment 2: The purpose of this embodiment is to use the IDEA execution time statistics plugin to automatically count the execution time of multiple consecutive code segments. By setting breakpoints before and after each code segment to be counted and relying on the plugin to listen for the execution and termination events of the breakpoints and record key time points, the execution time of each code segment can be calculated.
[0058] The so-called multi-segment continuous code means that several segments of code to be counted are continuous. For example, 10~43, 44~58, 59~100. These three segments of code are continuous but need to be counted for execution time separately.
[0059] The method for counting the time consumption of multi-segment continuous code using the IDEA time-consuming statistics plugin includes: S101. Set breakpoints before and after each segment of code to be counted.
[0060] A breakpoint is a pause point during code execution. By setting breakpoints before and after each segment of code to be counted, the starting and ending positions of each segment of code to be counted can be clearly defined, laying a foundation for accurately counting the code execution time later. To count the time consumption of the three segments of code separately, breakpoints should be set before the 10th line of code, between the 43rd and 44th lines of code, between the 58th and 59th lines of code, and after the 100th line of code.
[0061] S102. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it.
[0062] When encountering the breakpoint for the first time, that is, the breakpoint before the 10th line of code, this is just the program execution reaching a preset pause position. At this time, the formal counting of the execution time of the current segment of code to be counted has not started yet, so this termination event is ignored.
[0063] S103. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1.
[0064] When the code resumes execution from the breakpoint, it means that the current segment of code to be counted starts to execute. The plugin records the system time time1 at this time as the starting time of the execution of this segment of code.
[0065] S104. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2.
[0066] When the code execution stops at the next breakpoint, that is, the breakpoint after the 43rd line of code, it marks the end of the execution of the current segment of code from 10 to 43 lines. The plugin records the system time time2 at this time as the end time of the execution of this segment of code.
[0067] S105. The IDEA time-consuming statistics plugin outputs the code time consumption time = time2 - time1.
[0068] Subtract the start time time1 from the end time time2, and the obtained difference is the execution time consumption time of the current segment of code to be counted. This result is output for the convenience of developers to view.
[0069] S106. Repeat steps S103 to S105 until the execution time of all the codes to be counted is completed.
[0070] The execution time statistics of the codes from line 44 to 58 and from line 59 to 100 are obtained by repeating steps S103 to S105, which will not be elaborated here.
[0071] In addition, since there are many output execution time statistics results, forms such as tables and bar charts can be used for output to improve readability.
[0072] Embodiment 3: It aims to use the IDEA execution time statistics plug-in to count the execution time of multiple non-continuous code segments. Non-continuous code means that these code segments to be counted are not adjacent in the program, and there may be other codes that do not need to be counted for execution time in between. The solution is to set breakpoints before and after each code segment to be counted, and use the plug-in to monitor the execution and termination events of the breakpoints and record the key time points, so as to accurately calculate the execution time of each non-continuous code segment.
[0073] For example, it is necessary to count the execution time of three code segments from line 10 to 43, from line 58 to 79, and from line 81 to 100.
[0074] The method for using the IDEA execution time statistics plug-in to count the execution time of multiple non-continuous code segments includes: S201. Set breakpoints before and after each code segment to be counted.
[0075] The breakpoints are used to mark the start and end positions of each code segment to be counted. After setting breakpoints before and after the lines of each code segment to be counted, when the program executes to these breakpoints, it will pause, and the plug-in can monitor relevant events to record time and calculate the execution time. This is the basis of the entire statistical process and clarifies the code range to be counted.
[0076] In the above example, it is necessary to set breakpoints before line 10, after line 43, before line 58, after line 79, before line 81, and after line 100.
[0077] S202. When the code execution stops at the breakpoint, the IDEA execution time statistics plug-in monitors the termination event and ignores it.
[0078] When encountering the breakpoint for the first time, that is, the breakpoint before line 10, at this time, the program only executes to the preset pause position, but has not started to officially count the execution time of the current first code segment to be counted, so this termination event is ignored and waiting for the code to resume execution to start timing.
[0079] S203. When the code resumes execution, the IEDA execution time statistics plug-in monitors the execution event and records the system time time1.
[0080] The code resumes execution from the breakpoint, indicating the start of the execution of the first piece of code to be statistically analyzed. The plugin records the system time time1 at this moment as the start time of the execution of this piece of code, which will be used later to calculate the execution time of this piece of code.
[0081] S204. When the code stops executing at the next breakpoint, the IEDA execution time statistics plugin monitors the termination event and records the system time time2.
[0082] The code stops executing at the next breakpoint, that is, the breakpoint after the 43rd line of code, indicating the end of the execution of the first piece of code to be statistically analyzed. The plugin records the system time time2 at this moment as the end time of the execution of this piece of code.
[0083] S205. The IDEA execution time statistics plugin outputs the code execution time time_1 = time2 - time1.
[0084] Subtracting the start time time1 from the end time time2, the obtained difference is the execution time time_1 of the first piece of code to be statistically analyzed, and this result is output for the developer to view.
[0085] S206. When the code resumes execution, the IEDA execution time statistics plugin monitors the execution event and ignores it.
[0086] After the execution of the first piece of code to be statistically analyzed is completed, the program continues to execute and may pass through some code segments for which the execution time does not need to be statistically analyzed. When encountering breakpoints before and after these code segments and resuming execution, the plugin ignores the execution event to avoid misrecording the time and affecting the statistics of subsequent non - continuous code segments.
[0087] S207. When the code stops executing at the breakpoint, the IDEA execution time statistics plugin monitors the termination event and ignores it.
[0088] Similarly, when passing through code segments for which the execution time does not need to be statistically analyzed and stopping execution at breakpoints before and after these code segments, the plugin ignores the termination event to ensure that time recording and execution time calculation are only performed on non - continuous code segments that truly need to be statistically analyzed.
[0089] S208. When the code resumes execution, the IEDA execution time statistics plugin monitors the execution event and records the system time time1.
[0090] When the program reaches the breakpoint before the next piece of code to be statistically analyzed and resumes execution, the plugin records the system time time1 at this moment as the start time of the execution of this new piece of code to be statistically analyzed.
[0091] S209. When the code stops executing at the next breakpoint, the IEDA execution time statistics plugin monitors the termination event and records the system time time2.
[0092] The code execution stops at the breakpoint after reaching this section of the code to be statistically analyzed, and the plug-in records the system time time2 at this time as the end time of the execution of this section of code.
[0093] S210. The IDEA elapsed time statistical plug-in outputs the code elapsed time time = time2 - time1.
[0094] Subtract the start time time1 from the end time time2 again to obtain the execution elapsed time time of the current section of code to be statistically analyzed, and output the result.
[0095] S211. Repeat steps S206 to S210 until all the code to be statistically analyzed is completed.
[0096] For multiple non - continuous sections of code to be statistically analyzed, after completing the elapsed time statistics of one section of code, by repeating steps S206 - S210, the elapsed time statistics of each subsequent non - continuous section of code are carried out in turn until all the code to be statistically analyzed is completed.
[0097] The elapsed time statistics of lines 81 - 100 of the code are obtained by repeating steps S206 to S210, which will not be elaborated here.
[0098] Similarly, since there are many output elapsed time statistical results, forms such as tables and bar charts can be used for output, so as to improve readability.
[0099] Embodiment 4: As Figure 2 shown, the present invention also provides a code elapsed time statistical system based on an IDEA plug - in, including: A listener, which is used to listen for termination events when the code execution reaches the breakpoint and listen for execution events when the code continues to execute; when the execution event is listened for, the IDEA elapsed time statistical plug - in records the system time time1; when the termination event is listened for, the IDEA elapsed time statistical plug - in records the system time time2; An output interface, which is used to output the code elapsed time time = time2 - time1. In some other embodiments, the output interface can be a graphical output interface, which is used to output the code elapsed time in the form of a table or a bar chart.
[0100] In this embodiment, the listener includes a single - section statistical module for statistically analyzing the elapsed time of a single section of code and a multi - section statistical module for statistically analyzing the elapsed time of multiple sections of code.
[0101] The method for the single - section statistical module to statistically analyze the elapsed time of a single section of code includes: Set breakpoints before and after the code to be statistically analyzed; When the code execution stops at a breakpoint, the termination event is monitored and ignored; When the code resumes execution, the execution event is monitored and the system time time1 is recorded; When the code execution stops at the next breakpoint, the termination event is monitored and the system time time2 is recorded; Pass time1 and time2 to the output interface.
[0102] As an improvement, the method for the multi-segment statistics module to perform time-consuming statistics on multi-segment consecutive codes includes: S101. Set breakpoints before and after each segment of code to be statistically analyzed; S102. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S103. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1; S104. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2; S105. Pass time1 and time2 to the output interface; S106. Repeat steps S103 to S105 until all the codes to be statistically analyzed are completed.
[0103] The method for the multi-segment statistics module to perform time-consuming statistics on multi-segment non-consecutive codes includes: S201. Set breakpoints before and after each segment of code to be statistically analyzed; S202. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S203. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1; S204. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2; S205. The IDEA time-consuming statistics plugin outputs the code time-consuming time_1 = time2 - time1; S206. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and ignores it; S207. When the code execution stops at a breakpoint, the IDEA time-consuming statistics plugin monitors the termination event and ignores it; S208. When the code resumes execution, the IEDA time-consuming statistics plugin monitors the execution event and records the system time time1; S209. When the code execution stops at the next breakpoint, the IEDA time-consuming statistics plugin monitors the termination event and records the system time time2. S210. Pass time1 and time2 to the output interface. S211. Repeat steps S206 to S210 until all the code to be statistically analyzed is completed.
[0104] It should be noted that in this article, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including that element.
[0105] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a computer terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0106] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit and scope protected by the present invention and the claims. All of these are within the protection scope of the present invention.
Claims
1. A code time-consuming statistics method based on IDEA plug-in, characterized in that include: Build an IDEA time-consuming statistics plug-in, which can listen to the termination event when the code is executed to a breakpoint, and listen to the execution event when the code continues to be executed; When monitoring execution events, IDEA time statistics plug-in records system time time1; When the termination event is monitored, the IDEA time statistics plug-in records the system time time2; Load the IDEA time-consuming statistics plug-in on the IDEA platform, and start the program containing the code to be counted on the IDEA platform; Set breakpoints before and after the code to be counted; When the code stops executing at a breakpoint, the IDEA time statistics plug-in listens to the termination event and ignores it; When the code resumes execution, the IEDA time statistics plug-in monitors the execution event and records the system time time1; When the code stops executing at the next breakpoint, the IEDA time statistics plug-in monitors the termination event and records the system time time2; The IDEA time statistics plug-in outputs the code time time = time2-time1.
2. According to claim 1, a method for counting code time consumption based on IDEA plug-in is characterized in that The method for constructing the IDEA time-consuming statistics plug-in includes: Create a Java class to implement the XDebuggerManagerListener interface as a listener to monitor the termination event and execution event when the code is executed to the breakpoint; Rewrite the processStarted() method so that when the code is executed to the breakpoint and the listener listens to the execution event, the processStarted() method can be called to record the system time time1; Rewrite the processStopped() method so that when the code is executed to the breakpoint and the listener listens to the termination event, the processStopped() method can be called to record the system time time2; Subtract system time time1 from system time time2 to get the code time, and output the code time on the IDEA platform console.
3. According to a method for counting code time consumption based on IDEA plug-in according to claim 1, it is characterized in that: Methods for calculating the time consumption of multiple consecutive code segments include: S101, set breakpoints before and after each section of code to be counted; S102. When the code stops executing at the breakpoint, the IDEA time-consuming statistics plug-in monitors the termination event and ignores it; S103, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S104, when the code execution stops at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S105, IDEA time statistics plug-in output code time = time2-time1; S106. Repeat steps S103 to S105 until all the codes to be counted are counted.
4. According to a method for counting code time consumption based on IDEA plug-in according to claim 1, it is characterized in that: Methods for calculating the time consumption of multiple non-continuous codes include: S201, setting breakpoints before and after each section of code to be counted; S202. When the code stops executing at the breakpoint, the IDEA time-consuming statistics plug-in monitors the termination event and ignores it; S203, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S204, when the code execution stops at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S205, IDEA time statistics plug-in output code time time_1=time2-time1; S206, when the code resumes execution, the IEDA time-consuming statistics plug-in monitors the execution event and ignores it; S207, when the code execution stops at the breakpoint, the IDEA time consumption statistics plug-in listens to the termination event and ignores it; S208, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S209, when the code stops executing at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S210, IDEA time statistics plug-in output code time = time2-time1; S211, repeat steps S206 to S210 until all the codes to be counted are counted.
5. A method for counting code time consumption based on IDEA plug-in according to claim 3 or 4, characterized in that: Output the time consumption of multiple code segments with statistics in the form of tables or bar charts on the IDEA platform console.
6. A code time-consuming statistics system based on IDEA plug-in, characterized in that include: Listeners are used to listen for termination events when the code is executed to a breakpoint, and to listen for execution events when the code continues to be executed; When monitoring execution events, IDEA time statistics plug-in records system time time1; When the termination event is monitored, the IDEA time statistics plug-in records the system time time2; Output interface, used to output code time = time2-time1.
7. The code time-consuming statistics system based on IDEA plug-in according to claim 6 is characterized in that: The output interface is a graphical output interface, which is used to output the code time consumption in the form of a table or a bar graph.
8. The code time-consuming statistics system based on IDEA plug-in according to claim 6 is characterized in that: The listener includes a single-segment statistics module for performing time-consuming statistics on a single-segment code and a multi-segment statistics module for performing time-consuming statistics on multiple segments of code.
9. A code time-consuming statistics system based on IDEA plug-in according to claim 8, characterized in that The method for the single-segment statistics module to perform time-consuming statistics on a single-segment code includes: Set breakpoints before and after the code to be counted; When the code stops executing at the breakpoint, the termination event is listened and ignored; When the code resumes execution, the execution event is monitored and the system time time1 is recorded; When the code stops executing at the next breakpoint, the termination event is monitored and the system time time2 is recorded; Pass time1 and time2 to the output interface.
10. The code time-consuming statistics system based on IDEA plug-in according to claim 8 is characterized in that: The method for the multi-segment statistics module to perform time-consuming statistics on multiple segments of continuous code includes: S101, set breakpoints before and after each section of code to be counted; S102. When the code stops executing at the breakpoint, the IDEA time-consuming statistics plug-in monitors the termination event and ignores it; S103, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S104, when the code execution stops at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S105, passing time1 and time2 to the output interface; S106. Repeat steps S103 to S105 until all the codes to be counted are counted. The method for the multi-segment statistics module to perform time-consuming statistics on multiple segments of non-continuous codes includes: S201, setting breakpoints before and after each section of code to be counted; S202. When the code stops executing at the breakpoint, the IDEA time-consuming statistics plug-in monitors the termination event and ignores it; S203, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S204, when the code execution stops at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S205, IDEA time statistics plug-in output code time time_1=time2-time1; S206, when the code resumes execution, the IEDA time-consuming statistics plug-in monitors the execution event and ignores it; S207, when the code execution stops at the breakpoint, the IDEA time consumption statistics plug-in listens to the termination event and ignores it; S208, when the code resumes execution, the IEDA time consumption statistics plug-in monitors the execution event and records the system time time1; S209, when the code stops executing at the next breakpoint, the IEDA time consumption statistics plug-in monitors the termination event and records the system time time2; S210, transferring time1 and time2 to the output interface; S211, repeat steps S206 to S210 until all the codes to be counted are counted.
Citation Information
Patent Citations
Code segment time consumption calculation method and device, computer equipment and storage medium
CN119065964A