CN113238915B - Processing method, device, device, storage medium and program for calling information - Google Patents
Processing method, device, device, storage medium and program for calling information Download PDFInfo
- Publication number
- CN113238915B CN113238915B CN202110527239.4A CN202110527239A CN113238915B CN 113238915 B CN113238915 B CN 113238915B CN 202110527239 A CN202110527239 A CN 202110527239A CN 113238915 B CN113238915 B CN 113238915B
- Authority
- CN
- China
- Prior art keywords
- thread
- call
- calling
- information
- node
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3006—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is distributed, e.g. networked systems, clusters, multiprocessor systems
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/302—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3051—Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computing Systems (AREA)
- Physics & Mathematics (AREA)
- Quality & Reliability (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Debugging And Monitoring (AREA)
Abstract
本公开提供了一种调用信息的处理方法、装置、设备、存储介质及程序,涉及计算机技术中的调用链技术领域。具体实现方案为:在确定第一线程待调用第二线程执行第一对象时,生成第一对象对应的辅助对象,第一对象和辅助对象的生命周期相同,辅助对象中包括第一调用信息,第一调用信息包括第一对象的标识以及第一线程中调用第二线程的第一调用节点的标识,将第一对象和辅助对象传递至所述第二线程,在确定第二线程待执行第一对象时,根据辅助对象中的第一调用信息生成目标调用信息,以及通过第二线程执行第一对象。上述过程中,一方面提高了开发效率,另一方面保证了业务系统的安全性。
The present disclosure provides a method, device, device, storage medium and program for processing invocation information, and relates to the technical field of invocation chains in computer technology. The specific implementation scheme is: when it is determined that the first thread is to call the second thread to execute the first object, an auxiliary object corresponding to the first object is generated, the life cycle of the first object and the auxiliary object are the same, and the auxiliary object includes the first invocation information, The first call information includes the identifier of the first object and the identifier of the first call node in the first thread that calls the second thread, and the first object and the auxiliary object are delivered to the second thread. When there is an object, the target call information is generated according to the first call information in the auxiliary object, and the first object is executed through the second thread. In the above process, on the one hand, the development efficiency is improved, and on the other hand, the security of the business system is guaranteed.
Description
技术领域technical field
本公开涉及计算机技术中的调用链技术领域,尤其涉及一种调用信息的处理方法、装置、设备、存储介质及程序。The present disclosure relates to the technical field of call chains in computer technology, and in particular, to a method, apparatus, device, storage medium and program for processing call information.
背景技术Background technique
目前,很多业务系统采用分布式系统。分布式系统中可以部署多个应用,每个应用内部可以部署多个线程。在分布式系统中,一个业务请求的处理过程中可能会涉及较多的跨线程调用。At present, many business systems use distributed systems. Multiple applications can be deployed in a distributed system, and multiple threads can be deployed within each application. In a distributed system, many cross-thread calls may be involved in the processing of a service request.
一些场景中,可以采用链路追踪技术来对业务请求在业务系统中的处理过程进行追踪记录,以便根据追踪到的调用链路信息进行问题排查,或者,对业务系统性能进行分析等。相关技术中,需要开发人员在业务系统中显式添加监控代码的方式来实现链路追踪。具体的,在业务系统需要进行跨线程调用的位置添加监控代码,使得业务系统在进行跨线程调用之前,可以通过监控代码通知链路追踪系统,以便链路追踪系统对跨线程调用信息进行记录。In some scenarios, the link tracking technology can be used to track and record the processing process of the business request in the business system, so as to perform troubleshooting based on the tracked call link information, or analyze the performance of the business system. In the related art, developers need to explicitly add monitoring code to the business system to implement link tracking. Specifically, monitoring code is added where the business system needs to make cross-thread calls, so that the business system can notify the link tracking system through the monitoring code before making cross-thread calls, so that the link tracking system records the cross-thread call information.
然而,上述方式需要对业务系统的代码进行修改,一方面会使得开发效率较低,另一方面对业务系统具有侵入性,使得业务系统的安全性无法保证。However, the above method needs to modify the code of the business system. On the one hand, the development efficiency is low, and on the other hand, it is intrusive to the business system, so that the security of the business system cannot be guaranteed.
发明内容SUMMARY OF THE INVENTION
本公开提供了一种调用信息的处理方法、装置、设备、存储介质及程序。The present disclosure provides a method, apparatus, device, storage medium and program for processing call information.
根据本公开的第一方面,提供了一种调用信息的处理方法,包括:According to a first aspect of the present disclosure, a method for processing call information is provided, including:
在确定第一线程待调用第二线程执行第一对象时,生成所述第一对象对应的辅助对象,所述第一对象和所述辅助对象的生命周期相同,所述辅助对象中包括第一调用信息,所述第一调用信息包括:所述第一对象的标识以及所述第一线程中调用所述第二线程的第一调用节点的标识;When it is determined that the first thread is to call the second thread to execute the first object, an auxiliary object corresponding to the first object is generated, the life cycle of the first object and the auxiliary object are the same, and the auxiliary object includes the first object. call information, the first call information includes: the identifier of the first object and the identifier of the first calling node in the first thread that calls the second thread;
将所述第一对象和所述辅助对象传递至所述第二线程;passing the first object and the helper object to the second thread;
在确定所述第二线程待执行所述第一对象时,根据所述辅助对象中的所述第一调用信息生成目标调用信息,以及通过所述第二线程执行所述第一对象,所述目标调用信息包括:所述第一对象的标识、跨线程调用指示、所述第一调用节点的标识、所述第一对象在所述第二线程中的父调用节点的标识。When it is determined that the first object is to be executed by the second thread, target invocation information is generated according to the first invocation information in the auxiliary object, and the first object is executed by the second thread, the The target invocation information includes: an identifier of the first object, a cross-thread invocation indication, an identifier of the first invocation node, and an identifier of a parent invocation node of the first object in the second thread.
根据本公开的第二方面,提供了一种调用信息的处理装置,包括:According to a second aspect of the present disclosure, there is provided a processing apparatus for calling information, including:
第一处理模块,用于在确定第一线程待调用第二线程执行第一对象时,生成所述第一对象对应的辅助对象,所述第一对象和所述辅助对象的生命周期相同,所述辅助对象中包括第一调用信息,所述第一调用信息包括:所述第一对象的标识以及所述第一线程中调用所述第二线程的第一调用节点的标识;The first processing module is configured to generate an auxiliary object corresponding to the first object when it is determined that the first thread is to call the second thread to execute the first object, and the life cycle of the first object and the auxiliary object is the same, so The auxiliary object includes first call information, and the first call information includes: an identifier of the first object and an identifier of a first call node in the first thread that calls the second thread;
传递模块,用于将所述第一对象和所述辅助对象传递至所述第二线程;a delivery module, configured to deliver the first object and the auxiliary object to the second thread;
第二处理模块,用于在确定所述第二线程待执行所述第一对象时,根据所述辅助对象中的所述第一调用信息生成目标调用信息,以及通过所述第二线程执行所述第一对象,所述目标调用信息包括:所述第一对象的标识、跨线程调用指示、所述第一调用节点的标识、所述第一对象在所述第二线程中的父调用节点的标识。A second processing module, configured to generate target call information according to the first call information in the auxiliary object when it is determined that the first object is to be executed by the second thread, and execute the second thread through the second thread. The first object, the target call information includes: the identifier of the first object, the cross-thread call indication, the identifier of the first call node, the parent call node of the first object in the second thread 's identification.
根据本公开的第三方面,提供了一种电子设备,包括:According to a third aspect of the present disclosure, there is provided an electronic device, comprising:
至少一个处理器;以及at least one processor; and
与所述至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,
所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够执行第一方面所述的方法。The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method of the first aspect.
根据本公开的第四方面,提供了一种存储有计算机指令的非瞬时计算机可读存储介质,其中,所述计算机指令用于使所述计算机执行第一方面所述的方法。According to a fourth aspect of the present disclosure, there is provided a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to perform the method of the first aspect.
根据本公开的第五方面,提供了一种计算机程序产品,所述计算机程序产品包括:计算机程序,所述计算机程序存储在可读存储介质中,电子设备的至少一个处理器可以从所述可读存储介质读取所述计算机程序,所述至少一个处理器执行所述计算机程序使得电子设备执行第一方面所述的方法。According to a fifth aspect of the present disclosure, there is provided a computer program product, the computer program product comprising: a computer program stored in a readable storage medium, from which at least one processor of an electronic device can Reading the storage medium reads the computer program, and executing the computer program by the at least one processor causes the electronic device to perform the method of the first aspect.
应当理解,本部分所描述的内容并非旨在标识本公开的实施例的关键或重要特征,也不用于限制本公开的范围。本公开的其它特征将通过以下的说明书而变得容易理解。It should be understood that what is described in this section is not intended to identify key or critical features of embodiments of the disclosure, nor is it intended to limit the scope of the disclosure. Other features of the present disclosure will become readily understood from the following description.
附图说明Description of drawings
附图用于更好地理解本方案,不构成对本公开的限定。其中:The accompanying drawings are used for better understanding of the present solution, and do not constitute a limitation to the present disclosure. in:
图1A为一种分布式业务系统中的调用过程的示意图;1A is a schematic diagram of a calling process in a distributed business system;
图1B为一个应用中的各线程的调用栈的示意图;1B is a schematic diagram of the call stack of each thread in an application;
图2为本公开实施例提供的一种调用信息的处理方法的流程示意图;2 is a schematic flowchart of a method for processing call information provided by an embodiment of the present disclosure;
图3为本公开实施例提供的另一种调用信息的处理方法的流程示意图;3 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure;
图4为本公开实施例提供的又一种调用信息的处理方法的流程示意图;4 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure;
图5为本公开实施例提供的又一种调用信息的处理方法的流程示意图;FIG. 5 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure;
图6为本公开实施例提供的又一种调用信息的处理方法的流程示意图;6 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure;
图7为本公开实施例提供的一种跨线程调用场景的示意图;7 is a schematic diagram of a cross-thread calling scenario provided by an embodiment of the present disclosure;
图8为本公开实施例提供的另一种跨线程调用场景的示意图;8 is a schematic diagram of another cross-thread calling scenario provided by an embodiment of the present disclosure;
图9为本公开实施例提供的又一种跨线程调用场景的示意图;9 is a schematic diagram of yet another cross-thread calling scenario provided by an embodiment of the present disclosure;
图10为本公开实施例提供的一种调用信息的处理装置的结构示意图;FIG. 10 is a schematic structural diagram of an apparatus for processing call information according to an embodiment of the present disclosure;
图11为本公开实施例提供的一种电子设备的结构示意图。FIG. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
具体实施方式Detailed ways
以下结合附图对本公开的示范性实施例做出说明,其中包括本公开实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本公开的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.
随着互联网业务的发展,很多业务系统采用分布式系统架构。图1A为一种分布式业务系统中的调用过程的示意图。分布式业务系统中可以部署有多个应用。不同的应用提供的服务或者负责的职责不同,数据处理能力也不同。With the development of Internet business, many business systems adopt distributed system architecture. FIG. 1A is a schematic diagram of a calling process in a distributed service system. Multiple applications can be deployed in a distributed business system. Different applications provide different services or responsibilities, and have different data processing capabilities.
参见图1A,示例性的,假设分布式业务系统中部署有3个应用,分别为应用A、应用B和应用C。一个业务请求在分布式业务系统内部的处理过程可能如下:在应用A中调用应用B,在应用B中调用应用C。Referring to FIG. 1A, exemplarily, it is assumed that three applications are deployed in the distributed service system, namely application A, application B, and application C. The processing process of a service request in the distributed service system may be as follows: Application B is called in application A, and application C is called in application B.
其中,每个应用内部可以部署一个或者多个线程。这样,在分布式业务系统中,一个业务请求的处理过程可能会涉及较多的跨线程调用。继续参见图1A,示例性的,假设应用B中部署有线程1、线程2和线程3,业务请求的具体处理过程可能如下:服务A调用服务B中的线程1,在线程1的执行过程中,需要调用线程2,在线程2的执行过程中需要调用服务C。Among them, one or more threads can be deployed inside each application. In this way, in a distributed business system, the processing of a business request may involve more cross-thread calls. Continuing to refer to FIG. 1A , exemplarily, assuming that
图1A所示的调用过程中,针对应用B而言,应用B从应用A接收业务请求的线程是线程1,而应用B调用应用C的线程是线程3。可见,应用B的内部的多个线程之间存在跨线程调用的行为。In the calling process shown in FIG. 1A , for application B, the thread through which application B receives the service request from application A is
一些场景中,可以采用链路追踪技术来对业务请求在业务系统中的处理过程进行追踪记录,以便根据追踪到的调用链路信息进行问题排查,或者,对业务系统性能进行分析等。相关技术中,需要开发人员在业务系统中显式添加监控代码的方式来实现链路追踪。具体的,在业务系统需要进行跨线程调用的位置添加监控代码,使得业务系统在进行跨线程调用之前,可以通过监控代码通知链路追踪系统,以便链路追踪系统对跨线程调用信息进行记录。In some scenarios, the link tracking technology can be used to track and record the processing process of the business request in the business system, so as to perform troubleshooting based on the tracked call link information, or analyze the performance of the business system. In the related art, developers need to explicitly add monitoring code to the business system to implement link tracking. Specifically, monitoring code is added where the business system needs to make cross-thread calls, so that the business system can notify the link tracking system through the monitoring code before making cross-thread calls, so that the link tracking system records the cross-thread call information.
然而,上述方式需要对业务系统的代码进行修改,一方面会使得开发效率较低,另一方面对业务系统具有侵入性,使得业务系统的安全性无法保证。However, the above method needs to modify the code of the business system. On the one hand, the development efficiency is low, and on the other hand, it is intrusive to the business system, so that the security of the business system cannot be guaranteed.
为了解决上述技术问题中的至少一个,本公开提供一种调用信息的处理方法、装置、设备、存储介质及程序,应用于计算机技术中的调用链技术领域。In order to solve at least one of the above technical problems, the present disclosure provides a method, apparatus, device, storage medium and program for processing invocation information, which are applied to the technical field of invocation chains in computer technology.
本公开技术方案中,可以不用对业务系统的代码进行修改,而是可以在业务系统中集成探针程序,通过探针程序对业务系统的运行进行监控,当监控到第一线程待调用第二线程时,由探针程序对本次调用行为进行拦截,并将调用信息由第一线程传递到第二线程。上述过程中,由于无需对业务系统的代码进行修改,一方面提高了开发效率,另一方面保证了业务系统的安全性。另外,通过利用辅助对象来传递第一调用信息,使得不需要对第一对象进行修改,进一步保证了业务系统执行过程的安全性。In the technical solution of the present disclosure, instead of modifying the code of the business system, a probe program can be integrated in the business system, and the operation of the business system can be monitored through the probe program. Thread, the probe program intercepts the calling behavior, and transfers the calling information from the first thread to the second thread. In the above process, since there is no need to modify the code of the business system, the development efficiency is improved on the one hand, and the security of the business system is guaranteed on the other hand. In addition, by using the auxiliary object to transmit the first invocation information, the first object does not need to be modified, thereby further ensuring the security of the execution process of the business system.
为了便于理解,下面对本公开实施例中涉及的概念或者术语进行解释。For ease of understanding, concepts or terms involved in the embodiments of the present disclosure are explained below.
调用链路(Trace):一个分布式调用链为一条Trace,拥有一个唯一的traceId,本实施例讨论分布式系统中的单个应用内部的跨线程追踪问题,则Trace代表一个应用中的一次调用栈。Call chain (Trace): A distributed call chain is a trace with a unique traceId. This embodiment discusses the problem of cross-thread tracing within a single application in a distributed system, and Trace represents a call stack in an application .
Span:每次函数调用会产生一个Span,拥有一个唯一的SpanId。对于链路监控程序,可以不必在每个函数上都建立Span,仅对业务需要关注的重点函数上建立Span即可。Span: Each function call will generate a Span with a unique SpanId. For the link monitoring program, it is not necessary to establish a span on each function, but only on the key functions that need to be paid attention to by the business.
作用域(Scope):一个Scope包裹一个Span,同一个Span可以包裹于任意个Scope。一个Trace中包含若干个Scope,多个Scope之间通过parentScope字段链接到父级Scope形成链栈。栈顶的Scope所包含的Span代表当前线程所处的调用栈位置。在通常符合OpenTracing标准的链路监控系统中,Scope包含如下内容:(Span,parentScope)。其中Span为包裹的Span,parentScope为父级Scope。Scope: A Scope wraps a Span, and the same Span can be wrapped in any Scope. A Trace contains several Scopes, and multiple Scopes are linked to the parent Scope through the parentScope field to form a chain stack. The Span contained in the Scope at the top of the stack represents the position of the call stack where the current thread is located. In a link monitoring system that usually conforms to the OpenTracing standard, the Scope contains the following: (Span, parentScope). Where Span is the wrapped Span, and parentScope is the parent Scope.
调用栈:也可以称为Scope栈。一个应用内部包含若干个线程,每个线程内独立维护一个Scope栈,Scope栈中每个栈帧对应一个调用节点。每个调用节点具有Scope,Scope包裹一个Span,代表调用栈中的一个栈帧。图1B为一个应用中的各线程的调用栈的示意图。如图1B所示,在不考虑跨线程调用的场景下,各线程相互独立,每次新的函数被调用,可能创建一个新的调用节点,即创建一个新的Span以及包裹该Span的Scope,压栈入当前线程的Scope栈。所以,Scope栈所存储的Span序列,即为调用链在本应用内的调用栈。Call stack: It can also be called the Scope stack. An application contains several threads, each thread independently maintains a Scope stack, and each stack frame in the Scope stack corresponds to a call node. Each call node has a Scope, and the Scope wraps a Span, which represents a stack frame in the call stack. FIG. 1B is a schematic diagram of a call stack of each thread in an application. As shown in Figure 1B, without considering the scenario of cross-thread calling, each thread is independent of each other. Every time a new function is called, a new calling node may be created, that is, a new Span and a Scope that wraps the Span may be created. Push the stack into the Scope stack of the current thread. Therefore, the Span sequence stored in the Scope stack is the call stack of the call chain in this application.
下面结合几个具体的实施例对本公开的技术方案进行详细描述。下面几个实施例可以相互结合,对于相同或者相似的内容在某些实施例中可能不再重复描述。The technical solutions of the present disclosure will be described in detail below with reference to several specific embodiments. The following embodiments may be combined with each other, and the same or similar content may not be described repeatedly in some embodiments.
图2为本公开实施例提供的一种调用信息的处理方法的流程示意图。本实施例的方法可以由部署有分布式系统的各应用的电子设备执行。如图2所示,本实施例的方法包括:FIG. 2 is a schematic flowchart of a method for processing call information provided by an embodiment of the present disclosure. The method of this embodiment may be executed by an electronic device in which each application of the distributed system is deployed. As shown in Figure 2, the method of this embodiment includes:
S201:在确定第一线程待调用第二线程执行第一对象时,生成所述第一对象对应的辅助对象,所述第一对象和所述辅助对象的生命周期相同,所述辅助对象中包括第一调用信息,所述第一调用信息包括所述第一对象的标识以及所述第一线程中调用所述第二线程的第一调用节点的标识。S201: When it is determined that the first thread is to call the second thread to execute the first object, generate an auxiliary object corresponding to the first object, the first object and the auxiliary object have the same life cycle, and the auxiliary object includes First call information, where the first call information includes an identifier of the first object and an identifier of a first call node in the first thread that calls the second thread.
具体的,可以在分布式系统的应用中集成探针程序,在应用启动时,探针程序开始运行并对应用的运行过程进行监控。探针程序可以对应用中的跨线程调用行为进行监控。示例性的,探针程序可以监控到第一线程对第二线程的调用行为,并对该调用行为进行拦截。Specifically, a probe program can be integrated into the application of the distributed system, and when the application is started, the probe program starts to run and monitors the running process of the application. The probe program can monitor the behavior of cross-thread calls in the application. Exemplarily, the probe program can monitor the calling behavior of the first thread to the second thread, and intercept the calling behavior.
本实施例中,以第一线程调用第二线程执行第一对象的场景为例进行描述。其中,第一线程可以称为父线程,第二线程可以称为子线程。第一对象是指第一线程需要调用第二线程执行的任务对象。例如,第一对象可以为需要第二线程执行的代码片段。In this embodiment, a scenario in which the first thread calls the second thread to execute the first object is used as an example for description. The first thread may be referred to as a parent thread, and the second thread may be referred to as a child thread. The first object refers to a task object that the first thread needs to call the second thread to execute. For example, the first object may be a code fragment that needs to be executed by the second thread.
应理解的是,当业务系统采用的不同的编程语言时,第一对象可以为不同形式的对象。示例性的,在基于Java语言的业务系统中,第一对象可以runnable对象。runnable是将任务对象由父线程传递到子线程的一种机制。It should be understood that when the business system adopts different programming languages, the first object may be an object in different forms. Exemplarily, in a business system based on the Java language, the first object may be a runnable object. A runnable is a mechanism for passing task objects from a parent thread to a child thread.
一些示例中,可以将任务对象通过线程池传递到子线程。例如,父线程把需要执行的任务对象投递到线程池中,由线程池为任务对象分配一个子线程,从而实现将任务对象由父线程传递到子线程。这样,可以通过对线程池的executor.execute(runnable)的行为进行监控,当监控到线程池的executor.execute(runnable)行为时,说明拦截到跨线程调用行为。其中,executor.execute(runnable)为Java编程语言中用于向线程池中投递runnable对象的方法。In some examples, task objects can be passed to child threads through a thread pool. For example, the parent thread delivers the task object to be executed to the thread pool, and the thread pool assigns a child thread to the task object, thereby realizing the transfer of the task object from the parent thread to the child thread. In this way, the behavior of executor.execute(runnable) of the thread pool can be monitored. When the behavior of executor.execute(runnable) of the thread pool is monitored, it means that the behavior of cross-thread calling is intercepted. Among them, executor.execute(runnable) is a method in the Java programming language for delivering runnable objects to the thread pool.
另一些示例中,当父线程需要由子线程执行任务对象时,可以新建子线程,并将任务对象传递到新建的子线程。这样,可以通过对新建子线程new Thread(runnable)的行为进行监控,当监控到新建子线程new Thread(runnable)的行为时,说明拦截到跨线程调用行为。其中,new Thread(runnable)为Java编程语言中用于新建子线程的方法。In other examples, when the parent thread needs to execute the task object by the child thread, it can create a new child thread and pass the task object to the newly created child thread. In this way, the behavior of the newly created child thread new Thread(runnable) can be monitored. When the behavior of the newly created child thread new Thread(runnable) is monitored, it means that the cross-thread calling behavior is intercepted. Among them, new Thread(runnable) is a method for creating a new child thread in the Java programming language.
需要说明的是,上述示例中对跨线程调用行为的拦截方式是以Java语言为例进行示意的。针对不同的编程语言,采用的拦截方式可以不同,本实施例对此不作限定。应理解的是,无论何种编程语言,跨线程调用行为都是可以拦截到的。It should be noted that, in the above example, the interception method of the cross-thread calling behavior is illustrated by taking the Java language as an example. For different programming languages, different interception methods may be adopted, which are not limited in this embodiment. It should be understood that, regardless of the programming language, the behavior of cross-thread calls can be intercepted.
本实施例中,第一线程调用第二线程会在第一线程的调用栈中产生第一调用节点。为了描述方便,本实施例中将调用栈中每个调用节点的作用域(Scope)称为该调用节点的标识。第一调用信息可以包括第一对象的标识以及第一调用节点的标识。例如,第一调用节点的标识为第一调用节点的Scope,第一对象的标识可以为该Scope包裹的Span。In this embodiment, when the first thread calls the second thread, a first call node is generated in the call stack of the first thread. For the convenience of description, in this embodiment, the scope (Scope) of each call node in the call stack is referred to as the identifier of the call node. The first call information may include the identifier of the first object and the identifier of the first call node. For example, the identifier of the first calling node is the Scope of the first calling node, and the identifier of the first object may be the Span wrapped by the Scope.
本实施例中,在确定第一线程待调用第二线程执行第一对象(即拦截到跨线程调用行为)时,生成第一对象对应的辅助对象,辅助对象与第一对象的生命周期相同,并且,辅助对象中包括第一调用信息。In this embodiment, when it is determined that the first thread is to call the second thread to execute the first object (that is, the cross-thread calling behavior is intercepted), an auxiliary object corresponding to the first object is generated, and the auxiliary object has the same life cycle as the first object, And, the auxiliary object includes the first call information.
示例性的,以Java编程语言为例,辅助对象可以为伴生对象。例如,可以为第一对象创建伴生对象,该伴生对象的生命周期与第一对象的生命周期绑定,使得伴生对象与第一对象的生命周期相同。Illustratively, taking the Java programming language as an example, the auxiliary object may be a companion object. For example, a companion object may be created for the first object, and the life cycle of the companion object is bound to the life cycle of the first object, so that the companion object has the same life cycle as the first object.
S202:将所述第一对象和所述辅助对象传递至所述第二线程。S202: Transfer the first object and the auxiliary object to the second thread.
本实施例中,通过将第一调用信息携带在辅助对象中,使得在不对第一对象进行修改的情况下,可以通过辅助对象将第一调用信息由第一线程传递至第二线程。由于不需要对第一对象进行修改,保证了第一对象的安全性。In this embodiment, by carrying the first call information in the auxiliary object, the first call information can be transmitted from the first thread to the second thread through the auxiliary object without modifying the first object. Since the first object does not need to be modified, the security of the first object is guaranteed.
S203:在确定所述第二线程待执行所述第一对象时,根据所述辅助对象中的所述第一调用信息生成目标调用信息,以及通过所述第二线程执行所述第一对象,所述目标调用信息包括:所述第一对象的标识、跨线程调用指示、所述第一调用节点的标识、所述第一对象在所述第二线程中的父调用节点的标识。S203: when it is determined that the first object is to be executed by the second thread, generate target invocation information according to the first invocation information in the auxiliary object, and execute the first object through the second thread, The target call information includes: an identifier of the first object, a cross-thread call indication, an identifier of the first call node, and an identifier of a parent call node of the first object in the second thread.
本实施例中,由于辅助对象中携带了第一调用信息,辅助对象被传递到第二线程后,可以根据辅助对象中的第一调用信息生成目标调用信息。目标调用信息表征的是第一对象在第二线程中的相关信息。In this embodiment, since the auxiliary object carries the first invocation information, after the auxiliary object is passed to the second thread, the target invocation information can be generated according to the first invocation information in the auxiliary object. The target invocation information represents the related information of the first object in the second thread.
其中,目标调用信息包括:所述第一对象的标识、跨线程调用指示、所述第一调用节点的标识、所述第一对象在所述第二线程中的父调用节点的标识。跨线程调用指示用于指示第一对象是从其他线程通过跨线程调用传递到本线程的。The target invocation information includes: an identifier of the first object, a cross-thread invocation indication, an identifier of the first invocation node, and an identifier of a parent invocation node of the first object in the second thread. The cross-thread call indication is used to indicate that the first object is passed from another thread to this thread through a cross-thread call.
本实施例提供的调用信息的处理方法,包括:在确定第一线程待调用第二线程执行第一对象时,生成所述第一对象对应的辅助对象,所述第一对象和所述辅助对象的生命周期相同,所述辅助对象中包括第一调用信息,第一调用信息包括第一对象的标识以及第一线程中调用第二线程的第一调用节点的标识,将第一对象和辅助对象传递至所述第二线程,在确定第二线程待执行所述第一对象时,根据辅助对象中的第一调用信息生成目标调用信息,以及通过第二线程执行第一对象。上述过程中,由于无需对业务系统的代码进行修改,即可实现跨线程调用的链路追踪,一方面提高了开发效率,另一方面保证了业务系统的安全性。另外,通过利用辅助对象来传递第一调用信息,使得不需要对第一对象进行修改,进一步保证了业务系统执行过程的安全性。The method for processing call information provided by this embodiment includes: when it is determined that a first thread is to call a second thread to execute a first object, generating an auxiliary object corresponding to the first object, the first object and the auxiliary object The life cycle is the same, the auxiliary object includes the first call information, the first call information includes the identification of the first object and the identification of the first calling node in the first thread that calls the second thread, and the first object and the auxiliary object are combined. It is passed to the second thread, and when it is determined that the first object is to be executed by the second thread, target invocation information is generated according to the first invocation information in the auxiliary object, and the first object is executed by the second thread. In the above process, since there is no need to modify the code of the business system, the link tracking of cross-thread calls can be realized, which improves the development efficiency on the one hand, and ensures the security of the business system on the other hand. In addition, by using the auxiliary object to transmit the first invocation information, the first object does not need to be modified, which further ensures the security of the execution process of the business system.
在上述实施例的基础上,下面结合一个更具体的实施例对本公开技术方案进行更详细的描述。On the basis of the above embodiment, the technical solution of the present disclosure will be described in more detail below with reference to a more specific embodiment.
图3为本公开实施例提供的另一种调用信息的处理方法的流程示意图。如图3所示,本实施例的方法包括:FIG. 3 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure. As shown in Figure 3, the method of this embodiment includes:
S301:监测跨线程调用行为。S301: Monitor cross-thread calling behavior.
例如,Java编程语言中,对exec行为进行监测。当监测到exec行为时,确定需要进行跨线程调用。For example, in the Java programming language, the behavior of exec is monitored. When the exec behavior is detected, it is determined that a cross-thread call is required.
S302:在确定第一线程待调用第二线程执行第一对象时,获取第一对象。S302: Obtain the first object when it is determined that the first thread is to call the second thread to execute the first object.
S303:创建辅助对象。S303: Create an auxiliary object.
S304:将辅助对象的生命周期与第一对象的生命周期绑定。S304: Bind the life cycle of the auxiliary object with the life cycle of the first object.
例如,在Java编程语言中,第一对象可以为runnable对象。runnable对象可以为普通的class类对象。辅助对象可以为companion伴生对象。可以使用弱引用机制来实现辅助对象与第一对象之间的生命周期绑定关系。For example, in the Java programming language, the first object may be a runnable object. A runnable object can be an ordinary class object. Auxiliary objects can be companion objects. A weak reference mechanism can be used to implement the life cycle binding relationship between the auxiliary object and the first object.
S305:生成第一调用信息。S305: Generate first call information.
其中,第一调用信息包括第一对象的标识以及第一线程中调用第二线程的第一调用节点的标识。The first call information includes the identifier of the first object and the identifier of the first call node in the first thread that calls the second thread.
S306:将第一调用信息添加到辅助对象中。S306: Add the first call information to the auxiliary object.
S307:通过第一线程将第一对象和辅助对象传递到第二线程。S307: Pass the first object and the auxiliary object to the second thread through the first thread.
S308:监测第二线程对第一对象的执行行为。S308: Monitor the execution behavior of the second thread on the first object.
S309:在确定第二线程待执行第一对象时,获取第一对象对应的辅助对象。S309: When it is determined that the second thread is to execute the first object, acquire an auxiliary object corresponding to the first object.
S310:根据辅助对象中的第一调用信息,生成目标调用信息。S310: Generate target invocation information according to the first invocation information in the auxiliary object.
其中,目标调用信息包括:第一对象的标识、跨线程调用指示、第一调用节点的标识、第一对象在第二线程中的父调用节点的标识。Wherein, the target call information includes: the identifier of the first object, the cross-thread call indication, the identifier of the first call node, and the identifier of the parent call node of the first object in the second thread.
S311:通过第二线程执行第一对象。S311: Execute the first object through the second thread.
S312:第一对象执行结束后,将目标调用信息清除。S312: After the execution of the first object ends, clear the target call information.
例如,可以通过对runnable对象的run()行为进行监测。当监测到runnable.run()行为时,说明第二线程开始执行第一对象。在Java编程语言中,可以使用Java代理(agent)字节码增强技术来实现runnable.run()行为的拦截。在拦截到runnable.run()行为时,取出companion伴生对象,根据companion伴生对象中携带的第一调用信息生成目标调用信息,然后通过第二线程真正执行runnable.run()行为,并在runnable.run()行为执行完成后,清理目标调用信息,以恢复到runnable.run()行为之前的状态。For example, you can monitor the run() behavior of the runnable object. When the runnable.run() behavior is detected, it indicates that the second thread starts to execute the first object. In the Java programming language, interception of runnable.run() behavior can be achieved using Java agent bytecode enhancement techniques. When the runnable.run() behavior is intercepted, the companion object is taken out, the target call information is generated according to the first call information carried in the companion companion object, and then the runnable.run() behavior is actually executed through the second thread, and the runnable. After the execution of the run() behavior is complete, clean up the target invocation information to restore the state before the runnable.run() behavior.
S313:第一对象的生命周期结束,第一对象被销毁,辅助对象随之销毁。S313: The life cycle of the first object ends, the first object is destroyed, and the auxiliary object is destroyed accordingly.
本实施例提供的调用信息在不同线程之间的传递方式,不改变第一对象本身,而是使用生命周期绑定技术将第一对象(例如runnable对象)和辅助对象(例如companion伴生对象)的生命周期绑定,并在辅助对象中存储第一调用信息,将携带有第一调用信息的辅助对象随着第一对象传递至第二线程。这样,逻辑上视为第一对象(例如runnable对象)携带第一调用信息,而不需要对第一对象进行修改,保证第一对象的执行安全性,进而保证业务系统的执行安全性。另外,由于不需要对业务系统的代码进行修改,不会影响开发效率,并且能够实现对业务系统中所有跨线程调用行为进行记录。The transmission method of the call information provided by this embodiment between different threads does not change the first object itself, but uses the life cycle binding technology to combine the first object (for example, the runnable object) and the auxiliary object (for example, the companion object). The life cycle is bound, and the first call information is stored in the auxiliary object, and the auxiliary object carrying the first call information is delivered to the second thread along with the first object. In this way, it is logically considered that the first object (for example, the runnable object) carries the first invocation information without modifying the first object, thereby ensuring the execution security of the first object and thus the execution security of the business system. In addition, since there is no need to modify the code of the business system, the development efficiency will not be affected, and all cross-thread calling behaviors in the business system can be recorded.
图2和图3所示实施例中,描述的是采用辅助对象模式传递第一调用信息。在辅助对象模式中,需要对第一对象的执行行为(例如runnable.run()行为)进行拦截,而在一些场景下,一些对象的执行行为可能无法拦截。例如,在Java编程语言中,只有已存在的类才能使用Java Agent技术对方法进行拦截。对于一些使用lambda表达式等动态生成的对象类型,可能无法实现拦截。本公开实施例中,针对第一对象的执行行为无法拦截的场景,可以采用包装对象模式传递第一调用信息。下面结合图4进行介绍。In the embodiments shown in FIG. 2 and FIG. 3 , it is described that the first invocation information is transmitted using the auxiliary object mode. In the auxiliary object mode, the execution behavior of the first object (for example, the runnable.run() behavior) needs to be intercepted, and in some scenarios, the execution behavior of some objects may not be intercepted. For example, in the Java programming language, only existing classes can use Java Agent technology to intercept methods. For some dynamically generated object types such as lambda expressions, interception may not be possible. In this embodiment of the present disclosure, for a scenario where the execution behavior of the first object cannot be intercepted, the first invocation information may be transmitted in a wrapper object mode. The following description will be made with reference to FIG. 4 .
图4为本公开实施例提供的又一种调用信息的处理方法的流程示意图。如图4所示,本实施例的方法,包括:FIG. 4 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure. As shown in Figure 4, the method of this embodiment includes:
S401:在确定第一线程待调用第二线程执行第一对象时,获取第一对象的类型,第一对象的类型为第一类型或者第二类型,第一类型的对象的执行行为可被拦截,第二类型的对象的执行行为不可被拦截。S401: When it is determined that the first thread is to call the second thread to execute the first object, obtain the type of the first object, the type of the first object is the first type or the second type, and the execution behavior of the object of the first type can be intercepted , the execution behavior of objects of the second type cannot be intercepted.
本实施例中,可以根据对象的执行行为是否可被拦截,将对象划分为两种类型,分别为第一类型和第二类型。第一类型的对象的执行行为可被拦截,第二类型的对象的执行行为不可被拦截。In this embodiment, objects can be divided into two types, namely the first type and the second type, according to whether the execution behavior of the object can be intercepted. The execution behavior of the object of the first type can be intercepted, and the execution behavior of the object of the second type cannot be intercepted.
下面以Java编程语言为例进行举例说明。在Java编程语言中,lambda表达式生成的runnable对象是不适合拦截的,原因如下:The following takes the Java programming language as an example for illustration. In the Java programming language, runnable objects generated by lambda expressions are not suitable for interception for the following reasons:
(1)Java语言对每一次lambda表达式的执行,动态生成一个lambda表达式类。如果对每个lambda表达式类进行字节码增强,将产生过大开销。(1) The Java language dynamically generates a lambda expression class for each execution of a lambda expression. Bytecode enhancements to each lambda expression class would incur excessive overhead.
(2)Java语言中规定lambda表达式类不经过Instrumentation接口管理,故无法使用字节码增强技术进行拦截。Instrumentation指的是可以独立于应用程序之外的代理程序。(2) The Java language stipulates that the lambda expression class is not managed by the Instrumentation interface, so it cannot be intercepted using the bytecode enhancement technology. Instrumentation refers to agents that can be independent of applications.
基于上述原因,在Java编程语言中,可以将lambda表达式类的对象的类型识别为第二类型,将除lambda表达式类之外的其他类的对象的类型识别为第一类型。For the above reasons, in the Java programming language, the types of objects of the lambda expression class can be recognized as the second type, and the types of objects of other classes other than the lambda expression class can be recognized as the first type.
S402:若第一对象的类型为第一类型,则采用辅助对象模式将第一调用信息传递至第二线程。S402: If the type of the first object is the first type, use the auxiliary object mode to transmit the first call information to the second thread.
应理解,S402的具体实现方式可以参见图2或图3所示实施例的详细描述,此处不作赘述。It should be understood that for the specific implementation of S402, reference may be made to the detailed description of the embodiment shown in FIG. 2 or FIG. 3 , which is not repeated here.
S403:若第一对象的类型为第二类型,则采用包装对象模式将第一调用信息传递至第二线程。S403: If the type of the first object is the second type, the first call information is transmitted to the second thread by adopting the wrapping object mode.
本实施例中,包装对象模式是另一种调用信息在不同线程之间的传递方式。该方式中,对第一对象和第一调用信息进行包装得到包装对象,并将包装对象传递至所述第二线程。进而通过第二线程执行该包装对象。In this embodiment, the wrapping object mode is another way of transferring call information between different threads. In this manner, the first object and the first call information are packaged to obtain a packaged object, and the packaged object is delivered to the second thread. The wrapper object is then executed by the second thread.
下面结合一个具体的实施例,对图4所示实施例中的包装对象模式进行详细介绍。The packaging object mode in the embodiment shown in FIG. 4 will be described in detail below with reference to a specific embodiment.
图5为本公开实施例提供的又一种调用信息的处理方法的流程示意图。如图5所示,本实施例的方法,包括:FIG. 5 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure. As shown in Figure 5, the method of this embodiment includes:
S501:监测跨线程调用行为。S501: Monitor cross-thread calling behavior.
例如,Java编程语言中,对exec行为进行监测。当监测到exec行为时,确定需要进行跨线程调用。For example, in the Java programming language, the behavior of exec is monitored. When the exec behavior is detected, it is determined that a cross-thread call is required.
S502:在确定第一线程待调用第二线程执行第一对象时,获取第一对象。S502: Obtain the first object when it is determined that the first thread is to call the second thread to execute the first object.
S503:创建包装对象。S503: Create a packaging object.
S504:使用包装对象包装第一对象。S504: Use the wrapping object to wrap the first object.
S505:生成第一调用信息。S505: Generate first call information.
其中,第一调用信息包括:第一对象的标识以及第一线程中调用第二线程的第一调用节点的标识。Wherein, the first calling information includes: the identifier of the first object and the identifier of the first calling node in the first thread that calls the second thread.
S506:将第一调用信息添加到包装对象中。S506: Add the first call information to the packaging object.
S507:通过第一线程将包装对象传递到第二线程。S507: Pass the packaging object to the second thread through the first thread.
S508:通过第二线程执行包装对象的执行行为。S508: Execute the execution behavior of the packaging object through the second thread.
S509:获取包装对象中的第一调用信息。S509: Obtain the first call information in the packaging object.
S510:根据包装对象中的第一调用信息,生成目标调用信息。S510: Generate target invocation information according to the first invocation information in the packaging object.
目标调用信息包括:第一对象的标识、跨线程调用指示、第一调用节点的标识、第一对象在第二线程中的父调用节点的标识。The target call information includes: the identifier of the first object, the cross-thread call indication, the identifier of the first call node, and the identifier of the parent call node of the first object in the second thread.
S511:通过第二线程执行第一对象。S511: Execute the first object through the second thread.
S512:第一对象执行结束后,将目标调用信息清除。S512: After the execution of the first object ends, clear the target call information.
S513:包装对象执行结束后,包装对象的生命周期结束,包装对象被销毁,第一对象随之销毁。S513: After the execution of the packaging object ends, the life cycle of the packaging object ends, the packaging object is destroyed, and the first object is destroyed accordingly.
举例而言,以Java编程语言为例,可以实现runnable接口的TracedRunnable类的对象,采用TracedRunnable包装对象对runnable对象进行包装,并在TracedRunnable包装对象中携带第一调用信息。将TracedRunnable包装对象传递到第二线程。在第二线程中执行TracedRunnable.run()行为,取出TracedRunnable中携带的第一调用信息,根据第一调用信息生成目标调用信息,然后通过第二线程真正执行runnable.run()行为,并在runnable.run()行为执行完成后,清理目标调用信息,以恢复到runnable.run()行为之前的状态。For example, taking the Java programming language as an example, an object of the TracedRunnable class that implements the runnable interface can be used to wrap the runnable object with the TracedRunnable wrapper object, and the first call information is carried in the TracedRunnable wrapper object. Pass the TracedRunnable wrapper object to the second thread. Execute the TracedRunnable.run() behavior in the second thread, take out the first call information carried in the TracedRunnable, generate the target call information according to the first call information, and then actually execute the runnable.run() behavior through the second thread, and execute the runnable.run() behavior in the runnable After the execution of the .run() behavior is complete, clean up the target invocation information to restore the state before the runnable.run() behavior.
实际应用中,TraceRunnable包装对象对runnable对象的包装机制存在隐患,因为TraceRunnable包装对象仅仅包装了runnable对象run行为,而除了run行为之外的其他行为会被擦除。这样,如果runnable对象中还存在除了run行为以外的其它行为,例如,线程池用优先级队列对任务对象进行排序(compare)的行为,则由于TraceRunnable包装对象对runnable对象的包装过程中会擦除compare行为,会导致业务代码抛出异常,使得应用不可用。In practical applications, there is a hidden danger in the wrapping mechanism of the runnable object by the TraceRunnable wrapper object, because the TraceRunnable wrapper object only wraps the run behavior of the runnable object, and other behaviors except the run behavior will be erased. In this way, if there are other behaviors other than the run behavior in the runnable object, for example, the thread pool uses the priority queue to sort the task objects (compare), then because the TraceRunnable wrapper object will erase the runnable object during the wrapping process The compare behavior will cause the business code to throw an exception, making the application unavailable.
本公开实施例中,基于上述考虑,图4所示实施例中并不是所有场景都采用包装对象模式,而是在第一对象的run行为可被拦截的情况下,使用辅助对象模式传递调用信息,只有在第一对象的run行为不可拦截的情况下,才使用包装对象模式传递调用信息,从而最大程度保证业务系统的安全性。In the embodiment of the present disclosure, based on the above considerations, in the embodiment shown in FIG. 4, not all scenarios adopt the wrapper object mode, but the auxiliary object mode is used to transmit call information in the case that the run behavior of the first object can be intercepted , only when the run behavior of the first object cannot be intercepted, the wrapper object mode is used to transfer the call information, thereby ensuring the security of the business system to the greatest extent.
在Java编程语言中,由于只有lambda表达式类的对象的run行为是无法拦截的,因此,当第一对象为lambda表达式类的对象时,可以使用包装对象模式传递调用信息。针对除了lambda表达式类之外的其他对象,则可以采用辅助对象模式传递调用信息。In the Java programming language, since only the run behavior of an object of the lambda expression class cannot be intercepted, when the first object is an object of the lambda expression class, the wrapping object mode can be used to transfer the calling information. For objects other than the lambda expression class, the auxiliary object pattern can be used to pass the call information.
进一步的,lambda表达式的直接父类为Java.lang.Object类,中间不存在其它类型,故不存在其它行为被擦除的可能。并且,lambda表达式本身的类型是自动生成的,对用户透明,用户不可能在lambda表达式生成的runnable对象上调用其它除run()以外的行为。通过上述分析可见,lambda表达式类的对象只会存在run行为,而不会存在其他行为。因此,在Java语言中,即使针对lambda表达式类的对象采用包装对象模式,也能够保证业务系统的安全性。Further, the direct parent class of the lambda expression is the Java.lang.Object class, and there are no other types in the middle, so there is no possibility of other behaviors being erased. Moreover, the type of the lambda expression itself is automatically generated and transparent to the user, and it is impossible for the user to call other behaviors other than run() on the runnable object generated by the lambda expression. It can be seen from the above analysis that the object of the lambda expression class only has the run behavior, but no other behavior. Therefore, in the Java language, the security of the business system can be guaranteed even if the wrapper object pattern is adopted for the objects of the lambda expression class.
上述实施例重点描述了调用信息在第一线程和第二线程之间的传递方式。下面结合本实施例重点描述第一线程和第二线程对调用信息的编排处理过程。The above-mentioned embodiments focus on describing the way in which the call information is transmitted between the first thread and the second thread. The following describes the process of arranging and processing the call information by the first thread and the second thread with reference to this embodiment.
本实施例中,在跨线程调用的场景下,由于Scope栈是每个线程独立维护的,需要设计跨线程Scope和Span的编排机制。跨线程编排机制需要满足如下特征:In this embodiment, in the scenario of cross-thread calling, since the Scope stack is maintained independently by each thread, it is necessary to design a cross-thread Scope and Span orchestration mechanism. The cross-thread orchestration mechanism needs to meet the following characteristics:
(1)正确新增、删除来自本线程中的Span。(1) Correctly add and delete spans from this thread.
(2)在跨线程调用行为发生时,正确新增、删除来自父线程中的Span。(2) Correctly add and delete spans from the parent thread when the cross-thread calling behavior occurs.
(3)在父线程Scope栈持有一个Span期间,需要保证该Span对父线程的可读写,对子线程可读。(3) During the period when the parent thread Scope stack holds a Span, it is necessary to ensure that the Span is readable and writable to the parent thread and readable to the child thread.
(4)在父线程的Scope栈取消对一个Span的引用后,且尚有子线程Scope栈对该Span持有引用时,至少要保证该Span对子线程可读。(4) After the parent thread's Scope stack cancels a reference to a Span, and there is still a child thread's Scope stack holding a reference to the Span, at least ensure that the Span is readable by the child thread.
(5)在父线程和最后一个子线程的Scope栈均取消对一个Span的引用后,不需要保证Span的可访问性。(5) After the Scope stack of the parent thread and the last child thread both cancel the reference to a Span, there is no need to guarantee the accessibility of the Span.
(6)在一个Span可访问到的任意时刻,需要保证通过该Span可以访问到任意父级Span。但任何时刻都无需保证通过一个Span可以访问到它的任何子级Span。(6) At any time when a Span can be accessed, it is necessary to ensure that any parent Span can be accessed through the Span. But there is no guarantee that any of its child spans can be accessed through a span at any time.
基于上述分析,本实施例中,可以设定Span的数据结构如下:Based on the above analysis, in this embodiment, the data structure of Span can be set as follows:
class Span{class Span{
String traceId;String traceId;
String spanId;String spanId;
//其它所需字段//other required fields
}}
其中,traceId为调用链路对应的全局唯一的标识,spanId为Span对应的全局唯一的标识。The traceId is the globally unique identifier corresponding to the calling link, and the spanId is the globally unique identifier corresponding to the Span.
本实施例中,可以设定Scope的数据结构如下:In this embodiment, the data structure of the Scope can be set as follows:
class Scope{class Scope{
Span span;span span;
boolean isExternal;boolean isExternal;
Scope localParent;Scope localParent;
Scope externalParent;Scope externalParent;
}}
其中,Span为该Scope包裹的Span,isExternal代表该Span是本线程中创建的还是父线程传递到本线程中的。localParent代表本线程中的父级Scope,externalParent代表父线程发生跨线程调用行为时栈顶的Scope。Among them, Span is the Span wrapped by the Scope, and isExternal represents whether the Span is created in this thread or passed to this thread by the parent thread. localParent represents the parent Scope in this thread, and externalParent represents the Scope at the top of the stack when the parent thread has cross-thread calling behavior.
在上述Span和Scope的数据结构的基础上,下面结合图6对在第一线程中对第一调用信息的编排过程、在第二线程中对目标调用信息的编排过程进行详细描述。Based on the above data structures of Span and Scope, the process of arranging the first call information in the first thread and the process of arranging target call information in the second thread will be described in detail below with reference to FIG. 6 .
图6为本公开实施例提供的又一种调用信息的处理方法的流程示意图。如图6所示,本实施例的方法可以包括:FIG. 6 is a schematic flowchart of another method for processing call information provided by an embodiment of the present disclosure. As shown in FIG. 6 , the method of this embodiment may include:
S601:监测跨线程调用行为。S601: Monitor cross-thread calling behavior.
S602:在确定第一线程待调用第二线程执行第一对象时,获取第一线程对应的第一调用栈。S602: When it is determined that the first thread is to call the second thread to execute the first object, obtain a first call stack corresponding to the first thread.
其中,第一调用栈用于存储第一线程对应的调用节点。The first call stack is used to store the call node corresponding to the first thread.
S603:根据第一调用栈中的栈顶调用节点,生成第一调用信息。S603: Generate first call information according to the top call node in the first call stack.
具体的,第一调用栈的栈顶调用节点即为第一调用节点。第一调用栈中的栈顶调用节点的标识(例如栈顶scope),确定为第一调用节点的标识,第一调用栈中的栈顶调用节点包裹的span,即为第一对象的标识。这样,第一调用信息中包括了第一对象的标识,以及第一调用节点的标识。Specifically, the top call node of the first call stack is the first call node. The identifier of the call node on the top of the stack in the first call stack (for example, the scope on the top of the stack) is determined as the identifier of the first call node, and the span wrapped by the call node on the top of the stack in the first call stack is the identifier of the first object. In this way, the first call information includes the identifier of the first object and the identifier of the first call node.
S604:将第一调用信息和第一对象传递到第二线程中。S604: Transfer the first call information and the first object to the second thread.
举例而言,假设第一调用栈的栈顶调用节点为Scope1,Scope1中包裹Span1。则将包裹有Span1的Scope1作为第一调用信息传递到第二线程中。For example, it is assumed that the top call node of the first call stack is Scope1, and Span1 is wrapped in Scope1. Then, Scope1 wrapped with Span1 is passed to the second thread as the first call information.
应理解的是,S604中将第一调用信息和第一对象传递到第二线程中的方式,可以是采用辅助对象模式传递,还可以是采用包装对象模式传递,本实施例对此不作限定,具体可以参见前述实施例的详细描述。It should be understood that, in S604, the way of transmitting the first call information and the first object to the second thread may be transmitted in an auxiliary object mode or in a packaged object mode, which is not limited in this embodiment. For details, refer to the detailed description of the foregoing embodiments.
S605:任意次函数调用。S605: any number of function calls.
S606:将栈顶调用节点从第一调用栈中弹出。S606: Pop the call node at the top of the stack from the first call stack.
例如,Scope1的生命周期结束,将包裹有Span1的Scope1从第一调用栈中弹出。For example, when the life cycle of Scope1 ends, the Scope1 wrapped with Span1 is popped from the first call stack.
S607:获取第一调用信息中的第一对象的标识,以及第一调用节点的标识。S607: Acquire the identifier of the first object in the first calling information and the identifier of the first calling node.
示例性的,第二线程接收到第一调用信息后,可以从第一调用信息中获取到来自第一线程的Scope1,并取出Scope1中包裹的Span1。Exemplarily, after receiving the first call information, the second thread can obtain Scope1 from the first thread from the first call information, and take out Span1 wrapped in Scope1.
S608:获取第二线程对应的第二调用栈,第二调用栈用于存储第二线程对应的调用节点。S608: Acquire a second call stack corresponding to the second thread, where the second call stack is used to store a call node corresponding to the second thread.
这样,可以根据所述第一调用信息和所述第二调用栈,生成所述目标调用信息。一种可能的实现方式可以参见S609至S610。In this way, the target call information can be generated according to the first call information and the second call stack. For a possible implementation, see S609 to S610.
S609:根据第二调用栈,确定第一调用节点在第二线程中的父调用节点的标识。S609: Determine, according to the second call stack, the identifier of the parent call node of the first call node in the second thread.
若所述第二调用栈为空,则确定所述第一对象在所述第二线程中的父调用节点的标识为空;或者,If the second call stack is empty, determine that the identifier of the parent calling node of the first object in the second thread is empty; or,
若所述第二调用栈不为空,则将所述第二调用栈中栈顶调用节点的标识,确定为所述第一对象在所述第二线程中的父调用节点的标识。If the second call stack is not empty, the identifier of the call node at the top of the stack in the second call stack is determined as the identifier of the parent call node of the first object in the second thread.
S610:确定目标调用信息包括:跨线程调用指示、第一调用信息、以及第一调用节点在第二线程中的父调用节点的标识。S610: Determine the target invocation information including: a cross-thread invocation indication, first invocation information, and an identifier of a parent invocation node of the first invocation node in the second thread.
这样,可以根据跨线程调用指示、第一调用信息、以及第一调用节点在第二线程中的父调用节点的标识,生成目标调用信息。也就是说,目标调用信息包括:第一调用节点的标识、跨线程调用指示、第一调用节点在第二线程中的父调用节点的标识、第一调用节点在第一线程的标识。In this way, the target invocation information can be generated according to the cross-thread invocation indication, the first invocation information, and the identifier of the parent invocation node of the first invocation node in the second thread. That is, the target call information includes: the identifier of the first call node, the cross-thread call indication, the identifier of the parent call node of the first call node in the second thread, and the identifier of the first call node in the first thread.
S611:根据目标调用信息,生成第二调用节点。S611: Generate a second invocation node according to the target invocation information.
S612:将第二调用节点更新为第二调用栈的栈顶。S612: Update the second call node to the top of the second call stack.
举例而言,从第二线程对应的第二调用栈中获取栈顶Scope,记为Scope2。如果第二调用栈为空,则Scope2=null。For example, the top Scope of the stack is obtained from the second call stack corresponding to the second thread, and denoted as Scope2. If the second call stack is empty, then Scope2=null.
创建新的Scope,记为Scope3,使用Scope3包裹Span1,设置Scope3.localParent=Scope2,Scope3.externalParent=Scope1。将第二调用栈的栈顶指针指向Scope3。Create a new Scope, denoted as Scope3, use Scope3 to wrap Span1, set Scope3.localParent=Scope2, Scope3.externalParent=Scope1. Point the top-of-the-stack pointer of the second call stack to Scope3.
S613:通过第二线程执行第一对象。S613: Execute the first object through the second thread.
S614:第一对象执行结束后,将第二调用节点从第二调用栈中弹出。S614: After the execution of the first object is completed, pop the second call node from the second call stack.
例如,从第二调用栈中弹出Scope3,将第二调用栈的栈顶指针指向Scope3.localParent=Scope2。使得第二调用栈恢复到执行前的状态。For example, Scope3 is popped from the second call stack, and the stack top pointer of the second call stack is pointed to Scope3.localParent=Scope2. The second call stack is restored to the state before execution.
本实施例中,Span是跨线程的,随着不同线程进行传递,Scope是所属于单一线程的,在第一线程(父线程)、第二线程(子线程)的运行过程中任何时刻都不应该相互修改Scope栈。当父线程发生跨线程调用行为时,不修改父线程的Scope栈,仅将栈顶Scope传递到子线程。父线程完成传递后,不必等待子线程执行完任务,可以在任意时刻弹出父线程栈的Scope,并弹出Span。子线程接收到来自父线程的Scope,需要创建新的Scope来包装父线程栈顶Scope包裹的Span,并将新Scope的localParent链接到本线程栈顶Scope,externalParent链接到父线程栈顶Scope,然后将新的Scope压栈到本线程的Scope栈顶。该Span所对应的runnable任务执行结束后,子线程弹出Scope,并弹出Span,子线程Scope栈恢复到执行前的状态。In this embodiment, Span is cross-threaded, and as different threads are passed, Scope belongs to a single thread, and is not at any time during the running process of the first thread (parent thread) and the second thread (child thread). Scope stacks should be modified mutually. When the parent thread has a cross-thread calling behavior, the Scope stack of the parent thread is not modified, and only the top Scope of the stack is passed to the child thread. After the parent thread completes the transfer, it does not need to wait for the child thread to complete the task. The Scope of the parent thread stack can be popped up at any time, and the Span can be popped up. When the child thread receives the Scope from the parent thread, it needs to create a new Scope to wrap the Span wrapped by the Scope on the top of the stack of the parent thread, and link the localParent of the new Scope to the Scope on the top of the thread's stack, and the externalParent to the Scope on the top of the stack of the parent thread, and then Push the new Scope onto the top of this thread's Scope stack. After the execution of the runnable task corresponding to the Span is completed, the sub-thread pops the Scope and the Span, and the sub-thread Scope stack returns to the state before execution.
在图6所示实施例的基础上,还可以支持Span回溯。假设子线程的调用栈中的栈顶调用节点为ScopeC,其中包裹SpanC,要回溯到入口SpanA。其中,SpanA在父线程的调用栈中。On the basis of the embodiment shown in FIG. 6 , Span backtracking can also be supported. Assume that the top call node in the call stack of the child thread is ScopeC, which wraps SpanC and goes back to the entry SpanA. Among them, SpanA is in the call stack of the parent thread.
在进行回溯时,判断ScopeC对应的跨线程调用时父线程的栈顶Scope(即externalParent字段)是否为空,若externalParent字段不为空,则继续沿着externalParent字段递归向上查找,直到externalParen字段为空时,当前Scope包裹的Span即为入口Span。When backtracking, determine whether the parent thread's top Scope (ie externalParent field) is empty when the cross-thread call corresponding to ScopeC is empty. If the externalParent field is not empty, continue to search recursively along the externalParent field until the externalParent field is empty. , the Span wrapped by the current Scope is the entry Span.
通过本实施例对调用栈中的各调用节点的Scope数据结构进行合理编排,使得调用链路中的各调用节点支持跨线程回溯,从而能够应用于具有回溯需求的链路追踪场景中。回溯需求广泛存在于如结构化查询语言(Structured Query Language,SQL)、缓存(cache)、远程过程调用(Remote Procedure Call,RPC)等出口流量监控的场景中。This embodiment reasonably arranges the Scope data structure of each call node in the call stack, so that each call node in the call chain supports cross-thread backtracking, which can be applied to a link tracking scenario with backtracking requirements. Backtracking requirements widely exist in egress traffic monitoring scenarios such as Structured Query Language (SQL), cache (cache), and Remote Procedure Call (RPC).
在上述任意实施例的基础上,下面结合图7至图9以几个具体的跨线程调用场景为例,对本公开实施例中的调用信息的处理过程进行举例说明。On the basis of any of the above-mentioned embodiments, several specific cross-thread calling scenarios are used as examples to illustrate the processing process of calling information in the embodiments of the present disclosure with reference to FIGS. 7 to 9 .
下面几个跨线程调用场景中,基于如下假设:(1)父线程通过上述实施例中的跨线程传递方式和调用栈编排机制发生跨线程调用。(2)假设父线程投放Runnable到子线程之后,父线程均立即执行其它任意函数,产生SpanC。(3)Runnable在执行时,会产生SpanD。In the following several cross-thread call scenarios, the following assumptions are made: (1) The parent thread makes cross-thread calls through the cross-thread transfer method and the call stack arrangement mechanism in the above embodiment. (2) Suppose that after the parent thread puts the Runnable into the child thread, the parent thread immediately executes other arbitrary functions to generate SpanC. (3) When Runnable is executed, SpanD will be generated.
图7为本公开实施例提供的一种跨线程调用场景的示意图。如图7所示,线程1(父线程)将第一对象(以Runnable对象为例)传递给线程2(子线程)执行。这是普通的跨线程调用场景。FIG. 7 is a schematic diagram of a cross-thread calling scenario provided by an embodiment of the present disclosure. As shown in Figure 7, thread 1 (parent thread) passes the first object (take Runnable object as an example) to thread 2 (child thread) for execution. This is a normal cross-thread call scenario.
(1).初始状态时,假设线程1和线程2的调用栈如下:(1). In the initial state, it is assumed that the call stacks of
线程1的调用栈:[ScpoeA1(SpanA)]Call stack of thread 1: [ScpoeA1(SpanA)]
线程2的调用栈:[]Call stack for thread 2: []
(2).线程1在执行SpanA过程中,需要跨线程调用执行Runnable对象。线程1将Runnable对象投放到线程池,线程1和线程2的调用栈如下:(2).
线程1的调用栈:[ScpoeA1(SpanA),ScopeA2(SpanB)]Call stack of thread 1: [ScpoeA1(SpanA), ScopeA2(SpanB)]
线程2的调用栈:[]Call stack for thread 2: []
(3).线程1将Runnable对象投放到线程池后,ScopeA2(SpanB)弹出,线程1执行SpanC,线程1和线程2的调用栈如下:(3). After
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[]Call stack for thread 2: []
(4).线程2开始执行Runnable对象时,触发创建ScopeB1(SpanB),并在执行SpanB的过程中产生SpanD,线程1和线程2的调用栈如下:(4). When thread 2 starts to execute the Runnable object, it triggers the creation of ScopeB1 (SpanB), and generates SpanD during the execution of SpanB. The call stacks of
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[ScopeB1(SpanB),ScopeB2(SpanD)]Call stack of thread 2: [ScopeB1(SpanB),ScopeB2(SpanD)]
(5).线程2执行完Runnable对象之后,ScopeB1(SpanB)和ScopeB2(SpanD)被弹出,线程1和线程2的调用栈如下:(5). After thread 2 executes the Runnable object, ScopeB1(SpanB) and ScopeB2(SpanD) are popped up, and the call stacks of
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[]Call stack for thread 2: []
(6)线程1的SpanC执行结束,线程1和线程2的调用栈如下:(6) The SpanC execution of
线程1的调用栈:[ScopeA1(SpanA)]Call stack of thread 1: [ScopeA1(SpanA)]
线程2的调用栈:[]Call stack for thread 2: []
图7所示的跨线程调用场景中,最终形成的调用链如下:In the cross-thread call scenario shown in Figure 7, the final call chain is formed as follows:
SpanA→SpanB→SpanDSpanA→SpanB→SpanD
→SpanC→SpanC
也就是说,SpanB的父节点为SpanA,SpanD的父节点为SpanB,SpanC的父节点为SpanA。That is, the parent node of SpanB is SpanA, the parent node of SpanD is SpanB, and the parent node of SpanC is SpanA.
图8为本公开实施例提供的另一种跨线程调用场景的示意图。如图8所示,该场景中,线程1可能本身就是线程池线程。线程1将第一对象(以Runnable对象为例)投放到线程池,然后线程1被调度继续执行Runnable对象。例如Java语言中的ScheduledExecutorService,ForkJoinPool符合这种情景。其中,ScheduledExecutorService是基于线程池设计的定时任务类,ForkJoinPool是分叉/结合框架的类。FIG. 8 is a schematic diagram of another cross-thread calling scenario provided by an embodiment of the present disclosure. As shown in Figure 8, in this scenario,
(1).初始状态时,假设线程1的调用栈如下:(1). In the initial state, assume that the call stack of
[ScopeA1(SpanB)][ScopeA1(SpanB)]
(2).线程1将Runnable对象投放到线程池,线程1的调用栈如下:(2).
[ScopeA1(SpanB)][ScopeA1(SpanB)]
(3).线程1将Runnable对象投放到线程池后,ScopeA1(SpanB)弹出,线程1执行SpanC,线程1的调用栈如下:(3). After
[ScopeA2(SpanC)][ScopeA2(SpanC)]
(4).线程1开始执行Runnable对象时,触发创建ScopeA3(SpanB),并在执行SpanB的过程中产生SpanD,:线程1的调用栈如下:(4). When
[ScopeA3(SpanB),ScopeA4(SpanD)][ScopeA3(SpanB),ScopeA4(SpanD)]
(5).线程1执行完Runnable对象后,线程1的调用栈如下:(5). After
[][]
(6).结束,线程1的调用栈如下:(6). At the end, the call stack of
[][]
图8所示的跨线程调用场景中,最终形成的调用链如下:In the cross-thread call scenario shown in Figure 8, the final call chain is formed as follows:
SpanB→SpanDSpanB→SpanD
也就是说,SpanD的父节点为SpanB。That is, the parent node of SpanD is SpanB.
图9为本公开实施例提供的又一种跨线程调用场景的示意图。如图9所示,线程1(父线程)将第一对象(以Runnable对象为例)传递给线程2(子线程)执行,线程2执行Runnable对象,又通过某种方式将Runnable对象传递给线程1,线程1再次执行Runnable对象。这是一种极端的跨线程调用场景。FIG. 9 is a schematic diagram of yet another cross-thread calling scenario provided by an embodiment of the present disclosure. As shown in Figure 9, thread 1 (parent thread) passes the first object (take the Runnable object as an example) to thread 2 (child thread) for execution, thread 2 executes the Runnable object, and passes the Runnable object to the thread in some
(1).初始状态时,假设线程1和线程2的调用栈如下:(1). In the initial state, it is assumed that the call stacks of
线程1的调用栈:[ScopeA1(SpanA)]Call stack of thread 1: [ScopeA1(SpanA)]
线程2的调用栈:[]Call stack for thread 2: []
(2).线程1在执行SpanA过程中,需要跨线程调用执行Runnable对象。线程1将Runnable对象投放到线程池,线程1和线程2的调用栈如下:(2).
线程1的调用栈:[ScopeA1(SpanA),ScopeA2(SpanB)]Call stack of thread 1: [ScopeA1(SpanA), ScopeA2(SpanB)]
线程2的调用栈:[]Call stack for thread 2: []
(3).线程1将Runnable对象投放到线程池后,ScopeA2(SpanB)弹出,线程1执行SpanC,线程1和线程2的调用栈如下:(3). After
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[]Call stack for thread 2: []
(4).线程2开始执行Runnable对象时,触发创建ScopeB1(SpanB),并在执行SpanB的过程中产生SpanD,线程1和线程2的调用栈如下:(4). When thread 2 starts to execute the Runnable object, it triggers the creation of ScopeB1 (SpanB), and generates SpanD during the execution of SpanB. The call stacks of
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[ScopeB1(SpanB),ScopeB2(SpanD)]Call stack of thread 2: [ScopeB1(SpanB),ScopeB2(SpanD)]
(5).线程2运行结束(并返回Runnable对象给线程1)后,线程1和线程2的调用栈如下:(5). After thread 2 finishes running (and returns the Runnable object to thread 1), the call stacks of
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[]Call stack for thread 2: []
(6).线程1开始执行Runnable对象,触发创建ScopeA4(SpanB),并在执行SpanB的过程中产生SpanD,线程1和线程2的调用栈如下:(6).
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC),ScopeA4(SpanB),ScopeA5(SpanD)]Call stack of thread 1: [ScopeA1(SpanA), ScopeA3(SpanC), ScopeA4(SpanB), ScopeA5(SpanD)]
线程2的调用栈:[]Call stack for thread 2: []
(7).线程1运行完成后,线程1和线程2的调用栈如下:(7). After
线程1的调用栈:[ScopeA1(SpanA),ScopeA3(SpanC)]Call stack of thread 1: [ScopeA1(SpanA),ScopeA3(SpanC)]
线程2的调用栈:[]Call stack for thread 2: []
(8).结束,线程1和线程2的调用栈如下:(8). At the end, the call stacks of
线程1的调用栈:[ScopeA1(SpanA)]Call stack of thread 1: [ScopeA1(SpanA)]
线程2的调用栈:[]Call stack for thread 2: []
图9所示的跨线程调用场景中,最终形成的调用链如下:In the cross-thread call scenario shown in Figure 9, the final call chain is formed as follows:
SpanA→SpanCSpanA→SpanC
→SpanB→SpanD→SpanB→SpanD
→SpanD→SpanD
也就是说,SpanC的父节点为SpanA,SpanB的父节点为SpanA,SpanD的父节点为SpanB。That is, the parent node of SpanC is SpanA, the parent node of SpanB is SpanA, and the parent node of SpanD is SpanB.
在图9所示的跨线程调用场景中,在步骤(6)的时候,线程1引用的栈顶是SpanD,引用链路为SpanD→SpanB→SpanA,而Scope的链接则是ScopeA5→ScopeA4→ScopeA3→ScopeA1。故步骤(6)结束时,弹出SpanD和SpanB时,SpanB能正确地通过ScopeA4的externalParent关系链接到ScopeA1(SpanA)上,而线程1的Scope也能恢复到运行Runnable前的状态(步骤(5))。如果没有externalParent的机制,则SpanB会错误地链接到SpanC上。所以,externalParent与localParent两套链接机制,都是必不可少的。In the cross-thread calling scenario shown in Figure 9, in step (6), the top of the stack referenced by
图10为本公开实施例提供的一种调用信息的处理装置的结构示意图。本实施例的装置可以为软件和/或硬件的形式。如图10所示,本实施例提供的调用信息的处理装置1000,包括:第一处理模块1001、传递模块1002和第二处理模块1003。FIG. 10 is a schematic structural diagram of an apparatus for processing call information according to an embodiment of the present disclosure. The apparatus of this embodiment may be in the form of software and/or hardware. As shown in FIG. 10 , the
其中,第一处理模块1001,用于在确定第一线程待调用第二线程执行第一对象时,生成所述第一对象对应的辅助对象,所述第一对象和所述辅助对象的生命周期相同,所述辅助对象中包括第一调用信息,所述第一调用信息包括:所述第一对象的标识以及所述第一线程中调用所述第二线程的第一调用节点的标识;The
传递模块1002,用于将所述第一对象和所述辅助对象传递至所述第二线程;a
第二处理模块1003,用于在确定所述第二线程待执行所述第一对象时,根据所述辅助对象中的所述第一调用信息生成目标调用信息,以及通过所述第二线程执行所述第一对象,所述目标调用信息包括:所述第一对象的标识、跨线程调用指示、所述第一调用节点的标识、所述第一对象在所述第二线程中的父调用节点的标识。The
一种可能的实现方式中,所述第一处理模块1001包括:In a possible implementation manner, the
创建单元,用于创建所述辅助对象,并将所述辅助对象的生命周期与所述第一对象的生命周期绑定;A creation unit, configured to create the auxiliary object, and bind the life cycle of the auxiliary object to the life cycle of the first object;
第一生成单元,用于生成所述第一调用信息;a first generating unit, configured to generate the first invocation information;
添加单元,用于将所述第一调用信息添加到所述辅助对象中。An adding unit is configured to add the first call information to the auxiliary object.
一种可能的实现方式中,所述第一生成单元包括:In a possible implementation manner, the first generating unit includes:
获取子单元,用于获取所述第一线程对应的第一调用栈,所述第一调用栈用于存储所述第一线程对应的调用节点;an acquisition subunit, configured to acquire a first call stack corresponding to the first thread, where the first call stack is used to store a call node corresponding to the first thread;
生成子单元,用于根据所述第一调用栈中的栈顶调用节点,生成所述第一调用信息。A generating subunit is configured to generate the first call information according to the top call node in the first call stack.
一种可能的实现方式中,所述第二处理模块1003包括:In a possible implementation manner, the
第一获取单元,用于在所述辅助对象中获取所述第一调用信息;a first obtaining unit, configured to obtain the first invocation information in the auxiliary object;
第二获取单元,用于获取所述第二线程对应的第二调用栈,所述第二调用栈用于存储所述第二线程对应的调用节点;a second obtaining unit, configured to obtain a second call stack corresponding to the second thread, where the second call stack is configured to store a call node corresponding to the second thread;
第二生成单元,用于根据所述第一调用信息和所述第二调用栈,生成所述目标调用信息。A second generating unit, configured to generate the target call information according to the first call information and the second call stack.
一种可能的实现方式中,所述第二生成单元包括:In a possible implementation manner, the second generating unit includes:
第一确定子单元,用于根据所述第二调用栈,确定所述第一对象在所述第二线程中的父调用节点的标识;a first determining subunit, configured to determine, according to the second call stack, the identifier of the parent calling node of the first object in the second thread;
第二确定子单元,用于确定所述目标调用信息包括所述跨线程调用指示、所述第一调用信息、以及所述第一调用节点在所述第二线程中的父调用节点的标识。A second determination subunit, configured to determine that the target call information includes the cross-thread call indication, the first call information, and the identifier of the parent call node of the first call node in the second thread.
一种可能的实现方式中,所述第一确定子单元具体用于:In a possible implementation manner, the first determination subunit is specifically used for:
若所述第二调用栈为空,则确定所述第一对象在所述第二线程中的父调用节点的标识为空;或者,If the second call stack is empty, determine that the identifier of the parent calling node of the first object in the second thread is empty; or,
若所述第二调用栈不为空,则将所述第二调用栈中栈顶调用节点的标识,确定为所述第一对象在所述第二线程中的父调用节点的标识。If the second call stack is not empty, the identifier of the call node at the top of the stack in the second call stack is determined as the identifier of the parent call node of the first object in the second thread.
一种可能的实现方式中,所述第二处理模块1003还包括:In a possible implementation manner, the
第三生成单元,用于根据所述目标调用信息生成第二调用节点;a third generating unit, configured to generate a second calling node according to the target calling information;
更新单元,用于将所述第二调用节点更新为所述第二调用栈的栈顶。An update unit, configured to update the second call node to the top of the second call stack.
一种可能的实现方式中,所述第一处理模块1001具体用于:In a possible implementation manner, the
获取所述第一对象的类型,所述第一对象的类型为第一类型或者第二类型,所述第一类型的对象的执行行为可被拦截,所述第二类型的对象的执行行为不可被拦截;Obtain the type of the first object, the type of the first object is the first type or the second type, the execution behavior of the first type object can be intercepted, and the execution behavior of the second type object cannot be intercepted;
若所述第一对象的类型为所述第一类型,则生成所述第一对象对应的辅助对象。If the type of the first object is the first type, an auxiliary object corresponding to the first object is generated.
一种可能的实现方式中,所述第一处理模块1001还用于:若所述第一对象的类型为所述第二类型,则对所述第一对象和所述第一调用信息进行包装得到包装对象;In a possible implementation manner, the
所述传递模块1002还用于:将所述包装对象传递至所述第二线程;The
所述第二处理模块1003还用于:通过所述第二线程执行所述包装对象。The
本实施例提供的调用信息的处理装置,可用于执行上述任一方法实施例中的技术方案,其实现原理和技术效果类似,此处不作赘述。The apparatus for processing invocation information provided in this embodiment can be used to execute the technical solutions in any of the above method embodiments, and the implementation principles and technical effects thereof are similar, and will not be repeated here.
根据本公开的实施例,本公开还提供了一种电子设备和一种可读存储介质。According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
根据本公开的实施例,本公开还提供了一种计算机程序产品,计算机程序产品包括:计算机程序,计算机程序存储在可读存储介质中,电子设备的至少一个处理器可以从可读存储介质读取计算机程序,至少一个处理器执行计算机程序使得电子设备执行上述任一实施例提供的方案。According to an embodiment of the present disclosure, the present disclosure also provides a computer program product, the computer program product includes: a computer program, the computer program is stored in a readable storage medium, and at least one processor of the electronic device can read from the readable storage medium A computer program is taken, and at least one processor executes the computer program so that the electronic device executes the solution provided by any of the foregoing embodiments.
图11示出了可以用来实施本公开的实施例的示例电子设备1100的示意性框图。电子设备旨在表示各种形式的数字计算机,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备和其它类似的计算装置。本文所示的部件、它们的连接和关系、以及它们的功能仅仅作为示例,并且不意在限制本文中描述的和/或者要求的本公开的实现。11 shows a schematic block diagram of an example
如图11所示,电子设备1100包括计算单元1101,其可以根据存储在只读存储器(ROM)1102中的计算机程序或者从存储单元1108加载到随机访问存储器(RAM)1103中的计算机程序,来执行各种适当的动作和处理。在RAM 1103中,还可存储设备1100操作所需的各种程序和数据。计算单元1101、ROM 1102以及RAM 1103通过总线1104彼此相连。输入/输出(I/O)接口1105也连接至总线1104。As shown in FIG. 11 , the
设备1100中的多个部件连接至I/O接口1105,包括:输入单元1106,例如键盘、鼠标等;输出单元1107,例如各种类型的显示器、扬声器等;存储单元1108,例如磁盘、光盘等;以及通信单元1109,例如网卡、调制解调器、无线通信收发机等。通信单元1109允许设备1100通过诸如因特网的计算机网络和/或各种电信网络与其他设备交换信息/数据。Various components in the
计算单元1101可以是各种具有处理和计算能力的通用和/或专用处理组件。计算单元1101的一些示例包括但不限于中央处理单元(CPU)、图形处理单元(GPU)、各种专用的人工智能(AI)计算芯片、各种运行机器学习模型算法的计算单元、数字信号处理器(DSP)、以及任何适当的处理器、控制器、微控制器等。计算单元1101执行上文所描述的各个方法和处理,例如调用信息的处理方法。例如,在一些实施例中,调用信息的处理方法可被实现为计算机软件程序,其被有形地包含于机器可读介质,例如存储单元1108。在一些实施例中,计算机程序的部分或者全部可以经由ROM 1102和/或通信单元1109而被载入和/或安装到设备1100上。当计算机程序加载到RAM 1103并由计算单元1101执行时,可以执行上文描述的调用信息的处理方法的一个或多个步骤。备选地,在其他实施例中,计算单元1101可以通过其他任何适当的方式(例如,借助于固件)而被配置为执行调用信息的处理方法。
本文中以上描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、场可编程门阵列(FPGA)、专用集成电路(ASIC)、专用标准产品(ASSP)、芯片上系统的系统(SOC)、负载可编程逻辑设备(CPLD)、计算机硬件、固件、软件、和/或它们的组合中实现。这些各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和/或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。Various implementations of the systems and techniques described herein above may be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips system (SOC), load programmable logic device (CPLD), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include being implemented in one or more computer programs executable and/or interpretable on a programmable system including at least one programmable processor that The processor, which may be a special purpose or general-purpose programmable processor, may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device an output device.
用于实施本公开的方法的程序代码可以采用一个或多个编程语言的任何组合来编写。这些程序代码可以提供给通用计算机、专用计算机或其他可编程数据处理装置的处理器或控制器,使得程序代码当由处理器或控制器执行时使流程图和/或框图中所规定的功能/操作被实施。程序代码可以完全在机器上执行、部分地在机器上执行,作为独立软件包部分地在机器上执行且部分地在远程机器上执行或完全在远程机器或服务器上执行。Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer or other programmable data processing apparatus, such that the program code, when executed by the processor or controller, performs the functions/functions specified in the flowcharts and/or block diagrams. Action is implemented. The program code may execute entirely on the machine, partly on the machine, partly on the machine and partly on a remote machine as a stand-alone software package or entirely on the remote machine or server.
在本公开的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in connection with the instruction execution system, apparatus or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media may include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media would include one or more wire-based electrical connections, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read only memory (EPROM or flash memory), fiber optics, compact disk read only memory (CD-ROM), optical storage, magnetic storage, or any suitable combination of the foregoing.
为了提供与用户的交互,可以在计算机上实施此处描述的系统和技术,该计算机具有:用于向用户显示信息的显示装置(例如,CRT(阴极射线管)或者LCD(液晶显示器)监视器);以及键盘和指向装置(例如,鼠标或者轨迹球),用户可以通过该键盘和该指向装置来将输入提供给计算机。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。To provide interaction with a user, the systems and techniques described herein may be implemented on a computer having a display device (eg, a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user ); and a keyboard and pointing device (eg, a mouse or trackball) through which a user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (eg, visual feedback, auditory feedback, or tactile feedback); and can be in any form (including acoustic input, voice input, or tactile input) to receive input from the user.
可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(LAN)、广域网(WAN)和互联网。The systems and techniques described herein may be implemented on a computing system that includes back-end components (eg, as a data server), or a computing system that includes middleware components (eg, an application server), or a computing system that includes front-end components (eg, a user's computer having a graphical user interface or web browser through which a user may interact with implementations of the systems and techniques described herein), or including such backend components, middleware components, Or any combination of front-end components in a computing system. The components of the system may be interconnected by any form or medium of digital data communication (eg, a communication network). Examples of communication networks include: Local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
计算机系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。服务器可以是云服务器,又称为云计算服务器或云主机,是云计算服务体系中的一项主机产品,以解决了传统物理主机与VPS服务("Virtual Private Server",或简称"VPS")中,存在的管理难度大,业务扩展性弱的缺陷。服务器也可以为分布式系统的服务器,或者是结合了区块链的服务器。A computer system can include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server arises by computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also known as a cloud computing server or a cloud host. It is a host product in the cloud computing service system to solve the traditional physical host and VPS service ("Virtual Private Server", or "VPS" for short). , there are the defects of difficult management and weak business expansion. The server can also be a server of a distributed system, or a server combined with a blockchain.
应该理解,可以使用上面所示的各种形式的流程,重新排序、增加或删除步骤。例如,本发申请中记载的各步骤可以并行地执行也可以顺序地执行也可以不同的次序执行,只要能够实现本公开公开的技术方案所期望的结果,本文在此不进行限制。It should be understood that steps may be reordered, added or deleted using the various forms of flow shown above. For example, the steps described in the present application can be executed in parallel, sequentially or in different orders, and as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, no limitation is imposed herein.
上述具体实施方式,并不构成对本公开保护范围的限制。本领域技术人员应该明白的是,根据设计要求和其他因素,可以进行各种修改、组合、子组合和替代。任何在本公开的精神和原则之内所作的修改、等同替换和改进等,均应包含在本公开保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present disclosure should be included within the protection scope of the present disclosure.
Claims (18)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110527239.4A CN113238915B (en) | 2021-05-14 | 2021-05-14 | Processing method, device, device, storage medium and program for calling information |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202110527239.4A CN113238915B (en) | 2021-05-14 | 2021-05-14 | Processing method, device, device, storage medium and program for calling information |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN113238915A CN113238915A (en) | 2021-08-10 |
| CN113238915B true CN113238915B (en) | 2022-07-08 |
Family
ID=77134257
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202110527239.4A Active CN113238915B (en) | 2021-05-14 | 2021-05-14 | Processing method, device, device, storage medium and program for calling information |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN113238915B (en) |
Families Citing this family (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN114564320A (en) * | 2022-02-25 | 2022-05-31 | 苏州浪潮智能科技有限公司 | Method, device, equipment and medium for information transmission between parent threads and child threads |
| CN114816590A (en) * | 2022-04-25 | 2022-07-29 | 支付宝(杭州)信息技术有限公司 | Link information transmission method and device applied to multithreading |
Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111813465A (en) * | 2020-06-19 | 2020-10-23 | 北京字节跳动网络技术有限公司 | Information acquisition method, device, medium and equipment |
Family Cites Families (6)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| AU2003204108B1 (en) * | 2003-05-09 | 2004-11-11 | Majitek Pty Ltd | Interface for distributed objects and development platform therefor |
| US7458078B2 (en) * | 2003-11-06 | 2008-11-25 | International Business Machines Corporation | Apparatus and method for autonomic hardware assisted thread stack tracking |
| US8739189B2 (en) * | 2008-01-24 | 2014-05-27 | Mcafee, Inc. | System, method, and computer program product for invoking an application program interface within an interception of another application program interface |
| CN103246547B (en) * | 2012-02-14 | 2018-09-04 | 武汉亿阳信通科技有限公司 | The method and system of remote invocation of objects |
| CN109871290B (en) * | 2019-03-07 | 2021-02-05 | 腾讯科技(深圳)有限公司 | Call stack tracking method and device applied to Java and storage medium |
| CN111880866B (en) * | 2020-07-30 | 2024-03-12 | 广州方硅信息技术有限公司 | Cross-process callback execution method, device, equipment and storage medium |
-
2021
- 2021-05-14 CN CN202110527239.4A patent/CN113238915B/en active Active
Patent Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111813465A (en) * | 2020-06-19 | 2020-10-23 | 北京字节跳动网络技术有限公司 | Information acquisition method, device, medium and equipment |
Also Published As
| Publication number | Publication date |
|---|---|
| CN113238915A (en) | 2021-08-10 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| Burckhardt et al. | Durable functions: semantics for stateful serverless | |
| US11138031B2 (en) | Framework for authoring data loaders and data savers | |
| EP2992431B1 (en) | Activity based sampling of diagnostics data | |
| US10484506B2 (en) | Systems and processes for computer log analysis | |
| EP2386951B1 (en) | Failsafe mechanism for dynamic instrumentation of software using callbacks | |
| US8856742B2 (en) | Distributed debugging | |
| US8863096B1 (en) | Parallel symbolic execution on cluster of commodity hardware | |
| US9811356B2 (en) | Automated software configuration management | |
| CN102591899A (en) | Method and system for STREAM-BASED DEBUGGING TECHNIQUES | |
| KR20110124732A (en) | Software conditional dynamic instrumentation in specified transaction context | |
| JP2014142959A (en) | System and method for concurrent implementation of services | |
| De Heus et al. | Distributed transactions on serverless stateful functions | |
| US11321090B2 (en) | Serializing and/or deserializing programs with serializable state | |
| CN113238915B (en) | Processing method, device, device, storage medium and program for calling information | |
| CN109196476A (en) | Seamless high-performance interoperability between the different type figure of shared garbage collector | |
| Liu et al. | A robotic communication middleware combining high performance and high reliability | |
| US20180359317A1 (en) | System and method for non-intrusive context correlation across cloud services | |
| US20130212598A1 (en) | Dependency informer | |
| US8539512B2 (en) | Transactional environments for event and data binding handlers | |
| CN115794917A (en) | Method and device for importing resource data | |
| Karau et al. | Scaling Python with Ray | |
| Simonet et al. | Active Data: A Programming Model to Manage Data Life Cycle Across Heterogeneous Systems and Infrastructures | |
| Mukherjee et al. | Reliable state machines: A framework for programming reliable cloud services | |
| US20250335342A1 (en) | Ai exception interpreter | |
| Li et al. | Towards persistent memory based stateful serverless computing for big data applications |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |