WO2023010814A1 - Method and apparatus for monitoring dio network request - Google Patents

Method and apparatus for monitoring dio network request Download PDF

Info

Publication number
WO2023010814A1
WO2023010814A1 PCT/CN2022/072070 CN2022072070W WO2023010814A1 WO 2023010814 A1 WO2023010814 A1 WO 2023010814A1 CN 2022072070 W CN2022072070 W CN 2022072070W WO 2023010814 A1 WO2023010814 A1 WO 2023010814A1
Authority
WO
WIPO (PCT)
Prior art keywords
implementation
network request
aspectd
target network
layer
Prior art date
Application number
PCT/CN2022/072070
Other languages
French (fr)
Chinese (zh)
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 网宿科技股份有限公司
Publication of WO2023010814A1 publication Critical patent/WO2023010814A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/10Active monitoring, e.g. heartbeat, ping or trace-route
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 

Definitions

  • the present application relates to the technical field of the Internet, in particular to a method and device for monitoring Dio network requests.
  • Flutter is a mobile UI framework, using the Flutter framework to quickly build high-quality native user interfaces on IOS and Android systems.
  • network requests are bound to be used.
  • Dio is a network request plug-in in the Flutter plug-in library, which supports Restful API, FormData, interceptor, request cancellation, cookie management, file upload/download, timeout, custom adapter and other operations, so developers often use Dio network request plug-in Encapsulate network requests.
  • the purpose of this application is to provide a method and device for monitoring Dio network requests, which can monitor Flutter Dio network requests without modifying any code of the application itself.
  • the present application provides a method for monitoring Dio network requests on the one hand, the method is applied to a client, and the client is constructed with a Flutter application layer and an AspectD implementation layer, and the method includes: when When the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer generates a first hook function to hook the first implementation interface to obtain a dio instance; when the Flutter application layer calls the dio instance, and when sending the target network request based on the second implementation interface, the AspectD implementation layer generates a second hook function to perform hook processing on the second implementation interface, and marks it through the second hook function The sending time stamp and response time stamp of the target network request, so as to monitor the sending time and response time of the target network request.
  • another aspect of the present application also provides a device for monitoring Dio network requests, the device is applied to the client, the client is built with a Flutter application layer, and the device includes: AspectD embedded module , for embedding the AspectD implementation layer in the Flutter application layer; the AspectD implementation layer module is used for generating a first hook function for the first implementation when the Flutter application layer initiates a target network request based on the first implementation interface The interface is hooked to obtain the dio instance, and when the Flutter application layer calls the dio instance and sends the target network request based on the second implementation interface, a second hook function is generated for the second implementation The interface performs hook processing, and marks the sending timestamp and response timestamp of the target network request through the second hook function; the network request monitoring module is configured to monitor all The sending time and response time of the target network request.
  • AspectD embedded module for embedding the AspectD implementation layer in the Flutter application layer
  • the AspectD implementation layer module is used for generating a first hook function for the first
  • another aspect of the present application also provides a device for monitoring Dio network requests, the device includes a memory and a processor, the memory is used to store a computer program, when the computer program is processed When the server is executed, the above-mentioned method for monitoring Dio network requests is implemented.
  • the technical solution provided by this application first introduces the AspectD implementation layer into the Flutter framework, and then uses the AspectD implementation layer to hook the Flutter application layer to obtain a dio instance.
  • the AspectD implementation layer can monitor the network conditions such as the sending time of the network request and the loading time of the data, and when the Flutter application layer receives the corresponding response information, the AspectD implementation layer can also monitor the response time of the network request to monitor. In this way, by using the AspectD implementation layer to trace-freely bury the specific methods and specific locations in the underlying library of the Dio network request, the sending time and response of the Dio network request can be obtained without any modification of the Flutter application code. Duration and other data indicators.
  • Fig. 1 is a schematic diagram of client software architecture in the embodiment of the present application.
  • Fig. 2 is a flowchart of a method for monitoring a Dio network request in an embodiment of the present application
  • FIG. 3 is a schematic diagram of functional modules of a device for monitoring Dio network requests in an embodiment of the present application
  • FIG. 4 is a schematic structural diagram of an apparatus for monitoring Dio network requests in an embodiment of the present application.
  • Flutter is a mobile UI framework developed in the Dart language, which can be easily compiled into local codes for different platforms. Therefore, the Flutter framework can be used to quickly build high-quality native user interfaces on IOS and Android systems. Developers are increasingly using the Flutter framework to refactor or create new products.
  • Dio is a network request plug-in in the Flutter plug-in library.
  • Dio supports Restful API, FormData, interceptor, request cancellation, cookie management, file upload/download, timeout , custom adapter and other operations, so developers often use the Dio network request plug-in to encapsulate network requests under the Flutter framework.
  • AspectD is an AOP (Aspect Oriented Programming, aspect-oriented programming) open source library for Flutter. It is used to solve the problem of AOP for Flutter. It can dynamically and uniformly add functions without modifying the source code of Flutter.
  • AOP Application Oriented Programming, aspect-oriented programming
  • AspectD is to modify app.dill to realize the application of AOP in Flutter. Specifically, AspectD generates an intermediate product by compiling aop.dart, so that the dill file contains both the original project code and the AOP code, and then operates the dill file through the Dill transformation to extract which libraries/classes/methods need to be added. AOP code to add corresponding functions to the Flutter application layer without modifying the Flutter source code.
  • FIG. 1 is a schematic diagram of the client software architecture in the embodiment of the present application
  • FIG. 2 is a flowchart of a method for monitoring Dio network requests in the embodiment of the present application.
  • the method for monitoring Dio network requests described in this application is applied to the client, and the client is built with a Flutter application layer, so that the client can run applications developed based on the Flutter framework.
  • the Flutter application layer uses the Dio network request plug-in to encapsulate the network request.
  • the specific form of the client includes but is not limited to terminal devices such as mobile phones, tablet computers, and notebook computers.
  • the method for monitoring Dio network requests may include the following steps.
  • S101 Embedding an AspectD implementation layer in the Flutter application layer, so that when the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer generates a first hook function to the first implementation interface Perform hook processing to obtain a dio instance.
  • the developer can pre-set the entry point of the AspectD implementation layer for the Flutter application layer according to actual needs (such as monitoring the sending time and response time of network requests), and embed the set AspectD implementation layer into Flutter In the application layer, the AspectD implementation layer is used to monitor Dio network requests.
  • embedding the AspectD implementation layer in the Flutter application layer can be implemented in the following manner:
  • developers can first download the Flutter source code and AspectD source code, and then set environment variables such as the flutter image, local flutter source code address, flutter bin directory, dart bin directory, etc., and then switch to the git directory of Flutter, and copy the The git patch file is merged into the Flutter source code project, so that the AspectD source code is injected into the Flutter framework to complete the construction of the AspectD environment.
  • the Flutter application layer can use the Dio network request plug-in to initiate a network request.
  • the Flutter application layer can use the get or post method in the Dio network request plug-in to initiate a network request.
  • the Dio network request plug-in will create a dio_sendRequest_func interface (called the first implementation interface), and use the above-mentioned first implementation interface to create a dio instance.
  • the Flutter application layer can pass The dio instance initiates a network request (called a target network request).
  • the Dio network request plug-in can obtain the request header information and request body information of the target network request through the fetch method, and then encapsulate the target network request .
  • the Dio network request plug-in can send the encapsulated target network request to the external network through the corresponding interface.
  • the Dio network request plug-in can create a dio_fetch_func interface (called the second implementation interface), and then use this interface to send a packaged target network request to the outside. Therefore, if the developer needs to monitor the Dio network request, the developer can use the above-mentioned first implementation interface and the above-mentioned second implementation interface as the entry point of the AspectD implementation layer.
  • AspectD is the AspectD source code downloaded by the developer, and the example is generic Refers to the Flutter APP application that needs to be monitored (such as the Dio network request plug-in).
  • the AspectD implementation layer can obtain the corresponding dependencies from the aspectd_impl package at runtime to implement the corresponding functions.
  • the AspectD implementation layer may generate a first hook function to hook the above-mentioned first implementation interface to obtain a dio instance.
  • the AspectD implementation layer can monitor the first implementation interface (ie, the dio_sendRequest_func interface) during runtime. Specifically, the AspectD implementation layer may use method hook technology (hook) to perform hook processing on the first implementation interface.
  • the AspectD implementation layer may first generate a hook_dio_sendRequest_func function (called the first hook function) in the aspectd_impl package, and associate the first hook function with the first implementation interface.
  • the system When the Dio network request plug-in creates the first implementation interface, the system will generate a message notification, which is used to indicate that the first implementation interface has been established, and the system will also pass the message notification to the AspectD implementation layer, so when AspectD After the implementation layer receives the message notification, the AspectD implementation layer can call the first hook function, so as to realize the hooking of the first implementation interface by the first hook function. After the first hook function hooks the first implementation interface, the first hook function can take over the first implementation interface. In this way, when the Flutter application layer creates a dio instance through the above-mentioned first implementation interface, the AspectD implementation layer can obtain the dio instance generated by the Flutter application layer.
  • the AspectD implementation layer can also set an interceptor to monitor the target network request and target response message through the interceptor, wherein the target response message is the same as the target Corresponding to the network request, that is, the target response message is the response information that the responding end feeds back to the client after receiving the target network request.
  • the AspectD implementation layer can create an interceptor class to override the onRequest, onError, and onResponse methods to do some preprocessing before the Flutter application layer sends the request, when the request fails, and before receiving the response.
  • the implementation method can be as follows Code:
  • the AspectD implementation layer needs to release the first implementation interface, so that the first implementation interface can call the second implementation interface to Outgoing target network requests. Specifically, the AspectD implementation layer can unload the first hook function to cancel the hook between the first hook function and the first call interface. In this way, the first implementation interface will be released, so that the Flutter application layer can continue to pass through the original network
  • the request sending process (that is, calling the second implementation interface through the first implementation interface) sends out the target network request.
  • the Flutter application layer is configured with a proxy channel, that is, the client needs to send the target network request to the responder through the proxy server, then after the AspectD implementation layer obtains the dio instance generated by the Flutter application layer, the AspectD implementation layer still It is necessary to set a proxy for the dio instance, so that after the target network request is sent from the client, the target network request can first reach the proxy server, and then be transferred to the responder through the proxy server.
  • the AspectD implementation layer When the Flutter application layer calls the dio instance and sends the target network request based on the second implementation interface, the AspectD implementation layer generates a second hook function to hook the second implementation interface , and mark the sending time stamp and response time stamp of the target network request through the second hook function, so as to monitor the sending time and response time of the target network request.
  • the Flutter application layer can call the above-mentioned dio instance to encapsulate the target network request, and use the second implementation interface (that is, the dio_fetch_func interface) to send the encapsulated target to the outside network request.
  • the AspectD implementation layer can monitor the second implementation interface during runtime. Specifically, the AspectD implementation layer may use a method hook technology (hook) to perform hook processing on the second implementation interface.
  • the AspectD implementation layer may first generate a hook_fetch_func function (called a second hook function) in the aspectd_impl package, and associate the second hook function with the second implementation interface.
  • the system When the Dio network request plug-in creates the second implementation interface, the system will generate a message notification, which is used to indicate that the second implementation interface has been established, and the system will also pass the message notification to the AspectD implementation layer, so when AspectD After the implementation layer receives the message notification, the AspectD implementation layer can call the second hook function, so as to realize the hooking of the second implementation interface by the second hook function. After the second hook function hooks the second implementation interface, the second hook function can take over the second implementation interface. In this way, when the Flutter application layer sends out the target network request through the second implementation interface, the AspectD implementation layer can use the second hook function to mark the sending timestamp of the target network request.
  • the AspectD implementation layer can use the second hook function to mark the response timestamp of the target network request. After marking the sending time stamp and response time stamp of the target network request, the AspectD implementation layer can report the above time stamp to the monitoring terminal, so that developers can monitor the sending time and response time of the target network request.
  • the AspectD implementation layer marking the sending timestamp of the target network request through the second hook function includes the following steps:
  • the AspectD implementation layer marks the first timestamp through the second hook function
  • the AspectD implementation layer marks the second timestamp through the second hook function.
  • AspectD implements The layer may mark the first timestamp through the second hook function.
  • the AspectD implementation layer can mark the second time through the second hook function stamp. The first timestamp and the second timestamp are the sending timestamps of the target network request.
  • the developer can calculate the sending time of the target network request based on the difference between the first timestamp and the second timestamp , and then determine whether the Flutter application or network needs to be optimized.
  • the AspectD implementation layer marking the response timestamp of the target network request through the second hook function includes the following steps:
  • the AspectD implementation layer marks the third timestamp through the second hook function
  • the AspectD implementation layer marks the fourth timestamp through the second hook function.
  • the source station that is, the responder
  • the responder will receive the target network request.
  • the responder will feed back the response information (target response message) to the client.
  • the target response message will be received by the dio_fetch_func interface, that is, the target response message will be received by Passed to the second implementation interface. Therefore, the AspectD implementation layer can use the second hook function to monitor the response time of the target network request.
  • the second hook function may mark a time point (marked as a third time stamp) before the second implementation interface receives the target response message, and mark a time point (marked as a third time stamp) after the second implementation interface receives the target response message (marked as is the fourth timestamp).
  • the aforementioned third timestamp and the aforementioned fourth timestamp are response timestamps of the target network request.
  • the developer can calculate the target network request based on the difference between the third timestamp and the fourth timestamp Response time, and then determine whether to optimize the network or the response end.
  • the interceptor monitors the target network request and target response message in the following manner:
  • parse the target network request and the target response message to obtain the request header information and request body information of the target network request, and the response header information and response body information of the target response message.
  • the interceptor can intercept the second implementation interface, so that when the Dio network request plug-in uses the second implementation interface to send out the package
  • the interceptor can obtain the above-mentioned encapsulated target network request.
  • the interceptor can analyze the target network request, so as to obtain request header information and request body information of the target network request.
  • the interceptor can report the above request header information and request body information to the monitoring end, so that the developer can monitor the target network request Analysis to monitor target network requests. For example, the interceptor can analyze the target network request to obtain the cookie information, token information, host information, etc. stored in the request header information, as well as the post parameters and parameter data stored in the request body information, and then intercept The controller can report the obtained above information to the monitoring terminal. After the interceptor finishes reporting the request header information and request body information of the target network request, the interceptor will return the above target network request to the Flutter application layer, so that the Flutter application layer can continue to send the target network request outward.
  • the interceptor when the second implementation interface receives the target response message fed back by the responder, the interceptor can also obtain the above target response message, and then, the interceptor can analyze the above target response message to obtain the response of the target response message Header information and response body information. Furthermore, after the interceptor obtains the response header information and response body information of the target response message, the interceptor can report the above response header information and response body information to the monitoring terminal, so that the developer can monitor the target response message Analysis to realize the monitoring of target response messages.
  • the interceptor can return the above target response message to the Flutter application layer, so that the Flutter application layer can The terminal displays the target response message normally.
  • the present application also provides a device for monitoring Dio network requests, the device is applied to the client, the client is built with a Flutter application layer, the device includes:
  • the AspectD embedding module is used to embed the AspectD implementation layer in the Flutter application layer;
  • the AspectD implementation layer module is used to generate a first hook function to hook the first implementation interface to obtain a dio instance when the Flutter application layer initiates a target network request based on the first implementation interface, and when the Flutter When the application layer calls the dio instance and sends the target network request based on the second implementation interface, a second hook function is generated to perform hook processing on the second implementation interface, and the second hook function is used to mark the The sending timestamp and response timestamp of the target network request;
  • a network request monitoring module configured to monitor the sending time and response time of the target network request based on the sending time stamp and the response time stamp.
  • the AspectD embedding module is also used to inject the AspectD source code into the Flutter framework to create the AspectD implementation layer in the Flutter framework;
  • the AspectD implementation layer module is further configured to add dependencies of the first implementation interface and the second implementation interface, so as to perform buried setting for the first implementation interface and the second implementation interface.
  • the device also includes:
  • An interceptor setting module configured to set an interceptor to monitor the target network request and target response message, wherein the target response message corresponds to the target network request;
  • An interface release module configured to release the first implementation interface, so that the first implementation interface invokes the second implementation interface to send the target network request.
  • marking the sending timestamp of the target network request through the second hook function includes:
  • the Flutter application layer invokes the dio instance to send the target network request, the first timestamp is marked by the second hook function;
  • the Flutter application layer calls the dio instance to complete sending the target network request, the second timestamp is marked by the second hook function.
  • marking the response timestamp of the target network request through the second hook function includes:
  • monitoring the sending duration and response duration of the target network request includes:
  • monitoring the target network request and target response messages includes:
  • Parsing the target network request and the target response message to obtain request header information and request body information of the target network request, and response header information and response body information of the target response message.
  • the present application also provides a device for monitoring Dio network requests
  • the device includes a memory and a processor
  • the memory is used to store a computer program, when the computer program is executed by the processor , the method for monitoring Dio network requests as described above can be implemented.
  • the device may include a processor, an internal bus, and a memory.
  • the memory may include internal memory and non-volatile memory.
  • the processor reads the corresponding computer program from the non-volatile memory into the memory and runs it.
  • FIG. 4 is only a schematic diagram, which does not limit the structure of the above-mentioned device.
  • the device may also include more or fewer components than those shown in FIG.
  • ⁇ 4 may also include other processing hardware, such as a GPU (Graphics Processing Unit, image processor), or an external communication port.
  • processing hardware such as a GPU (Graphics Processing Unit, image processor), or an external communication port.
  • GPU Graphics Processing Unit, image processor
  • the processor may include a central processing unit (CPU) or a graphics processing unit (GPU), and of course it may also include other single-chip microcomputers with logic processing capabilities, logic gate circuits, integrated circuits, etc., or other appropriate combination.
  • the memory described in this embodiment may be a memory device for storing information.
  • a device that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function that does not have a physical form can also be a memory, such as RAM, FIFO, etc.; in a system, a storage with a physical form A device can also be called a memory, etc.
  • the storage may also be implemented in the form of cloud storage, and the specific implementation manner is not limited in this specification.
  • the technical solution provided by this application first introduces the AspectD implementation layer into the Flutter framework, and then uses the AspectD implementation layer to hook the Flutter application layer to obtain a dio instance.
  • the AspectD implementation layer can monitor the network conditions such as the sending time of the network request and the loading time of the data, and when the Flutter application layer receives the corresponding response information, the AspectD implementation layer can also monitor the response time of the network request to monitor. In this way, by using the AspectD implementation layer to trace-freely bury the specific methods and specific locations in the underlying library of the Dio network request, the sending time and response of the Dio network request can be obtained without any modification of the Flutter application code. Duration and other data indicators.
  • the AspectD implementation layer can also monitor the request header information and request body information of the network request, as well as the response header information and response body information of the response information, so that developers can according to the monitoring situation, Targeted optimization of Flutter applications.
  • each embodiment can be implemented by means of software plus a necessary general-purpose hardware platform, and of course can also be implemented by hardware.
  • the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Environmental & Geological Engineering (AREA)
  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Debugging And Monitoring (AREA)
  • Computer And Data Communications (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

Disclosed in embodiments of the present application is a method for monitoring a dio network request. The method comprises: embedding an AspectD implementation layer into a Flutter application layer, so that when the Flutter application layer initiates a target network request on the basis of a first implementation interface, the AspectD implementation layer generates a first hook function to perform hooking processing on the first implementation interface to obtain a dio instance; and when the Flutter application layer calls the dio instance, and externally sends the target network request on the basis of a second implementation interface, the AspectD implementation layer generates a second hook function to perform hooking processing on the second implementation interface, and marks a sending timestamp and a response timestamp of the target network request by means of the second hook function.

Description

一种对Dio网络请求进行监控的方法和装置A method and device for monitoring Dio network requests
交叉引用cross reference
本申请基于申请号为“202110887717.2”、申请日为2021年08月03日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此以引入方式并入本申请。This application is based on the Chinese patent application with the application number "202110887717.2" and the filing date is August 3, 2021, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is hereby incorporated by reference. Apply.
技术领域technical field
本申请涉及互联网技术领域,特别涉及一种对Dio网络请求进行监控的方法和装置。The present application relates to the technical field of the Internet, in particular to a method and device for monitoring Dio network requests.
背景技术Background technique
Flutter是一款移动UI框架,利用Flutter框架可以快速在IOS和Android系统上构建高质量的原生用户界面。在Flutter应用开发过程中,势必需要用到网络请求。Dio是Flutter插件库中的一款网络请求插件,支持Restful API、FormData、拦截器、请求取消、Cookie管理、文件上传/下载、超时、自定义适配器等操作,因此开发者经常使用Dio网络请求插件对网络请求进行封装。Flutter is a mobile UI framework, using the Flutter framework to quickly build high-quality native user interfaces on IOS and Android systems. In the Flutter application development process, network requests are bound to be used. Dio is a network request plug-in in the Flutter plug-in library, which supports Restful API, FormData, interceptor, request cancellation, cookie management, file upload/download, timeout, custom adapter and other operations, so developers often use Dio network request plug-in Encapsulate network requests.
当一个产品开发完毕交付到用户手中后,开发者为了更好的了解用户的使用情况、数据的加载情况,通常需要对网络请求的发送时长、数据的加载时间等网络情况进行监控。然而,目前并不存在对Flutter Dio网络请求进行监控的方案。After a product is developed and delivered to the user, in order to better understand the user's usage and data loading, the developer usually needs to monitor network conditions such as the sending time of network requests and data loading time. However, currently there is no solution for monitoring Flutter Dio network requests.
鉴于此,有必要提供一种对Dio网络请求进行监控的方法和装置以解决上述不足。In view of this, it is necessary to provide a method and device for monitoring Dio network requests to solve the above-mentioned shortcomings.
发明内容Contents of the invention
本申请的目的在于提供一种对Dio网络请求进行监控的方法和装置,可以在不修改应用本身任何代码的情况下,实现对Flutter Dio网络请求的监控。The purpose of this application is to provide a method and device for monitoring Dio network requests, which can monitor Flutter Dio network requests without modifying any code of the application itself.
为实现上述目的,本申请一方面提供一种对Dio网络请求进行监控的方法,所述方法应用于客户端中,所述客户端构建有Flutter应用层和AspectD实现层,所述方法包括:当所述Flutter应用层基于第一实现接口发起目标网络请求时,所述AspectD实现层生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例;当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,所述AspectD实现层生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求 的发送时间戳和响应时间戳,以监控所述目标网络请求的发送时长和响应时长。In order to achieve the above purpose, the present application provides a method for monitoring Dio network requests on the one hand, the method is applied to a client, and the client is constructed with a Flutter application layer and an AspectD implementation layer, and the method includes: when When the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer generates a first hook function to hook the first implementation interface to obtain a dio instance; when the Flutter application layer calls the dio instance, and when sending the target network request based on the second implementation interface, the AspectD implementation layer generates a second hook function to perform hook processing on the second implementation interface, and marks it through the second hook function The sending time stamp and response time stamp of the target network request, so as to monitor the sending time and response time of the target network request.
为实现上述目的,本申请另一方面还提供一种对Dio网络请求进行监控的装置,所述装置应用于客户端中,所述客户端构建有Flutter应用层,所述装置包括:AspectD嵌入模块,用于在所述Flutter应用层中嵌入AspectD实现层;AspectD实现层模块,用于当所述Flutter应用层基于第一实现接口发起目标网络请求时,生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例,以及当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求的发送时间戳和响应时间戳;网络请求监控模块,用于基于所述发送时间戳和所述响应时间戳,监控所述目标网络请求的发送时长和响应时长。In order to achieve the above purpose, another aspect of the present application also provides a device for monitoring Dio network requests, the device is applied to the client, the client is built with a Flutter application layer, and the device includes: AspectD embedded module , for embedding the AspectD implementation layer in the Flutter application layer; the AspectD implementation layer module is used for generating a first hook function for the first implementation when the Flutter application layer initiates a target network request based on the first implementation interface The interface is hooked to obtain the dio instance, and when the Flutter application layer calls the dio instance and sends the target network request based on the second implementation interface, a second hook function is generated for the second implementation The interface performs hook processing, and marks the sending timestamp and response timestamp of the target network request through the second hook function; the network request monitoring module is configured to monitor all The sending time and response time of the target network request.
为实现上述目的,本申请另一方面还提供一种对Dio网络请求进行监控的装置,所述装置包括存储器和处理器,所述存储器用于存储计算机程序,当所述计算机程序被所述处理器执行时,实现上述对Dio网络请求进行监控的方法。In order to achieve the above purpose, another aspect of the present application also provides a device for monitoring Dio network requests, the device includes a memory and a processor, the memory is used to store a computer program, when the computer program is processed When the server is executed, the above-mentioned method for monitoring Dio network requests is implemented.
由此可见,本申请提供的技术方案,首先在Flutter框架中引入AspectD实现层,然后利用AspectD实现层对Flutter应用层进行挂钩处理,以获取dio实例,这样当Flutter应用层调用dio实例对网络请求进行封装时,AspectD实现层便可以对网络请求的发送时长、数据的加载时间等网络情况进行监控,并且当Flutter应用层接收到对应的响应信息时,AspectD实现层同样可以对网络请求的响应时长进行监控。如此,通过利用AspectD实现层对Dio网络请求底层库中的特定方法和特定位置进行无痕埋点,便可以在不对Flutter应用代码进行任何修改的情况下,获取到Dio网络请求的发送时长、响应时长等数据指标。It can be seen that the technical solution provided by this application first introduces the AspectD implementation layer into the Flutter framework, and then uses the AspectD implementation layer to hook the Flutter application layer to obtain a dio instance. When encapsulating, the AspectD implementation layer can monitor the network conditions such as the sending time of the network request and the loading time of the data, and when the Flutter application layer receives the corresponding response information, the AspectD implementation layer can also monitor the response time of the network request to monitor. In this way, by using the AspectD implementation layer to trace-freely bury the specific methods and specific locations in the underlying library of the Dio network request, the sending time and response of the Dio network request can be obtained without any modification of the Flutter application code. Duration and other data indicators.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings that need to be used in the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can also be obtained based on these drawings without creative effort.
图1是本申请实施例中客户端软件架构示意图;Fig. 1 is a schematic diagram of client software architecture in the embodiment of the present application;
图2本申请实施例中对Dio网络请求进行监控的方法的流程图;Fig. 2 is a flowchart of a method for monitoring a Dio network request in an embodiment of the present application;
图3是本申请实施例中对Dio网络请求进行监控的装置的功能模块示意图;FIG. 3 is a schematic diagram of functional modules of a device for monitoring Dio network requests in an embodiment of the present application;
图4是本申请实施例中对Dio网络请求进行监控的装置的结构示意图。FIG. 4 is a schematic structural diagram of an apparatus for monitoring Dio network requests in an embodiment of the present application.
具体实施方式Detailed ways
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施例作进一步地详细描述。In order to make the purpose, technical solution and advantages of the present application clearer, the embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings.
Flutter是一款移动UI框架,其使用Dart语言开发,Dart语言可以方便地被编译成不同平台的本地代码,因此利用Flutter框架可以快速在IOS和Android系统上构建高质量的原生用户界面,这就使得开发者越来越多的使用Flutter框架来重构或新建其产品。Flutter is a mobile UI framework developed in the Dart language, which can be easily compiled into local codes for different platforms. Therefore, the Flutter framework can be used to quickly build high-quality native user interfaces on IOS and Android systems. Developers are increasingly using the Flutter framework to refactor or create new products.
在Flutter应用开发过程中,势必需要用到网络请求,而Dio是Flutter插件库中的一款网络请求插件,Dio支持Restful API、FormData、拦截器、请求取消、Cookie管理、文件上传/下载、超时、自定义适配器等操作,因此在Flutter框架下开发者经常使用Dio网络请求插件对网络请求进行封装。In the Flutter application development process, network requests are bound to be used, and Dio is a network request plug-in in the Flutter plug-in library. Dio supports Restful API, FormData, interceptor, request cancellation, cookie management, file upload/download, timeout , custom adapter and other operations, so developers often use the Dio network request plug-in to encapsulate network requests under the Flutter framework.
当一个产品开发完毕交付到用户手中后,开发者为了更好的了解用户的使用情况、数据的加载情况,通常需要对网络请求的发送时长、数据的加载时间等网络情况进行监控。然而,目前并不存在对Flutter Dio网络请求进行监控的方案,这就使得开发者无法对Flutter应用进行针对性的优化。After a product is developed and delivered to the user, in order to better understand the user's usage and data loading, the developer usually needs to monitor network conditions such as the sending time of network requests and data loading time. However, currently there is no solution for monitoring Flutter Dio network requests, which prevents developers from optimizing Flutter applications.
因此,如何对Flutter Dio网络请求进行监控,以获取Dio网络请求的发送时长、响应时长等数据指标,便成为本领域亟待解决的问题。Therefore, how to monitor the Flutter Dio network request to obtain data indicators such as the sending time and response time of the Dio network request has become an urgent problem in this field.
本申请提供的技术方案可以解决上述不足。The technical solution provided by this application can solve the above-mentioned deficiencies.
为便于理解本申请中涉及到的AspectD内容,下面对其进行简要介绍。In order to facilitate the understanding of the AspectD content involved in this application, a brief introduction is given below.
AspectD是针对Flutter的AOP(Aspect Oriented Programming,面向切面编程)开源库,用于解决AOP for Flutter的问题,可以在不修改Flutter源代码的情况下动态统一地添加功能。AspectD is an AOP (Aspect Oriented Programming, aspect-oriented programming) open source library for Flutter. It is used to solve the problem of AOP for Flutter. It can dynamically and uniformly add functions without modifying the source code of Flutter.
Flutter在编译时,首先由编译前端将dart代码转换为中间文件app.dill,然后在debug模式下,将app.dill转换为kernel_blob.bin,在release模式下,app.dill被转换为framework。AspectD就是对app.dill进行修改,从而实现在Flutter中应用AOP。具体的,AspectD通过编译aop.dart生成中间产物,使得dill文件中既包含原始项目代码,也包含AOP代码,然后通过Dill变换对dill文件进行操作,提取出哪些库/类/方法需要添加怎样的AOP代码,从而在不修改Flutter源代码的情况下,对Flutter应用层添加相应的功能。When compiling Flutter, the front end first converts the dart code into the intermediate file app.dill, then converts app.dill into kernel_blob.bin in debug mode, and converts app.dill into framework in release mode. AspectD is to modify app.dill to realize the application of AOP in Flutter. Specifically, AspectD generates an intermediate product by compiling aop.dart, so that the dill file contains both the original project code and the AOP code, and then operates the dill file through the Dill transformation to extract which libraries/classes/methods need to be added. AOP code to add corresponding functions to the Flutter application layer without modifying the Flutter source code.
请一并参阅图1和图2,图1为本申请实施例中客户端软件架构示意图,图2为本申请实施例中对Dio网络请求进行监控的方法的流程图。Please refer to FIG. 1 and FIG. 2 together. FIG. 1 is a schematic diagram of the client software architecture in the embodiment of the present application, and FIG. 2 is a flowchart of a method for monitoring Dio network requests in the embodiment of the present application.
本申请所述对Dio网络请求进行监控的方法应用于客户端中,该客户端构建有Flutter应用层,从而使得该客户端可以运行基于Flutter框架开发的应用程序。同时,在该客户端中,Flutter应用层使用Dio网络请求插件对网络请求进行封装。需要特别指出的是,客户端的具 体形式包括但不限于手机、平板电脑、笔记本电脑等终端设备。对Dio网络请求进行监控的方法可以包括以下步骤。The method for monitoring Dio network requests described in this application is applied to the client, and the client is built with a Flutter application layer, so that the client can run applications developed based on the Flutter framework. At the same time, in the client, the Flutter application layer uses the Dio network request plug-in to encapsulate the network request. It should be pointed out that the specific form of the client includes but is not limited to terminal devices such as mobile phones, tablet computers, and notebook computers. The method for monitoring Dio network requests may include the following steps.
S101:在所述Flutter应用层中嵌入AspectD实现层,以使得当所述Flutter应用层基于第一实现接口发起目标网络请求时,所述AspectD实现层生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例。S101: Embedding an AspectD implementation layer in the Flutter application layer, so that when the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer generates a first hook function to the first implementation interface Perform hook processing to obtain a dio instance.
在本实施例中,开发者可以根据实际需要(例如对网络请求的发送时长和响应时长进行监控),预先设置AspectD实现层针对Flutter应用层的切入点,并将设置完毕的AspectD实现层嵌入Flutter应用层中,从而利用AspectD实现层监控Dio网络请求。In this embodiment, the developer can pre-set the entry point of the AspectD implementation layer for the Flutter application layer according to actual needs (such as monitoring the sending time and response time of network requests), and embed the set AspectD implementation layer into Flutter In the application layer, the AspectD implementation layer is used to monitor Dio network requests.
在一个实施例中,在Flutter应用层中嵌入AspectD实现层可以通过如下方式实现:In one embodiment, embedding the AspectD implementation layer in the Flutter application layer can be implemented in the following manner:
首先,将AspectD源码注入Flutter框架中,以在所述Flutter框架中创建所述AspectD实现层;First, inject the AspectD source code into the Flutter framework to create the AspectD implementation layer in the Flutter framework;
然后,在所述AspectD实现层中添加第一实现接口和第二实现接口的依赖项,以使得所述AspectD实现层对所述第一实现接口和所述第二实现接口进行埋点设置。Then, add dependencies of the first implementation interface and the second implementation interface in the AspectD implementation layer, so that the AspectD implementation layer performs buried setting for the first implementation interface and the second implementation interface.
在实际应用中,开发者首先可以下载Flutter源码和AspectD源码,然后设置flutter镜像、本地flutter源码地址、flutter bin目录、dart bin目录等环境变量,之后切换到Flutter的git目录,将AspectD源码中的git patch文件合并到Flutter源码工程中,从而将AspectD源码注入Flutter框架中,以完成AspectD环境的搭建。之后,开发者可以删除原有flutter sdk目录下的缓存文件(即删除原来的Flutter编译工具),并重新构建新的Flutter编译工具,然后利用flutter命令创建一个新的Flutter包(称为aspectd_impl),这样,开发者就完成了在Flutter框架中创建AspectD实现层的工作。In practical applications, developers can first download the Flutter source code and AspectD source code, and then set environment variables such as the flutter image, local flutter source code address, flutter bin directory, dart bin directory, etc., and then switch to the git directory of Flutter, and copy the The git patch file is merged into the Flutter source code project, so that the AspectD source code is injected into the Flutter framework to complete the construction of the AspectD environment. After that, developers can delete the cache files in the original flutter sdk directory (that is, delete the original Flutter compilation tool), rebuild the new Flutter compilation tool, and then use the flutter command to create a new Flutter package (called aspectd_impl), In this way, the developer has completed the work of creating the AspectD implementation layer in the Flutter framework.
在完成AspectD实现层的创建工作后,开发者还需要确定AspectD实现层针对Flutter应用层的切入点,以完成相关的操作。下文以开发者对Dio网络请求进行监控为例,对如何确定AspectD实现层的切入点进行说明。After completing the creation of the AspectD implementation layer, developers also need to determine the entry point of the AspectD implementation layer for the Flutter application layer to complete related operations. The following takes the developer's monitoring of Dio network requests as an example to explain how to determine the entry point of the AspectD implementation layer.
在实际应用中,Flutter应用层可以使用Dio网络请求插件发起一条网络请求,具体的,Flutter应用层可以使用Dio网络请求插件中的get或者post方法发起网络请求。当Flutter应用层利用Dio网络请求插件发起目标网络请求时,Dio网络请求插件将会创建dio_sendRequest_func接口(称为第一实现接口),并利用上述第一实现接口创建dio实例,最终Flutter应用层可以通过该dio实例发起网络请求(称为目标网络请求)。In practical applications, the Flutter application layer can use the Dio network request plug-in to initiate a network request. Specifically, the Flutter application layer can use the get or post method in the Dio network request plug-in to initiate a network request. When the Flutter application layer uses the Dio network request plug-in to initiate a target network request, the Dio network request plug-in will create a dio_sendRequest_func interface (called the first implementation interface), and use the above-mentioned first implementation interface to create a dio instance. Finally, the Flutter application layer can pass The dio instance initiates a network request (called a target network request).
当Flutter应用层基于上述第一实现接口,通过上述dio实例发起目标网络请求时,Dio网络请求插件可以通过fetch方法获取目标网络请求的请求头部信息和请求体信息,然后对目标 网络请求进行封装。当Dio网络请求插件完成目标网络请求的封装后,Dio网络请求插件可以通过相应的接口向外网发送封装好的目标网络请求。具体的,Dio网络请求插件可以创建dio_fetch_func接口(称为第二实现接口),然后利用该接口向外发送封装好的目标网络请求。因此,如果开发者需要对Dio网络请求进行监控,开发者可以将上述第一实现接口和上述第二实现接口作为AspectD实现层的切入点。When the Flutter application layer initiates a target network request through the above-mentioned dio instance based on the above-mentioned first implementation interface, the Dio network request plug-in can obtain the request header information and request body information of the target network request through the fetch method, and then encapsulate the target network request . After the Dio network request plug-in completes the encapsulation of the target network request, the Dio network request plug-in can send the encapsulated target network request to the external network through the corresponding interface. Specifically, the Dio network request plug-in can create a dio_fetch_func interface (called the second implementation interface), and then use this interface to send a packaged target network request to the outside. Therefore, if the developer needs to monitor the Dio network request, the developer can use the above-mentioned first implementation interface and the above-mentioned second implementation interface as the entry point of the AspectD implementation layer.
在实际应用中,当开发者完成AspectD实现层的创建工作后,其可以在aspectd_impl包中添加AspectD&example依赖项,从而对Flutt的相关库进行关联,其中,AspectD为开发者下载的AspectD源码,example泛指需要进行监控的Flutter APP应用(例如Dio网络请求插件)。当开发者在aspectd_impl包中添加AspectD&example依赖项后,AspectD实现层便可以在运行时从aspectd_impl包中获取相应的依赖项,以实现相应的功能。针对Dio网络请求监控功能,开发者可以将上述第一实现接口和上述第二实现接口的依赖项添加进aspectd_impl包中,从而使得AspectD实现层可以对上述第一实现接口和上述第二实现接口进行埋点设置。In practical applications, after the developer completes the creation of the AspectD implementation layer, he can add AspectD&example dependencies in the aspectd_impl package to associate Flutt-related libraries. AspectD is the AspectD source code downloaded by the developer, and the example is generic Refers to the Flutter APP application that needs to be monitored (such as the Dio network request plug-in). After the developer adds AspectD&example dependencies in the aspectd_impl package, the AspectD implementation layer can obtain the corresponding dependencies from the aspectd_impl package at runtime to implement the corresponding functions. For the Dio network request monitoring function, developers can add the dependencies of the above-mentioned first implementation interface and the above-mentioned second implementation interface into the aspectd_impl package, so that the AspectD implementation layer can implement the above-mentioned first implementation interface and the above-mentioned second implementation interface. Buried point settings.
在一个实施例中,当Flutter应用层基于第一实现接口发起目标网络请求时,AspectD实现层可以生成第一钩子函数对上述第一实现接口进行挂钩处理,以获取dio实例。在实际应用中,由于开发者已经在aspectd_impl包中添加了上述第一实现接口的依赖项,因此AspectD实现层在运行时可以对第一实现接口(即dio_sendRequest_func接口)进行监控。具体的,AspectD实现层可以利用方法挂钩技术(hook)对第一实现接口进行挂钩处理。AspectD实现层首先可以在aspectd_impl包中生成hook_dio_sendRequest_func函数(称为第一钩子函数),并将第一钩子函数与第一实现接口进行关联。In one embodiment, when the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer may generate a first hook function to hook the above-mentioned first implementation interface to obtain a dio instance. In practical application, since the developer has added the dependencies of the above-mentioned first implementation interface in the aspectd_impl package, the AspectD implementation layer can monitor the first implementation interface (ie, the dio_sendRequest_func interface) during runtime. Specifically, the AspectD implementation layer may use method hook technology (hook) to perform hook processing on the first implementation interface. The AspectD implementation layer may first generate a hook_dio_sendRequest_func function (called the first hook function) in the aspectd_impl package, and associate the first hook function with the first implementation interface.
由于Dio网络请求插件在创建第一实现接口时,系统会生成一个消息通知,该消息通知用于表示第一实现接口已经建立,同时系统还会将该消息通知传递到AspectD实现层,这样当AspectD实现层在接收到该消息通知后,AspectD实现层便可以调用第一钩子函数,从而实现第一钩子函数对第一实现接口的挂钩。当第一钩子函数对第一实现接口进行挂钩处理后,第一钩子函数便可以接管第一实现接口。这样,当Flutter应用层通过上述第一实现接口创建dio实例时,AspectD实现层便可以获取到Flutter应用层生成的dio实例。When the Dio network request plug-in creates the first implementation interface, the system will generate a message notification, which is used to indicate that the first implementation interface has been established, and the system will also pass the message notification to the AspectD implementation layer, so when AspectD After the implementation layer receives the message notification, the AspectD implementation layer can call the first hook function, so as to realize the hooking of the first implementation interface by the first hook function. After the first hook function hooks the first implementation interface, the first hook function can take over the first implementation interface. In this way, when the Flutter application layer creates a dio instance through the above-mentioned first implementation interface, the AspectD implementation layer can obtain the dio instance generated by the Flutter application layer.
在一个实施例中,当AspectD实现层获取到Flutter应用层生成的dio实例后,AspectD实现层还可以设置拦截器,以通过拦截器监控目标网络请求和目标响应消息,其中,目标响应消息与目标网络请求相对应,亦即目标响应消息为响应端在接收到目标网络请求后,向客户端反馈的响应信息。在实际应用中,AspectD实现层可以创建一个拦截器类来覆盖onRequest、onError、onResponse方法,以在Flutter应用层发送请求之前、请求失败时、接收响应之前做 一些预处理,其实现方式可以通过如下代码实现:In one embodiment, after the AspectD implementation layer obtains the dio instance generated by the Flutter application layer, the AspectD implementation layer can also set an interceptor to monitor the target network request and target response message through the interceptor, wherein the target response message is the same as the target Corresponding to the network request, that is, the target response message is the response information that the responding end feeds back to the client after receiving the target network request. In practical applications, the AspectD implementation layer can create an interceptor class to override the onRequest, onError, and onResponse methods to do some preprocessing before the Flutter application layer sends the request, when the request fails, and before receiving the response. The implementation method can be as follows Code:
dio=new Dio(options);dio = new Dio(options);
//添加拦截器//add interceptor
dio.interceptors.add(InterceptorsWrapper(onRequest:(RequestOptions options){dio.interceptors.add(InterceptorsWrapper(onRequest:(RequestOptions options){
print("请求之前");print("before request");
//在发送请求之前做一些预处理// Do some preprocessing before sending the request
      return options;//continuereturn options; //continue
    },onResponse:(Response response){},onResponse:(Response response){
print("响应之前");print("before response");
//在返回响应数据之前做一些预处理// Do some preprocessing before returning the response data
      return response;//continuereturn response; //continue
    },onError:(DioError e){},onError:(DioError e){
print("错误之前");print("before error");
//当请求失败时做一些预处理// Do some preprocessing when the request fails
      return e;//continuereturn e;//continue
    }));}));
由于第一实现接口和第二实现接口属于继承关系,因此,当AspectD实现层对拦截器进行设置后,AspectD实现层需要释放第一实现接口,从而使得第一实现接口可以调用第二实现接口向外发送目标网络请求。具体的,AspectD实现层可以卸载第一钩子函数,以撤销第一钩子函数与第一调用接口的挂钩,这样,第一实现接口将会被释放,从而使得Flutter应用层可以继续通过原有的网络请求发送流程(即通过第一实现接口调用第二实现接口)向外发送目标网络请求。Since the first implementation interface and the second implementation interface belong to the inheritance relationship, when the AspectD implementation layer sets the interceptor, the AspectD implementation layer needs to release the first implementation interface, so that the first implementation interface can call the second implementation interface to Outgoing target network requests. Specifically, the AspectD implementation layer can unload the first hook function to cancel the hook between the first hook function and the first call interface. In this way, the first implementation interface will be released, so that the Flutter application layer can continue to pass through the original network The request sending process (that is, calling the second implementation interface through the first implementation interface) sends out the target network request.
需要特别指出的是,如果Flutter应用层配置有代理通道,即客户端需要经过代理服务器向响应端发送目标网络请求,那么AspectD实现层在获取到Flutter应用层生成的dio实例后,AspectD实现层还需要对dio实例设置代理,从而使得目标网络请求在从客户端发出后,目标网络请求可以首先到达代理服务器,然后再经代理服务器中转到达响应端。通过在客户端和响应端之间设置代理服务器,我们可以引入CDN网络来提高用户访问网站的响应速度,从而解决因为链路问题而导致的数据加载缓慢的问题。It should be pointed out that if the Flutter application layer is configured with a proxy channel, that is, the client needs to send the target network request to the responder through the proxy server, then after the AspectD implementation layer obtains the dio instance generated by the Flutter application layer, the AspectD implementation layer still It is necessary to set a proxy for the dio instance, so that after the target network request is sent from the client, the target network request can first reach the proxy server, and then be transferred to the responder through the proxy server. By setting up a proxy server between the client and the responder, we can introduce a CDN network to improve the response speed of the user's access to the website, thereby solving the problem of slow data loading caused by link problems.
需要特别指出的是,本申请以对Dio网络请求进行监控为例进行说明只是示意性的,基于本申请的思想,本领域的技术人员也可以对其它Flutter项目进行监控。在对其它Flutter项 目进行监控时,本领域的技术人员只需根据需要确定新的AspectD实现层切入点即可。It should be pointed out that the example of monitoring Dio network requests in this application is only illustrative. Based on the idea of this application, those skilled in the art can also monitor other Flutter projects. When monitoring other Flutter projects, those skilled in the art only need to determine the new AspectD implementation layer entry point as needed.
S102:当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,所述AspectD实现层生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求的发送时间戳和响应时间戳,以监控所述目标网络请求的发送时长和响应时长。S102: When the Flutter application layer calls the dio instance and sends the target network request based on the second implementation interface, the AspectD implementation layer generates a second hook function to hook the second implementation interface , and mark the sending time stamp and response time stamp of the target network request through the second hook function, so as to monitor the sending time and response time of the target network request.
在本实施例中,当第一实现接口创建dio实例后,Flutter应用层便可以调用上述dio实例对目标网络请求进行封装,并利用第二实现接口(即dio_fetch_func接口)向外发送封装好的目标网络请求。在实际应用中,由于开发者已经在aspectd_impl包中添加了上述第二实现接口的依赖项,因此AspectD实现层在运行时可以对第二实现接口进行监控。具体的,AspectD实现层可以利用方法挂钩技术(hook)对第二实现接口进行挂钩处理。AspectD实现层首先可以在aspectd_impl包中生成hook_fetch_func函数(称为第二钩子函数),并将第二钩子函数与第二实现接口进行关联。In this embodiment, after the first implementation interface creates a dio instance, the Flutter application layer can call the above-mentioned dio instance to encapsulate the target network request, and use the second implementation interface (that is, the dio_fetch_func interface) to send the encapsulated target to the outside network request. In practical application, since the developer has added the dependencies of the above-mentioned second implementation interface in the aspectd_impl package, the AspectD implementation layer can monitor the second implementation interface during runtime. Specifically, the AspectD implementation layer may use a method hook technology (hook) to perform hook processing on the second implementation interface. The AspectD implementation layer may first generate a hook_fetch_func function (called a second hook function) in the aspectd_impl package, and associate the second hook function with the second implementation interface.
由于Dio网络请求插件在创建第二实现接口时,系统会生成一个消息通知,该消息通知用于表示第二实现接口已经建立,同时系统还会将该消息通知传递到AspectD实现层,这样当AspectD实现层在接收到该消息通知后,AspectD实现层便可以调用第二钩子函数,从而实现第二钩子函数对第二实现接口的挂钩。当第二钩子函数对第二实现接口进行挂钩处理后,第二钩子函数便可以接管第二实现接口。这样,当Flutter应用层通过第二实现接口向外发送目标网络请求时,AspectD实现层便可以利用第二钩子函数标记目标网络请求的发送时间戳。相应的,当Flutter应用层通过第二实现接口接收到响应端反馈的目标响应消息时,AspectD实现层便可以利用第二钩子函数标记目标网络请求的响应时间戳。AspectD实现层在标记完目标网络请求的发送时间戳和响应时间戳后,便可以将上述时间戳上报至监控端,从而使得开发者可以监控目标网络请求的发送时长和响应时长。When the Dio network request plug-in creates the second implementation interface, the system will generate a message notification, which is used to indicate that the second implementation interface has been established, and the system will also pass the message notification to the AspectD implementation layer, so when AspectD After the implementation layer receives the message notification, the AspectD implementation layer can call the second hook function, so as to realize the hooking of the second implementation interface by the second hook function. After the second hook function hooks the second implementation interface, the second hook function can take over the second implementation interface. In this way, when the Flutter application layer sends out the target network request through the second implementation interface, the AspectD implementation layer can use the second hook function to mark the sending timestamp of the target network request. Correspondingly, when the Flutter application layer receives the target response message fed back by the responder through the second implementation interface, the AspectD implementation layer can use the second hook function to mark the response timestamp of the target network request. After marking the sending time stamp and response time stamp of the target network request, the AspectD implementation layer can report the above time stamp to the monitoring terminal, so that developers can monitor the sending time and response time of the target network request.
在一个实施例中,AspectD实现层通过第二钩子函数标记目标网络请求的发送时间戳包括以下步骤:In one embodiment, the AspectD implementation layer marking the sending timestamp of the target network request through the second hook function includes the following steps:
首先,在Flutter应用层调用dio实例发送目标网络请求之前,AspectD实现层通过第二钩子函数标记第一时间戳;First, before the Flutter application layer calls the dio instance to send the target network request, the AspectD implementation layer marks the first timestamp through the second hook function;
然后,在Flutter应用层调用dio实例完成目标网络请求的发送之后,AspectD实现层通过第二钩子函数标记第二时间戳。Then, after the Flutter application layer invokes the dio instance to complete sending the target network request, the AspectD implementation layer marks the second timestamp through the second hook function.
在实际应用中,当Dio网络请求插件完成目标网络请求的封装,而尚未发送目标网络请求的请求头部信息和请求体信息时(即Flutter应用层调用dio实例发送目标网络请求之前), AspectD实现层可以通过第二钩子函数标记第一时间戳。当Dio网络请求插件利用第二实现接口向外发送封装好的目标网络请求时(即Flutter应用层调用dio实例完成目标网络请求的发送之后),AspectD实现层可以通过第二钩子函数标记第二时间戳。上述第一时间戳和上述第二时间戳即为目标网络请求的发送时间戳。In practical applications, when the Dio network request plug-in completes the encapsulation of the target network request, but has not yet sent the request header information and request body information of the target network request (that is, before the Flutter application layer calls the dio instance to send the target network request), AspectD implements The layer may mark the first timestamp through the second hook function. When the Dio network request plug-in uses the second implementation interface to send the encapsulated target network request (that is, after the Flutter application layer calls the dio instance to complete the sending of the target network request), the AspectD implementation layer can mark the second time through the second hook function stamp. The first timestamp and the second timestamp are the sending timestamps of the target network request.
当AspectD实现层将上述第一时间戳和上述第二时间戳上报至监控端后,开发者便可以根据第一时间戳和第二时间戳之间的差值,计算出目标网络请求的发送时长,进而判断是否需要对Flutter应用或者网络进行优化。After the AspectD implementation layer reports the above-mentioned first timestamp and the above-mentioned second timestamp to the monitoring terminal, the developer can calculate the sending time of the target network request based on the difference between the first timestamp and the second timestamp , and then determine whether the Flutter application or network needs to be optimized.
在一个实施例中,AspectD实现层通过第二钩子函数标记目标网络请求的响应时间戳包括以下步骤:In one embodiment, the AspectD implementation layer marking the response timestamp of the target network request through the second hook function includes the following steps:
首先,在第二实现接口接收到目标响应消息前,AspectD实现层通过第二钩子函数标记第三时间戳;First, before the second implementation interface receives the target response message, the AspectD implementation layer marks the third timestamp through the second hook function;
当第二实现接口接收到目标响应消息后,AspectD实现层通过第二钩子函数标记第四时间戳。After the second implementation interface receives the target response message, the AspectD implementation layer marks the fourth timestamp through the second hook function.
在实际应用中,当目标网络请求发出外网后,目标网络请求指向的源站(即响应端)将接收到目标网络请求。当响应端接收到目标网络请求后,响应端会向客户端反馈响应信息(即目标响应消息),而基于Dio网络请求插件的特点,目标响应消息将由dio_fetch_func接口负责接收,即目标响应消息会被传递至第二实现接口。因此,AspectD实现层可以利用第二钩子函数对目标网络请求的响应时间进行监控。具体的,第二钩子函数可以在第二实现接口接收到目标响应消息之前标记一个时间点(记为第三时间戳),并在第二实现接口接收到目标响应消息之后标记一个时间点(记为第四时间戳)。上述第三时间戳和上述第四时间戳即为目标网络请求的响应时间戳。In practical applications, when the target network request is sent to the external network, the source station (that is, the responder) to which the target network request points will receive the target network request. When the responder receives the target network request, the responder will feed back the response information (target response message) to the client. Based on the characteristics of the Dio network request plug-in, the target response message will be received by the dio_fetch_func interface, that is, the target response message will be received by Passed to the second implementation interface. Therefore, the AspectD implementation layer can use the second hook function to monitor the response time of the target network request. Specifically, the second hook function may mark a time point (marked as a third time stamp) before the second implementation interface receives the target response message, and mark a time point (marked as a third time stamp) after the second implementation interface receives the target response message (marked as is the fourth timestamp). The aforementioned third timestamp and the aforementioned fourth timestamp are response timestamps of the target network request.
相应的,当AspectD实现层将上述第三时间戳和上述第四时间戳上报至监控端后,开发者便可以根据第三时间戳和第四时间戳之间的差值,计算出目标网络请求的响应时长,进而判断是否需要对网络或者响应端进行优化。Correspondingly, after the AspectD implementation layer reports the third timestamp and the fourth timestamp to the monitoring terminal, the developer can calculate the target network request based on the difference between the third timestamp and the fourth timestamp Response time, and then determine whether to optimize the network or the response end.
在一个实施例中,拦截器监控目标网络请求和目标响应消息可以通过如下方式实现:In one embodiment, the interceptor monitors the target network request and target response message in the following manner:
首先,拦截第二实现接口,以获取目标网络请求和目标响应消息;First, intercept the second implementation interface to obtain the target network request and target response message;
然后,解析目标网络请求和目标响应消息,以获取目标网络请求的请求头部信息和请求体信息,以及目标响应消息的响应头部信息和响应体信息。Then, parse the target network request and the target response message to obtain the request header information and request body information of the target network request, and the response header information and response body information of the target response message.
在实际应用中,当AspectD实现层创建拦截器类以覆盖onRequest、onError、onResponse方法后,拦截器便可以对第二实现接口进行拦截,这样当Dio网络请求插件利用第二实现接 口向外发送封装好的目标网络请求时,拦截器便可以获取到上述封装好的目标网络请求。当拦截器获取到上述目标网络请求后,拦截器可以对目标网络请求进行解析,从而获取目标网络请求的请求头部信息和请求体信息。进一步的,当拦截器获取到目标网络请求的请求头部信息和请求体信息后,拦截器可以将上述请求头部信息和请求体信息上报至监控端,从而使得开发者可以对目标网络请求进行分析,以实现对目标网络请求的监控。例如,拦截器可以对目标网络请求进行解析,从而获取到请求头部信息中存放的cookie信息、token信息、host信息等,以及请求体信息中存放的post参数和参数数据等信息,之后,拦截器可以将获取到的上述信息上报至监控端。当拦截器完成目标网络请求的请求头部信息和请求体信息的上报工作后,拦截器将向Flutter应用层返回上述目标网络请求,从而使得Flutter应用层可以继续向外发送目标网络请求。In practical applications, when the AspectD implementation layer creates an interceptor class to cover the onRequest, onError, and onResponse methods, the interceptor can intercept the second implementation interface, so that when the Dio network request plug-in uses the second implementation interface to send out the package When there is a good target network request, the interceptor can obtain the above-mentioned encapsulated target network request. After the interceptor obtains the above-mentioned target network request, the interceptor can analyze the target network request, so as to obtain request header information and request body information of the target network request. Furthermore, when the interceptor obtains the request header information and request body information of the target network request, the interceptor can report the above request header information and request body information to the monitoring end, so that the developer can monitor the target network request Analysis to monitor target network requests. For example, the interceptor can analyze the target network request to obtain the cookie information, token information, host information, etc. stored in the request header information, as well as the post parameters and parameter data stored in the request body information, and then intercept The controller can report the obtained above information to the monitoring terminal. After the interceptor finishes reporting the request header information and request body information of the target network request, the interceptor will return the above target network request to the Flutter application layer, so that the Flutter application layer can continue to send the target network request outward.
相应的,当第二实现接口接收到响应端反馈的目标响应消息后,拦截器同样可以获取到上述目标响应消息,之后,拦截器可以对上述目标响应消息进行解析,从而获取目标响应消息的响应头部信息和响应体信息。进一步的,当拦截器获取到目标响应消息的响应头部信息和响应体信息后,拦截器可以将上述响应头部信息和响应体信息上报至监控端,从而使得开发者可以对目标响应消息进行分析,以实现对目标响应消息的监控。Correspondingly, when the second implementation interface receives the target response message fed back by the responder, the interceptor can also obtain the above target response message, and then, the interceptor can analyze the above target response message to obtain the response of the target response message Header information and response body information. Furthermore, after the interceptor obtains the response header information and response body information of the target response message, the interceptor can report the above response header information and response body information to the monitoring terminal, so that the developer can monitor the target response message Analysis to realize the monitoring of target response messages.
需要特别指出的是,当拦截器完成目标响应消息的响应头部信息和响应体信息的上报工作后,拦截器可以将上述目标响应消息返回给Flutter应用层,这样,Flutter应用层就可以在客户端正常展示目标响应消息。It should be pointed out that after the interceptor finishes reporting the response header information and response body information of the target response message, the interceptor can return the above target response message to the Flutter application layer, so that the Flutter application layer can The terminal displays the target response message normally.
请参阅图3,本申请还提供一种对Dio网络请求进行监控的装置,所述装置应用于客户端中,所述客户端构建有Flutter应用层,所述装置包括:Please refer to Figure 3, the present application also provides a device for monitoring Dio network requests, the device is applied to the client, the client is built with a Flutter application layer, the device includes:
AspectD嵌入模块,用于在所述Flutter应用层中嵌入AspectD实现层;The AspectD embedding module is used to embed the AspectD implementation layer in the Flutter application layer;
AspectD实现层模块,用于当所述Flutter应用层基于第一实现接口发起目标网络请求时,生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例,以及当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求的发送时间戳和响应时间戳;The AspectD implementation layer module is used to generate a first hook function to hook the first implementation interface to obtain a dio instance when the Flutter application layer initiates a target network request based on the first implementation interface, and when the Flutter When the application layer calls the dio instance and sends the target network request based on the second implementation interface, a second hook function is generated to perform hook processing on the second implementation interface, and the second hook function is used to mark the The sending timestamp and response timestamp of the target network request;
网络请求监控模块,用于基于所述发送时间戳和所述响应时间戳,监控所述目标网络请求的发送时长和响应时长。A network request monitoring module, configured to monitor the sending time and response time of the target network request based on the sending time stamp and the response time stamp.
在一个实施例中,AspectD嵌入模块,还用于将AspectD源码注入Flutter框架中,以在所述Flutter框架中创建所述AspectD实现层;In one embodiment, the AspectD embedding module is also used to inject the AspectD source code into the Flutter framework to create the AspectD implementation layer in the Flutter framework;
AspectD实现层模块,还用于添加所述第一实现接口和所述第二实现接口的依赖项,以对所述第一实现接口和所述第二实现接口进行埋点设置。The AspectD implementation layer module is further configured to add dependencies of the first implementation interface and the second implementation interface, so as to perform buried setting for the first implementation interface and the second implementation interface.
在一个实施例中,所述装置还包括:In one embodiment, the device also includes:
拦截器设置模块,用于设置拦截器,以监控所述目标网络请求和目标响应消息,其中,所述目标响应消息与所述目标网络请求相对应;An interceptor setting module, configured to set an interceptor to monitor the target network request and target response message, wherein the target response message corresponds to the target network request;
接口释放模块,用于释放所述第一实现接口,以使得所述第一实现接口调用所述第二实现接口向外发送所述目标网络请求。An interface release module, configured to release the first implementation interface, so that the first implementation interface invokes the second implementation interface to send the target network request.
在一个实施例中,通过所述第二钩子函数标记所述目标网络请求的发送时间戳包括:In one embodiment, marking the sending timestamp of the target network request through the second hook function includes:
在所述Flutter应用层调用所述dio实例发送所述目标网络请求之前,通过所述第二钩子函数标记第一时间戳;Before the Flutter application layer invokes the dio instance to send the target network request, the first timestamp is marked by the second hook function;
在所述Flutter应用层调用所述dio实例完成所述目标网络请求的发送之后,通过所述第二钩子函数标记第二时间戳。After the Flutter application layer calls the dio instance to complete sending the target network request, the second timestamp is marked by the second hook function.
在一个实施例中,通过所述第二钩子函数标记所述目标网络请求的响应时间戳包括:In one embodiment, marking the response timestamp of the target network request through the second hook function includes:
在所述第二实现接口接收到所述目标响应消息前,通过所述第二钩子函数标记第三时间戳;Before the second implementation interface receives the target response message, mark a third timestamp through the second hook function;
当所述第二实现接口接收到所述目标响应消息后,通过所述第二钩子函数标记第四时间戳。After the second implementation interface receives the target response message, mark the fourth timestamp through the second hook function.
在一个实施例中,监控所述目标网络请求的发送时长和响应时长包括:In one embodiment, monitoring the sending duration and response duration of the target network request includes:
基于所述第一时间戳和所述第二时间戳,计算所述目标网络请求的发送时长;calculating the sending duration of the target network request based on the first timestamp and the second timestamp;
基于所述第三时间戳和所述第四时间戳,计算所述目标网络请求的响应时长。Based on the third time stamp and the fourth time stamp, calculate the response duration of the target network request.
在一个实施例中,监控所述目标网络请求和目标响应消息包括:In one embodiment, monitoring the target network request and target response messages includes:
拦截所述第二实现接口,以获取所述目标网络请求和所述目标响应消息;intercepting the second implementation interface to obtain the target network request and the target response message;
解析所述目标网络请求和所述目标响应消息,以获取所述目标网络请求的请求头部信息和请求体信息,以及所述目标响应消息的响应头部信息和响应体信息。Parsing the target network request and the target response message to obtain request header information and request body information of the target network request, and response header information and response body information of the target response message.
请参阅图4,本申请还提供一种对Dio网络请求进行监控的装置,所述装置包括存储器和处理器,所述存储器用于存储计算机程序,当所述计算机程序被所述处理器执行时,可以实现如上述的对Dio网络请求进行监控的方法。具体地,在硬件层面,该装置可以包括处理器、内部总线和存储器。所述存储器可以包括内存以及非易失性存储器。处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行。本领域普通技术人员可以理解,图4所示的结构仅为示意,其并不对上述装置的结构造成限定。例如,所述装置还可包括比图4中所示 更多或者更少的组件,例如还可以包括其他的处理硬件,如GPU(Graphics Processing Unit,图像处理器),或者对外通信端口等。当然,除了软件实现方式之外,本申请并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等。Please refer to Figure 4, the present application also provides a device for monitoring Dio network requests, the device includes a memory and a processor, the memory is used to store a computer program, when the computer program is executed by the processor , the method for monitoring Dio network requests as described above can be implemented. Specifically, at the hardware level, the device may include a processor, an internal bus, and a memory. The memory may include internal memory and non-volatile memory. The processor reads the corresponding computer program from the non-volatile memory into the memory and runs it. Those of ordinary skill in the art can understand that the structure shown in FIG. 4 is only a schematic diagram, which does not limit the structure of the above-mentioned device. For example, the device may also include more or fewer components than those shown in FIG. 4 , for example, may also include other processing hardware, such as a GPU (Graphics Processing Unit, image processor), or an external communication port. Of course, in addition to the software implementation, the present application does not exclude other implementations, such as logic devices or a combination of software and hardware.
本实施例中,所述的处理器可以包括中央处理器(CPU)或图形处理器(GPU),当然也可以包括其他的具有逻辑处理能力的单片机、逻辑门电路、集成电路等,或其适当组合。本实施例所述的存储器可以是用于保存信息的记忆设备。在数字系统中,能保存二进制数据的设备可以是存储器;在集成电路中,一个没有实物形式的具有存储功能的电路也可以为存储器,如RAM、FIFO等;在系统中,具有实物形式的存储设备也可以叫存储器等。实现的时候,该存储器也可以采用云存储器的方式实现,具体实现方式,本说明书不做限定。In this embodiment, the processor may include a central processing unit (CPU) or a graphics processing unit (GPU), and of course it may also include other single-chip microcomputers with logic processing capabilities, logic gate circuits, integrated circuits, etc., or other appropriate combination. The memory described in this embodiment may be a memory device for storing information. In a digital system, a device that can store binary data can be a memory; in an integrated circuit, a circuit with a storage function that does not have a physical form can also be a memory, such as RAM, FIFO, etc.; in a system, a storage with a physical form A device can also be called a memory, etc. During implementation, the storage may also be implemented in the form of cloud storage, and the specific implementation manner is not limited in this specification.
需要说明的是,本说明书中的对Dio网络请求进行监控的装置,具体的实现方式可以参照方法实施例的描述,在此不作一一赘述。It should be noted that, the specific implementation of the device for monitoring Dio network requests in this specification can refer to the description of the method embodiment, and details are not repeated here.
由此可见,本申请提供的技术方案,首先在Flutter框架中引入AspectD实现层,然后利用AspectD实现层对Flutter应用层进行挂钩处理,以获取dio实例,这样当Flutter应用层调用dio实例对网络请求进行封装时,AspectD实现层便可以对网络请求的发送时长、数据的加载时间等网络情况进行监控,并且当Flutter应用层接收到对应的响应信息时,AspectD实现层同样可以对网络请求的响应时长进行监控。如此,通过利用AspectD实现层对Dio网络请求底层库中的特定方法和特定位置进行无痕埋点,便可以在不对Flutter应用代码进行任何修改的情况下,获取到Dio网络请求的发送时长、响应时长等数据指标。同时,通过设置拦截器,AspectD实现层还可以对网络请求的请求头部信息和请求体信息,以及响应信息的响应头部信息和响应体信息进行监控,这样,开发者便可以根据监控情况,对Flutter应用进行针对性的优化。It can be seen that the technical solution provided by this application first introduces the AspectD implementation layer into the Flutter framework, and then uses the AspectD implementation layer to hook the Flutter application layer to obtain a dio instance. When encapsulating, the AspectD implementation layer can monitor the network conditions such as the sending time of the network request and the loading time of the data, and when the Flutter application layer receives the corresponding response information, the AspectD implementation layer can also monitor the response time of the network request to monitor. In this way, by using the AspectD implementation layer to trace-freely bury the specific methods and specific locations in the underlying library of the Dio network request, the sending time and response of the Dio network request can be obtained without any modification of the Flutter application code. Duration and other data indicators. At the same time, by setting the interceptor, the AspectD implementation layer can also monitor the request header information and request body information of the network request, as well as the response header information and response body information of the response information, so that developers can according to the monitoring situation, Targeted optimization of Flutter applications.
通过以上的实施例的描述,本领域的技术人员可以清楚地了解到各实施例可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件来实现。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general-purpose hardware platform, and of course can also be implemented by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.
以上所述仅为本申请的较佳实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above descriptions are only preferred embodiments of the application, and are not intended to limit the application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the application shall be included in the protection of the application. within range.

Claims (11)

  1. 一种对Dio网络请求进行监控的方法,所述方法应用于客户端中,所述客户端构建有Flutter应用层,所述方法包括:A kind of method that Dio network request is monitored, and described method is applied in client, and described client is constructed with Flutter application layer, and described method comprises:
    在所述Flutter应用层中嵌入AspectD实现层,以使得当所述Flutter应用层基于第一实现接口发起目标网络请求时,所述AspectD实现层生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例;Embedding the AspectD implementation layer in the Flutter application layer, so that when the Flutter application layer initiates a target network request based on the first implementation interface, the AspectD implementation layer generates a first hook function to hook the first implementation interface Process to get the dio instance;
    当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,所述AspectD实现层生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求的发送时间戳和响应时间戳,以监控所述目标网络请求的发送时长和响应时长。When the Flutter application layer calls the dio instance and sends the target network request based on the second implementation interface, the AspectD implementation layer generates a second hook function to hook the second implementation interface, and The sending time stamp and response time stamp of the target network request are marked by the second hook function, so as to monitor the sending time and response time of the target network request.
  2. 根据权利要求1所述的方法,其中,所述在所述Flutter应用层中嵌入AspectD实现层,包括:The method according to claim 1, wherein said embedding AspectD implementation layer in said Flutter application layer comprises:
    将AspectD源码注入Flutter框架中,以在所述Flutter框架中创建所述AspectD实现层;Inject the AspectD source code into the Flutter framework to create the AspectD implementation layer in the Flutter framework;
    在所述AspectD实现层中添加所述第一实现接口和所述第二实现接口的依赖项,以使得所述AspectD实现层对所述第一实现接口和所述第二实现接口进行埋点设置。Adding dependencies of the first implementation interface and the second implementation interface in the AspectD implementation layer, so that the AspectD implementation layer performs buried setting for the first implementation interface and the second implementation interface .
  3. 根据权利要求1所述的方法,其中,当所述AspectD实现层获取dio实例后,所述方法还包括:The method according to claim 1, wherein, after the AspectD implementation layer obtains the dio instance, the method further comprises:
    设置拦截器,以监控所述目标网络请求和目标响应消息,其中,所述目标响应消息与所述目标网络请求相对应;setting an interceptor to monitor the target network request and target response message, wherein the target response message corresponds to the target network request;
    释放所述第一实现接口,以使得所述第一实现接口调用所述第二实现接口向外发送所述目标网络请求。The first implementation interface is released, so that the first implementation interface invokes the second implementation interface to send the target network request.
  4. 根据权利要求1所述的方法,其中,所述AspectD实现层通过所述第二钩子函数标记所述目标网络请求的发送时间戳,包括:The method according to claim 1, wherein the AspectD implementation layer marks the sending timestamp of the target network request through the second hook function, comprising:
    在所述Flutter应用层调用所述dio实例发送所述目标网络请求之前,所述AspectD实现层通过所述第二钩子函数标记第一时间戳;Before the Flutter application layer invokes the dio instance to send the target network request, the AspectD implementation layer marks the first timestamp through the second hook function;
    在所述Flutter应用层调用所述dio实例完成所述目标网络请求的发送之后,所述AspectD实现层通过所述第二钩子函数标记第二时间戳。After the Flutter application layer invokes the dio instance to complete sending the target network request, the AspectD implementation layer marks a second timestamp through the second hook function.
  5. 根据权利要求4所述的方法,其中,所述AspectD实现层通过所述第二钩子函数标记所述目标网络请求的响应时间戳,包括:The method according to claim 4, wherein the AspectD implementation layer marks the response timestamp of the target network request through the second hook function, comprising:
    在所述第二实现接口接收到所述目标响应消息前,所述AspectD实现层通过所述第二钩子函数标记第三时间戳;Before the second implementation interface receives the target response message, the AspectD implementation layer marks a third timestamp through the second hook function;
    当所述第二实现接口接收到所述目标响应消息后,所述AspectD实现层通过所述第二钩子函数标记第四时间戳。After the second implementation interface receives the target response message, the AspectD implementation layer marks a fourth timestamp through the second hook function.
  6. 根据权利要求5所述的方法,其中,所述监控所述目标网络请求的发送时长和响应时长,包括:The method according to claim 5, wherein the monitoring the sending duration and response duration of the target network request comprises:
    基于所述第一时间戳和所述第二时间戳,计算所述目标网络请求的发送时长;calculating the sending duration of the target network request based on the first timestamp and the second timestamp;
    基于所述第三时间戳和所述第四时间戳,计算所述目标网络请求的响应时长。Based on the third time stamp and the fourth time stamp, calculate the response duration of the target network request.
  7. 根据权利要求3所述的方法,其中,所述监控所述目标网络请求和目标响应消息,包括:The method according to claim 3, wherein said monitoring said target network request and target response messages comprises:
    拦截所述第二实现接口,以获取所述目标网络请求和所述目标响应消息;intercepting the second implementation interface to obtain the target network request and the target response message;
    解析所述目标网络请求和所述目标响应消息,以获取所述目标网络请求的请求头部信息和请求体信息,以及所述目标响应消息的响应头部信息和响应体信息。Parsing the target network request and the target response message to obtain request header information and request body information of the target network request, and response header information and response body information of the target response message.
  8. 一种对Dio网络请求进行监控的装置,所述装置应用于客户端中,所述客户端构建有Flutter应用层,所述装置包括:A kind of device that Dio network request is monitored, and described device is applied in client, and described client is built with Flutter application layer, and described device comprises:
    AspectD嵌入模块,用于在所述Flutter应用层中嵌入AspectD实现层;The AspectD embedding module is used to embed the AspectD implementation layer in the Flutter application layer;
    AspectD实现层模块,用于当所述Flutter应用层基于第一实现接口发起目标网络请求时,生成第一钩子函数对所述第一实现接口进行挂钩处理,以获取dio实例,以及当所述Flutter应用层调用所述dio实例,并基于第二实现接口向外发送所述目标网络请求时,生成第二钩子函数对所述第二实现接口进行挂钩处理,并通过所述第二钩子函数标记所述目标网络请求的发送时间戳和响应时间戳;The AspectD implementation layer module is used to generate a first hook function to hook the first implementation interface to obtain a dio instance when the Flutter application layer initiates a target network request based on the first implementation interface, and when the Flutter When the application layer calls the dio instance and sends the target network request based on the second implementation interface, a second hook function is generated to perform hook processing on the second implementation interface, and the second hook function is used to mark the The sending timestamp and response timestamp of the target network request;
    网络请求监控模块,用于基于所述发送时间戳和所述响应时间戳,监控所述目标网络请求的发送时长和响应时长。A network request monitoring module, configured to monitor the sending time and response time of the target network request based on the sending time stamp and the response time stamp.
  9. 根据权利要求8所述的装置,其中,所述AspectD嵌入模块,还用于将AspectD源码注入Flutter框架中,以在所述Flutter框架中创建所述AspectD实现层;The device according to claim 8, wherein the AspectD embedding module is also used to inject the AspectD source code into the Flutter framework to create the AspectD implementation layer in the Flutter framework;
    所述AspectD实现层模块,还用于添加所述第一实现接口和所述第二实现接口的依赖项,以对所述第一实现接口和所述第二实现接口进行埋点设置。The AspectD implementation layer module is further configured to add dependencies of the first implementation interface and the second implementation interface, so as to perform buried setting for the first implementation interface and the second implementation interface.
  10. 根据权利要求8所述的装置,其中,所述装置还包括:The device according to claim 8, wherein the device further comprises:
    拦截器设置模块,用于设置拦截器,以监控所述目标网络请求和目标响应消息,其中,所述目标响应消息与所述目标网络请求相对应;An interceptor setting module, configured to set an interceptor to monitor the target network request and target response message, wherein the target response message corresponds to the target network request;
    接口释放模块,用于释放所述第一实现接口,以使得所述第一实现接口调用所述第二实现接口向外发送所述目标网络请求。An interface release module, configured to release the first implementation interface, so that the first implementation interface invokes the second implementation interface to send the target network request.
  11. 一种对Dio网络请求进行监控的装置,所述装置包括存储器和处理器,所述存储器用于存储计算机程序,当所述计算机程序被所述处理器执行时,实现如权利要求1至7中任一权利要求所述的方法。A device for monitoring a Dio network request, the device includes a memory and a processor, the memory is used to store a computer program, and when the computer program is executed by the processor, the implementation of claims 1 to 7 A method as claimed in any one of the claims.
PCT/CN2022/072070 2021-08-03 2022-01-14 Method and apparatus for monitoring dio network request WO2023010814A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110887717.2A CN113765740B (en) 2021-08-03 2021-08-03 Method and device for monitoring Dio network request
CN202110887717.2 2021-08-03

Publications (1)

Publication Number Publication Date
WO2023010814A1 true WO2023010814A1 (en) 2023-02-09

Family

ID=78788470

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/072070 WO2023010814A1 (en) 2021-08-03 2022-01-14 Method and apparatus for monitoring dio network request

Country Status (2)

Country Link
CN (1) CN113765740B (en)
WO (1) WO2023010814A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113765740B (en) * 2021-08-03 2022-12-20 网宿科技股份有限公司 Method and device for monitoring Dio network request
CN114363204A (en) * 2021-12-09 2022-04-15 网宿科技股份有限公司 Request monitoring method, network device and storage medium
CN114745415B (en) * 2022-03-17 2024-03-26 中汽创智科技有限公司 Vehicle service communication data processing method, device, equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050203904A1 (en) * 2004-03-11 2005-09-15 International Business Machines Corporation System and method for measuring latch contention
US20120117644A1 (en) * 2010-11-04 2012-05-10 Ridgeway Internet Security, Llc System and Method for Internet Security
CN103825783A (en) * 2014-03-10 2014-05-28 珠海市君天电子科技有限公司 Test method and device
CN112235357A (en) * 2020-09-23 2021-01-15 建信金融科技有限责任公司 Cross-platform application development system
CN113765740A (en) * 2021-08-03 2021-12-07 网宿科技股份有限公司 Method and device for monitoring Dio network request

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106708899B (en) * 2015-11-17 2021-04-27 阿里巴巴集团控股有限公司 Automatic point burying method and device
CN112242972B (en) * 2019-07-16 2022-06-03 腾讯科技(武汉)有限公司 Network request processing method, device, storage medium and terminal
CN110737589A (en) * 2019-09-10 2020-01-31 北京字节跳动网络技术有限公司 automatic point burying method, device, medium and electronic equipment
CN111090433B (en) * 2019-10-23 2023-10-20 贝壳技术有限公司 Data processing method, device and storage medium
CN111314419B (en) * 2020-01-16 2023-01-10 广州酷狗计算机科技有限公司 Network request method and device
CN112463519A (en) * 2020-11-05 2021-03-09 广州博恒信息科技有限责任公司 Flatter-based page use behavior data non-buried point statistical method, equipment and storage medium
CN112953969A (en) * 2021-03-30 2021-06-11 平安科技(深圳)有限公司 Network request response method and device, computer equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050203904A1 (en) * 2004-03-11 2005-09-15 International Business Machines Corporation System and method for measuring latch contention
US20120117644A1 (en) * 2010-11-04 2012-05-10 Ridgeway Internet Security, Llc System and Method for Internet Security
CN103825783A (en) * 2014-03-10 2014-05-28 珠海市君天电子科技有限公司 Test method and device
CN112235357A (en) * 2020-09-23 2021-01-15 建信金融科技有限责任公司 Cross-platform application development system
CN113765740A (en) * 2021-08-03 2021-12-07 网宿科技股份有限公司 Method and device for monitoring Dio network request

Also Published As

Publication number Publication date
CN113765740B (en) 2022-12-20
CN113765740A (en) 2021-12-07

Similar Documents

Publication Publication Date Title
WO2023010814A1 (en) Method and apparatus for monitoring dio network request
TWI705336B (en) Equipment and method for supporting online upgrade
CN111176626B (en) Cross-programming-language code calling method and device, medium and equipment
CN111159614B (en) Webpage resource acquisition method and device
US10896404B2 (en) Computer readable storage media for dynamic service deployment and methods and systems for utilizing same
WO2019072008A1 (en) Security scanning method and apparatus for mini program, and electronic device
CN109743359B (en) Hybrid communication processing method and device, computer equipment and storage medium
CN111880987A (en) Dynamic monitoring method and device of application program, storage medium and electronic device
Chen et al. Instaguard: Instantly deployable hot-patches for vulnerable system programs on android
CN109784039B (en) Construction method of safe operation space of mobile terminal, electronic equipment and storage medium
CN107577609A (en) A kind of embedded system dynamic module adjustment method of Intrusion Detection based on host end dynamic link
CN109725887B (en) Data interaction method and device based on message research and development framework and terminal equipment
CN110895468A (en) Method and device for realizing service enhancement
CN110928571A (en) Business program development method and device
CN113467784A (en) Application program processing method and device and computer readable storage medium
Tang et al. Xdebloat: Towards automated feature-oriented app debloating
CN109508249B (en) Crash processing method and device and electronic equipment
CN106778269B (en) Method and device for preventing injection of driving layer and client
CN113553088A (en) Patch package distribution method and device, computer equipment and storage medium
WO2023083071A1 (en) View interaction method and apparatus, electronic device, and computer readable medium
CN110825373A (en) Dynamic method and device for mobile terminal
CN114327404A (en) File processing method and device, electronic equipment and computer readable medium
Zhou et al. MCAF: Developing an Annotation‐Based Offloading Framework for Mobile Cloud Computing
CN107450946B (en) Chrome webpage and terminal software communication method, equipment and storage medium
WO2020015151A1 (en) Parameter insertion method and apparatus for database table, terminal device, and storage medium

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: 22851542

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE