CN106776302A - Calculate method, the device of method execution time in JAVA projects - Google Patents
Calculate method, the device of method execution time in JAVA projects Download PDFInfo
- Publication number
- CN106776302A CN106776302A CN201611093078.8A CN201611093078A CN106776302A CN 106776302 A CN106776302 A CN 106776302A CN 201611093078 A CN201611093078 A CN 201611093078A CN 106776302 A CN106776302 A CN 106776302A
- Authority
- CN
- China
- Prior art keywords
- proxy
- target directory
- execution time
- time
- class
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 227
- 238000004364 calculation method Methods 0.000 claims description 9
- 238000012216 screening Methods 0.000 claims description 4
- 238000012423 maintenance Methods 0.000 abstract description 8
- 238000004904 shortening Methods 0.000 abstract description 5
- 230000009286 beneficial effect Effects 0.000 abstract description 2
- 239000003795 chemical substances by application Substances 0.000 description 16
- 230000008569 process Effects 0.000 description 9
- 238000012986 modification Methods 0.000 description 4
- 230000004048 modification Effects 0.000 description 4
- 238000010586 diagram Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 201000004569 Blindness Diseases 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000009826 distribution Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
- 230000008439 repair process Effects 0.000 description 1
- 238000003860 storage Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Prevention of errors by analysis, debugging or testing of software
- G06F11/3604—Analysis of software for verifying properties of programs
- G06F11/3612—Analysis of software for verifying properties of programs by runtime analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
本发明公开了一种计算JAVA项目中方法执行时间的方法,包括:获取指定JAVA项目的目标目录中全部的字节码文件;从所述字节码文件中获取类路径;根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间;该方法可以完全抛弃传统的人工方式,从而极大的缩短了查找耗时方法的时间,提高软件开发和运维的时效,降低成本;本发明还公开了一种计算JAVA项目中方法执行时间的装置,具有上述有益效果。
The invention discloses a method for calculating the execution time of a method in a JAVA project, comprising: obtaining all bytecode files in a target directory of a specified JAVA project; obtaining a class path from the bytecode file; , create a proxy class corresponding to each class path and a corresponding proxy method; wherein, the proxy method includes a program that records the proxy start time and proxy end time of each method in the proxy class; the proxy end time and the proxy end time The proxy start time difference is obtained to obtain the corresponding execution time of each method in the target directory; this method can completely abandon the traditional manual method, thereby greatly shortening the time for finding time-consuming methods and improving the timeliness of software development and operation and maintenance , cost reduction; the invention also discloses a device for calculating the execution time of a method in a JAVA project, which has the beneficial effects above.
Description
技术领域technical field
本发明涉及数据处理技术领域,特别涉及一种计算JAVA项目中方法执行时间的方法、装置。The invention relates to the technical field of data processing, in particular to a method and a device for calculating the execution time of a method in a JAVA project.
背景技术Background technique
Java是由Sun Microsystems公司于1995年5月推出的高级程序设计语言。Java可运行于多个平台,如Windows,Mac OS,及其他多种UNIX版本的系统。因其简单性、面向对象、分布性、编译和解释性、稳健性、安全性、可移植性、高性能、多线程性、动态性等特点,JAVA语言被广泛应用于信息技术相关的各个行业。其提供的对网络应用的支持和多媒体的存取,也会推动JAVA语言在互联网和企业网络的Web应用。而且其开放性和创新性也吸引了全世界最多的软件技术开发者的青睐。Java is an advanced programming language launched by Sun Microsystems in May 1995. Java can run on multiple platforms, such as Windows, Mac OS, and other systems of various UNIX versions. Because of its simplicity, object-oriented, distribution, compilation and interpretation, robustness, security, portability, high performance, multithreading, dynamics, etc., the JAVA language is widely used in various industries related to information technology . The support for network applications and multimedia access it provides will also promote the web application of JAVA language on the Internet and enterprise networks. Moreover, its openness and innovation have also attracted the favor of the world's largest software technology developers.
但是,在一些实体项目中,常常因为开发者的代码编写不规范或调用API方式不正确,导致程序执行缓慢,轻者影响用户体验,重者可能导致系统崩溃等不可预知的产品风险。比如某用户点击软件的确定按钮,软件无响应或者经过很长一段时间后才反馈执行结果,往往遇到此种情况后,软件开发人员首先需要通过打印的日志分析软件执行过程,或者通过Debug调试的方式跟踪软件的执行过程,以定位软件耗时的具体类的具体方法。该人工的方式既费时间,又费人力,而且具有一定的主观和盲目性。所以,如何高效的计算JAVA方法执行时间,快速定位问题的方法,是本领域技术人员需要解决的技术问题。However, in some real projects, it is often because the developer's code is not standardized or the method of calling the API is incorrect, resulting in slow program execution, which affects the user experience in the slightest, and may lead to unpredictable product risks such as system crashes. For example, when a user clicks the OK button of the software, the software does not respond or the execution result is fed back after a long period of time. When encountering such a situation, the software developer first needs to analyze the software execution process through the printed log, or through Debug debugging Track the execution process of the software in a way to locate the specific method of the specific class that consumes time in the software. This manual method is time-consuming and labor-intensive, and has certain subjectivity and blindness. Therefore, how to efficiently calculate the execution time of the JAVA method and quickly locate the problem is a technical problem to be solved by those skilled in the art.
发明内容Contents of the invention
本发明的目的是提供一种计算JAVA项目中方法执行时间的方法及装置,可以完全抛弃传统的人工方式,从而极大的缩短了查找耗时方法的时间,提高软件开发和运维的时效,降低成本。The purpose of the present invention is to provide a method and device for calculating the execution time of a method in a JAVA project, which can completely abandon the traditional manual method, thereby greatly shortening the time for finding time-consuming methods, and improving the timeliness of software development and operation and maintenance. cut costs.
为解决上述技术问题,本发明提供一种计算JAVA项目中方法执行时间的方法,所述方法包括:In order to solve the problems of the technologies described above, the present invention provides a method for calculating the execution time of a method in a JAVA project, said method comprising:
获取指定JAVA项目的目标目录中全部的字节码文件;Obtain all bytecode files in the target directory of the specified JAVA project;
从所述字节码文件中获取类路径;get the classpath from said bytecode file;
根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法,并执行所述代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;According to the class path, create a proxy class and a corresponding proxy method corresponding to each class path, and execute the proxy method; wherein, the proxy method includes recording the proxy start time and proxy end time of each method in the proxy class program of;
将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间。The execution time corresponding to each method in the target directory is obtained by making a difference between the proxy end time and the proxy start time.
可选的,获取指定JAVA项目的目标目录中全部的字节码文件,包括:Optionally, obtain all bytecode files in the target directory of the specified JAVA project, including:
指定JAVA项目的目标目录;Specify the target directory of the JAVA project;
扫描所述目标目录,筛选出后缀名为.class的字节码文件。The target directory is scanned to filter out bytecode files with a suffix of .class.
可选的,得到所述目标目录中各方法对应的执行时间之后,还包括:Optionally, after obtaining the execution time corresponding to each method in the target directory, further include:
输出所述目标目录中各方法对应的执行时间到指定设备。Output the execution time corresponding to each method in the target directory to the designated device.
可选的,输出所述目标目录中各方法对应的执行时间到指定设备,包括:Optionally, output the execution time corresponding to each method in the target directory to the specified device, including:
将所述目标目录中各方法对应的执行时间按照时长进行降序排列,形成输出序列;Arranging the execution time corresponding to each method in the target directory in descending order according to the duration to form an output sequence;
按照所述输出序列输出所述目标目录中各方法对应的执行时间到指定设备。Output the execution time corresponding to each method in the target directory to the designated device according to the output sequence.
可选的,得到所述目标目录中各方法对应的执行时间之后,还包括:Optionally, after obtaining the execution time corresponding to each method in the target directory, further include:
将所述执行时间与设定时间阈值进行比较,确定大于所述设定时间阈值的执行时间;comparing the execution time with a set time threshold, and determining an execution time greater than the set time threshold;
输出大于所述设定时间阈值的执行时间对应方法在所述目标目录中的定位信息。Outputting the location information of the method corresponding to the execution time greater than the set time threshold in the target directory.
本发明还提供一种计算JAVA项目中方法执行时间的装置,包括:The present invention also provides a device for calculating the execution time of a method in a JAVA project, comprising:
字节码文件获取模块,用于获取指定JAVA项目的目标目录中全部的字节码文件;The bytecode file obtaining module is used to obtain all bytecode files in the target directory of the specified JAVA project;
类路径获取模块,用于从所述字节码文件中获取类路径;A class path obtaining module, used to obtain the class path from the bytecode file;
代理方法执行模块,用于根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法,并执行所述代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;The proxy method execution module is used to create a proxy class corresponding to each class path and a corresponding proxy method according to the class path, and execute the proxy method; wherein, the proxy method includes records of each method in the proxy class Procedures for agency start time and agency end time;
执行时间计算模块,用于将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间。The execution time calculation module is used to make a difference between the agent end time and the agent start time to obtain the execution time corresponding to each method in the target directory.
可选的,所述字节码文件获取模块包括:Optionally, the bytecode file acquisition module includes:
指定目标目录单元,用于指定JAVA项目的目标目录;Specify the target directory unit, which is used to specify the target directory of the JAVA project;
筛选单元,用于扫描所述目标目录,筛选出后缀名为.class的字节码文件。The screening unit is configured to scan the target directory, and filter out bytecode files with a suffix of .class.
可选的,该装置还包括:Optionally, the device also includes:
输出模块,用于输出所述目标目录中各方法对应的执行时间到指定设备。An output module, configured to output the execution time corresponding to each method in the target directory to a designated device.
可选的,所述输出模块包括:Optionally, the output module includes:
排序单元,用于将所述目标目录中各方法对应的执行时间按照时长进行降序排列,形成输出序列;A sorting unit, configured to sort the execution times corresponding to the methods in the target directory in descending order according to the duration to form an output sequence;
输出单元,用于按照所述输出序列输出所述目标目录中各方法对应的执行时间到指定设备。An output unit, configured to output the execution time corresponding to each method in the target directory to a designated device according to the output sequence.
可选的,该装置还包括:Optionally, the device also includes:
比较模块,用于将所述执行时间与设定时间阈值进行比较,确定大于所述设定时间阈值的执行时间;A comparison module, configured to compare the execution time with a set time threshold, and determine an execution time greater than the set time threshold;
定位信息输出模块,用于输出大于所述设定时间阈值的执行时间对应方法在所述目标目录中的定位信息。The location information output module is configured to output the location information in the target directory corresponding to the method whose execution time is greater than the set time threshold.
本发明所提供的一种计算JAVA项目中方法执行时间的方法,包括:获取指定JAVA项目的目标目录中全部的字节码文件;从所述字节码文件中获取类路径;根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间;A method for calculating the execution time of a method in a JAVA project provided by the present invention includes: obtaining all bytecode files in the target directory of the specified JAVA project; obtaining a class path from the bytecode file; Path, create the proxy class corresponding to each class path and the corresponding proxy method; wherein, the proxy method includes a program that records the proxy start time and proxy end time of each method in the proxy class; the proxy end time and the proxy end time The starting time of the agent is made a difference to obtain the execution time corresponding to each method in the target directory;
可见,该方法可以完全抛弃传统的人工方式,通过创建的代理类及对应的代理方法,自动记录代理类中各方法的代理开始时间及代理结束时间,得到目标目录中各方法对应的执行时间;从而极大的缩短了查找耗时方法的时间,提高软件开发和运维的时效,降低成本;本发明还提供了一种计算JAVA项目中方法执行时间的装置,具有上述有益效果,在此不再赘述。It can be seen that this method can completely abandon the traditional manual method, automatically record the proxy start time and proxy end time of each method in the proxy class through the created proxy class and the corresponding proxy method, and obtain the corresponding execution time of each method in the target directory; Thereby, the time for finding time-consuming methods is greatly shortened, the timeliness of software development and operation and maintenance is improved, and the cost is reduced; the present invention also provides a device for calculating the execution time of methods in a JAVA project, which has the above-mentioned beneficial effects, and is not described here. Let me repeat.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only It is an embodiment of the present invention, and those skilled in the art can also obtain other drawings according to the provided drawings without creative work.
图1为本发明实施例所提供的计算JAVA项目中方法执行时间的方法的流程图;Fig. 1 is the flowchart of the method for calculating the method execution time in the JAVA project that the embodiment of the present invention provides;
图2为本发明实施例所提供的另一计算JAVA项目中方法执行时间的方法的流程图;Fig. 2 is the flowchart of another method for calculating the method execution time in the JAVA project provided by the embodiment of the present invention;
图3为本发明实施例所提供的计算JAVA项目中方法执行时间的终止的结构框图;Fig. 3 is the block diagram of the structure of calculating the termination of the method execution time in the JAVA project provided by the embodiment of the present invention;
图4为本发明实施例所提供的另一计算JAVA项目中方法执行时间的终止的结构框图。FIG. 4 is a structural block diagram of another calculation method execution time termination in a JAVA project provided by an embodiment of the present invention.
具体实施方式detailed description
本发明的核心是提供一种计算JAVA项目中方法执行时间的方法及装置,可以完全抛弃传统的人工方式,从而极大的缩短了查找耗时方法的时间,提高软件开发和运维的时效,降低成本。The core of the present invention is to provide a method and device for calculating the execution time of a method in a JAVA project, which can completely abandon the traditional manual method, thereby greatly shortening the time for finding time-consuming methods, and improving the timeliness of software development and operation and maintenance. cut costs.
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of embodiments of the present invention, but not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
请参考图1,图1为本发明实施例所提供的计算JAVA项目中方法执行时间的方法的流程图;所述方法包括:Please refer to Fig. 1, Fig. 1 is the flow chart of the method for calculating the method execution time in the JAVA project provided by the embodiment of the present invention; Said method comprises:
S100、获取指定JAVA项目的目标目录中全部的字节码文件;S100. Obtain all bytecode files in the target directory of the specified JAVA project;
其中,这里的目标目录可以是由用户进行设定,用户可以根据自身的需求选择需要进行执行时间计算的目标目录。例如可以是JAVA项目所在的目录或者指定更细粒度的包含字节码文件的目录。即这里的目标目录可以是JAVA项目目录或者更细粒度的某个文件子目录。目标目录的数量可以是一个也可以是多个,即用户可以指定JAVA项目中全部想要进行执行时间计算的目录作为目标目录。因此,本实施例并不对目标目录的数量及目录大小进行限定。Wherein, the target directory here may be set by the user, and the user may select the target directory for execution time calculation according to his own needs. For example, it can be the directory where the JAVA project is located or specify a finer-grained directory containing bytecode files. That is, the target directory here can be a JAVA project directory or a file subdirectory with finer granularity. The number of target directories can be one or more, that is, the user can designate all directories in the JAVA project for which execution time calculation is to be performed as target directories. Therefore, this embodiment does not limit the number and size of the target directories.
具体的,该步骤的具体过程为指定目标目录,扫描目标目录,确定目标目录中包含的全部字节码文件;即指定JAVA项目的目录作为目标目录,扫描该目录,并获取项目中的所有class文件,即原始的字节码文件,可选的,获取指定JAVA项目的目标目录中全部的字节码文件可以包括:Specifically, the specific process of this step is to specify the target directory, scan the target directory, and determine all the bytecode files contained in the target directory; that is, specify the directory of the JAVA project as the target directory, scan the directory, and obtain all the class files in the project File, that is, the original bytecode file. Optionally, obtaining all bytecode files in the target directory of the specified JAVA project may include:
指定JAVA项目的目标目录;Specify the target directory of the JAVA project;
扫描所述目标目录,筛选出后缀名为.class的字节码文件。The target directory is scanned to filter out bytecode files with a suffix of .class.
具体的,指定目标目录可以是根据用户输入的目标目录名称确定目标目录;其中,输入的过程可以是键盘输入,也可以是语音输入等。本实施例并不限定指定JAVA项目的目标目录的具体方式。在指定目标目录后加载目标目录的文件,并过滤扩展名为.class的字节码文件。Specifically, specifying the target directory may be to determine the target directory according to the name of the target directory input by the user; wherein, the input process may be keyboard input or voice input. This embodiment does not limit the specific manner of specifying the target directory of the JAVA project. After specifying the target directory, load the files of the target directory, and filter the bytecode files with the extension .class.
进一步,扫描后目标目录中若未含有后缀名为.class的字节码文件,则可以立即结束计算JAVA项目中方法执行时间的方法。Further, if the target directory does not contain a bytecode file with the suffix .class after scanning, the method for calculating the execution time of the method in the JAVA project can be terminated immediately.
S110、从所述字节码文件中获取类路径;S110. Obtain a class path from the bytecode file;
具体的,从提取的全部字节码文件中确定其包含的类路径,这里的类路径数量可以是多个,具体类路径的数量与具体的字节码文件有关。Specifically, the class paths included in all the extracted bytecode files are determined, where the number of class paths may be multiple, and the specific number of class paths is related to specific bytecode files.
S120、根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法,并执行所述代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;S120. According to the class path, create a proxy class and a corresponding proxy method corresponding to each class path, and execute the proxy method; wherein, the proxy method includes recording the proxy start time and the proxy method of each method in the proxy class end time program;
S130、将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间。S130. Taking the difference between the proxy end time and the proxy start time to obtain the execution time corresponding to each method in the target directory.
具体的,本步骤中为每一个类路径创建对应的代理类及对应的代理方法。例如目标目录中包含三个类路径,每个类路径均包含两个方法时,这里的代理类有三个分别于三个类路径对应。三个代理类又对应三个代理方法,这里的代理方法用于代理执行所对应的代理类内的方法。Specifically, in this step, a corresponding proxy class and a corresponding proxy method are created for each class path. For example, if the target directory contains three classpaths, and each classpath contains two methods, there are three proxy classes corresponding to the three classpaths. The three proxy classes correspond to three proxy methods, where the proxy methods are used to execute the methods in the corresponding proxy classes.
这里的代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序。以上述例子继续说明,由于每个类路径均包含两个方法,即每一个代理方法中包含两个方法,可以得到该类中每个方法的代理开始时间及代理结束时间。即上述例子中总共可以得到六个代理开始时间及代理结束时间。即在每个类路径对应的类里的JAVA代理方法在开始执行前和执行结束后分别记录时间,标记为代理开始时间和代理结束时间;依据【代理结束时间-代理开始时间】,计算得出JAVA中方法执行的时长。The proxy method here includes a program that records the proxy start time and proxy end time of each method in the proxy class. Using the above example to continue to illustrate, since each class path contains two methods, that is, each proxy method contains two methods, the proxy start time and proxy end time of each method in the class can be obtained. That is, in the above example, a total of six agent start times and agent end times can be obtained. That is, the JAVA proxy method in the class corresponding to each classpath records the time before execution and after execution, and marks it as the proxy start time and proxy end time; according to [proxy end time - proxy start time], the calculation is The duration of method execution in JAVA.
根据各个代理结束时间与所述代理开始时间,可以得到目标目录中各方法对应的执行时间。这里的代理结束时间与所述代理开始时间作差的计算过程也可以在代理方法中进行,即可以直接输出代理方法对应的各方法的执行时间。也可以是装置中有另外的单独计算执行时间的程序,将代理结束时间与所述代理开始时间作差计算执行时间。According to the end time of each agent and the start time of the agent, the execution time corresponding to each method in the target directory can be obtained. Here, the calculation process of the difference between the proxy end time and the proxy start time can also be performed in the proxy method, that is, the execution time of each method corresponding to the proxy method can be directly output. It may also be that there is another program in the device that calculates the execution time independently, and the execution time is calculated by taking the difference between the agent end time and the agent start time.
即仍以上述例子继续说明,则目标目录中有三个类,每个类有两个方法,即有三个代理类和对应的代理方法,每个代理方法执行对应的两个方法,总共可以得到六个方法的执行时间。That is, continue to illustrate with the above example, there are three classes in the target directory, each class has two methods, that is, there are three proxy classes and corresponding proxy methods, each proxy method executes the corresponding two methods, and a total of six execution time of a method.
该方法的具体过程可以是获取目标目录的字节码文件,从字节码文件中获取类路径,根据上述获取的类路径,为每个类路径创建代理类及代理方法,在代理方法中记录该类中各个方法开始执行和执行结束的时间,依据【代理结束时间-代理开始时间】,计算得出被代理的各JAVA方法执行时长。The specific process of this method can be to obtain the bytecode file of the target directory, obtain the class path from the bytecode file, create a proxy class and proxy method for each class path according to the above obtained class path, and record in the proxy method The start and end times of each method in this class are calculated based on [proxy end time - proxy start time] to calculate the execution duration of each JAVA method being proxied.
基于上述技术方案,本发明实施例提的计算JAVA项目中方法执行时间的方法,该方法可以完全抛弃传统的人工方式,通过创建的代理类及对应的代理方法,自动记录代理类中各方法的代理开始时间及代理结束时间,得到目标目录中各方法对应的执行时间;从而极大的缩短了查找耗时方法的时间,提高软件开发和运维的时效,降低成本。Based on the above technical solution, the embodiment of the present invention proposes a method for calculating the execution time of a method in a JAVA project. This method can completely abandon the traditional manual method, and automatically record the time of each method in the proxy class through the created proxy class and the corresponding proxy method. The agent start time and agent end time can be used to obtain the corresponding execution time of each method in the target directory; thus greatly shortening the time for finding time-consuming methods, improving the timeliness of software development and operation and maintenance, and reducing costs.
基于上述实施例,请参考图2,为了使得开发人员可以更加及时的得到目标目录中各方法的执行时间,在上述实施例得到所述目标目录中各方法对应的执行时间之后,本实施例可以包括:Based on the above embodiment, please refer to Figure 2. In order to enable developers to obtain the execution time of each method in the target directory in a more timely manner, after the execution time corresponding to each method in the target directory is obtained in the above embodiment, this embodiment can include:
S200、获取指定JAVA项目的目标目录中全部的字节码文件;S200. Obtain all bytecode files in the target directory of the specified JAVA project;
S210、从所述字节码文件中获取类路径;S210. Obtain a class path from the bytecode file;
S220、根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法,并执行所述代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;S220. According to the class path, create a proxy class and a corresponding proxy method corresponding to each class path, and execute the proxy method; wherein, the proxy method includes recording the proxy start time and the proxy method of each method in the proxy class end time program;
S230、将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间。S230. Taking the difference between the proxy end time and the proxy start time to obtain the execution time corresponding to each method in the target directory.
S240、输出所述目标目录中各方法对应的执行时间到指定设备。S240. Output the execution time corresponding to each method in the target directory to the specified device.
具体的,当得到目标目录中各方法对应的执行时间后及时将其发送到指定设备,使得开发人员可以及时得到执行时间数据,进而及时对JAVA项目中的代码进行维护。这里的指定设备可以是开发人员的手机,电脑等设备。输出过程可以是根据开发人员预留的路径发送执行时间信息到指定设备。本实施例并不对指定设备以及指定设备的数量进行限定。Specifically, after obtaining the execution time corresponding to each method in the target directory, it is sent to the designated device in time, so that the developer can obtain the execution time data in time, and then maintain the code in the JAVA project in time. The designated device here can be the developer's mobile phone, computer and other devices. The output process can be to send the execution time information to the specified device according to the path reserved by the developer. This embodiment does not limit the specified device and the quantity of the specified device.
例如,当运行代理方法,得到目标目录中各方法对应的执行时间后将其发送到用户手机,以便用户可以及时了解到目标目录中各方法对应的执行时间。进行及时对不符合时间要求的方法代码进行修改。For example, when the proxy method is run, the execution time corresponding to each method in the target directory is obtained and then sent to the user's mobile phone, so that the user can know the execution time corresponding to each method in the target directory in time. Make timely modifications to method codes that do not meet the time requirements.
进一步,在输出到执行时间指定设备的基础上,还可以在得到执行时间数据后发出提示信息,提示用户代理方法执行结束。Further, on the basis of outputting to the execution time specifying device, a prompt message may also be sent after the execution time data is obtained, prompting the user agent to end the execution of the method.
其中,S200到S230的具体内容请参考S100到S130的内容,在此不再赘述。Wherein, for the specific content of S200 to S230, please refer to the content of S100 to S130, which will not be repeated here.
基于上述实施例,由于用户指定的目标目录可能会包含很多的类,每个类中有可能会包含多个方法。因此该方法最终得到的目标目录中各方法对应的执行时间可能很多,如果随机排序发送给开发人员,开发人员需要花费时间从中查找是否存在用时较长的方法,且由于执行时间数量众多,可能会出现遗漏现象。因此在本实施例中为了提高用户获取数据的可靠性及高效性。在本实施例中输出所述目标目录中各方法对应的执行时间到指定设备可以包括:Based on the above embodiment, since the target directory specified by the user may contain many classes, each class may contain multiple methods. Therefore, the execution time corresponding to each method in the target directory obtained by this method may be a lot. If the random order is sent to the developer, the developer needs to spend time to find out whether there is a method that takes a long time, and due to the large number of execution times, it may be Omission occurs. Therefore, in this embodiment, in order to improve the reliability and efficiency of data acquisition by users. In this embodiment, outputting the execution time corresponding to each method in the target directory to the designated device may include:
将所述目标目录中各方法对应的执行时间按照时长进行降序排列,形成输出序列;Arranging the execution time corresponding to each method in the target directory in descending order according to the duration to form an output sequence;
按照所述输出序列输出所述目标目录中各方法对应的执行时间到指定设备。Output the execution time corresponding to each method in the target directory to the designated device according to the output sequence.
具体的,即输出时按照执行时间从长到短进行顺序输出。这样排在第一个的执行时间对应的方法耗时最长,可能是最不符合执行时长要求的方法。使开发人员第一时间可以获取最有价值的信息。因为执行时间很小的方法基本上是符合要求的方法不需要再进行代码修改。反倒是耗时较长的方法极有可能是需要开发人员进行维护的。即使开发人员可以在尽可能短的时间内获取到其最关心的数据。且还可以提高开发人员的处理速度,例如当排在第一个的执行时间都满足要求时,后续的都会满足时间要求。开发人员即可以不需要一一查看后续方法的代码。进一步提高软件开发和运维的时效,降低成本。Specifically, output is performed sequentially according to the execution time from the longest to the shortest. In this way, the method corresponding to the first execution time takes the longest, and may be the method that does not meet the execution time requirement the least. So that developers can obtain the most valuable information at the first time. Because the method with a small execution time is basically a method that meets the requirements and does not require code modification. On the contrary, the method that takes a long time is very likely to require maintenance by developers. Even the data that developers care about most can be obtained in the shortest possible time. And it can also improve the processing speed of the developer. For example, when the execution time of the first one meets the requirements, the subsequent ones will all meet the time requirements. Developers don't need to look at the code of subsequent methods one by one. Further improve the timeliness of software development and operation and maintenance, and reduce costs.
下面举例说明上述过程:The following example illustrates the above process:
步骤1、指定要查找的JAVA项目目录或者更细粒度的某个文件子目录,作为目标目录。Step 1. Specify the JAVA project directory to be searched or a subdirectory of a file at a finer granularity as the target directory.
步骤2、针对步骤1中指定的目标目录查找过滤后缀为.class的JAVA字节码文件,如果存在,则执行步骤3,如果不存在,则退出。Step 2. Search for the JAVA bytecode file with the filter suffix .class for the target directory specified in step 1. If it exists, execute step 3. If it does not exist, exit.
步骤3、根据步骤2中查找到的JAVA字节码文件,解析获取对应的类路径。Step 3. According to the JAVA bytecode file found in step 2, analyze and obtain the corresponding class path.
步骤4、创建类的代理,并为其中的所有方法创建代理方法,在代理方法中加入记录代理开始时间和代理结束时间的方法程序。Step 4. Create a proxy of the class, and create proxy methods for all the methods in it, and add a method program to record the proxy start time and proxy end time in the proxy method.
步骤5、根据【代理结束时间-代理开始时间】计算方法的执行时间。Step 5. Calculate the execution time of the method according to [agent end time-agent start time].
步骤6、按执行时间降序排列,输出各方法对应的执行时间。Step 6. Arrange in descending order of execution time, and output the execution time corresponding to each method.
基于上述任意实施例,为了进一步提高计算得到的执行时间数据的可用性,本实施例在得到所述目标目录中各方法对应的执行时间之后,还可以包括:Based on any of the above embodiments, in order to further improve the availability of the calculated execution time data, after obtaining the execution time corresponding to each method in the target directory, this embodiment may further include:
将所述执行时间与设定时间阈值进行比较,确定大于所述设定时间阈值的执行时间;comparing the execution time with a set time threshold, and determining an execution time greater than the set time threshold;
输出大于所述设定时间阈值的执行时间对应方法在所述目标目录中的定位信息。Outputting the location information of the method corresponding to the execution time greater than the set time threshold in the target directory.
其中,这里的设定时间阈值可以由开发人员根据实际JAVA项目的要求进行设定。因此,本实施例并不对设定时间阈值的数值进行限定。Wherein, the setting time threshold here can be set by the developer according to the requirements of the actual JAVA project. Therefore, this embodiment does not limit the value of the set time threshold.
具体的,为了进一步从全部的执行时间中筛选出可用信息,本实施例中可以利用设定时间阈值作为筛选条件进行筛选;即将不符合时间要求的执行时间对应的方法筛选出来,即输出大于所述设定时间阈值的执行时间对应方法在所述目标目录中的定位信息。可以使开发人员快速定位到需要进行代码维护的原始代码位置。这里的定位信息可以是直接输出大于所述设定时间阈值的执行时间对应方法的代码,或者是输出大于所述设定时间阈值的执行时间对应方法在JAVA项目中的位置(例如哪个目录下,哪个子目录下,哪个类中,对应的代码开始到终止行数等)。Specifically, in order to further filter out the available information from all the execution time, in this embodiment, the set time threshold can be used as the filter condition for screening; that is, the method corresponding to the execution time that does not meet the time requirement is screened out, that is, the output is greater than the specified The execution time of the set time threshold corresponds to the location information of the method in the target directory. Developers can quickly locate the original code location that needs to be maintained. The location information here can be the code that directly outputs the execution time corresponding method greater than the set time threshold, or the position in the JAVA project that outputs the execution time corresponding method greater than the set time threshold (such as which directory, In which subdirectory, in which class, the number of lines from the beginning to the end of the corresponding code, etc.).
基于上述技术方案,本发明实施例提的计算JAVA项目中方法执行时间的方法,该方法可以完全抛弃传统的人工方式,从而极大的缩短了查找耗时方法的时间,而且通过基于这种方法获取的方法执行时间,再结合执行设定时间阈值的配置,可以及时定位到软件执行过程中急待优化的代码片断,快速反馈至指定的开发人员进行优化修复。可以高效率的查找JAVA项目中执行耗时较长的类以及其中的方法,提高软件开发和运维的时效,降低成本。Based on the above technical solution, the embodiment of the present invention proposes a method for calculating the execution time of a method in a JAVA project. This method can completely abandon the traditional manual method, thereby greatly shortening the time for finding time-consuming methods. Moreover, based on this method The obtained method execution time, combined with the configuration of the execution set time threshold, can locate the code fragments that need to be optimized in the software execution process in time, and quickly feed back to the designated developer for optimization and repair. It can efficiently find classes and methods in JAVA projects that take a long time to execute, improve the timeliness of software development and operation and maintenance, and reduce costs.
下面对本发明实施例提供的计算JAVA项目中方法执行时间的装置进行介绍,下文描述的计算JAVA项目中方法执行时间的装置与上文描述的计算JAVA项目中方法执行时间的方法可相互对应参照。The following is an introduction to the device for calculating the execution time of a method in a JAVA project provided by an embodiment of the present invention. The device for calculating the execution time of a method in a JAVA project described below and the method for calculating the execution time of a method in a JAVA project described above can be referred to in correspondence.
请参考图3,图3为本发明实施例所提供的计算JAVA项目中方法执行时间的终止的结构框图;该装置可以包括:Please refer to Fig. 3, Fig. 3 is the structural block diagram of the termination of the calculation method execution time in the JAVA project that Fig. 3 provides for the embodiment of the present invention; This device can comprise:
字节码文件获取模块100,用于获取指定JAVA项目的目标目录中全部的字节码文件;Bytecode file obtaining module 100, used to obtain all bytecode files in the target directory of the specified JAVA project;
类路径获取模块200,用于从所述字节码文件中获取类路径;A class path obtaining module 200, configured to obtain a class path from the bytecode file;
代理方法执行模块300,用于根据所述类路径,创建每一个类路径对应的代理类及对应的代理方法,并执行所述代理方法;其中,所述代理方法中包含记录代理类中各方法的代理开始时间及代理结束时间的程序;The proxy method execution module 300 is used to create a proxy class corresponding to each class path and a corresponding proxy method according to the class path, and execute the proxy method; wherein, the proxy method includes recording each method in the proxy class The procedures for the proxy start time and proxy end time;
执行时间计算模块400,用于将所述代理结束时间与所述代理开始时间作差,得到所述目标目录中各方法对应的执行时间。The execution time calculation module 400 is configured to make a difference between the agent end time and the agent start time to obtain the execution time corresponding to each method in the target directory.
基于上述实施例,所述字节码文件获取模块100可以包括:Based on the foregoing embodiments, the bytecode file acquisition module 100 may include:
指定目标目录单元,用于指定JAVA项目的目标目录;Specify the target directory unit, which is used to specify the target directory of the JAVA project;
筛选单元,用于扫描所述目标目录,筛选出后缀名为.class的字节码文件。The screening unit is configured to scan the target directory, and filter out bytecode files with a suffix of .class.
基于上述任意实施例,请参考图4,该装置还可以包括:Based on any of the above embodiments, please refer to FIG. 4, the device may also include:
输出模块500,用于输出所述目标目录中各方法对应的执行时间到指定设备。The output module 500 is configured to output the execution time corresponding to each method in the target directory to a specified device.
基于上述实施例,所述输出模块500可以包括:Based on the foregoing embodiments, the output module 500 may include:
排序单元,用于将所述目标目录中各方法对应的执行时间按照时长进行降序排列,形成输出序列;A sorting unit, configured to sort the execution times corresponding to the methods in the target directory in descending order according to the duration to form an output sequence;
输出单元,用于按照所述输出序列输出所述目标目录中各方法对应的执行时间到指定设备。An output unit, configured to output the execution time corresponding to each method in the target directory to a designated device according to the output sequence.
基于上述任意实施例,该装置还可以包括:Based on any of the above embodiments, the device may further include:
比较模块,用于将所述执行时间与设定时间阈值进行比较,确定大于所述设定时间阈值的执行时间;A comparison module, configured to compare the execution time with a set time threshold, and determine an execution time greater than the set time threshold;
定位信息输出模块,用于输出大于所述设定时间阈值的执行时间对应方法在所述目标目录中的定位信息。The location information output module is configured to output the location information in the target directory corresponding to the method whose execution time is greater than the set time threshold.
说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似部分互相参见即可。对于实施例公开的装置而言,由于其与实施例公开的方法相对应,所以描述的比较简单,相关之处参见方法部分说明即可。Each embodiment in the description is described in a progressive manner, each embodiment focuses on the difference from other embodiments, and the same and similar parts of each embodiment can be referred to each other. As for the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and for the related information, please refer to the description of the method part.
专业人员还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Professionals can further realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software or a combination of the two. In order to clearly illustrate the possible For interchangeability, in the above description, the composition and steps of each example have been generally described according to their functions. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present invention.
结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be directly implemented by hardware, software modules executed by a processor, or a combination of both. Software modules can be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other Any other known storage medium.
以上对本发明所提供的计算JAVA项目中方法执行时间的方法及装置进行了详细介绍。本文中应用了具体个例对本发明的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本发明的方法及其核心思想。应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理的前提下,还可以对本发明进行若干改进和修饰,这些改进和修饰也落入本发明权利要求的保护范围内。The method and device for calculating the execution time of a method in a JAVA project provided by the present invention have been introduced in detail above. In this paper, specific examples are used to illustrate the principle and implementation of the present invention, and the descriptions of the above embodiments are only used to help understand the method and core idea of the present invention. It should be pointed out that for those skilled in the art, without departing from the principle of the present invention, some improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611093078.8A CN106776302A (en) | 2016-12-01 | 2016-12-01 | Calculate method, the device of method execution time in JAVA projects |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611093078.8A CN106776302A (en) | 2016-12-01 | 2016-12-01 | Calculate method, the device of method execution time in JAVA projects |
Publications (1)
Publication Number | Publication Date |
---|---|
CN106776302A true CN106776302A (en) | 2017-05-31 |
Family
ID=58915769
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611093078.8A Pending CN106776302A (en) | 2016-12-01 | 2016-12-01 | Calculate method, the device of method execution time in JAVA projects |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106776302A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107656849A (en) * | 2017-09-28 | 2018-02-02 | 新华三技术有限公司 | A kind of software system performance positioning problems method and device |
CN111240927A (en) * | 2020-01-03 | 2020-06-05 | 北京小米移动软件有限公司 | Method, device and storage medium for detecting time consumption of method in program |
CN111427773A (en) * | 2020-03-06 | 2020-07-17 | 平安科技(深圳)有限公司 | Web application resource monitoring method, electronic device, and computer-readable storage medium |
US12093414B1 (en) * | 2019-12-09 | 2024-09-17 | Amazon Technologies, Inc. | Efficient detection of in-memory data accesses and context information |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6622299B1 (en) * | 1999-07-06 | 2003-09-16 | International Business Machines Corporation | Computer system, program product and method for dynamically providing an indication to a programmer of the efficiency of a program that is being written |
CN104636237A (en) * | 2015-01-19 | 2015-05-20 | 上海新炬网络信息技术有限公司 | Monitoring method for Web application system service performance based on Java platform |
CN105653458A (en) * | 2016-01-06 | 2016-06-08 | 北京京东尚科信息技术有限公司 | Method and device for detecting high-time-consumption Java method in target Java items |
-
2016
- 2016-12-01 CN CN201611093078.8A patent/CN106776302A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6622299B1 (en) * | 1999-07-06 | 2003-09-16 | International Business Machines Corporation | Computer system, program product and method for dynamically providing an indication to a programmer of the efficiency of a program that is being written |
CN104636237A (en) * | 2015-01-19 | 2015-05-20 | 上海新炬网络信息技术有限公司 | Monitoring method for Web application system service performance based on Java platform |
CN105653458A (en) * | 2016-01-06 | 2016-06-08 | 北京京东尚科信息技术有限公司 | Method and device for detecting high-time-consumption Java method in target Java items |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107656849A (en) * | 2017-09-28 | 2018-02-02 | 新华三技术有限公司 | A kind of software system performance positioning problems method and device |
CN107656849B (en) * | 2017-09-28 | 2021-12-07 | 新华三技术有限公司 | Method and device for positioning performance problem of software system |
US12093414B1 (en) * | 2019-12-09 | 2024-09-17 | Amazon Technologies, Inc. | Efficient detection of in-memory data accesses and context information |
CN111240927A (en) * | 2020-01-03 | 2020-06-05 | 北京小米移动软件有限公司 | Method, device and storage medium for detecting time consumption of method in program |
CN111240927B (en) * | 2020-01-03 | 2024-01-30 | 北京小米移动软件有限公司 | Method, device and storage medium for detecting time consumption of method in program |
CN111427773A (en) * | 2020-03-06 | 2020-07-17 | 平安科技(深圳)有限公司 | Web application resource monitoring method, electronic device, and computer-readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111610978B (en) | Applet conversion method, device, equipment and storage medium | |
US10185546B2 (en) | Service extraction and application composition | |
CN114546738B (en) | General testing methods, systems, terminals and storage media for servers | |
Tonella et al. | Interpolated n-grams for model based testing | |
CN112596932B (en) | Service registration and interception method, device, electronic device and readable storage medium | |
CN108415998B (en) | Application dependency relationship updating method, terminal, device and storage medium | |
CN110955409B (en) | Method and device for creating resources on cloud platform | |
CN106776302A (en) | Calculate method, the device of method execution time in JAVA projects | |
CN112379888B (en) | Code change analysis method | |
CN111177113A (en) | Data migration method and device, computer equipment and storage medium | |
US20200371902A1 (en) | Systems and methods for software regression detection | |
CN106294149A (en) | A kind of method detecting Android application component communication leak | |
CN113448985A (en) | API (application program interface) interface generation method, calling method and device and electronic equipment | |
CN116523457A (en) | Workflow processing method, device, equipment and storage medium based on business process | |
CN113918637A (en) | A process engine platform creation method and system based on BPMN2.0 specification | |
CN111008017B (en) | Oclin-based pre-review method for files to be submitted and related components | |
CN111506339A (en) | Method and device for processing change information of Software Development Kit (SDK) | |
CN111352631B (en) | Interface compatibility detection method and device | |
JP4989086B2 (en) | System and method for performing a streaming check on a data format for UDT | |
CN112306634A (en) | Method and apparatus for updating workload according to configuration changes in cloud platform | |
CN116578282A (en) | Code generation method, device, electronic equipment and medium | |
CN108804103A (en) | A kind of scan interface simultaneously generates the method that can call api interface document | |
CN110990648A (en) | Virus query method, server and computer readable storage medium | |
CN108763474B (en) | Method, device and storage medium for acquiring transaction correlation and executing regression test | |
CN115292194B (en) | Method for debugging flow, electronic equipment and computer readable storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170531 |