WO2020024343A1 - 方法调用链跟踪方法、电子装置及计算机可读存储介质 - Google Patents

方法调用链跟踪方法、电子装置及计算机可读存储介质 Download PDF

Info

Publication number
WO2020024343A1
WO2020024343A1 PCT/CN2018/101752 CN2018101752W WO2020024343A1 WO 2020024343 A1 WO2020024343 A1 WO 2020024343A1 CN 2018101752 W CN2018101752 W CN 2018101752W WO 2020024343 A1 WO2020024343 A1 WO 2020024343A1
Authority
WO
WIPO (PCT)
Prior art keywords
call chain
request
call
chain information
output
Prior art date
Application number
PCT/CN2018/101752
Other languages
English (en)
French (fr)
Inventor
陈青龙
Original Assignee
网宿科技股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 网宿科技股份有限公司 filed Critical 网宿科技股份有限公司
Priority to EP18928865.7A priority Critical patent/EP3828696A4/en
Priority to US16/981,267 priority patent/US11099889B2/en
Publication of WO2020024343A1 publication Critical patent/WO2020024343A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3636Software debugging by tracing the execution of the program
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Definitions

  • the present invention relates to the technical field of method invocation, and in particular to a method invocation method tracking method, an electronic device, and a computer-readable storage medium.
  • a method (also called a function) is a block of code that implements a specific function.
  • the implementation of a function is always completed by one or more methods. For example, to log in to a website, users need to implement multiple methods such as user verification, password verification, and loading of the contents of each module on the homepage. Some of these methods may be used in multiple places. For example, the password format verification method can be called when the payment password and login password are set. Because a method may be called in multiple places, the calling entry is different, and the implemented functions and processing procedures may be different. During the implementation of the method invocation, it is necessary to perform exception handling (such as exception capture output log). Without the log output of the entire call chain, it is difficult to determine which business process or business branch caused the error.
  • exception handling such as exception capture output log
  • the current method of implementing the method call chain is mainly to record the call relationship at the beginning of the method implementation, and output the call chain log after the process is processed.
  • a method needs to implement an interface, or a method of adding invocation chain records to a method. For the code that has been developed, if you want to add this function, it is equivalent to refactoring the code again, and the maintenance cost is high.
  • the present invention provides a method call chain tracking method, an electronic device, and a computer-readable storage medium to solve at least one of the above technical problems.
  • the present invention proposes a method call chain tracking method, which includes:
  • the call chain information of the method is recorded before the method call request is executed, and the recorded call chain information is output after the method call request is completed.
  • whether the call chain information needs to be output is controlled by a printMethodCallChain parameter, and when the parameter value is true, it indicates that the call chain information needs to be output; when the parameter value is false, it indicates that It is not necessary to output the call chain information.
  • the intercepting before the method is called, and judging whether to output the call chain information of the method according to the configuration item includes:
  • Interception is performed before executing the method call request to determine whether the request ID is cached to determine whether the call chain information needs to be output.
  • the call chain information of the method is recorded before the call request of the method is executed, and the recorded call is output after the call request of the method is completed
  • the chain information includes:
  • the recorded call chain information is output.
  • the method further includes:
  • the request ID in the cache is removed.
  • the method is intercepted by a slice interception of the Spring-AOP framework.
  • the present invention also provides an electronic device including a memory and a processor, where the memory stores a method call chain tracking program that can be run on the processor, and the method call chain tracking program When executed by the processor, the following method is implemented:
  • the call chain information of the method is recorded before the method call request is executed, and the recorded call chain information is output after the method call request is completed.
  • whether the call chain information needs to be output is controlled by a printMethodCallChain parameter, and when the parameter value is true, it indicates that the call chain information needs to be output; when the parameter value is false, it indicates that It is not necessary to output the call chain information.
  • the intercepting before the method is called, and judging whether to output the call chain information of the method according to the configuration item includes:
  • Interception is performed before executing the method call request to determine whether the request ID is cached to determine whether the call chain information needs to be output.
  • the call chain information of the method is recorded before the call request of the method is executed, and the recorded call is output after the call request of the method is completed
  • the chain information includes:
  • the recorded call chain information is output.
  • the method call chain tracking program when executed by the processor, it is further implemented:
  • the request ID in the cache is removed.
  • the method is intercepted by a slice interception of the Spring-AOP framework.
  • the present invention also provides a computer-readable storage medium storing a method call chain tracking program that can be executed by at least one processor, So that the at least one processor executes the method call chain tracking method as described above.
  • the method call chain tracking method, electronic device and computer-readable storage medium provided by the present invention can be implemented by setting configuration items and introducing the Spring-AOP framework without refactoring the code. Trace of the call chain.
  • the request processing logic is complex and multi-branch, the business logic can be quickly located according to the call chain information. When the request is handled abnormally, it can help quickly locate the problem.
  • FIG. 1 is a schematic structural diagram of an electronic device according to a first embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a method call chain tracking method according to a second embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of a method call chain tracking method according to a third embodiment of the present invention.
  • first and second in the present invention are only used for description purposes, and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. . Therefore, the features defined as “first” and “second” may explicitly or implicitly include at least one of the features.
  • technical solutions between the various embodiments can be combined with each other, but must be based on those that can be realized by a person of ordinary skill in the art. When the combination of technical solutions conflicts or cannot be realized, such a combination of technical solutions should be considered nonexistent It is also not within the protection scope claimed by the present invention.
  • a first embodiment of the present invention provides an electronic device 1 for implementing a method call chain tracking method.
  • the electronic device 1 may be a server, a smart phone, a tablet computer, a personal computer, a portable computer, and other electronic devices with computing functions.
  • the electronic device 1 includes a memory 11, a processor 13, a network interface 15 and a communication bus 17.
  • the network interface 15 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the communication bus 17 is used to implement connection communication between these components.
  • the memory 11 includes at least one type of readable storage medium.
  • the at least one type of readable storage medium may be a non-volatile storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory, and the like.
  • the memory 11 may be an internal storage unit of the electronic device 1, such as a hard disk of the electronic device 1.
  • the memory 11 may also be an external storage unit of the electronic device 1, for example, a plug-in hard disk, a Smart Memory Card (SMC) provided on the electronic device 1, and security. Digital (Secure Digital, SD) card, Flash card (Flash card), etc.
  • the memory 11 may be used to store application software installed on the electronic device 1 and various types of data, such as the program code of the method call chain tracking program 10 and related data generated during the running process.
  • the processor 13 may be a central processing unit, a microprocessor, or other data processing chip in some embodiments, and is configured to run program codes or process data stored in the memory 11.
  • FIG. 1 only shows the electronic device 1 with the components 11-17 and the method call chain tracking program 10, but it should be understood that FIG. 1 does not show all the components of the electronic device 1 and can be implemented more or less instead s component.
  • the program code of the method call chain tracking program 10 is stored in the memory 11 as a computer storage medium.
  • the processor 13 executes the program code of the method call chain tracking program 10 To achieve the following method:
  • the call chain information of the method is recorded before the method call request is executed, and the recorded call chain information is output after the method call request is completed.
  • a second embodiment of the present invention provides a method call chain tracking method.
  • the execution order of the steps in the flowchart shown in FIG. 2 may be changed, and some steps may be omitted.
  • the method includes the following steps:
  • step S10 a configuration item of whether the current application performs method call chain tracking is set.
  • the configuration item is used to customize whether to perform method call chain tracking, that is, whether to output (print) method call chain information.
  • printMethodCallChain parameter in the configuration item, it can be controlled whether different applications need to enable call chain information printing.
  • the parameter value is true, it means that the configuration item is open and the method call chain information needs to be printed; when the parameter value is false, it means that the configuration item is closed and the method call chain information does not need to be printed.
  • the configuration item is open, when the corresponding request is received, it will be marked that the request needs to print the call chain information, and the corresponding method call chain information will be recorded before each method call.
  • step S20 the method is intercepted before the method is called, and it is judged according to the configuration item whether the call chain information of the method needs to be output.
  • Spring-AOP Oriented Programming
  • Spring-AOP Oriented Programming
  • the interception method by Spring-AOP does not need to modify the code block that has been developed originally, and implements the tracking of the method call chain without refactoring the code.
  • step S30 when the call chain information needs to be output, the call chain information of the method is recorded before the method call request is executed, and the recorded call chain information is output after the method call request is completed.
  • steps S20 and S30 please refer to the relevant steps in FIG. 3 and the following third embodiment.
  • a third embodiment of the present invention provides a method call chain tracking method.
  • the execution order of the steps in the flowchart shown in FIG. 3 may be changed, and some steps may be omitted.
  • the method includes the following steps:
  • step S100 a configuration item of whether the current application performs method call chain tracking is set.
  • the configuration item is used to customize whether to perform method call chain tracking, that is, whether to output (print) method call chain information.
  • printMethodCallChain parameter in the configuration item, it can be controlled whether different applications need to enable call chain information printing.
  • this parameter When the value of this parameter is true, it means that the configuration item is open, and the method call chain information needs to be printed; when the parameter value is false, it means that the configuration item is closed, and the method call chain information does not need to be printed.
  • Once the configuration item is open when the corresponding request is received, it will be marked that the request needs to print the call chain information, and the corresponding method call chain information will be recorded before each method call.
  • step S200 when a method call request is received, it is determined whether the call chain information needs to be output according to the configuration item. When required, step S300 is performed. When not required, step S400 is performed.
  • the current application When the current application receives a method invocation request, it is determined whether it is necessary to output the invocation chain information according to the parameter value of the configuration item. That is, when the printMethodCallChain parameter value of the configuration item is true, it is judged that the method call chain information needs to be output; when the parameter value is false, it is judged that the method call chain information is not required to be output.
  • step S300 a request ID of the method invocation request is cached. Then step S400 is performed.
  • the request ID of the method call request is buffered in memory for recording the call chain information when the method call is executed later.
  • step S400 an interception is performed before executing the method call to determine whether a request ID is cached. If yes, step S500 is performed. If not, step S600 is performed.
  • step S500 the call chain information of the method to be called is recorded. Then step S600 is performed.
  • the request ID When it is determined that the request ID is cached, it means that the call chain information of the method needs to be output, before the method call request is executed, the call chain information of the method to be called is recorded, and then the method call request is executed.
  • the corresponding method name is recorded in the queue corresponding to the cached request ID.
  • step S600 the method call request is executed.
  • Step S700 After processing the method call request, determine whether the request ID is cached. If yes, step S800 is performed. If not, the process ends.
  • step S800 the recorded call chain information is output and the request ID in the cache is removed.
  • the data in the queue corresponding to the request ID is printed out sequentially, and the entire queue data output is the call sequence (call chain) of the method.
  • the request ID in the cache needs to be removed.
  • the method call chain tracking method provided in this embodiment can implement the method call chain tracking by setting configuration items and introducing the Spring-AOP framework without refactoring the code.
  • the request processing logic is complex and multi-branch, you can quickly locate the business logic based on the call chain information.
  • the request is handled abnormally, it can help you quickly locate the problem without spending too much time analyzing the logic of the code. problem.
  • the present invention also provides another embodiment, that is, providing a computer-readable storage medium storing the method call chain tracking program 10, which can be processed by at least one The processor executes to cause the at least one processor to execute the method call chain tracking method as described above.
  • the methods in the above embodiments can be implemented by means of software plus a necessary universal hardware platform, and of course, also by hardware, but in many cases the former is better.
  • Implementation Based on such an understanding, the technical solution of the present invention, in essence, or a part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, The optical disc) includes several instructions for causing a client (which may be a mobile phone, a computer, an electronic device, an air conditioner, or a network device, etc.) to execute the methods described in the embodiments of the present invention.
  • a client which may be a mobile phone, a computer, an electronic device, an air conditioner, or a network device, etc.

