Traffic statistics method and device, electronic equipment, storage medium and product
By obtaining and configuring the thread name and performing traffic statistics according to the system hierarchical structure, the problem in the existing technology that the internal thread traffic of the application cannot be counted in a fine-grained manner is solved, and the accuracy and fine-grainedness of the statistics are improved.
Patent Information
- Application Number
- CN202410685740.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-13
AI Technical Summary
The existing technology cannot perform traffic statistics on each thread within the application, resulting in coarse-grained statistics and unable to meet fine-grained traffic statistics requirements.
By obtaining the name of each thread of the application, and configuring the thread name into the structures of different system structure layers according to the hierarchical order of the system layer, the target thread name is determined when responding to statistical requirements, and traffic statistics are performed on the thread corresponding to the thread name. .
It implements traffic statistics in units of threads, improves the accuracy and fine-grainedness of traffic statistics, and meets the traffic statistics requirements for each thread.
Smart Images

Figure CN118646680A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of traffic statistics, and in particular to a method, device, electronic equipment, storage medium and product for traffic statistics. Background Art
[0002] The reason why applications can develop rapidly in a short period of time is that they meet the needs of society and people's lives, and the diversity of applications is the reason why they can have a long-term impact on people's lives. However, different applications will generate a lot of traffic, and it is necessary to count the traffic generated in the applications.
[0003] There are many interfaces for traffic statistics, but the traffic statistics methods are all for traffic statistics of a certain application, and cannot be counted for threads. In other words, the existing traffic statistics are coarse-grained and cannot meet the requirements of traffic statistics for each thread. Therefore, how to perform traffic statistics for threads running inside an application has become a technical problem that needs to be solved urgently in the existing technology. Summary of the invention
[0004] The present invention provides a method, device, electronic device, storage medium and product for flow statistics, so as to solve the problem in the prior art that flow statistics according to threads cannot be satisfied.
[0005] According to one aspect of the present invention, a method for collecting traffic statistics is provided, wherein the method comprises:
[0006] Get the corresponding thread name for each thread of the application;
[0007] Allocating the thread names to structures of different system structure layers according to the hierarchical order of the system layers;
[0008] In response to the statistical requirement, a thread name matching the target thread of the statistical requirement is determined in the structure of each system structure layer, and traffic statistics are performed on the thread corresponding to the thread name.
[0009] According to another aspect of the present invention, a device for collecting traffic statistics is provided, wherein the device comprises:
[0010] A name acquisition module is used to obtain the corresponding thread name for each thread of the application;
[0011] A name configuration module, used to configure the thread name to structures of different system structure layers according to the hierarchical order of the system layer;
[0012] The traffic statistics module is used to determine, in response to a statistical requirement, a thread name matching a target thread of the statistical requirement in the structure of each system structure layer, and perform traffic statistics on the thread corresponding to the thread name.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor so that the at least one processor can execute the traffic statistics method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for collecting traffic statistics according to any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the computer program implements the method for collecting traffic statistics as described in any one of the embodiments of the present invention.
[0019] The technical solution of the embodiment of the present invention obtains the corresponding thread name for each thread of the application, configures the thread name to the structures of different system structure layers according to the hierarchical order of the system hierarchy, and determines the thread name that matches the target thread of the statistical requirement in the structure of each system structure layer in response to the statistical requirement, performs traffic statistics on the thread corresponding to the thread name, and uses the thread name as an identifier to perform traffic statistics through the thread, thereby achieving traffic statistics with a finer statistical granularity and improving the accuracy of traffic statistics.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 This is a flow chart of a method for traffic statistics provided according to Embodiment 1 of the present invention;
[0023] Figure 2 is a flow chart of another method for traffic statistics provided according to the second embodiment of the present invention;
[0024] Figure 3 This is a flow statistics block diagram in an operating system provided according to Embodiment 3 of the present invention;
[0025] Figure 4 is a flowchart of a method for traffic statistics provided according to Embodiment 3 of the present invention;
[0026] Figure 5 This is a schematic diagram of the structure of a device for collecting traffic statistics according to a fourth embodiment of the present invention;
[0027] Figure 6 It is a structural schematic diagram of an electronic device for implementing the method for traffic statistics according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment 1
[0031] Figure 11 is a flow chart of a method for performing traffic statistics according to the first embodiment of the present invention. This embodiment is applicable to the case where traffic statistics are performed according to threads. The method can be performed by a device for performing traffic statistics. The device for performing traffic statistics can be implemented in the form of hardware and / or software. The device for performing traffic statistics can be configured in an electronic device. Figure 1 As shown, the method includes:
[0032] S110. Obtain a corresponding thread name for each thread of the application.
[0033] Among them, the application can be understood as software developed and designed to complete a specific task. The application can run in electronic devices such as mobile phones and tablets. A thread is the smallest unit that the operating system can schedule operations. It is included in the process and is the actual operating unit in the process. Each thread executes different tasks in parallel. The thread name is the identification information of each thread, and the corresponding thread can be found according to the thread name.
[0034] In the embodiment of the invention, there are multiple threads in each application, and there is a corresponding thread name for each thread. The thread name can be obtained using the get Name method of the Thread class, or all thread names in the application can be extracted by calling a network socket.
[0035] S120 , configuring the thread names to structures of different system structure layers according to the hierarchical order of the system layers.
[0036] Among them, system layering is to decompose the system according to different functions and uses, and divide it into different system structure layers. Applications need to run in mobile operating systems, such as Android and iOS. For different mobile operating systems, there are system structure layers with hierarchical order. Structure refers to a custom data type that combines different types of data to form a whole. The structures corresponding to different system structure layers may have different data storage structures.
[0037] In one embodiment, the system structure layer may include at least a kernel layer, a system layer, a framework layer and an application layer; the system layer and the framework layer are connected by a preset Java native interface. Taking the Android system as an example, the kernel layer is the underlying core part of the Android system, which provides basic operating system functions, such as process management, memory management, file system management, network protocol stack, etc. At the same time, the kernel layer is also a bridge between hardware and software. It is responsible for managing and controlling hardware devices and providing hardware support for upper-layer applications. The system layer is a part of the Android operating system, located above the kernel layer, and is responsible for providing various system services and managing system resources. The framework layer is the basis for application development. It provides many commonly used application programming interfaces (Application Programming Interface, API) and tools, allowing developers to quickly and efficiently develop high-quality applications. The application layer is the part that users interact directly with, and it includes various applications and services. The preset Java Native Interface (Java Native Interface, JNI) refers to a pre-set programming framework for the Java language to interact with other programming languages (such as C, C++, etc.). The main function of the preset Java Native Interface is to provide a standard way for Java programs to interact with native code through a virtual machine. By pre-setting the Java Native Interface, Java programs can access low-level system functions, use existing libraries, and interact with hardware.
[0038] In an embodiment of the invention, after obtaining the thread name of the application, the thread name can be stored in the system layer of the system hierarchy. Since in the process of counting traffic, it is necessary to query the thread name layer by layer from the application layer of the system hierarchy to determine the corresponding thread. Therefore, it is necessary to propagate the thread name to the structures of different system structure layers layer by layer according to the hierarchical order of the system hierarchy. In one embodiment, the system layer can search for the thread name in the structure of the kernel layer, and store the thread name in the structure corresponding to the system layer itself. At the same time, the thread name can be added to the structure of the preset Java local interface, and the data structure of the thread name can be converted, and the thread name after the data structure conversion can be added to the structure of the framework layer, and the thread name can be reported to the application layer of the system hierarchy. The application layer receives the thread name reported by the framework layer and stores it in the corresponding structure. In one embodiment, for configuring the thread name to the structures of different system structure layers according to the hierarchical order, it can be that the previous system structure layer actively reports the thread name, or the subsequent system structure layer calls the interface to obtain the thread name. For example, the application layer can actively call the thread name stored in the architecture layer; the architecture layer can also report the thread name to the application layer.
[0039] S130 . In response to a statistical requirement, determine a thread name that matches a target thread of the statistical requirement in a structure of each system structure layer, and perform traffic statistics on threads corresponding to the thread name.
[0040] The statistical requirement refers to the traffic statistical requirement, which may include at least the target thread, the start time of the thread and the current time, so as to perform traffic statistics on the target thread in the time period between the start time and the current time of the thread.
[0041] In an embodiment of the invention, the target thread, the start time of the thread running and the current time in the statistical requirements can be extracted, and the thread name can be matched in the structure of the system structure layer layer by layer according to the target thread to determine the thread corresponding to the thread name. Then extract the uplink data traffic and downlink data traffic of the thread between the start time and the current time of the thread running, and use the uplink data traffic and the downlink data traffic as the statistical traffic. In the actual operation process, the pre-set traffic statistics interface can be called to extract the uplink data traffic and the downlink data traffic. For example, the downlink data traffic can be determined by summary Rx+=bucket.get RxBytes(); the uplink data traffic can be determined by summary Tx+=bucket.get TxBytes(). In one embodiment, when the number of target threads is multiple, the matching thread names can be put into a bucket (container), and then the downlink data traffic and the uplink data traffic of the thread corresponding to each thread name are determined respectively, and then the downlink data traffic and the uplink data traffic corresponding to the next thread are determined.
[0042] An embodiment of the present invention obtains a corresponding thread name for each thread of an application, configures the thread name to structures of different system structure layers according to the hierarchical order of the system layering, determines a thread name matching a target thread of the statistical requirement in the structure of each system structure layer in response to statistical requirements, performs traffic statistics on threads corresponding to the thread names, uses the thread names as identifiers to determine corresponding threads, and then performs traffic statistics through the threads, thereby achieving traffic statistics with a finer statistical granularity and improving the accuracy of traffic statistics.
[0043] In one embodiment, before creating a corresponding thread name for each thread of the application, the method further includes:
[0044] Create a network socket;
[0045] Create the structure of each system structure layer layer by layer according to the system hierarchy.
[0046] A network socket is an interface for communicating in a computer network, which allows applications to send and receive data over the network. Network sockets are usually provided by the operating system to provide applications with a simple and efficient way to communicate over the network. By calling a network socket, all thread names in the application can be extracted.
[0047] In the embodiment of the invention, a network socket can be created by calling a socket function. For example, the inet_socket_create function can be called to create a network socket. At the same time, the structure of each system structure layer can be defined layer by layer, and then the structure variables can be declared to complete the creation of the structure of each system structure layer. By creating a network socket and creating a structure of each system structure layer, the subsequent thread name can be extracted and saved.
[0048] In one embodiment, the method for traffic statistics further includes:
[0049] In the kernel layer of the system layer, add the permission to obtain the thread name.
[0050] In an embodiment, the acquisition permission may be added in filter.c in the kernel layer, otherwise the interface call may fail. For example, a "caseBPF_FUNC_get_current_comm; return & bpf_get_current_comm_proto;" statement may be added in filter.c to enable successful call when the thread name is obtained through the bpf_get_current_comm() function.
[0051] Embodiment 2
[0052] Figure 2 1 is a flow chart of another method for traffic statistics provided according to the second embodiment of the present invention. This embodiment is further optimized and expanded based on the above embodiment and can be combined with various optional technical solutions in the above embodiment. Figure 2 As shown, the method includes:
[0053] S210 , calling a network socket to extract all thread names in the application.
[0054] In the embodiment of the invention, a network socket may be called to extract the thread name in the application program through the network socket.
[0055] S220: Store the thread name in a structure of the kernel layer of the system hierarchy.
[0056] In an embodiment, a pid_thread_map may be constructed in advance in a structure of the kernel layer, and the obtained thread name may be stored in the pid_thread_map.
[0057] S230: Call a preset traffic statistics interface to obtain a thread name in a structure of a kernel layer of a system hierarchy, and add the thread name to a structure of a system layer of the system hierarchy.
[0058] The preset traffic statistics interface refers to a preset interface for obtaining network traffic data, and the preset traffic statistics interface may include a traffic statistics interface function, for example, a bpf_traffic_account function, etc. In an embodiment, the structure of the system layer may include a StatsKey structure.
[0059] In an embodiment, a preset traffic statistics interface may be called to extract the thread name in the structure of the kernel layer, and the thread name may be saved in the structure of the system layer. In an actual operation process, a bpf_traffic_account function may be called to obtain the thread name in the bpf_traffic_account function.
[0060] S240, calling a Java native interface function to extract a thread name from a structure of a system layer of a system hierarchy, adding the thread name to a structure of a preset Java native interface, and converting a data structure of the thread name.
[0061] Among them, the Java native interface function can be used to implement the interaction between Java and native code.
[0062] In the embodiment of the invention, a Java local interface function can be called to extract the thread name from the structure of the system layer, and the thread name can be added to the structure of the preset Java local interface to convert the thread name into a data structure that can be extracted by the framework layer. For example, the thread name can be converted into a Net / NetworkStats data structure.
[0063] S250: Add the thread name after the data structure conversion to the structure of the framework layer of the system layer, and report the thread name to the application layer of the system layer.
[0064] In the embodiment of the invention, the framework layer of the system layer can obtain the thread name after the data structure is converted, save the thread name in the local structure, and report the thread name to the application layer of the system layer.
[0065] S260: extracting the thread name from the structure of the framework layer of the system layer at the application layer of the system layer for storage.
[0066] In the embodiment of the invention, after receiving the corresponding project reported by the framework layer of the system layer, the application layer of the system layer can store the thread name in the structure.
[0067] In one embodiment, after the application layer of the system layer extracts the thread name in the structure of the framework layer of the system layer for storage, the method further includes:
[0068] The thread name reported by the framework layer of the system layer is uploaded to the preset traffic statistics interface through the application layer of the system layer.
[0069] In an embodiment, after the application layer obtains the thread name reported by the framework layer, the thread name may be uploaded to a preset traffic statistics interface so that the preset traffic statistics interface retrieves the corresponding thread according to the thread name.
[0070] S270: Extract the start time and current time of the thread running in the statistical requirement.
[0071] In the embodiment of the invention, the statistical requirement can be parsed to determine the start time and current time of the thread running in the statistical requirement.
[0072] S280 , matching the thread name corresponding to the target thread in the structure of the system structure layer layer by layer, and determining the thread corresponding to the thread name.
[0073] In the embodiment of the invention, the thread name corresponding to the target thread can be matched in the corresponding structure layer by layer in the order of application layer, architecture layer, system layer to kernel layer to determine the thread corresponding to the thread name. Since the corresponding thread cannot be determined according to the thread name at the application layer, architecture layer and system layer, it is necessary to query the kernel layer to determine the thread corresponding to the thread name.
[0074] S290, calling a preset traffic statistics interface to respectively extract the uplink data traffic and the downlink data traffic of the thread between the start time of the thread running and the current time, and taking the uplink data traffic and the downlink data traffic as the traffic of the thread.
[0075] In the embodiment of the invention, a preset traffic statistics interface can be called to extract the uplink data traffic and downlink data traffic of a thread between the start time of the thread running and the current time, and the uplink data traffic and downlink data traffic are used as the traffic of the thread. When there are multiple threads, the uplink data traffic and downlink data traffic of each thread can be determined at one time.
[0076] The embodiment of the present invention extracts all thread names in the application by calling a network socket, stores the thread names in a structure of a kernel layer of a system hierarchy, and establishes a corresponding relationship between threads and thread names; propagates the thread names from the kernel layer to the system layer, the architecture layer, and the application layer layer by layer, so as to facilitate querying the thread corresponding to the thread name from the application layer layer by layer; extracts the start time and the current time of the thread running in the statistical requirements, matches the thread name corresponding to the target thread in the structure of the system structure layer layer by layer, determines the thread corresponding to the thread name, calls a preset traffic statistics interface to respectively extract the uplink data traffic and the downlink data traffic of the thread between the start time and the current time of the thread running, uses the uplink data traffic and the downlink data traffic as the traffic of the thread, implements traffic statistics according to the thread, reduces the granularity of data traffic statistics, and improves the accuracy of traffic statistics.
[0077] Embodiment 3
[0078] Figure 3 is a flow statistics block diagram in an operating system provided according to Embodiment 3 of the present invention, such as Figure 3 As shown, this embodiment is a further description of a traffic statistics method based on the above implementation. Figure 3 As shown, the operating system includes: an application layer (Application), a framework layer (Framework), a system layer (System) and a kernel layer (Kernel).
[0079] The application layer includes a traffic mall, which can call the preset traffic statistics interface to obtain traffic information layer by layer. The framework layer includes usage network states, traffic statistics service, network statistics encoder, network statistics collection, and network statistics factory. The framework layer is connected to the system layer through the Java native interface call (JNI). The system layer includes Net.c, which is mainly responsible for the implementation of some network-related configuration, operation, management, query functions and Berkeley Packet Filter (BPF) network statistics (BPF NetworkStats). The kernel layer includes eBPF MAP, which is used to store thread names, and filter.c is used to store access permissions.
[0080] like Figure 3As shown in the figure, the arrows are the data routing during the traffic flow. In actual applications, when the system layer Net.c obtains the thread name in the eBPF MAP, it needs to obtain the access permission in filter.c, obtain the data through BPF Network Stats, and transmit the data to the framework layer through the Java local interface. The framework layer performs data flow and transmits the data to the traffic mall of the application layer for traffic statistics.
[0081] Figure 4 FIG. 1 is a flowchart of a method for traffic statistics provided according to Embodiment 3 of the present invention. Figure 4 As shown in the figure, the operating system includes the kernel layer, the system layer, the framework layer and the application layer. The system layer and the framework layer are connected through a preset Java local interface. The netd module calls inet_socket_create in the "cgroupsock / inet / cerate" node of BPF to create a network socket, and creates pid_thread_map by calling the DEFINE_BPF_MAP function to store the thread name. The kernel layer calls bpf_get_current_comm to obtain the thread name of the current network socket and saves it in pid_thread_map. The system layer obtains the thread name, saves it in the corresponding structure, and transmits the thread name to JNI. The traffic statistics interface bpf_traffic_account can obtain the thread name threadName from pid_thread_map, and add the threadName field in the StatsKey structure to save the thread name obtained by pid_thread_map. In netd, bpf_get_current_comm is called to obtain the thread name information. It is necessary to add the acquisition permission in filter.c of the kernel layer (kernel), otherwise the interface call will fail. Add the thread name to the structure of the preset Java local interface and convert the data structure of the thread name. JNI implements the conversion from states_line to net / NetworkStats data structure. Add the thread name pname to the structure (Net / NetworkStats) of the framework layer and the application layer, and upload the thread name to the preset traffic statistics interface. When the application layer (app) calls the preset traffic statistics interface (0NetworkManage) to obtain traffic, it can parse the pname in the Bucket to obtain the traffic information of each thread.
[0082] Embodiment 4
[0083] Figure 5 FIG. 4 is a schematic diagram of a flow statistics device according to a fourth embodiment of the present invention. Figure 5 As shown, the device includes: a name acquisition module 51, a name configuration module 52 and a traffic statistics module 53.
[0084] The name acquisition module 51 is used to acquire the corresponding thread name for each thread of the application program;
[0085] A name configuration module 52, used to configure thread names to structures of different system structure layers according to the hierarchical order of the system layer;
[0086] The traffic statistics module 53 is used to determine, in response to the statistical requirement, a thread name matching the target thread of the statistical requirement in the structure of each system structure layer, and perform traffic statistics on the thread corresponding to the thread name.
[0087] In an embodiment of the present invention, a name acquisition module is used to obtain a corresponding thread name for each thread of an application program. A name configuration module configures the thread name to structures of different system structure layers according to the hierarchical order of the system hierarchy. A traffic statistics module determines, in response to statistical requirements, a thread name that matches a target thread of the statistical requirements in the structure of each system structure layer, performs traffic statistics on threads corresponding to the thread names, uses the thread names as identifiers to determine corresponding threads, and then performs traffic statistics through the threads, thereby achieving traffic statistics at a finer statistical granularity and improving the accuracy of traffic statistics.
[0088] The flow statistics device further includes:
[0089] Socket creation module, used to create network sockets;
[0090] The structure creation module is used to create the structure of each system structure layer layer by layer according to the system hierarchy.
[0091] The name acquisition module 51 includes:
[0092] The name calling unit is used to call the network socket to extract all thread names in the application;
[0093] The name storage unit is used to store the thread name in a structure of the kernel layer of the system hierarchy.
[0094] The name configuration module 52 includes:
[0095] A first name configuration unit is used to call a preset traffic statistics interface to obtain a thread name in a structure of a kernel layer of a system hierarchy, and add the thread name to a structure of a system layer of the system hierarchy;
[0096] The second name configuration unit is used to call the Java local interface function to extract the thread name in the structure of the system layer of the system layer, add the thread name to the structure of the preset Java local interface, and convert the data structure of the thread name;
[0097] A third name configuration unit is used to add the thread name after the data structure is converted into a structure of the framework layer of the system layer, and report the thread name to the application layer of the system layer;
[0098] The fourth name configuration unit is used to extract the thread name in the structure of the framework layer of the system layer at the application layer of the system layer for storage.
[0099] The flow statistics device further includes:
[0100] The name reporting module is used to upload the thread name reported by the framework layer of the system layer to the preset traffic statistics interface through the application layer of the system layer.
[0101] The traffic statistics module 53 includes:
[0102] A time extraction unit is used to extract the start time and current time of the thread running in the statistical requirements;
[0103] A name matching unit, used to match the thread name corresponding to the target thread in the structure of the system structure layer layer by layer, and determine the thread corresponding to the thread name;
[0104] The traffic statistics unit is used to call a preset traffic statistics interface to respectively extract the uplink data traffic and downlink data traffic of the thread between the start time of the thread running and the current time, and use the uplink data traffic and the downlink data traffic as the traffic of the thread.
[0105] The flow statistics device further includes:
[0106] The permission configuration module is used to add the permission to obtain the thread name in the kernel layer of the system layer.
[0107] The system structure layer in the traffic statistics device at least includes a kernel layer, a system layer, a framework layer and an application layer; the system layer and the framework layer are connected via a preset Java local interface.
[0108] The device for traffic statistics provided in the embodiment of the present invention can execute the method for traffic statistics provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0109] Embodiment 5
[0110] Figure 61 is a schematic diagram of the structure of an electronic device that implements the method of traffic statistics of an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0111] like Figure 6 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0112] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0113] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the method of traffic statistics.
[0114] In some embodiments, the method for traffic statistics may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for traffic statistics described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the method for traffic statistics in any other appropriate manner (e.g., by means of firmware).
[0115] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0116] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0117] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0118] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0119] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0120] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0121] In one embodiment, the embodiment of the present invention further includes a computer program product, the computer program product includes a computer program, and when the computer program is executed by a processor, the method for traffic statistics of any embodiment of the present invention is implemented.
[0122] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0123] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0124] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for traffic statistics, characterized in that: include: Get the corresponding thread name for each thread of the application; Allocating the thread names to structures of different system structure layers according to the hierarchical order of the system layers; In response to the statistical requirement, a thread name matching the target thread of the statistical requirement is determined in the structure of each system structure layer, and traffic statistics are performed on the thread corresponding to the thread name.
2. The method according to claim 1, characterized in that: Before creating a corresponding thread name for each thread of the application, the method further includes: Create a network socket; The structures of the system structure layers are created layer by layer according to the system hierarchy.
3. The method according to claim 2, characterized in that The obtaining of a corresponding thread name for each thread of the application comprises: Calling the network socket to extract all thread names in the application; The thread name is stored in a structure of a kernel layer of the system hierarchy.
4. The method according to claim 1, characterized in that: The configuring the thread names to structures of different system structure layers according to the hierarchical order of the system layers includes: Calling a preset traffic statistics interface to obtain the thread name in the structure of the kernel layer of the system hierarchy, and adding the thread name to the structure of the system layer of the system hierarchy; Calling a Java native interface function to extract the thread name in the structure of the system layer of the system hierarchy, adding the thread name to the structure of a preset Java native interface, and converting the data structure of the thread name; Add the thread name after the data structure conversion to the structure of the framework layer of the system layer, and report the thread name to the application layer of the system layer; The thread name in the structure of the framework layer of the system layer is extracted and stored at the application layer of the system layer.
5. The method according to claim 4, characterized in that After the thread name in the structure of the framework layer of the system layer is extracted and stored at the application layer of the system layer, the method further includes: The thread name reported by the framework layer of the system layer is uploaded to a preset traffic statistics interface through the application layer of the system layer.
6. The method according to claim 1, characterized in that In response to the statistical requirement, determining, in the structure of each of the system structure layers, a thread name matching a target thread of the statistical requirement, and performing traffic statistics on the thread corresponding to the thread name, includes: Extract the start time and current time of the thread running in the statistical requirement; Matching the thread name corresponding to the target thread in the structure of the system structure layer layer by layer, and determining the thread corresponding to the thread name; The preset traffic statistics interface is called to respectively extract the uplink data traffic and the downlink data traffic of the thread between the start time of the thread running and the current time, and the uplink data traffic and the downlink data traffic are used as the traffic of the thread.
7. The method according to claim 1, characterized in that The method further comprises: In the kernel layer of the system hierarchy, an access permission for obtaining the thread name is added.
8. The method according to claim 1, characterized in that The system structure layer at least includes a kernel layer, a system layer, a framework layer and an application layer; the system layer and the framework layer are connected via a preset Java local interface.
9. A device for flow statistics, characterized in that: include: A name acquisition module is used to obtain the corresponding thread name for each thread of the application; A name configuration module, used to configure the thread name to structures of different system structure layers according to the hierarchical order of the system layer; The traffic statistics module is used to determine, in response to a statistical requirement, a thread name matching a target thread of the statistical requirement in the structure of each system structure layer, and perform traffic statistics on the thread corresponding to the thread name.
10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the traffic statistics method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method for traffic statistics according to any one of claims 1 to 8 when executed.
12. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the computer program implements the method for collecting traffic statistics according to any one of claims 1 to 8.
Citation Information
Cited By
Network index acquisition method and device, electronic equipment and storage medium
CN121056369A