Abstract

一种方法调用链跟踪方法,电子装置及计算机可读存储介质,该方法包括:设置当前应用是否进行方法调用链跟踪的配置项(S10);在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息(S20);当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息(S30)。上述调用链跟踪方法、电子装置及计算机可读存储介质能够通过设置配置项和引入Spring-AOP框架,在不重构代码的前提下,实现方法调用链的跟踪。

Description

方法调用链跟踪方法、电子装置及计算机可读存储介质 技术领域
本发明涉及方法调用技术领域,尤其涉及一种方法调用链跟踪方法、电子装置及计算机可读存储介质。
背景技术
方法(又称作函数)是指实现某些特定功能的代码块。软件实现过程中,一个功能的实现总是由一个或者多个方法来完成的。例如,用户要登录一个网站,需要有用户校验、密码校验、首页各个模块内容加载等多个方法来一起实现。其中有些方法可能被多个地方使用,如密码的格式校验方法可以在支付密码、登录密码设置的时候被调用。由于一个方法可能被多处调用,调用的入口不一样,实现的功能及处理流程就可能不一样。在方法的调用实现过程中,需要执行异常处理(如异常捕获输出日志),如果没有整个调用链的日志输出,就很难判断是哪个业务流程或业务分支产生的错误。
当前实现方法调用链的方式主要为:在方法实现开始时记录调用关系,流程处理完输出调用链日志。但是,由于要在每个方法增加调用方法的记录,就需要方法实现某个接口,或者是方法上增加调用链记录的相关方法。针对已经开发完的代码,如果要增加这个功能就相当于要重构一遍代码,维护成本高。
发明内容
有鉴于此,本发明提出一种方法调用链跟踪方法、电子装置及计算机可读存储介质,以解决至少一个上述技术问题。
首先,为实现上述目的,本发明提出一种方法调用链跟踪方法,该方法 包括:
设置当前应用是否进行方法调用链跟踪的配置项;
在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息;及
当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息。
可选地,所述配置项中通过printMethodCallChain参数控制是否需要输出所述调用链信息,当所述参数值为true时,表示需要输出所述调用链信息;当所述参数值为false时,表示不需要输出所述调用链信息。
可选地,所述在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息包括:
当接收到所述方法的调用请求时,根据所述配置项判断是否需要输出所述调用链信息;
当判断出需要输出所述调用链信息时,缓存所述方法调用请求的请求ID;
在执行所述方法的调用请求之前进行拦截,判断是否缓存有所述请求ID,以确定是否需要输出所述调用链信息。
可选地,所述当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息包括:
当判断出缓存有所述请求ID时,记录所述方法的调用链信息,然后执行所述方法的调用请求;
处理完所述方法的调用请求后,判断是否缓存有所述请求ID;
当判断出缓存有所述请求ID时,输出所记录的所述调用链信息。
可选地,所述方法还包括:
在输出所记录的所述调用链信息后,移除缓存中的所述请求ID。
可选地,通过Spring-AOP框架的切片拦截对所述方法进行拦截。
此外,为实现上述目的,本发明还提供一种电子装置,包括存储器、处理器,所述存储器上存储有可在所述处理器上运行的方法调用链跟踪程序,所述方法调用链跟踪程序被所述处理器执行时实现如下方法:
设置当前应用是否进行方法调用链跟踪的配置项;
在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息;及
当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息。
可选地,所述配置项中通过printMethodCallChain参数控制是否需要输出所述调用链信息,当所述参数值为true时,表示需要输出所述调用链信息;当所述参数值为false时,表示不需要输出所述调用链信息。
可选地,所述在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息包括:
当接收到所述方法的调用请求时,根据所述配置项判断是否需要输出所述调用链信息;
当判断出需要输出所述调用链信息时,缓存所述方法调用请求的请求ID;
在执行所述方法的调用请求之前进行拦截,判断是否缓存有所述请求ID,以确定是否需要输出所述调用链信息。
可选地,所述当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息包括:
当判断出缓存有所述请求ID时,记录所述方法的调用链信息,然后执行所述方法的调用请求;
处理完所述方法的调用请求后,判断是否缓存有所述请求ID;
当判断出缓存有所述请求ID时,输出所记录的所述调用链信息。
可选地,所述方法调用链跟踪程序被所述处理器执行时还实现:
在输出所记录的所述调用链信息后,移除缓存中的所述请求ID。
可选地,通过Spring-AOP框架的切片拦截对所述方法进行拦截。
进一步地,为实现上述目的,本发明还提供一种计算机可读存储介质,所述计算机可读存储介质存储有方法调用链跟踪程序,所述方法调用链跟踪程序可被至少一个处理器执行,以使所述至少一个处理器执行如上述的方法调用链跟踪方法。
相较于现有技术,本发明所提出的方法调用链跟踪方法、电子装置及计算机可读存储介质,可以通过设置配置项和引入Spring-AOP框架,在不重构代码的前提下,实现方法调用链的跟踪。在请求的处理逻辑复杂多分支的时候,可以根据调用链信息快速的定位业务逻辑,在请求处理异常的时候,可以帮助快速定位问题。
附图说明
图1是本发明第一实施例提出的一种电子装置的架构示意图;
图2是本发明第二实施例提出的一种方法调用链跟踪方法的流程示意图;
图3是本发明第三实施例提出的一种方法调用链跟踪方法的流程示意图。
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都 属于本发明保护的范围。
需要说明的是,在本发明中涉及“第一”、“第二”等的描述仅用于描述目的,而不能理解为指示或暗示其相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。另外,各个实施例之间的技术方案可以相互结合,但是必须是以本领域普通技术人员能够实现为基础,当技术方案的结合出现相互矛盾或无法实现时应当认为这种技术方案的结合不存在,也不在本发明要求的保护范围之内。
第一实施例
参阅图1所示,本发明第一实施例提出一种实现方法调用链跟踪方法的电子装置1。
在本实施例中,所述电子装置1可以是服务器、智能手机、平板电脑、个人电脑、便携计算机以及其它具有运算功能的电子设备。
所述电子装置1包括:存储器11、处理器13、网络接口15及通信总线17。其中,网络接口15可选地可以包括标准的有线接口、无线接口(如WI-FI接口)。通信总线17用于实现这些组件之间的连接通信。
存储器11至少包括一种类型的可读存储介质。所述至少一种类型的可读存储介质可为如闪存、硬盘、多媒体卡、卡型存储器等的非易失性存储介质。在一些实施例中,所述存储器11可以是所述电子装置1的内部存储单元,例如该电子装置1的硬盘。在另一些实施例中,所述存储器11也可以是所述电子装置1的外部存储单元,例如所述电子装置1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。
所述存储器11可以用于存储安装于所述电子装置1的应用软件及各类数据,例如方法调用链跟踪程序10的程序代码及其运行过程中产生的相关数据。
处理器13在一些实施例中可以是一中央处理器,微处理器或其它数据处理芯片,用于运行存储器11中存储的程序代码或处理数据。
图1仅示出了具有组件11-17以及方法调用链跟踪程序10的电子装置1,但是应理解的是,图1并未示出电子装置1的所有组件,可以替代实施更多或者更少的组件。
在图1所示的电子装置1实施例中,作为一种计算机存储介质的存储器11中存储方法调用链跟踪程序10的程序代码,处理器13执行所述方法调用链跟踪程序10的程序代码时,实现如下方法:
(1)设置当前应用是否进行方法调用链跟踪的配置项。
(2)在方法调用前进行拦截,根据所述配置项判断是否需要输出该方法的调用链信息。
(3)当需要输出调用链信息时,在执行方法调用请求前记录该方法的调用链信息,在完成方法调用请求后输出所记录的调用链信息。
上述方法的详细说明请参阅下述第二实施例至第三实施例,在此不再赘述。
第二实施例
参阅图2所示,本发明第二实施例提出一种方法调用链跟踪方法。在本实施例中,根据不同的需求,图2所示的流程图中的步骤的执行顺序可以改变,某些步骤可以省略。该方法包括以下步骤:
步骤S10,设置当前应用是否进行方法调用链跟踪的配置项。
所述配置项用于自定义的控制是否进行方法调用链跟踪,即是否需要输出(打印)方法调用链信息。通过在所述配置项中设置printMethodCallChain参数,可以控制不同应用是否需要开启调用链信息打印。当该参数值为true时,表示该配置项为打开状态,需要打印方法调用链信息;当该参数值为false时,表示该配置项为关闭状态,不需要打印方法调用链信息。一旦该配置项为打 开状态,则在接收到相应请求时会标记该请求需要打印调用链信息,每个方法调用之前就会记录相应的方法调用链信息。
步骤S20,在方法调用前进行拦截,根据所述配置项判断是否需要输出该方法的调用链信息。
引入Spring-AOP(面向切面编程)框架,在配置文件中配置需要拦截的方法、类、包。通过Spring-AOP的切片拦截,可以针对需要拦截的代码块方法设置拦截,判断当前请求是否需要打印调用链信息。通过Spring-AOP进行拦截的方式,不需要修改原来已经开发完成的代码块,在不重构代码的前提下,实现方法调用链的跟踪。
步骤S30,当需要输出调用链信息时,在执行方法调用请求前记录该方法的调用链信息,在完成方法调用请求后输出所记录的调用链信息。
具体地,在对该方法进行拦截后,如果判断出需要打印调用链信息,则在执行方法调用请求前记录当前要调用的方法的调用链信息,然后执行该方法调用请求,并在完成该方法调用请求后输出所记录的调用链信息。如果判断出不需要打印调用链信息,则跳过,继续执行原来拦截的方法。
关于步骤S20和S30的具体介绍,请参图3中相关步骤及下述第三实施例。
第三实施例
参阅图3所示,本发明第三实施例提出一种方法调用链跟踪方法。在本实施例中,根据不同的需求,图3所示的流程图中的步骤的执行顺序可以改变,某些步骤可以省略。该方法包括以下步骤:
步骤S100,设置当前应用是否进行方法调用链跟踪的配置项。
所述配置项用于自定义的控制是否进行方法调用链跟踪,即是否需要输出(打印)方法调用链信息。通过在所述配置项中设置printMethodCallChain参数,可以控制不同应用是否需要开启调用链信息打印。当该参数值为true时,表示该配置项为打开状态,需要打印方法调用链信息;当该参数值为false时, 表示该配置项为关闭状态,不需要打印方法调用链信息。一旦该配置项为打开状态,则在接收到相应请求时会标记该请求需要打印调用链信息,每个方法调用之前就会记录相应的方法调用链信息。
步骤S200,当接收到方法调用请求时,根据所述配置项判断是否需要输出调用链信息。当需要时,执行步骤S300。当不需要时,执行步骤S400。
当前应用接收到方法调用请求时,根据所述配置项的参数值判断是否需要输出调用链信息。也就是说,当所述配置项的printMethodCallChain参数值为true时,判断需要输出方法调用链信息;当该参数值为false时,判断不需要输出方法调用链信息。
步骤S300,缓存所述方法调用请求的请求ID。然后执行步骤S400。
当根据该配置项判断出需要输出方法调用链信息时,在内存中缓存该方法调用请求的请求ID,用于后面方法调用执行的时候记录调用链信息。
步骤S400,在执行方法调用之前进行拦截,判断是否缓存有请求ID。若是,则执行步骤S500。若否,则执行步骤S600。
在当前应用中引入Spring-AOP框架,在配置文件中配置需要拦截的方法、类、包。通过Spring-AOP的切片拦截,可以针对需要拦截的代码块方法设置拦截,通过判断内存中是否缓存有该请求ID确定是否需要输出该方法的调用链信息。
步骤S500,记录当前要调用的方法的调用链信息。然后执行步骤S600。
当判断出缓存有该请求ID时,表示需要输出该方法的调用链信息,在执行该方法调用请求前记录当前要调用的方法的调用链信息,然后执行该方法调用请求。在本实施例中,是将对应的方法名记录到缓存的请求ID对应的队列中。
步骤S600,执行该方法调用请求。
当判断出缓存没有该请求ID,或者已记录该方法的调用链信息后,继续执行被拦截的该方法调用请求。
步骤S700,处理完该方法调用请求后,判断是否缓存有该请求ID。若是,则执行步骤S800。若否,则流程结束。
在该方法调用请求处理完成后,通过是否缓存有该请求ID确定是否需要输出该方法的调用链信息。如果缓存中存在该请求ID,则需要输出该方法的调用链信息,否则不需要输出。调用链信息且移除缓存中的请求ID。
步骤S800,输出所记录的调用链信息且移除缓存中的该请求ID。
具体地,当判断出需要输出该方法的调用链信息时,将该请求ID对应的队列中的数据依次打印出来,输出的整个队列数据就是该方法的调用顺序(调用链)。同时,还需要移除缓存中的该请求ID。
本实施例提供的方法调用链跟踪方法,可以通过设置配置项和引入Spring-AOP框架,在不重构代码的前提下,实现方法调用链的跟踪。在请求的处理逻辑复杂多分支的时候,可以根据调用链信息快速的定位业务逻辑,在请求处理异常的时候,可以帮助快速定位问题,不至于花费太多时间分析代码逻辑,可能还无法定位出问题。
第四实施例
本发明还提供了另一种实施方式,即提供一种计算机可读存储介质,所述计算机可读存储介质存储有方法调用链跟踪程序10,所述方法调用链跟踪程序10可被至少一个处理器执行,以使所述至少一个处理器执行如上述的方法调用链跟踪方法。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘) 中,包括若干指令用以使得一台客户端(可以是手机,计算机,电子装置,空调器,或者网络设备等)执行本发明各个实施例所述的方法。
以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。

Claims (13)

  1. 一种方法调用链跟踪方法,其特征在于,所述方法包括:
    设置当前应用是否进行方法调用链跟踪的配置项;
    在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息;及
    当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息。
  2. 如权利要求1所述的方法调用链跟踪方法,其特征在于,所述配置项中通过printMethodCallChain参数控制是否需要输出所述调用链信息,当所述参数值为true时,表示需要输出所述调用链信息;当所述参数值为false时,表示不需要输出所述调用链信息。
  3. 如权利要求1或2所述的方法调用链跟踪方法,其特征在于,所述在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息包括:
    当接收到所述方法的调用请求时,根据所述配置项判断是否需要输出所述调用链信息;
    当判断出需要输出所述调用链信息时,缓存所述方法调用请求的请求ID;
    在执行所述方法的调用请求之前进行拦截,判断是否缓存有所述请求ID,以确定是否需要输出所述调用链信息。
  4. 如权利要求3所述的方法调用链跟踪方法,其特征在于,所述当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法 的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息包括:
    当判断出缓存有所述请求ID时,记录所述方法的调用链信息,然后执行所述方法的调用请求;
    处理完所述方法的调用请求后,判断是否缓存有所述请求ID;
    当判断出缓存有所述请求ID时,输出所记录的所述调用链信息。
  5. 如权利要求4所述的方法调用链跟踪方法,其特征在于,所述方法还包括:
    在输出所记录的所述调用链信息后,移除缓存中的所述请求ID。
  6. 如权利要求1所述的方法调用链跟踪方法,其特征在于,通过Spring-AOP框架的切片拦截对所述方法进行拦截。
  7. 一种电子装置,其特征在于,所述电子装置包括存储器、处理器,所述存储器上存储有可在所述处理器上运行的方法调用链跟踪程序,所述方法调用链跟踪程序被所述处理器执行时实现如下方法:
    设置当前应用是否进行方法调用链跟踪的配置项;
    在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息;及
    当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息。
  8. 如权利要求7所述的电子装置,其特征在于,所述配置项中通过printMethodCallChain参数控制是否需要输出所述调用链信息,当所述参数值为true时,表示需要输出所述调用链信息;当所述参数值为false时,表示不 需要输出所述调用链信息。
  9. 如权利要求7或8所述的电子装置,其特征在于,所述在方法调用前进行拦截,根据所述配置项判断是否需要输出所述方法的调用链信息包括:
    当接收到所述方法的调用请求时,根据所述配置项判断是否需要输出所述调用链信息;
    当判断出需要输出所述调用链信息时,缓存所述方法调用请求的请求ID;
    在执行所述方法的调用请求之前进行拦截,判断是否缓存有所述请求ID,以确定是否需要输出所述调用链信息。
  10. 如权利要求9所述的电子装置,其特征在于,所述当判断出需要输出所述调用链信息时,在执行所述方法的调用请求前记录所述方法的调用链信息,在完成所述方法的调用请求后输出所记录的调用链信息包括:
    当判断出缓存有所述请求ID时,记录所述方法的调用链信息,然后执行所述方法的调用请求;
    处理完所述方法的调用请求后,判断是否缓存有所述请求ID;
    当判断出缓存有所述请求ID时,输出所记录的所述调用链信息。
  11. 如权利要求10所述的电子装置,其特征在于,所述方法调用链跟踪程序被所述处理器执行时还实现:
    在输出所记录的所述调用链信息后,移除缓存中的所述请求ID。
  12. 如权利要求7所述的电子装置,其特征在于,通过Spring-AOP框架的切片拦截对所述方法进行拦截。
  13. 一种计算机可读存储介质,所述计算机可读存储介质存储有方法调用 链跟踪程序,所述方法调用链跟踪程序可被至少一个处理器执行,以使所述至少一个处理器执行如权利要求1-6中任一项所述的方法调用链跟踪方法。
PCT/CN2018/101752 2018-07-30 2018-08-22 方法调用链跟踪方法、电子装置及计算机可读存储介质 WO2020024343A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP18928865.7A EP3828696A4 (en) 2018-07-30 2018-08-22 PROCESS CALL CHAIN TRACING, ELECTRONIC DEVICE AND COMPUTER READABLE RECORDING MEDIA
US16/981,267 US11099889B2 (en) 2018-07-30 2018-08-22 Method-call-chain tracking method, electronic device, and computer readable storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810854255.2 2018-07-30
CN201810854255.2A CN110780883A (zh) 2018-07-30 2018-07-30 方法调用链跟踪方法、电子装置及计算机可读存储介质

Publications (1)

Publication Number Publication Date
WO2020024343A1 true WO2020024343A1 (zh) 2020-02-06

Family

ID=69231044

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/101752 WO2020024343A1 (zh) 2018-07-30 2018-08-22 方法调用链跟踪方法、电子装置及计算机可读存储介质

Country Status (4)

Country Link
US (1) US11099889B2 (zh)
EP (1) EP3828696A4 (zh)
CN (1) CN110780883A (zh)
WO (1) WO2020024343A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10542072B1 (en) * 2017-10-04 2020-01-21 Parallels International Gmbh Utilities toolbox for remote session and client architecture
CN112328451B (zh) * 2020-11-05 2023-03-17 浪潮云信息技术股份公司 一种基于场景的服务监控方法
CN112558947B (zh) * 2020-12-18 2024-04-05 京东科技控股股份有限公司 程序调用追踪方法、装置以及存储介质
CN112667511A (zh) * 2020-12-30 2021-04-16 广州凡科互联网科技股份有限公司 一种通过插入代码来追踪java程序内部调用链的方法
CN113064790B (zh) * 2021-03-15 2023-08-11 上海浦东发展银行股份有限公司 基于配置中心的调用链数据采集系统、方法及存储介质
CN113419775B (zh) * 2021-05-31 2022-11-04 济南浪潮数据技术有限公司 一种固件配置方法、系统、设备以及介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150309915A1 (en) * 2014-04-23 2015-10-29 Microsoft Corporation Call chain interval resource impact aggregation differencing
CN106357463A (zh) * 2016-11-07 2017-01-25 深圳盛灿科技股份有限公司 非入侵式的访问链路跟踪实现方法及其系统
CN106502874A (zh) * 2016-10-26 2017-03-15 南京途牛科技有限公司 一种调用链跟踪方法
CN107870762A (zh) * 2016-09-28 2018-04-03 北京京东尚科信息技术有限公司 Soa调用链路跟踪的方法、装置及系统
CN108173915A (zh) * 2017-12-21 2018-06-15 中国联合网络通信集团有限公司 调用链处理方法及装置

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8271996B1 (en) * 2008-09-29 2012-09-18 Emc Corporation Event queues
JP5679740B2 (ja) * 2010-08-26 2015-03-04 キヤノン株式会社 周辺装置制御システム、周辺装置、情報処理装置及び制御方法
US9658941B2 (en) * 2013-01-28 2017-05-23 Rackspace Us, Inc. Methods and systems of function-specific tracing
US9417988B2 (en) * 2013-02-26 2016-08-16 Red Hat, Inc. Tracking subclasses of and operations performed by generic objects in a computer system
CN104731650A (zh) * 2013-12-18 2015-06-24 青岛海尔空调器有限总公司 系统接口调用信息的获取方法和装置
US10289614B2 (en) * 2015-02-11 2019-05-14 Centurylink Intellectual Property Llc Database code-module performance and reliability metrics instrumentation
US9846633B2 (en) * 2015-10-06 2017-12-19 Ca, Inc. Generating tests for testing software applications
CN108196833B (zh) * 2018-01-09 2021-02-02 武汉斗鱼网络科技有限公司 Aop代理框架的实现方法、存储介质、电子设备及系统

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20150309915A1 (en) * 2014-04-23 2015-10-29 Microsoft Corporation Call chain interval resource impact aggregation differencing
CN107870762A (zh) * 2016-09-28 2018-04-03 北京京东尚科信息技术有限公司 Soa调用链路跟踪的方法、装置及系统
CN106502874A (zh) * 2016-10-26 2017-03-15 南京途牛科技有限公司 一种调用链跟踪方法
CN106357463A (zh) * 2016-11-07 2017-01-25 深圳盛灿科技股份有限公司 非入侵式的访问链路跟踪实现方法及其系统
CN108173915A (zh) * 2017-12-21 2018-06-15 中国联合网络通信集团有限公司 调用链处理方法及装置

Also Published As

Publication number Publication date
US11099889B2 (en) 2021-08-24
EP3828696A1 (en) 2021-06-02
CN110780883A (zh) 2020-02-11
EP3828696A4 (en) 2021-09-22
US20210042150A1 (en) 2021-02-11

Similar Documents

Publication Publication Date Title
WO2020024343A1 (zh) 方法调用链跟踪方法、电子装置及计算机可读存储介质
JP6783923B2 (ja) サービス操作リスクを管理するための方法及びデバイス
CN108346028B (zh) 一种业务审批处理方法、装置及系统
WO2014139300A1 (en) Method and device for loading a plug-in
WO2020108152A1 (zh) 身份数据的防误用方法及装置、电子设备
WO2020082829A1 (zh) 一种用户年龄预测方法、装置及设备
CN108600259B (zh) 设备的认证和绑定方法及计算机存储介质、服务器
WO2020000727A1 (zh) 服务器、业务数据校验的方法及存储介质
US20180174150A1 (en) Systems and methods for processing a payment transaction authorization request
CN112433935A (zh) 测试方法、装置、电子设备及存储介质
CN112433936A (zh) 测试方法、装置及存储介质
CN112600803B (zh) Web端数据签名方法、装置及计算机设备
CN111865726B (zh) 业务消息测试方法、装置、计算机系统和存储介质
CN114637672A (zh) 自动化数据测试方法、装置、计算机设备及存储介质
WO2020215905A1 (zh) 数据投放方法、装置、设备及计算机可读存储介质
CN114090689A (zh) 基于联盟链的智能合约数据处理方法、及其相关设备
CN111767544A (zh) 多频重放攻击漏洞确定方法、装置、设备及可读存储介质
CN112749073B (zh) 业务测试方法、装置、存储介质及电子设备
CN114327836A (zh) 智能合约处理方法、装置、设备及存储介质
CN113204946B (zh) 数据控制方法、装置、设备及存储介质
CN115242625B (zh) 服务部署方法、装置、计算机设备及可读存储介质
US11832343B1 (en) System, method, and computer program for protecting against unintentional deletion of an eSIM from a mobile device
CN109194734A (zh) 消息推送方法、装置、服务器及可读存储介质
US20210390594A1 (en) Electronic product and service fulfillment
CN115690822A (zh) 图纸的审核方法、装置、电子设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18928865

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2018928865

Country of ref document: EP

Effective date: 20210224