[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN107743080B - Flow statistical method and device, computer equipment and computer readable storage medium - Google Patents

Flow statistical method and device, computer equipment and computer readable storage medium Download PDF

Info

Publication number
CN107743080B
CN107743080B CN201710924596.8A CN201710924596A CN107743080B CN 107743080 B CN107743080 B CN 107743080B CN 201710924596 A CN201710924596 A CN 201710924596A CN 107743080 B CN107743080 B CN 107743080B
Authority
CN
China
Prior art keywords
data
moment
file
terminal
traffic
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710924596.8A
Other languages
Chinese (zh)
Other versions
CN107743080A (en
Inventor
晏印
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
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 Guangdong Oppo Mobile Telecommunications Corp Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN201710924596.8A priority Critical patent/CN107743080B/en
Publication of CN107743080A publication Critical patent/CN107743080A/en
Application granted granted Critical
Publication of CN107743080B publication Critical patent/CN107743080B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • H04L43/0876Network utilisation, e.g. volume of load or congestion level
    • H04L43/0888Throughput
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2462Approximate or statistical queries
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W24/00Supervisory, monitoring or testing arrangements
    • H04W24/08Testing, supervising or monitoring using real traffic
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W28/00Network traffic management; Network resource management
    • H04W28/02Traffic management, e.g. flow control or congestion control
    • H04W28/10Flow control between communication endpoints
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W8/00Network data management
    • H04W8/18Processing of user or subscriber data, e.g. subscribed services, user preferences or user profiles; Transfer of user or subscriber data
    • H04W8/183Processing at user equipment or user record carrier
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W8/00Network data management
    • H04W8/22Processing or transfer of terminal data, e.g. status or physical capabilities
    • H04W8/24Transfer of terminal data

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Fuzzy Systems (AREA)
  • Environmental & Geological Engineering (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

本申请提供一种流量统计方法和装置、计算机设备、计算机可读存储介质。所述方法包括:获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻;从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间;从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据;根据所述第一流量数据和第二流量数据统计流量数据。上述流量统计方法和装置、计算机设备、计算机可读存储介质,提高流量统计的效率。

The present application provides a traffic statistics method and apparatus, computer equipment, and computer-readable storage medium. The method includes: obtaining a first moment and a second moment, the first moment being later than the second moment; reading first traffic data from a first file, the first file being used to store traffic data consumed by the terminal from a third moment to the first moment, the third moment being between the first moment and the second moment; reading second traffic data from a second file, the second file being used to store traffic data consumed by the terminal before the first moment, the second traffic data representing traffic data consumed by the terminal from the second moment to the third moment; and counting traffic data based on the first traffic data and the second traffic data. The above-mentioned traffic statistics method and apparatus, computer equipment, and computer-readable storage medium improve the efficiency of traffic statistics.

Description

流量统计方法和装置、计算机设备、计算机可读存储介质Traffic statistics method and apparatus, computer equipment, computer readable storage medium

技术领域technical field

本申请涉及计算机技术领域,特别是涉及流量统计方法和装置、计算机设备、计算机可读存储介质。The present application relates to the field of computer technology, and in particular, to a method and apparatus for traffic statistics, computer equipment, and computer-readable storage media.

背景技术Background technique

智能终端可以通过无线信号实现数据的传输,从而实现不同智能终端之间的通信。为了让用户合理使用无线信号,并使运营商实现对无线信号的合理化管理,需要对无线信号的使用情况进行实时统计,流量就是指通过无线信号实现上网或数据增值业务时所产生的数据量。一般地,智能终端在统计流量时,会调用专用的统计接口,并通过专用的统计接口来查询并统计流量的实时数据。为了实现流量的精确管理,智能终端需要实时对流量进行查询和统计,也就需要实时调用智能终端的专用统计接口。The intelligent terminal can realize data transmission through wireless signals, so as to realize the communication between different intelligent terminals. In order to allow users to use wireless signals reasonably and enable operators to achieve rational management of wireless signals, it is necessary to conduct real-time statistics on the use of wireless signals. Generally, when collecting traffic statistics, an intelligent terminal will call a dedicated statistics interface, and query and collect real-time traffic data through the dedicated statistics interface. In order to achieve accurate traffic management, the smart terminal needs to query and make statistics on the traffic in real time, so it needs to call the dedicated statistics interface of the smart terminal in real time.

发明内容SUMMARY OF THE INVENTION

本申请实施例提供一种流量统计方法和装置、计算机设备、计算机可读存储介质,可以提高流量统计的效率。Embodiments of the present application provide a traffic statistics method and apparatus, computer equipment, and a computer-readable storage medium, which can improve the efficiency of traffic statistics.

一种流量统计方法,所述方法包括:A traffic statistics method, the method includes:

获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻;obtaining a first moment and a second moment, the first moment is later than the second moment;

从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间;Read the first traffic data from the first file, where the first file is used to save the traffic data consumed by the terminal from the third time to the first time, and the third time is located between the first time and the first time. between two moments;

从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据;Read the second traffic data from the second file, where the second file is used to save the traffic data consumed by the terminal before the first moment, the second traffic data represents the terminal from the second moment to the third Traffic data consumed at three moments;

根据所述第一流量数据和第二流量数据统计流量数据。Traffic data is counted according to the first traffic data and the second traffic data.

一种流量统计装置,所述装置包括:A traffic statistics device, the device includes:

参数获取模块,用于获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻;a parameter acquisition module, configured to acquire a first moment and a second moment, the first moment being later than the second moment;

第一数据获取模块,用于从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间;The first data acquisition module is used to read the first traffic data from the first file, and the first file is used to save the traffic data consumed by the terminal from the third moment to the first moment, and the third moment is located between the first time instant and the second time instant;

第二数据获取模块,用于从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据;A second data acquisition module, configured to read second traffic data from a second file, where the second file is used to save traffic data consumed by the terminal before the first moment, and the second traffic data represents all traffic data Traffic data consumed by the terminal from the second moment to the third moment;

流量数据模块,用于根据所述第一流量数据和第二流量数据统计流量数据。The traffic data module is configured to count traffic data according to the first traffic data and the second traffic data.

一种计算机设备,包括存储器及处理器,所述存储器中储存有计算机可读指令,所述指令被所述处理器执行时,使得所述处理器执行如下步骤:A computer device, comprising a memory and a processor, wherein computer-readable instructions are stored in the memory, and when the instructions are executed by the processor, the processor is caused to perform the following steps:

获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻;obtaining a first moment and a second moment, the first moment is later than the second moment;

从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间;Read the first traffic data from the first file, where the first file is used to save the traffic data consumed by the terminal from the third time to the first time, and the third time is located between the first time and the first time. between two moments;

从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据;Read the second traffic data from the second file, where the second file is used to save the traffic data consumed by the terminal before the first moment, the second traffic data represents the terminal from the second moment to the third Traffic data consumed at three moments;

根据所述第一流量数据和第二流量数据统计流量数据。Traffic data is counted according to the first traffic data and the second traffic data.

一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如下步骤:A computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:

获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻;obtaining a first moment and a second moment, the first moment is later than the second moment;

从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间;Read the first traffic data from the first file, where the first file is used to save the traffic data consumed by the terminal from the third time to the first time, and the third time is located between the first time and the first time. between two moments;

从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据;Read the second traffic data from the second file, where the second file is used to save the traffic data consumed by the terminal before the first moment, the second traffic data represents the terminal from the second moment to the third Traffic data consumed at three moments;

根据所述第一流量数据和第二流量数据统计流量数据。Traffic data is counted according to the first traffic data and the second traffic data.

上述实施例提供的流量统计方法和装置、计算机设备、计算机可读存储介质,首先获取第一时刻和第二时刻,并根据第一时刻和第二时刻将时间段进行划分,从第一文件中读取第一流量数据,从第二文件中读取第二流量数据,并根据第一流量数据和第二流量数据统计流量数据。这样分别进行统计,提高了流量统计的效率。The traffic statistics method and device, computer equipment, and computer-readable storage medium provided by the above-mentioned embodiments first acquire the first moment and the second moment, and divide the time period according to the first moment and the second moment, and extract the data from the first file. The first traffic data is read, the second traffic data is read from the second file, and the traffic data is counted according to the first traffic data and the second traffic data. In this way, statistics are performed separately, which improves the efficiency of traffic statistics.

附图说明Description of drawings

为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without any creative effort.

图1为一个实施例中流量统计方法的应用环境图;Fig. 1 is the application environment diagram of the traffic statistics method in one embodiment;

图2为一个实施例中终端的部分架构图;2 is a partial architecture diagram of a terminal in one embodiment;

图3为一个实施例中实现虚拟SIM卡的交互时序图;Fig. 3 is the interaction sequence diagram of realizing virtual SIM card in one embodiment;

图4为一个实施例中流量统计方法的流程图;4 is a flowchart of a traffic statistics method in one embodiment;

图5为另一个实施例中流量统计方法的流程图;Fig. 5 is the flow chart of the traffic statistics method in another embodiment;

图6为一个实施例中流量统计系统的结构示意图;6 is a schematic structural diagram of a traffic statistics system in one embodiment;

图7为另一个实施例中流量统计系统的结构示意图;7 is a schematic structural diagram of a traffic statistics system in another embodiment;

图8为一个实施例中流量统计模块统计流量数据的流程图;8 is a flow chart of a flow statistics module for statistics flow data in one embodiment;

图9为另一个实施例中流量查询系统的结构示意图;9 is a schematic structural diagram of a traffic query system in another embodiment;

图10为一个实施例中存储流量数据的数据列表的示意图;10 is a schematic diagram of a data list storing traffic data in one embodiment;

图11为一个实施例中存储流量数据的数据对象的示意图;11 is a schematic diagram of a data object storing traffic data in one embodiment;

图12为一个实施例中流量统计结果的终端显示图;12 is a terminal display diagram of traffic statistics results in one embodiment;

图13为另一个实施例中流量统计结果的终端显示图;13 is a terminal display diagram of traffic statistics results in another embodiment;

图14为一个实施例中流量统计装置的结构示意图;14 is a schematic structural diagram of a flow statistics device in an embodiment;

图15为另一个实施例中流量统计装置的结构示意图;15 is a schematic structural diagram of a flow statistics device in another embodiment;

图16为一个实施例中终端内部结构框图;16 is a block diagram of the internal structure of the terminal in one embodiment;

图17为与本申请实施例提供的计算机设备相关的手机的部分结构的框图。FIG. 17 is a block diagram of a partial structure of a mobile phone related to a computer device provided by an embodiment of the present application.

具体实施方式Detailed ways

为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.

可以理解,本申请所使用的术语“第一”、“第二”等可在本文中用于描述各种元件,但这些元件不受这些术语限制。这些术语仅用于将第一个元件与另一个元件区分。举例来说,在不脱离本申请的范围的情况下,可以将第一客户端称为第二客户端,且类似地,可将第二客户端称为第一客户端。第一客户端和第二客户端两者都是客户端,但其不是同一客户端。It will be understood that the terms "first", "second", etc. used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish a first element from another element. For example, a first client may be referred to as a second client, and similarly, a second client may be referred to as a first client, without departing from the scope of this application. Both the first client and the second client are clients, but they are not the same client.

图1为一个实施例中流量统计方法的应用环境图。如图1所示,该应用环境包括服务器11和终端12。服务器11为虚拟网络运营商用于向终端12提供网络流量的服务器,可为云服务器。服务器11可向终端12提供虚拟SIM(Subscriber Identity Module,用户身份识别模块)卡信息以及使用该虚拟SIM卡实现网络通信的服务。终端12上可设置有虚拟SIM卡APP(Application,应用程序)121、虚拟SIM卡SDK(Software Development Kit,软件开发工具包)122、虚拟SIM卡操作系统123以及虚拟SIM卡适配层124。该虚拟SIM卡APP 121、虚拟SIM卡SDK122、虚拟SIM卡操作系统123以及虚拟SIM卡适配层124均可设置于终端12上的应用处理器(Application Processor,AP)内。该服务器11可通过虚拟SIM卡APP121,向虚拟SIM卡操作系统123发送虚拟SIM卡信息;虚拟SIM卡操作系统123可通过虚拟SIM卡适配层124,实现与设置在基带处理器(Baseband Processor,BP)内的射频通讯控制软件进行通信,以实现使用虚拟SIM卡进行网络通信。虚拟SIM卡SDK 122可用于虚拟SIM卡APP 121的集成和调用。其中,服务器11可以向终端12提供虚拟SIM卡APP 121相关接口,通过该接口实现和终端12之间的通信。该接口可包括用户及设备管理、套餐及订单管理、SIM资源的加密传输等接口。服务器11可以以REST ful应用程序编程接口(Application ProgrammingInterface,API)的方式向虚拟SIM卡APP 121提供相关接口。虚拟SIM卡信息可以但不限于包括虚拟SIM卡的基本信息、虚拟SIM卡购买的订单信息、虚拟SIM卡的流量使用信息、期限信息等。服务器11和终端12可以通过对产生的流量数据进行统计,并通过统计的流量数据实现对虚拟SIM卡APP121对应的用户信息的管理。FIG. 1 is an application environment diagram of a traffic statistics method in one embodiment. As shown in FIG. 1 , the application environment includes a server 11 and a terminal 12 . The server 11 is a server used by the virtual network operator to provide network traffic to the terminal 12, and may be a cloud server. The server 11 can provide the terminal 12 with virtual SIM (Subscriber Identity Module, subscriber identity module) card information and the service of implementing network communication by using the virtual SIM card. The terminal 12 may be provided with a virtual SIM card APP (Application) 121 , a virtual SIM card SDK (Software Development Kit, software development kit) 122 , a virtual SIM card operating system 123 and a virtual SIM card adaptation layer 124 . The virtual SIM card APP 121 , the virtual SIM card SDK 122 , the virtual SIM card operating system 123 and the virtual SIM card adaptation layer 124 can all be set in an application processor (Application Processor, AP) on the terminal 12 . The server 11 can send virtual SIM card information to the virtual SIM card operating system 123 through the virtual SIM card APP121; the virtual SIM card operating system 123 can be implemented and set in the baseband processor (Baseband Processor, BP) to communicate with the radio frequency communication control software in order to implement network communication using a virtual SIM card. The virtual SIM card SDK 122 can be used for integration and calling of the virtual SIM card APP 121 . The server 11 may provide the terminal 12 with an interface related to the virtual SIM card APP 121, and communicate with the terminal 12 through the interface. The interface may include interfaces such as user and device management, package and order management, and encrypted transmission of SIM resources. The server 11 may provide relevant interfaces to the virtual SIM card APP 121 in the form of a RESTful application programming interface (Application Programming Interface, API). The virtual SIM card information may include, but is not limited to, basic information of the virtual SIM card, purchase order information of the virtual SIM card, data usage information of the virtual SIM card, term information, and the like. The server 11 and the terminal 12 can perform statistics on the generated traffic data, and realize the management of the user information corresponding to the virtual SIM card APP121 through the statistical traffic data.

图2为一个实施例中终端的部分架构图,该架构图中包含的模块为与虚拟SIM卡相关的模块。如图2所示,终端的应用层上可设置有虚拟SIM卡操作系统、虚拟SIM卡适配层、虚拟SIM卡APP以及实体SIM卡管理模块。在框架层(Framework层)可设置有Telephony接口层和无线接口层(Radio Interface Layer)java层。调制解调器(Modem)可为由包含基带处理器、射频和其它外围芯片等组成的一个模块,为GSM/GPRS Modem。其中,Telephony接口层用于提供通用的接口,虚拟SIM卡操作系统通过Telephony接口层与Modem进行Socket交互,可实现判断是否有虚拟卡、虚拟卡所在的卡槽位置等。虚拟SIM卡操作系统通过虚拟SIM卡适配层与切换至虚拟SIM卡通道的Modem进行Socket交互,可实现对虚拟卡的激活、关闭,以及使用虚拟SIM卡进行网络通信功能等功能。可以理解的,图2中示出的结构,仅仅是与本申请方案相关的部分模块,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的模块,或者组合某些模块,或者具有不同的模块布置。实体SIM卡管理模块可与Telephony接口层进行通信,并实现对实体卡信息的关联及实体SIM卡相关业务的处理。FIG. 2 is a partial architecture diagram of a terminal in an embodiment, and the modules included in the architecture diagram are modules related to a virtual SIM card. As shown in FIG. 2 , the application layer of the terminal may be provided with a virtual SIM card operating system, a virtual SIM card adaptation layer, a virtual SIM card APP, and a physical SIM card management module. The framework layer (Framework layer) may be provided with a Telephony interface layer and a radio interface layer (Radio Interface Layer) java layer. A modem (Modem) can be a module consisting of a baseband processor, a radio frequency and other peripheral chips, and is a GSM/GPRS Modem. Among them, the Telephony interface layer is used to provide a general interface, and the virtual SIM card operating system communicates with the Modem through the Telephony interface layer. The virtual SIM card operating system performs Socket interaction with the Modem switched to the virtual SIM card channel through the virtual SIM card adaptation layer, which can realize functions such as activating and closing the virtual card, and using the virtual SIM card for network communication functions. It can be understood that the structure shown in FIG. 2 is only a part of the modules related to the solution of the present application, and does not constitute a limitation on the computer equipment to which the solution of the present application is applied. show more or fewer modules, or combine certain modules, or have a different arrangement of modules. The entity SIM card management module can communicate with the Telephony interface layer, and realize the association of entity card information and the processing of related services of the entity SIM card.

在一个实施例中,终端可通过虚拟SIM卡APP向用户提供虚拟SIM卡的管理操作界面,并在侦测到作用于该管理操作界面上相关操作时,产生相应的虚拟SIM卡处理指令,并将该处理指令发送至虚拟SIM卡操作系统。该虚拟SIM卡操作系统可模拟真实SIM卡的系统逻辑,实现了用于进行网络通信所需的相关规范的协议和文件系统。虚拟SIM卡操作系统可接收来自虚拟SIM卡App的处理指令,通过虚拟SIM卡适配层向Modem发送与该处理指令对应的消息,并可接收Modem作出的响应信息,共同实现使用虚拟SIM卡进行网络通信功能。其中,上述的相关规范的协议可包括国际标准化组织(International Organization forStandardization,ISO)7816以及3代合作项目(3rd Generation Partnership Project,3GPP)关于通用集成电路卡(Universal Integrated Circuit Card,UICC)和通用用户身份识别模块(Universal Subscriber Identity Module,USIM)等规范的协议。In one embodiment, the terminal can provide the user with a management operation interface of the virtual SIM card through the virtual SIM card APP, and when detecting a relevant operation acting on the management operation interface, generate a corresponding virtual SIM card processing instruction, and The processing instruction is sent to the virtual SIM card operating system. The virtual SIM card operating system can simulate the system logic of a real SIM card, and implements a protocol and a file system of relevant specifications required for network communication. The virtual SIM card operating system can receive the processing instruction from the virtual SIM card App, send the message corresponding to the processing instruction to the Modem through the virtual SIM card adaptation layer, and can receive the response information from the Modem, so as to jointly realize the use of the virtual SIM card. Network communication function. Wherein, the above-mentioned agreement of relevant specifications may include International Organization for Standardization (ISO) 7816 and 3rd Generation Partnership Project (3GPP) on Universal Integrated Circuit Card (Universal Integrated Circuit Card, UICC) and universal user Standardized protocols such as the Universal Subscriber Identity Module (USIM).

在一个实施例中,该处理指令可包括对相应虚拟SIM卡的套餐购买指令、启用指令、失效指令以及关闭指令等。所实现的使用虚拟SIM卡进行网络通信的内容包括但不限于实现虚拟SIM卡信息的交互管理、状态的动态更新以及流量的统计和限速等,比如可实现对虚拟SIM卡信息的存储删除以及虚拟SIM卡的启用关闭等。In one embodiment, the processing instruction may include a package purchase instruction, an activation instruction, an invalidation instruction, and a closing instruction for the corresponding virtual SIM card, and the like. The content of using the virtual SIM card for network communication includes, but is not limited to, the interactive management of virtual SIM card information, the dynamic update of status, and the statistics and speed limit of traffic, such as storage and deletion of virtual SIM card information and Enable and disable virtual SIM cards, etc.

在一个实施例中,如图3所示,提供了一种时序图,该时序图包含了对虚拟SIM卡进行的套餐购买、启用和失效的场景下,各个模块之间的交互过程。参考图3所示,其中,套餐购买的过程包括步骤302~312;套餐激活的过程包括步骤314~324;套餐失效的过程包括步骤326~336。In one embodiment, as shown in FIG. 3 , a sequence diagram is provided, and the sequence diagram includes the interaction process between various modules in the scenario of package purchase, activation and invalidation of the virtual SIM card. Referring to FIG. 3 , the process of purchasing the package includes steps 302 to 312 ; the process of activating the package includes steps 314 to 324 ; the process of invalidating the package includes steps 326 to 336 .

步骤302,终端通过虚拟SIM卡APP向服务器发送虚拟SIM卡购买请求。Step 302, the terminal sends a virtual SIM card purchase request to the server through the virtual SIM card APP.

在一个实施例中,终端可通过虚拟SIM卡APP向用户展示虚拟SIM卡购买界面,并侦测作用于该界面上的购买操作,根据侦测到的购买操作触发购买指令,向服务器发送虚拟SIM卡购买请求。其中,该购买界面上可提供相应的购买操作的虚拟按钮,在接收到对该虚拟按钮的点击操作时,可触发购买指令,或者可在检测到预设的于该购买指令对应的语音信息或者运动信息时,触发该购买指令。比如,可在检测到包含“购买虚拟卡”的语音信息,或者对终端进行上下摇晃等预设运动信息时,可触发购买指令。In one embodiment, the terminal can display the virtual SIM card purchase interface to the user through the virtual SIM card APP, detect the purchase operation acting on the interface, trigger the purchase instruction according to the detected purchase operation, and send the virtual SIM card to the server Card purchase request. Wherein, a virtual button corresponding to a purchase operation may be provided on the purchase interface, and a purchase instruction may be triggered when a click operation on the virtual button is received, or a preset voice message corresponding to the purchase instruction may be detected or When the information is exercised, the purchase instruction is triggered. For example, a purchase instruction can be triggered when a voice message including "purchase a virtual card" or preset motion information such as shaking the terminal up and down is detected.

在一个实施例中,终端可通过预设的虚拟SIM卡APP与服务器之间的对应通信接口,向服务器发送该虚拟SIM卡购买请求。其中,该购买请求中包含用户标识。该用户标识用于唯一标识对应用户的身份,可由预设位数的数字、字母或其它字符所构成。In one embodiment, the terminal may send the virtual SIM card purchase request to the server through a preset corresponding communication interface between the virtual SIM card APP and the server. Wherein, the purchase request includes the user ID. The user identification is used to uniquely identify the identity of the corresponding user, and may be composed of preset digits, letters or other characters.

步骤304,服务器根据接收的虚拟SIM卡购买请求,获取对应的虚拟SIM卡套餐信息。Step 304, the server obtains the corresponding virtual SIM card package information according to the received virtual SIM card purchase request.

在一个实施例中,服务器可为用于向终端提供网络流量的服务器,服务器可根据该购买请求,获取一种或多种与该购买请求相匹配的虚拟SIM卡套餐信息。在一个实施例中,该购买请求中还可包含终端的位置信息,服务器可获取一种或多种与该位置信息相匹配的虚拟SIM卡套餐信息。其中,每种套餐信息中包含对应的流量总量、有效时间以及价格其中等一种或多种字段信息。流量总量表示可对应套餐可使用的上网流量总量,比如为10GB上网流量。有效时间可包含该套餐的有效时长,比如为24小时、3天或7天等。价格表示购买对应套餐所需支付的费用信息。In one embodiment, the server may be a server for providing network traffic to the terminal, and the server may obtain one or more virtual SIM card package information matching the purchase request according to the purchase request. In one embodiment, the purchase request may further include location information of the terminal, and the server may acquire one or more virtual SIM card package information matching the location information. Wherein, each package information includes one or more fields of information such as the corresponding total amount of traffic, valid time, and price. The total amount of traffic indicates the total amount of Internet traffic that can be used by the corresponding package, such as 10GB of Internet traffic. The validity period may include the validity period of the package, such as 24 hours, 3 days, or 7 days. The price indicates the fee information required to purchase the corresponding package.

步骤306,服务器向终端发送该虚拟SIM卡套餐信息。Step 306, the server sends the virtual SIM card package information to the terminal.

在一个实施例中,服务器可向终端发送与该请求匹配的与该虚拟SIM卡购买请求对应的虚拟SIM卡套餐信息。在一个实施例中,可发送多个虚拟SIM卡套餐信息,以供用户选择。In one embodiment, the server may send the virtual SIM card package information corresponding to the virtual SIM card purchase request that matches the request to the terminal. In one embodiment, multiple virtual SIM card package information may be sent for selection by the user.

步骤308,终端通过虚拟SIM卡APP接收该套餐信息,并向服务器发送套餐选择指令。Step 308, the terminal receives the package information through the virtual SIM card APP, and sends a package selection instruction to the server.

在一个实施例中,终端可通过虚拟SIM卡APP接收该套餐信息,并进行展示。终端可通过虚拟SIM卡APP侦测作用于套餐信息展示界面上的选取操作,根据侦测到的选取操作,确定对应选取的套餐,生成对该套餐的套餐选择指令,将该套餐选择指令发送至服务器。其中,选取的套餐可包括一个或多个。In one embodiment, the terminal may receive the package information through the virtual SIM card APP, and display it. The terminal can detect the selection operation acting on the package information display interface through the virtual SIM card APP, determine the corresponding selected package according to the detected selection operation, generate a package selection instruction for the package, and send the package selection instruction to server. The selected package may include one or more packages.

步骤310,服务器接收该套餐选择指令,向终端发送与该套餐选择指令对应的套餐数据。Step 310: The server receives the package selection instruction, and sends package data corresponding to the package selection instruction to the terminal.

在一个实施例中,服务器可接收终端发送的套餐选择指令,识别该套餐选择指令对应的套餐信息。其中,套餐选择指令中可包含选取的套餐信息的套餐标识,服务器可确定该套餐标识对应的套餐信息,并获取该套餐信息对应的套餐数据。套餐标识用于唯一标识一种套餐的套餐信息。套餐数据包含虚拟SIM卡的基本数据和流量数据。该基本数据包含虚拟SIM卡的运营商信息、入网参数信息、虚拟SIM卡标识等用于实现虚拟SIM卡网络通信的必要数据。流量数据包括对应的网络通信可用流量的大小以及有效时间等信息。In one embodiment, the server may receive a package selection instruction sent by the terminal, and identify package information corresponding to the package selection instruction. The package selection instruction may include a package identifier of the selected package information, and the server may determine package information corresponding to the package identifier, and obtain package data corresponding to the package information. The package identifier is used to uniquely identify package information of a package. The package data includes the basic data and traffic data of the virtual SIM card. The basic data includes the operator information of the virtual SIM card, the network access parameter information, the virtual SIM card identifier, and other necessary data for realizing the network communication of the virtual SIM card. The traffic data includes information such as the size of the corresponding available traffic for network communication and the valid time.

步骤312,终端通过虚拟SIM卡APP接收该套餐数据,并通过虚拟SIM卡操作系统对套餐数据进行存储。Step 312, the terminal receives the package data through the virtual SIM card APP, and stores the package data through the virtual SIM card operating system.

在一个实施例中,终端可通过虚拟SIM卡APP接收服务器发送的套餐数据,并将该套餐数据转发至虚拟SIM卡操作系统。虚拟SIM卡操作系统可将接收到的套餐数据,通过虚拟SIM卡适配层发送至终端的Modem,并指示Modem对套餐数据进行存储。In one embodiment, the terminal may receive package data sent by the server through the virtual SIM card APP, and forward the package data to the virtual SIM card operating system. The virtual SIM card operating system can send the received package data to the Modem of the terminal through the virtual SIM card adaptation layer, and instruct the Modem to store the package data.

步骤314,终端通过虚拟SIM卡APP获取套餐激活指令。Step 314, the terminal obtains the package activation instruction through the virtual SIM card APP.

在一个实施例中,终端可通过虚拟SIM卡APP展示套餐激活界面,并可通过虚拟SIM卡APP侦测作用于套餐信息展示界面上的激活操作,根据侦测到的激活操作,确定对应激活的套餐,生成对该套餐的套餐激活指令,将该套餐激活指令发送至服务器。In one embodiment, the terminal can display the package activation interface through the virtual SIM card APP, and can detect the activation operation acting on the package information display interface through the virtual SIM card APP, and determine the corresponding activation according to the detected activation operation. package, generate a package activation instruction for the package, and send the package activation instruction to the server.

步骤316,通过虚拟SIM卡APP将套餐激活指令发送至虚拟SIM卡操作系统。Step 316: Send the package activation instruction to the virtual SIM card operating system through the virtual SIM card APP.

在一个实施例中,虚拟SIM卡APP通过与虚拟SIM卡操作系统之间预设的通信方式,向该虚拟SIM卡操作系统发送套餐激活指令,该套餐激活指令中包含对应待激活套餐的套餐标识,使得虚拟SIM卡操作系统可根据该套餐标识以及用户标识,确定待激活的套餐。In one embodiment, the virtual SIM card APP sends a package activation instruction to the virtual SIM card operating system through a preset communication method with the virtual SIM card operating system, where the package activation instruction includes a package identifier corresponding to the package to be activated , so that the virtual SIM card operating system can determine the package to be activated according to the package identifier and the user identifier.

步骤318,终端通过虚拟SIM卡操作系统进行套餐激活处理。Step 318, the terminal performs package activation processing through the virtual SIM card operating system.

虚拟SIM卡操作系统可通过上述的Telephony接口层,向Modem转发该套餐激活指令,Modem根据接收到的套餐激活指令,提取对应的套餐数据,将对应的套餐数据进行激活处理。The virtual SIM card operating system can forward the package activation instruction to the Modem through the above-mentioned Telephony interface layer, and the Modem extracts the corresponding package data according to the received package activation instruction, and activates the corresponding package data.

步骤320,通过虚拟SIM卡操作系统向虚拟SIM卡APP反馈激活处理结果。Step 320, the activation processing result is fed back to the virtual SIM card APP through the virtual SIM card operating system.

虚拟SIM卡操作系统可获取Modem进行激活处理的处理结果,并将获取的处理结果发送至虚拟SIM卡APP,并指示虚拟SIM卡APP进一步向服务器反馈激活处理结果。虚拟SIM卡APP可在终端界面上展示激活处理结果,以供用户查阅。激活处理结果可包括激活成功和激活失败的结果。The virtual SIM card operating system can acquire the processing result of the activation processing performed by the Modem, send the acquired processing result to the virtual SIM card APP, and instruct the virtual SIM card APP to further feed back the activation processing result to the server. The virtual SIM card APP can display the activation processing result on the terminal interface for the user to consult. The activation processing results may include activation success and activation failure results.

步骤322,终端通过虚拟SIM卡APP向服务器发送激活使用请求。Step 322, the terminal sends an activation and use request to the server through the virtual SIM card APP.

在一个实施例中,虚拟SIM卡APP可通过上述预设的接口,将获取到的激活处理结果发送至服务器,当该激活处理结果为激活成功时,该终端进一步通过虚拟SIM卡APP,向服务器发送激活使用通知,该通知用于指示服务器开始提供使用该虚拟SIM卡进行网络通信的服务。In one embodiment, the virtual SIM card APP can send the acquired activation processing result to the server through the above-mentioned preset interface. When the activation processing result is successful, the terminal further sends the server to the server through the virtual SIM card APP. An activation use notification is sent, and the notification is used to instruct the server to start providing the service of using the virtual SIM card for network communication.

步骤324,服务器接收该激活使用请求,并向终端反馈启动套餐监控的响应信息。Step 324, the server receives the activation and use request, and feeds back the response information of starting the package monitoring to the terminal.

在一个实施例中,服务器在接收到激活使用请求后,启动对该激活的套餐数据的使用服务,并可按照一定的频率监控对该套餐数据的使用状态,以提供使用该对应套餐数据进行网络通信的服务,并向终端的APP反馈套餐监控的响应信息。使得用户可获知服务器以成功开启了网络通信服务。In one embodiment, after receiving the activation and use request, the server starts the use service of the activated package data, and can monitor the usage status of the package data according to a certain frequency, so as to provide network access using the corresponding package data. Communication service, and feedback the response information of package monitoring to the APP of the terminal. So that the user can know the server to successfully start the network communication service.

步骤326,终端通过虚拟SIM卡APP获取套餐失效指令。Step 326, the terminal obtains the package invalidation instruction through the virtual SIM card APP.

在一个实施例中,虚拟SIM卡APP可调用终端内部设置的计时器来统计该套餐数据的使用时间,或者可获取当前时间,根据该使用时间或者当前获取时间判定该套餐数据已经失效时,自动触发套餐失效指令。或者终端还可通过虚拟SIM卡APP展示套餐管理界面,并可通过虚拟SIM卡APP侦测作用于套餐信息展示界面上的失效操作,根据侦测到的失效操作,确定对应失效的套餐,生成对该套餐的套餐失效请求,将该套餐失效请求发送至服务器。In one embodiment, the virtual SIM card APP can call a timer set inside the terminal to count the usage time of the package data, or can obtain the current time, and when it is determined that the package data has expired according to the usage time or the current acquisition time, automatically Trigger the package invalidation instruction. Or the terminal can also display the package management interface through the virtual SIM card APP, and can detect the invalid operation acting on the package information display interface through the virtual SIM card APP, and determine the corresponding invalid package according to the detected invalid operation, and generate a pair of For the package invalidation request of the package, send the package invalidation request to the server.

步骤328,终端通过虚拟SIM卡APP向服务器发送套餐失效请求。Step 328, the terminal sends a package invalidation request to the server through the virtual SIM card APP.

在一个实施例中,虚拟SIM卡APP可在侦测到套餐数据失效后,向服务器发送套餐失效请求,该请求用于指示服务器进行相关套餐是否失效的确认检测。其中,该请求中携带套餐标识。In one embodiment, the virtual SIM card APP can send a package invalidation request to the server after detecting that the package data is invalid, and the request is used to instruct the server to perform a confirmation detection on whether the relevant package is invalid. Wherein, the request carries the package identifier.

步骤330,服务器接收该套餐失效请求,并进行套餐失效处理。Step 330, the server receives the package invalidation request, and performs package invalidation processing.

在一个实施例中,服务器可根据接收到的套餐失效请求,检测对应套餐是否失效,若确认失效,则可进行套餐失效处理,终止该对应套餐数据的网络通信服务。In one embodiment, the server may detect whether the corresponding package is invalid according to the received package invalidation request, and if it is confirmed to be invalid, the server may perform package invalidation processing to terminate the network communication service of the corresponding package data.

步骤332,服务器向终端反馈套餐失效的确认信息。Step 332, the server feeds back confirmation information of the invalidation of the package to the terminal.

步骤334,终端通过虚拟SIM卡APP接收该确认信息,并向虚拟SIM卡操作系统发送套餐失效处理指令。Step 334, the terminal receives the confirmation information through the virtual SIM card APP, and sends a package invalidation processing instruction to the virtual SIM card operating system.

终端在接收到套餐已经失效的确认信息后,生成套餐失效处理指令,将该处理指令发送至虚拟SIM卡操作系统,该指令中携带套餐标识。After receiving the confirmation information that the package has become invalid, the terminal generates a package invalidation processing instruction, and sends the processing instruction to the virtual SIM card operating system, and the instruction carries the package identifier.

步骤336,终端虚拟SIM卡操作系统进行套餐失效处理。Step 336, the terminal virtual SIM card operating system performs package invalidation processing.

在一个实施例中,该虚拟SIM卡操作系统可进一步向Modem转发套餐失效处理指令,以指示Modem删除对应的套餐数据,或者终止使用该套餐数据进行虚拟SIM卡通信,并还可进一步恢复终端内被涉及到的实体SIM卡的正常通信。In one embodiment, the virtual SIM card operating system can further forward a package invalidation processing instruction to the Modem to instruct the Modem to delete the corresponding package data, or terminate the use of the package data for virtual SIM card communication, and further restore the terminal The normal communication of the involved physical SIM card.

图4为一个实施例中流量统计方法的流程图。如图4所示,该流量统计方法包括步骤402至步骤406。其中:FIG. 4 is a flowchart of a traffic statistics method in one embodiment. As shown in FIG. 4 , the traffic statistics method includes steps 402 to 406 . in:

步骤402,获取第一时刻和第二时刻,第一时刻晚于第二时刻。Step 402: Obtain a first time and a second time, where the first time is later than the second time.

在一个实施例中,在统计流量数据的时候,需要输入统计参数,并根据统计参数来统计流量数据。统计参数是指在进行流量数据统计时所需的参数,统计参数中可以但不限于包括第一时刻和第二时刻。流量数据是指通过移动通信技术上网或使用相关增值业务时所产生的数据量。其中,移动通信技术是指使移动用户与固定点用户之间或移动用户之间的进行通信的技术,可以当不限于是GPRS(General Packet Radio Service,通用分组无线服务技术)、EDGE(Enhanced Data Rate for GSM Evolution,增强型数据速率GSM演进技术)、TD-SCDMA(Time Division-Synchronous Code Division Multiple Access,时分同步码分多址)、HSDPA(High Speed Downlink Packet Access,高速下行分组接入)、WCDMA(Wideband Code Division Multiple Access,宽带码分多址)和LTE(Long TermEvolution,长期演进)等。In one embodiment, when statistics on traffic data are performed, statistics parameters need to be input, and traffic data are collected according to the statistics parameters. Statistical parameters refer to parameters required when statistics of traffic data are performed, and the statistical parameters may include, but are not limited to, the first moment and the second moment. Traffic data refers to the amount of data generated when surfing the Internet or using related value-added services through mobile communication technology. Among them, the mobile communication technology refers to the technology that enables communication between mobile users and fixed-point users or between mobile users, which may be not limited to GPRS (General Packet Radio Service, general packet radio service technology), EDGE (Enhanced Data Rate for GSM Evolution, Enhanced Data Rate GSM Evolution Technology), TD-SCDMA (Time Division-Synchronous Code Division Multiple Access, Time Division Synchronous Code Division Multiple Access), HSDPA (High Speed Downlink Packet Access, High Speed Downlink Packet Access), WCDMA ( Wideband Code Division Multiple Access) and LTE (Long Term Evolution, Long Term Evolution), etc.

可以理解的是,统计的流量数据是指统计某一个时间段内的流量数据,例如统计一个月内的流量数据,或者统计某一天内的流量数据。第一时刻就是指统计流量数据的截止时刻,第二时刻则是指进行流量统计的起始时刻。例如,统计2017年8月份的流量,则第一时刻是2017年8月31日24:00,第二时刻就可以是2017年8月1日00:00。第一时刻是指当前时刻之前的某个时间,也可以是指当前时刻,当前时刻一般可以直接通过一个时间函数进行获取。例如,当前时刻为14:22,那么结束时间就为14:22之前的某个时间,也可以是14:22。若获取当前时刻,则可以通过date.getYear()函数获取当前年份,通过date.getMonth()获取当前月份,通过date.getDate()获取当前日期。It can be understood that the statistics of traffic data refer to statistics of traffic data within a certain period of time, for example, statistics of traffic data within a month, or statistics of traffic data within a certain day. The first moment refers to the cut-off moment for statistics of traffic data, and the second moment refers to the start moment of traffic statistics. For example, to count the traffic in August 2017, the first moment is 24:00 on August 31, 2017, and the second moment can be 00:00 on August 1, 2017. The first moment refers to a certain time before the current moment, and may also refer to the current moment. The current moment can generally be obtained directly through a time function. For example, if the current time is 14:22, then the end time is some time before 14:22, or 14:22. If the current moment is obtained, the current year can be obtained through the date.getYear() function, the current month can be obtained through date.getMonth(), and the current date can be obtained through date.getDate().

步骤404,从第一文件中读取第一流量数据,第一文件用于保存终端从第三时刻到第一时刻所消耗的流量数据,第三时刻位于第一时刻和第二时刻之间。Step 404: Read the first traffic data from the first file, where the first file is used to save the traffic data consumed by the terminal from the third time to the first time, and the third time is located between the first time and the second time.

可以理解的是,智能终端在使用无线信号进行通信的时候,需要通过专用的通信通道来传输数据,通过统计这些通信通道中所产生的数据量即为统计的流量。不同的无线信号在传输数据的时候,所使用的通信通道不同,通过统计各个通信通道的数据量,可以统计出各个无线信号的流量。一般来说,智能终端中会安装各种应用程序,通过应用程序来实现人机交互的应用,所以各个应用程序在执行任务的时候就会消耗流量。It can be understood that when an intelligent terminal communicates using a wireless signal, it needs to transmit data through a dedicated communication channel, and the statistical traffic is calculated by counting the amount of data generated in these communication channels. Different wireless signals use different communication channels when transmitting data. By counting the data volume of each communication channel, the traffic of each wireless signal can be counted. Generally speaking, various application programs are installed in the smart terminal, and the application of human-computer interaction is realized through the application program, so each application program will consume traffic when performing tasks.

在一个实施例中,智能终端中所有应用模块的流量数据是通过内核层中的流量统计模块来记录和统计的,内核层中的流量统计模块统计的流量数据会记录在一个文件中,应用层中的应用程序可以通过调用流量统计接口查询该文件中记录的流量数据。输入第一时刻和第二时刻,就可以查询从第一时刻和第二时刻之间所产生的流量数据。例如,统计2017年1月1日00:00到2017年1月11日00:00的流量数据。In one embodiment, the traffic data of all application modules in the smart terminal is recorded and counted by the traffic statistics module in the kernel layer, and the traffic data collected by the traffic statistics module in the kernel layer will be recorded in a file, and the application layer The application in the file can query the traffic data recorded in this file by calling the traffic statistics interface. Enter the first time and the second time, you can query the traffic data generated between the first time and the second time. For example, count the traffic data from 00:00 on January 1, 2017 to 00:00 on January 11, 2017.

步骤406,从第二文件中读取第二流量数据,第二文件用于保存终端在第一时刻之前所消耗的流量数据,第二流量数据表示终端从第二时刻到第三时刻所消耗的流量数据。Step 406, read the second traffic data from the second file, the second file is used to save the traffic data consumed by the terminal before the first moment, and the second traffic data represents the traffic consumed by the terminal from the second moment to the third moment. traffic data.

在本申请提供的实施例中,第一文件和第二文件都用于存储终端所消耗的流量数据,第一文件中存储的是终端从第三时刻到第一时刻所消耗的流量数据,第二文件中存储的是终端在第一时刻之前所消耗的流量数据。从第一文件中获取第三时刻到第一时刻所消耗的流量数据,从第二文件中获取第二时刻到第三时刻所消耗的流量数据。第一流量数据表示终端从第三时刻到第一时刻所消耗的流量数据,第二流量数据表示终端从第二时刻到第三时刻所消耗的流量数据。In the embodiment provided by this application, both the first file and the second file are used to store the traffic data consumed by the terminal, and the first file stores the traffic data consumed by the terminal from the third moment to the first moment, and the What is stored in the second file is the traffic data consumed by the terminal before the first moment. The flow data consumed from the third time to the first time is obtained from the first file, and the flow data consumed from the second time to the third time is obtained from the second file. The first traffic data represents the traffic data consumed by the terminal from the third time to the first time, and the second traffic data represents the traffic data consumed by the terminal from the second time to the third time.

举例说明,第一时刻为9月2日00:00,第二时刻为8月28日00:00,第三时刻为9月1日00:00。那么第一文件中保存的就是9月1日00:00到9月2日00:00之间所消耗的流量数据,第二文件中保存的就是9月2日00:00之前所消耗的流量数据。则可以从第一文件中获取9月1日00:00到9月2日00:00之间所消耗的流量数据,从第二文件中获取8月28日00:00到9月1日00:00之间所消耗的流量数据。For example, the first moment is 00:00 on September 2, the second moment is 00:00 on August 28, and the third moment is 00:00 on September 1. Then the first file saves the traffic data consumed between September 1st 00:00 and September 2nd 00:00, and the second file saves the traffic consumed before September 2nd 00:00 data. Then, the traffic data consumed between 00:00 on September 1 and 00:00 on September 2 can be obtained from the first file, and the data from 00:00 on August 28 to 00:00 on September 1 can be obtained from the second file. Traffic data consumed between :00.

步骤408,根据第一流量数据和第二流量数据统计流量数据。Step 408: Statistics traffic data according to the first traffic data and the second traffic data.

统计的流量数据是指智能终端当前时刻之前的某个时间段内所产生的流量数据。具体地,可以统计当前流量数据,则当前流量数据就是指当前时刻之前的某个时刻到当前时刻之间所产生的流量数据。首先获取第一流量数据和第二流量数据,然后根据第一流量数据和第二流量数据可以统计终端所消耗的流量数据。例如,当前时刻为19:00,那么统计的流量数据可以是指12:00到17:00之间所消耗的流量数据,也可以是指17:00到19:00之间所消耗的流量数据。当前流量数据可以是指12:00到19:00之间所消耗的流量数据。The statistical traffic data refers to the traffic data generated by the intelligent terminal in a certain period of time before the current moment. Specifically, the current traffic data can be counted, and the current traffic data refers to the traffic data generated between a certain time before the current time and the current time. First, the first traffic data and the second traffic data are acquired, and then the traffic data consumed by the terminal can be counted according to the first traffic data and the second traffic data. For example, if the current time is 19:00, the statistical traffic data can refer to the traffic data consumed between 12:00 and 17:00, or it can refer to the traffic data consumed between 17:00 and 19:00. . The current traffic data may refer to traffic data consumed between 12:00 and 19:00.

进一步地,智能终端可以通过内核层中的流量统计模块来实现流量的统计,该内核流量统计模块可以统计智能终端中所有应用模块所产生的流量数据,应用层可以通过专用的流量统计接口来获取该流量统计模块所统计的流量数据。在调用流量统计接口去获取流量数据的时候,统计参数可以包括起始时刻和截止时刻,然后查找起始时刻和截止时刻之间的流量数据。一般地,统计的某个应用模块所产生的流量数据,流量数据可以包括数据的接收量和发送量,接收量是指接收到的数据包的字节总数,发送流量是指发送的数据包的字节总数。统计参数具体还可以包括应用标识、起始时刻和截止时刻等,则可以统计应用标识对应的应用模块在起始时刻和截止时刻之间所消耗的流量数据。其中,应用标识是指需要进行统计的产生流量消耗的应用模块的唯一标识,应用模块是指应用程序对应的功能模块。例如,智能终端在安装应用程序时,会对每个应用程序分配一个UID(UserIdentification,用户身份证明),在进行流量统计的时候,输入该UID、起始时刻和截止时刻,就可以统计该UID对应的应用程序从起始时刻和截止时刻之间所消耗的流量数据。Further, the smart terminal can implement traffic statistics through the traffic statistics module in the kernel layer. The kernel traffic statistics module can count the traffic data generated by all application modules in the smart terminal, and the application layer can obtain it through a dedicated traffic statistics interface. Traffic data collected by the traffic statistics module. When calling the traffic statistics interface to obtain traffic data, the statistical parameters can include the start time and the end time, and then search the traffic data between the start time and the end time. Generally, the statistics of the traffic data generated by an application module, the traffic data can include the amount of data received and the amount of data sent, the amount of received refers to the total number of bytes in the received data packets, and the transmitted traffic refers to the Total number of bytes. The statistical parameters may also specifically include an application identifier, a start time, and an end time, etc., then the traffic data consumed by the application module corresponding to the application identifier between the start time and the end time can be counted. Wherein, the application identifier refers to the unique identifier of the application module that generates traffic consumption and needs to be counted, and the application module refers to the function module corresponding to the application program. For example, when a smart terminal installs an application, it will assign a UID (UserIdentification) to each application. When performing traffic statistics, enter the UID, start time and end time to count the UID. The traffic data consumed by the corresponding application between the start time and the end time.

具体地,应用层中可以包括实体SIM卡模块和虚拟SIM卡模块。其中,实体SIM卡模块和虚拟SIM卡模块都可以实现移动通信功能,不同的是,实体SIM卡模块是通过硬件集成用户身份信息来实现移动通信功能的,虚拟SIM卡模块是通过软件存储用户身份信息来实现移动通信功能的。实体SIM卡模块会实时调用专用的流量统计接口来查询流量数据,从而统计某一个时间段内的流量数据。在一个实施例中,实体SIM卡模块每次都只会统计当前月份内的流量数据,即实时统计当前月份开始时刻到当前时刻的之间的流量数据,到了下一个月就会重新统计流量数据,并将上一个月统计的流量数据清零。例如,若当前时刻为2017年9月21日12:00,那么实体SIM卡模块统计的就是2017年9月1日00:00到2017年9月21日12:00之间所产生的流量数据。当到达每个月1号00:00时,将当前统计的流量数据进行清零,并重新开始统计。Specifically, the application layer may include a physical SIM card module and a virtual SIM card module. Among them, both the physical SIM card module and the virtual SIM card module can realize the mobile communication function. The difference is that the physical SIM card module realizes the mobile communication function through hardware integration of user identity information, and the virtual SIM card module stores the user identity through software. information to realize mobile communication functions. The physical SIM card module will call the dedicated traffic statistics interface in real time to query the traffic data, so as to count the traffic data in a certain period of time. In one embodiment, the physical SIM card module only counts the traffic data in the current month each time, that is, the traffic data between the start time of the current month and the current time is counted in real time, and the traffic data will be counted again in the next month. , and reset the traffic data for the previous month to zero. For example, if the current time is 12:00 on September 21, 2017, the physical SIM card module counts the traffic data generated between 00:00 on September 1, 2017 and 12:00 on September 21, 2017 . When reaching 00:00 on the 1st of each month, the current statistics of traffic data will be cleared and the statistics will be restarted.

实体SIM卡模块将统计的流量数据记录在框架层中的数据文件中,这样虚拟SIM卡模块每次需要统计流量的时候就可以直接通过框架层中的数据文件来读取,不用每次都去调用流量统计接口从内核层中读取流量数据,减少了大量的功耗。然而,由于实体SIM卡模块统计的是某一个时间段内的流量数据,如果虚拟SIM卡模块需要统计时间段超过了实体SIM卡模块统计的这个时间段,那么虚拟SIM卡模块就可以一部分流量数据通过实体SIM卡模块对应的数据文件中读取,一部分流量通过调用流量统计接口,从内核中的数据文件中读取。例如,虚拟SIM卡模块需要统计2017年8月8日00:00到2017年9月21日12:00之间所产生的流量数据,而实体SIM卡模块只统计了2017年9月1日00:00到2017年9月21日之间的流量数据,那么2017年9月1日00:00到2017年9月21日之间产生的这部分流量数据就可以直接通过实体SIM卡模块对应的数据文件中读取,2017年8月8日00:00到2017年9月1日00:00之间所产生的这部分流量数据就需要虚拟SIM卡模块去调用流量统计接口,从内核中的数据文件中获取。The physical SIM card module records the statistical traffic data in the data file in the framework layer, so that the virtual SIM card module can directly read the data file in the framework layer every time it needs to count traffic, without going to the data file every time. Calling the traffic statistics interface to read traffic data from the kernel layer reduces a lot of power consumption. However, since the physical SIM card module counts the traffic data within a certain time period, if the virtual SIM card module needs to count the time period exceeds the physical SIM card module's statistical time period, then the virtual SIM card module can collect part of the traffic data. It is read from the data file corresponding to the physical SIM card module, and a part of the traffic is read from the data file in the kernel by calling the traffic statistics interface. For example, the virtual SIM card module needs to count the traffic data generated between 00:00 on August 8, 2017 and 12:00 on September 21, 2017, while the physical SIM card module only counts on September 1, 2017 00 :00 to September 21, 2017 traffic data, then this part of the traffic data generated between September 1, 2017 00:00 to September 21, 2017 can be directly passed through the physical SIM card module. Read from the data file, this part of the traffic data generated between 00:00 on August 8, 2017 and 00:00 on September 1, 2017 requires the virtual SIM card module to call the traffic statistics interface. obtained from the data file.

上述实施例提供的流量统计方法,首先获取第一时刻和第二时刻,并根据第一时刻和第二时刻将时间段进行划分,从第一文件中读取第一流量数据,从第二文件中读取第二流量数据,并根据第一流量数据和第二流量数据统计流量数据。这样分别进行统计,提高了流量统计的效率。The traffic statistics method provided by the above embodiment firstly obtains the first moment and the second moment, divides the time period according to the first moment and the second moment, reads the first traffic data from the first file, and obtains the first traffic data from the second file. The second traffic data is read in, and the traffic data is counted according to the first traffic data and the second traffic data. In this way, statistics are performed separately, which improves the efficiency of traffic statistics.

图5为另一个实施例中流量统计方法的流程图。如图5所示,该流量统计方法包括步骤502至步骤518。其中:FIG. 5 is a flowchart of a traffic statistics method in another embodiment. As shown in FIG. 5 , the traffic statistics method includes steps 502 to 518 . in:

步骤502,获取第一时刻和第二时刻,第一时刻晚于第二时刻。Step 502: Obtain a first time and a second time, where the first time is later than the second time.

在一个实施例中,步骤502具体可以包括:检测到统计指令时,获取第一时刻和第二时刻。统计指令是指触发进行流量统计的指令,该统计指令可以是用户手动触发的,也可以是在系统满足预设条件时,自动触发的。一般来说,统计指令是由智能终端的应用层中的应用程序发起的。In one embodiment, step 502 may specifically include: acquiring the first moment and the second moment when the statistical instruction is detected. The statistics instruction refers to an instruction that triggers traffic statistics. The statistics instruction may be manually triggered by the user, or may be automatically triggered when the system satisfies a preset condition. Generally speaking, the statistical command is initiated by the application program in the application layer of the smart terminal.

例如,用户可以通过智能终端向运营商购买虚拟SIM卡,购买虚拟SIM卡后服务器会向智能终端分配虚拟SIM卡对应的用户信息、流量信息和对应的位置代码,然后用户就可以通过虚拟SIM卡对应的流量数据进行上网。其中,用户信息是指识别不同用户的信息,位置代码是指虚拟SIM卡对应的地理位置识别码,只有智能终端在该地理位置范围内是才开始进行流量统计。其中,地理位置识别码可以但不限于是MCC(Mobile Country Code,移动设备国家代码)码、MSIN(Mobile Subscriber Identification Number,移动用户识别号码)等。智能终端可以实时获取当前所在地理位置,若当前所在地理位置为虚拟SIM卡的地理位置标识对应的地理位置范围内,则触发统计指令,开始统计流量。同时,在触发统计指令之后,智能终端还可以向服务器发送统计请求,该统计请求用于指示服务器对该虚拟SIM卡所使用的流量进行统计。For example, a user can purchase a virtual SIM card from an operator through a smart terminal. After purchasing the virtual SIM card, the server will allocate the user information, traffic information and corresponding location code corresponding to the virtual SIM card to the smart terminal, and then the user can pass the virtual SIM card. Corresponding traffic data to access the Internet. The user information refers to information identifying different users, the location code refers to the geographic location identification code corresponding to the virtual SIM card, and the traffic statistics are started only when the smart terminal is within the geographic location range. The geographic location identification code may be, but is not limited to, an MCC (Mobile Country Code, mobile device country code) code, an MSIN (Mobile Subscriber Identification Number, mobile subscriber identification number), and the like. The smart terminal can obtain the current geographic location in real time, and if the current geographic location is within the geographic location range corresponding to the geographic location identifier of the virtual SIM card, a statistics instruction is triggered to start traffic statistics. Meanwhile, after triggering the statistics instruction, the smart terminal may also send a statistics request to the server, where the statistics request is used to instruct the server to perform statistics on the traffic used by the virtual SIM card.

步骤504,从终端的内核层中的第二文件中读取第一流量数据,并将第一流量数据保存到终端的框架层的内存中。Step 504: Read the first traffic data from the second file in the kernel layer of the terminal, and save the first traffic data in the memory of the framework layer of the terminal.

在本申请提供的实施例中,智能终端会通过内核层的流量统计模块来统一对各个应用程序所产生的流量进行统计,然后将统计的流量记录在一个内核层对应的数据文件中,应用层的应用程序需要查询流量的时候,可以通过专用的流量统计接口读取该内核层的数据文件获取流量数据,然后将读取的流量数据存储在框架层的数据文件中。下次需要查询这部分流量数据时,可以直接从框架层的数据文件中读取,不需要再去调用流量统计接口,这样可以减少系统的功耗。In the embodiment provided in this application, the intelligent terminal will uniformly collect statistics on the traffic generated by each application program through the traffic statistics module at the kernel layer, and then record the statistics traffic in a data file corresponding to the kernel layer, and the application layer When the application needs to query the traffic, it can read the data file of the kernel layer through the dedicated traffic statistics interface to obtain the traffic data, and then store the read traffic data in the data file of the framework layer. The next time you need to query this part of the traffic data, you can directly read it from the data file of the framework layer without calling the traffic statistics interface, which can reduce the power consumption of the system.

步骤506,从终端的内存中读取第一流量数据,将第一流量数据保存到第一文件中,并将第一文件存储在终端的缓存中,第一文件用于保存终端从第三时刻到第一时刻所消耗的流量数据。Step 506: Read the first traffic data from the memory of the terminal, save the first traffic data in the first file, and store the first file in the cache of the terminal, where the first file is used to save the terminal from the third moment. Traffic data consumed up to the first moment.

在一个实施例中,第一文件是指终端的框架层中存储流量数据的数据文件。一般来说,第一文件中存储在终端的缓存中。终端可以从内核层中的第二文件中获取第一流量数据,并将第一流量数据保存在终端的内存中。下次需要读取第一流量数据的时候,直接将内存中的第一流量数据保存到第一文件中,并将第一文件放到终端的缓存中,并通过缓存中的第一文件读取与第一流量数据。其中,内存(Memory)是指终端中的内存储器,用于存放CPU(Central Processing Unit,中央处理器)中的运算数据。缓存就是数据交换的缓冲区(Cache),一般情况下,当某终端需要读取数据时,会首先从缓存中查找需要的数据,如果找到了则直接执行,找不到的话则从内存中找,这样可以节省查找时间。In one embodiment, the first file refers to a data file that stores traffic data in the framework layer of the terminal. Generally speaking, the first file is stored in the cache of the terminal. The terminal may acquire the first traffic data from the second file in the kernel layer, and save the first traffic data in the memory of the terminal. The next time you need to read the first traffic data, directly save the first traffic data in the memory to the first file, put the first file in the cache of the terminal, and read it through the first file in the cache with the first traffic data. The memory (Memory) refers to an internal memory in the terminal, which is used to store operation data in a CPU (Central Processing Unit, central processing unit). The cache is the buffer (Cache) for data exchange. Generally, when a terminal needs to read data, it will first look for the required data from the cache. If it is found, it will be executed directly. If it cannot be found, it will be found in the memory. , which saves search time.

可以理解的是,流量数据可以以数据结构的形式存储的。数据结构是指存储数据及数据元素之间的关系的集合,例如数据结构可以是hash表、红黑树、二叉树等形式。一般来说,保存的是很长一段时间内的流量数据,以便于需要时对流量数据进行查询。内核层中的流量统计模块统计的流量数据一开始存储在内存中,在保存流量数据的时候,会对流量数据的总量设一个上限值,当流量数据的总量达到这个上限值,会将内存中的流量数据转存到指定的文件中,这样即便是关闭智能终端,记录的流量数据也不会丢失。It can be understood that the traffic data may be stored in the form of a data structure. A data structure refers to a collection of stored data and relationships between data elements. For example, a data structure can be in the form of a hash table, a red-black tree, and a binary tree. Generally speaking, the traffic data for a long period of time is saved so that the traffic data can be queried when needed. The traffic data counted by the traffic statistics module in the kernel layer is initially stored in the memory. When saving the traffic data, an upper limit is set for the total amount of traffic data. When the total amount of traffic data reaches this upper limit, The traffic data in the memory will be dumped to the specified file, so that even if the smart terminal is turned off, the recorded traffic data will not be lost.

在一个实施例中,流量统计模块在统计流量的时候,会统计各个应用模块在各个时间段内的消耗的流量数据,并将这个各个时间段内的流量数据与对应的应用标识进行存储。其中,应用模块是指智能终端中的应用程序对应的功能模块,应用标识是区分这个应用模块的唯一标识。例如,在Android系统中在安装应用程序的时候,会给安装的应用程序分配一个UID,则系统就可以通过UID来区分各个应用程序对应的功能模块。在查询流量数据的时候,可以查询起始时刻到截止时刻的各个时间段对应的流量数据,并根据查询的各个时间段对应的流量数据计算流量数据。例如,流量统计模块每半小时记录一次流量数据,记录的流量数据表示所记录的半小时内消耗的流量。如果要统计12:00到14:00之间的流量数据,那么可以从数据文件中查找12:00~12:30、12:30~13:00、13:00~13:30和13:30~14:00这四个时间段内的流量数据,分别为10MB、20MB、30MB和12MB,那么统计的历史流量就为这个时间段内的流量数据的总和,即为72MB。In one embodiment, when the traffic statistics module collects traffic statistics, the traffic data consumed by each application module in each time period is counted, and the traffic data in each time period and the corresponding application identifier are stored. The application module refers to the function module corresponding to the application program in the smart terminal, and the application identifier is the unique identifier for distinguishing the application module. For example, when an application is installed in the Android system, a UID is assigned to the installed application, and the system can use the UID to distinguish the function modules corresponding to each application. When querying traffic data, you can query the traffic data corresponding to each time period from the start time to the end time, and calculate the traffic data according to the traffic data corresponding to each time period queried. For example, the traffic statistics module records traffic data every half an hour, and the recorded traffic data represents the traffic consumed within the recorded half hour. If you want to count the traffic data between 12:00 and 14:00, you can find 12:00~12:30, 12:30~13:00, 13:00~13:30 and 13:30 from the data file The traffic data in the four time periods of ~14:00 are 10MB, 20MB, 30MB and 12MB respectively, then the statistical historical traffic is the sum of the traffic data in this time period, which is 72MB.

步骤508,从终端的缓存中读取第一文件,并从第一文件中读取第一流量数据。Step 508: Read the first file from the cache of the terminal, and read the first traffic data from the first file.

在一个实施例中,第一文件位于框架层中,从第一流量数据存放在框架层中的第一文件中。终端需要读取第一流量数据的时候,可以直接在框架层中获取第一文件,再从第一文件中读取第一流量数据,这样不用再去内核层中读取流量数据,节省了读取时间。其中,应用层应是终端的最高层,直接为应用进程提供服务的。框架层用于为终端开发应用程序提供开发框架。内核层为终端的硬件和软件栈之间的抽象层,它可隐藏具体硬件细节而为上层提供统一的服务。In one embodiment, the first file is located in the framework layer, and the data from the first traffic is stored in the first file in the framework layer. When the terminal needs to read the first traffic data, it can directly obtain the first file in the framework layer, and then read the first traffic data from the first file, so that there is no need to read the traffic data in the kernel layer, which saves reading Take time. Among them, the application layer should be the highest layer of the terminal, and directly provide services for the application process. The framework layer is used to provide a development framework for terminal development applications. The kernel layer is the abstraction layer between the hardware and software stack of the terminal, which can hide the specific hardware details and provide unified services for the upper layer.

步骤510,通过流量统计接口输入第二时刻和第三时刻。Step 510: Input the second time and the third time through the traffic statistics interface.

在一个实施例中,第一文件保存在终端的框架层中,第二文件保存在终端的内核层中,第一文件只存储了某一个时间段内的流量数据,第二文件中存储了所有流量数据。流量统计接口是指从内核层读取流量数据的接口,一般地从流量统计接口中传入统计参数,然后根据统计参数统计从内核层的数据文件中读取流量数据。通过流量统计接口输入第二时刻和第三时刻,然后从第二文件中查找第二时刻到第三时刻之间的流量数据。In one embodiment, the first file is stored in the framework layer of the terminal, the second file is stored in the kernel layer of the terminal, the first file only stores traffic data within a certain time period, and the second file stores all traffic data. The traffic statistics interface refers to the interface for reading traffic data from the kernel layer. Generally, statistics parameters are imported from the traffic statistics interface, and then the traffic data is read from the data file of the kernel layer according to the statistics parameters. Input the second time and the third time through the traffic statistics interface, and then look up the traffic data between the second time and the third time from the second file.

步骤512,根据第二时刻和第三时刻从终端的内核层中的文件系统中获取第二文件,并从第二文件中读取第二流量数据,通过流量统计接口返回第二流量数据。Step 512: Acquire the second file from the file system in the kernel layer of the terminal according to the second time and the third time, read the second traffic data from the second file, and return the second traffic data through the traffic statistics interface.

在一个实施例中,第一文件就可以是指框架层中对应的用于记录流量数据的数据文件,第二文件可以是指该内核层对应的用于记录流量数据的数据文件。第一流量数据是指从第一文件中获取的终端消耗的流量数据,第二流量数据是指从第二文件中获取的终端消耗的流量数据。In one embodiment, the first file may refer to a data file corresponding to the framework layer for recording traffic data, and the second file may refer to a data file corresponding to the kernel layer for recording traffic data. The first traffic data refers to the traffic data consumed by the terminal obtained from the first file, and the second traffic data refers to the traffic data consumed by the terminal obtained from the second file.

根据第二时刻和第三时刻从终端的内核层中的文件系统中获取第二文件,并从第二文件中读取第二流量数据,通过流量统计接口返回第二流量数据。文件系统是指存储数据文件的系统,例如文件系统可以是proc文件系统,其中proc文件系统是一种无存储的文件系统,当读其中的文件时,根据传入的参数动态生成文件内容。Obtain the second file from the file system in the kernel layer of the terminal according to the second time and the third time, read the second traffic data from the second file, and return the second traffic data through the traffic statistics interface. A file system refers to a system that stores data files. For example, a file system can be a proc file system. The proc file system is a file system without storage. When reading a file, the file content is dynamically generated according to the incoming parameters.

图6为一个实施例中流量统计系统的结构示意图。如图6所示,该流量查询系统包括流量统计应用程序602、流量统计框架604和流量统计模块606。其中,流量统计应用程序602位于该系统的应用层,用于发起流量查询请求。可以理解的是,流量统计应用程序602可以向流量统计框架604发送流量查询请求,该请求中包含第一时刻和第二时刻,还可以包括网络类型参数,网络类型是指统计的使用流量数据的网络的类型,一般的网络类型包括Wi-Fi网络、数据网络等类型。流量统计框架604位于该系统的框架层,用于接收流量统计应用程序602的流量查询请求,并根据该流量查询请求中的统计参数从流量统计模块606中获取历史流量,查询的结果发送给流量统计应用程序602。FIG. 6 is a schematic structural diagram of a traffic statistics system in an embodiment. As shown in FIG. 6 , the traffic query system includes a traffic statistics application program 602 , a traffic statistics framework 604 and a traffic statistics module 606 . The traffic statistics application 602 is located in the application layer of the system, and is used to initiate a traffic query request. It can be understood that the traffic statistics application 602 can send a traffic query request to the traffic statistics framework 604, and the request includes the first moment and the second moment, and may also include a network type parameter, and the network type refers to the statistical usage of traffic data. The type of network, general network types include Wi-Fi network, data network and other types. The traffic statistics framework 604 is located in the framework layer of the system, and is used to receive the traffic query request of the traffic statistics application 602, and obtain historical traffic from the traffic statistics module 606 according to the statistical parameters in the traffic query request, and send the query result to the traffic Statistics application 602 .

图7为另一个实施例中流量统计系统的结构示意图。如图7所示,该系统分为应用层、框架层和内核层。应用层中包含流量消耗应用程序,流量消耗应用程序是指消耗流量数据的应用程序。例如,流量消耗应用程序可以是游戏APP,用户通过手机中的游戏APP打游戏,在使用该游戏APP打游戏的过程中,该游戏APP会产生流量数据的消耗。智能终端在运行流量消耗应用程序的时候,与服务器进行数据传输时,会产生流量数据的消耗。流量消耗应用程序通过框架层中的接口与内核层进行通信。当有网络访问发生时,流量统计模块会查询这个网络是由哪个应用程序访问的,然后统计发送和接收的流量数据的数据量,并将统计的流量数据记录到内存中。框架层需要查询这些流量数据时,内核层通过文件系统将这些流量数据映射到一个数据文件中。框架层会通过系统接口进行获取读取这些文件,获取流量数据。运输层用于传输数据和文件,网络层用于定义不同终端之间的传输的数据包。FIG. 7 is a schematic structural diagram of a traffic statistics system in another embodiment. As shown in Figure 7, the system is divided into application layer, framework layer and kernel layer. The application layer includes traffic consuming applications, and traffic consuming applications refer to applications that consume traffic data. For example, the data consumption application may be a game APP. The user plays a game through the game APP in the mobile phone. During the process of using the game APP to play the game, the game APP will consume data of traffic. When the smart terminal runs the data consumption application and transmits the data with the server, it will consume the traffic data. Traffic consuming applications communicate with the kernel layer through interfaces in the framework layer. When a network access occurs, the traffic statistics module will query which application the network is accessed by, then count the data volume of the traffic data sent and received, and record the statistical traffic data into the memory. When the framework layer needs to query the traffic data, the kernel layer maps the traffic data to a data file through the file system. The framework layer will obtain and read these files through the system interface to obtain traffic data. The transport layer is used to transfer data and files, and the network layer is used to define the data packets transmitted between different terminals.

举例来说,Android内核层的流量统计功能,是由Xt_qtaguid这个模块负责完成的。这个模块主要代码位于kernel/net/netfilter/xt_qtaguid.c中。Xt_qtaguid模块利用了内核层的netfilter架构,实现了一个网络匹配器,并设定了一定的网络接口匹配规则。该匹配器在系统启动时,由netd进程通过iptables命令载入运行。当有网络访问发生时,netfilter框架会通知Xt_qtaguid模块进行处理,主要查询下这个网络访问是哪个uid的模块访问的,发送和接收的数据量有多少,并将流量数据记录到内存中。当framework层需要访问这些流量数据的时候,Xt_qtaguid模块通过proc文件系统映射出一个proc文件并将流量数据写到这个文件中供framework层读取。For example, the traffic statistics function of the Android kernel layer is completed by the module Xt_qtaguid. The main code of this module is located in kernel/net/netfilter/xt_qtaguid.c. The Xt_qtaguid module uses the netfilter architecture of the kernel layer to implement a network matcher and set certain network interface matching rules. The matcher is loaded and run by the netd process through the iptables command when the system starts. When a network access occurs, the netfilter framework will notify the Xt_qtaguid module to process it, mainly query which uid module accesses the network access, how much data is sent and received, and records the traffic data in memory. When the framework layer needs to access the traffic data, the Xt_qtaguid module maps a proc file through the proc file system and writes the traffic data to this file for the framework layer to read.

在一个实施例中,流量统计模块统计流量的流程如图8所示。流量统计模块在开始统计流量数据之前需要对数据进行初始化。首先创建目录,然后创建流量统计proc文件系统以及网络接口状态的proc文件系统,并注册网络匹配器。最后将该匹配器添加到iptable中,并注册misc_register模块。当发生网络访问时,接收网络数据收发通知,开始对流量数据进行统计。通过匹配器匹配处理函数,然后对流量数据进行解析和统计,并将统计的流量数据进行保存。其中,可以通过二叉树的形式保存数据,索引值是应用模块的UID,树枝节点是个多维数组结构,保存流量数据。上层应用要读取流量数据的时候,通过调用proc文件系统关联的读函数把内存数据写入数据文件,并从数据文件中读取流量数据。In one embodiment, the flow of the traffic statistics module for statistics is shown in FIG. 8 . The traffic statistics module needs to initialize the data before starting to collect traffic data. First create the directory, then create the traffic statistics proc file system and the proc file system of the network interface status, and register the network matcher. Finally add the matcher to iptable and register the misc_register module. When network access occurs, it receives notification of network data sending and receiving, and starts to collect statistics on traffic data. The processing function is matched by the matcher, then the traffic data is analyzed and counted, and the counted traffic data is saved. Among them, the data can be saved in the form of a binary tree, the index value is the UID of the application module, and the branch node is a multi-dimensional array structure to save the traffic data. When the upper-layer application wants to read the traffic data, it writes the memory data into the data file by calling the read function associated with the proc file system, and reads the traffic data from the data file.

图9为另一个实施例中流量查询系统的结构示意图。如图9所示,流量统计应用程序发起流量查询请求,框架层中的核心服务模块用于响应流量查询请求、协调数据查询模块和序列化存储模块。数据查询模块通过流量读取接口提供查询流量的接口,由流量查询服务读取内核层中的流量统计proc文件系统的数据,再将数据返回给核心服务模块。核心服务模块将流量数据发送到序列化存储模块。序列化存储模块接收到数据之后,将流量数据按照一定的格式先缓存在内存中。在需要读取流量数据的时候,将缓存内容保存到序列化文件中或从序列化文件中恢复数据到缓存里面。一般地,流量数据可以以数据列表的形式进行存储,以应用模块的模块标识进行区分,每个元素是一个数据对象,存储了模块标识对应的流量数据。FIG. 9 is a schematic structural diagram of a traffic query system in another embodiment. As shown in Figure 9, the traffic statistics application program initiates a traffic query request, and the core service module in the framework layer is used to respond to the traffic query request, coordinate the data query module and the serialized storage module. The data query module provides an interface for querying traffic through the traffic reading interface, and the traffic query service reads the data of the traffic statistics proc file system in the kernel layer, and then returns the data to the core service module. The core service module sends traffic data to the serialized storage module. After the serialized storage module receives the data, it first caches the traffic data in the memory according to a certain format. When you need to read traffic data, save the cache content to the serialized file or restore the data from the serialized file to the cache. Generally, the traffic data can be stored in the form of a data list, which is distinguished by the module identifier of the application module, each element is a data object, and stores the traffic data corresponding to the module identifier.

可以理解的是,流量统计模块在统计流量的时候,会统计各个应用模块在各个时间段内的消耗的流量,并将这个各个时间段内的流量与对应的模块标识进行存储,具体地可以以数据列表的形式进行存储。图10为一个实施例中存储流量数据的数据列表的示意图。如图10所示,流量数据以Hash表的形式进行存储。Hash表的索引Key主要以应用模块的UID和网络接口进行区分,数据对象中的数据按照时间轴存储各个时间段的流量数据。数据对象中包括流量接收量、接收包、发送量和发送包。接收/发送量是指接收和发送的数据包的字节总量,接收/发送包是指接收和发送的数据包的个数。具体地,图11为一个实施例中存储流量数据的数据对象的示意图。如图11所示,一个数据对象中将时间轴划分为固定大小的时间段,并分别将各个时间段内统计的流量数据进行存储。需要获取流量数据时,输入开始时间和结束时间,并获取开始时间到结束时间内的各个时间段对应的流量数据,就可以知道开始时间到结束时间之间产生的总的流量数据。It can be understood that when the traffic statistics module collects traffic statistics, it will count the traffic consumed by each application module in each time period, and store the traffic in each time period and the corresponding module identifier. The data is stored in the form of a list. FIG. 10 is a schematic diagram of a data list storing traffic data in one embodiment. As shown in Figure 10, the traffic data is stored in the form of a Hash table. The index key of the Hash table is mainly distinguished by the UID of the application module and the network interface. The data in the data object stores the traffic data of each time period according to the time axis. The data objects include traffic received, received packets, sent, and sent packets. Received/sent volume refers to the total number of bytes of data packets received and sent, and received/sent packets refers to the number of received and sent data packets. Specifically, FIG. 11 is a schematic diagram of a data object storing traffic data in one embodiment. As shown in FIG. 11 , in a data object, the time axis is divided into time periods of fixed size, and the statistics of traffic data in each time period are stored separately. When you need to obtain traffic data, enter the start time and end time, and obtain the traffic data corresponding to each time period from the start time to the end time, then you can know the total traffic data generated between the start time and the end time.

步骤514,获取网络类型参数和/或应用标识。Step 514: Obtain network type parameters and/or application identifiers.

在一个实施例中,统计参数中还可以包括网络类型参数,网络类型参数是指访问网络类型的参数,网络类型一般可以包括Wi-Fi(Wireless Fidelity,无线保真)网络接口、2G网络接口、3G网络接口和4G网络接口等类型。则可以分别对各个不同的网络接口所产生的数据流量进行统计。统计参数中还可以包括应用标识,应用标识是指区分不同应用模块的唯一标识。根据应用标识可以获取流量数据,可以对各个应用模块对应的流量数据进行统计。In one embodiment, the statistical parameters may further include network type parameters, the network type parameters refer to parameters of the access network type, and the network type may generally include a Wi-Fi (Wireless Fidelity, wireless fidelity) network interface, a 2G network interface, 3G network interface and 4G network interface and other types. Then the data traffic generated by each different network interface can be counted separately. The statistical parameters may also include an application identifier, and the application identifier refers to a unique identifier that distinguishes different application modules. The traffic data can be obtained according to the application identifier, and the traffic data corresponding to each application module can be counted.

步骤516,将第一流量数据和第二流量数据根据网络类型参数和/或应用标识进行划分。Step 516: Divide the first traffic data and the second traffic data according to network type parameters and/or application identifiers.

输入第一时刻和第二时刻,统计得到的是终端在第一时刻和第二时刻之间所消耗的流量数据。统计得到的流量数据可以根据网络类型参数和/或应用标识进行区分,然后得到网络类型参数和/或应用标识对应的第一流量数据和第二流量数据。Enter the first time and the second time, and the statistics obtained are the traffic data consumed by the terminal between the first time and the second time. The traffic data obtained by statistics can be distinguished according to the network type parameter and/or the application identifier, and then the first traffic data and the second traffic data corresponding to the network type parameter and/or the application identifier are obtained.

步骤518,根据第一流量数据和第二流量数据,统计网络类型参数和/或应用标识对应的流量数据。Step 518, according to the first traffic data and the second traffic data, count traffic data corresponding to network type parameters and/or application identifiers.

在一个实施例中,将获取的第一流量数据和第二流量数据相加,则可以得到流量数据,然后可以得到统计网络类型参数和/或应用标识对应的流量数据。统计的流量数据可以在智能终端的界面上进行显示,并通过每次统计的流量数据生成数据报表,并将数据报表进行显示,以使用户可以实时查看流量的使用情况。还可以根据统计的流量数据生成提示信息,并将提示信息显示在智能终端的界面上。例如,在统计到一天之内所消耗的流量超过500MB,通过提示框对用户进行提示。In one embodiment, the acquired first traffic data and the second traffic data are added to obtain traffic data, and then traffic data corresponding to statistical network type parameters and/or application identifiers can be obtained. The statistical traffic data can be displayed on the interface of the smart terminal, and a data report can be generated from the traffic data collected each time, and the data report can be displayed, so that the user can view the traffic usage in real time. It is also possible to generate prompt information according to the statistical traffic data, and display the prompt information on the interface of the intelligent terminal. For example, if the traffic consumed in one day exceeds 500MB, the user will be prompted through a prompt box.

图12为一个实施例中流量统计结果的终端显示图。如图12所示,该流量统计结果中包含了不同网络类型的流量数据的统计结果,以及当前剩余流量。并通过曲线图将流量统计结果分别进行展示,用户可以通过展示界面查看每天的流量数据。FIG. 12 is a terminal display diagram of traffic statistics results in one embodiment. As shown in FIG. 12 , the traffic statistics result includes the statistics results of traffic data of different network types and the current remaining traffic. The traffic statistics results are displayed separately through the curve graph, and users can view the daily traffic data through the display interface.

图13为另一个实施例中流量统计结果的终端显示图。如图13所示,该流量统计结果中包含了各个应用程序所消耗的流量数据,并分别进行展示。通过曲线图展示各个应用程序所消耗的流量数据的变化。FIG. 13 is a terminal display diagram of traffic statistics results in another embodiment. As shown in Figure 13, the traffic statistics result includes the traffic data consumed by each application and is displayed separately. The changes in the traffic data consumed by each application are displayed through graphs.

上述实施例提供的流量统计方法,首先获取第一时刻和第二时刻,并根据第一时刻和第二时刻将时间段进行划分,分别将第一流量数据和第二流量数据保存在第一文件和第二文件中。从第一文件中读取第一流量数据,从第二文件中读取第二流量数据,并根据第一流量数据和第二流量数据统计流量数据。由于第一文件保存在框架层中,读取数据的速度比较快,这样不用每次读取流量数据都从内核层中读取,提高了流量统计的效率。The traffic statistics method provided by the above embodiment firstly obtains the first moment and the second moment, divides the time period according to the first moment and the second moment, and saves the first traffic data and the second traffic data in the first file respectively. and in the second file. The first traffic data is read from the first file, the second traffic data is read from the second file, and the traffic data is counted according to the first traffic data and the second traffic data. Since the first file is stored in the framework layer, the speed of reading data is relatively fast, so that the traffic data does not need to be read from the kernel layer every time the traffic data is read, which improves the efficiency of traffic statistics.

图14为一个实施例中流量统计装置的结构示意图。如图14所示,该流量统计装置1400中包括参数获取模块1402、第一数据获取模块1404、第二数据获取模块1406和流量数据模块1408。其中:FIG. 14 is a schematic structural diagram of a flow statistics apparatus in an embodiment. As shown in FIG. 14 , the traffic statistics device 1400 includes a parameter acquisition module 1402 , a first data acquisition module 1404 , a second data acquisition module 1406 and a traffic data module 1408 . in:

参数获取模块1402,用于获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻。A parameter acquisition module 1402, configured to acquire a first time and a second time, where the first time is later than the second time.

第一数据获取模块1404,用于从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间。The first data acquisition module 1404 is configured to read the first traffic data from the first file, the first file is used to save the traffic data consumed by the terminal from the third moment to the first moment, the third The time instant lies between the first time instant and the second time instant.

第二数据获取模块1406,用于从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据。The second data acquisition module 1406 is configured to read second traffic data from a second file, where the second file is used to save the traffic data consumed by the terminal before the first moment, and the second traffic data represents Traffic data consumed by the terminal from the second moment to the third moment.

流量数据模块1408,用于根据所述第一流量数据和第二流量数据统计流量数据。The traffic data module 1408 is configured to count traffic data according to the first traffic data and the second traffic data.

上述实施例提供的流量统计装置,首先获取第一时刻和第二时刻,并根据第一时刻和第二时刻将时间段进行划分,从第一文件中读取第一流量数据,从第二文件中读取第二流量数据,并根据第一流量数据和第二流量数据统计流量数据。这样分别进行统计,提高了流量统计的效率。The traffic statistics device provided by the above embodiment first obtains the first moment and the second moment, divides the time period according to the first moment and the second moment, reads the first traffic data from the first file, and reads the first traffic data from the second file. The second traffic data is read in, and the traffic data is counted according to the first traffic data and the second traffic data. In this way, statistics are performed separately, which improves the efficiency of traffic statistics.

图15为另一个实施例中流量统计装置的结构示意图。如图15所示,该流量统计装置1500中包括参数获取模块1502、第一数据获取模块1504、第二数据获取模块1506、数据划分模块1508和流量数据模块1510。其中:FIG. 15 is a schematic structural diagram of a flow statistics device in another embodiment. As shown in FIG. 15 , the traffic statistics device 1500 includes a parameter acquisition module 1502 , a first data acquisition module 1504 , a second data acquisition module 1506 , a data division module 1508 and a traffic data module 1510 . in:

参数获取模块1502,用于获取第一时刻和第二时刻,所述第一时刻晚于所述第二时刻。A parameter acquisition module 1502, configured to acquire a first time and a second time, where the first time is later than the second time.

第一数据获取模块1504,用于从第一文件中读取第一流量数据,所述第一文件用于保存所述终端从第三时刻到第一时刻所消耗的流量数据,所述第三时刻位于所述第一时刻和第二时刻之间。The first data acquisition module 1504 is configured to read the first traffic data from the first file, and the first file is used to save the traffic data consumed by the terminal from the third moment to the first moment. The time instant lies between the first time instant and the second time instant.

第二数据获取模块1506,用于从第二文件中读取第二流量数据,所述第二文件用于保存所述终端在第一时刻之前所消耗的流量数据,所述第二流量数据表示所述终端从第二时刻到第三时刻所消耗的流量数据。The second data acquisition module 1506 is configured to read second traffic data from a second file, where the second file is used to save the traffic data consumed by the terminal before the first moment, and the second traffic data represents Traffic data consumed by the terminal from the second moment to the third moment.

数据划分模块1508,用于获取网络类型参数和/或应用标识,将所述第一流量数据和第二流量数据根据所述网络类型参数和/或应用标识进行划分。A data division module 1508, configured to acquire network type parameters and/or application identifiers, and divide the first traffic data and the second traffic data according to the network type parameters and/or application identifiers.

流量数据模块1510,用于根据所述第一流量数据和第二流量数据,统计所述网络类型参数和/或应用标识对应的流量数据。The traffic data module 1510 is configured to count the traffic data corresponding to the network type parameter and/or the application identifier according to the first traffic data and the second traffic data.

上述实施例提供的流量统计装置,首先获取第一时刻和第二时刻,并根据第一时刻和第二时刻将时间段进行划分,从第一文件中读取第一流量数据,从第二文件中读取第二流量数据,并根据第一流量数据和第二流量数据统计流量数据。这样分别进行统计,提高了流量统计的效率。The traffic statistics device provided by the above embodiment first obtains the first moment and the second moment, divides the time period according to the first moment and the second moment, reads the first traffic data from the first file, and reads the first traffic data from the second file. The second traffic data is read in, and the traffic data is counted according to the first traffic data and the second traffic data. In this way, statistics are performed separately, which improves the efficiency of traffic statistics.

在一个实施例中,第一数据获取模块1504还用于从终端的内存中读取第一流量数据,将所述第一流量数据保存到第一文件中,并将所述第一文件存储在所述终端的缓存中;从所述终端的缓存中读取第一文件,并从所述第一文件中读取第一流量数据。In one embodiment, the first data acquisition module 1504 is further configured to read the first traffic data from the memory of the terminal, save the first traffic data into a first file, and store the first file in a in the cache of the terminal; read the first file from the cache of the terminal, and read the first traffic data from the first file.

在一个实施例中,第一数据获取模块1504还用于从所述终端的内核层中的第二文件中读取第一流量数据,并将所述第一流量数据保存到所述终端的框架层的内存中。In one embodiment, the first data acquisition module 1504 is further configured to read the first traffic data from the second file in the kernel layer of the terminal, and save the first traffic data to the framework of the terminal layer in memory.

在一个实施例中,第二数据获取模块1506还用于调用流量统计接口,通过所述流量统计接口从第二文件中读取第二流量数据,所述第二文件存储在所述终端的内核层中。In one embodiment, the second data acquisition module 1506 is further configured to call a traffic statistics interface, and read the second traffic data from a second file through the traffic statistics interface, and the second file is stored in the kernel of the terminal in the layer.

在一个实施例中,第二数据获取模块1506还用于通过所述流量统计接口输入第二时刻和第三时刻;根据所述第二时刻和第三时刻从第二文件中读取第二流量数据,通过所述流量统计接口返回第二流量数据。In one embodiment, the second data acquisition module 1506 is further configured to input the second time and the third time through the traffic statistics interface; read the second traffic from the second file according to the second time and the third time data, and return the second traffic data through the traffic statistics interface.

在一个实施例中,第二数据获取模块1506还用于根据所述第二时刻和第三时刻从所述终端的内核层中的文件系统中获取第二文件,并从所述第二文件中读取第二流量数据。In one embodiment, the second data obtaining module 1506 is further configured to obtain a second file from the file system in the kernel layer of the terminal according to the second time and the third time, and obtain a second file from the second file Read the second flow data.

本申请实施例还提供了一种计算机可读存储介质。一个或多个包含计算机可执行指令的非易失性计算机可读存储介质,当所述计算机可执行指令被一个或多个处理器执行时,使得所述处理器执行时实现本申请实施例提供的流量统计方法。如图16所示,该终端包括通过系统总线连接的处理器、存储器。其中,该处理器用于提供计算和控制能力,支撑整个计算机设备的运行。存储器用于存储数据、程序等,存储器上存储至少一个计算机程序,该计算机程序可被处理器执行,以实现本申请实施例中提供的适用于终端的流量统计方法。存储器可包括磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random-Access-Memory,RAM)等。例如,在一个实施例中,存储器包括非易失性存储介质及内存储器。非易失性存储介质存储有操作系统和计算机程序。该计算机程序可被处理器所执行,以用于实现以下各个实施例所提供的流量统计方法。内存储器为非易失性存储介质中的操作系统计算机程序提供高速缓存的运行环境。该计算机设备可以是手机、平板电脑或者个人数字助理或穿戴式设备等。The embodiment of the present application also provides a computer-readable storage medium. One or more non-volatile computer-readable storage media containing computer-executable instructions, when the computer-executable instructions are executed by one or more processors, so that when the processors execute the instructions provided by the embodiments of the present application traffic statistics. As shown in Figure 16, the terminal includes a processor and a memory connected through a system bus. Among them, the processor is used to provide computing and control capabilities to support the operation of the entire computer equipment. The memory is used for storing data, programs, etc., and at least one computer program is stored in the memory, and the computer program can be executed by the processor to implement the traffic statistics method applicable to the terminal provided in the embodiment of the present application. The memory may include a non-volatile storage medium such as a magnetic disk, an optical disk, and a read-only memory (Read-Only Memory, ROM), or a random-access-memory (Random-Access-Memory, RAM) and the like. For example, in one embodiment, the memory includes a non-volatile storage medium and internal memory. The nonvolatile storage medium stores an operating system and a computer program. The computer program can be executed by the processor to implement the traffic statistics methods provided in the following embodiments. Internal memory provides a cached execution environment for operating system computer programs in non-volatile storage media. The computer device may be a mobile phone, a tablet computer, a personal digital assistant or a wearable device, or the like.

本申请实施例还提供了一种计算机设备。如图17所示,为了便于说明,仅示出了与本申请实施例相关的部分,具体技术细节未揭示的,请参照本申请实施例方法部分。该计算机设备可以为包括手机、平板电脑、PDA(Personal Digital Assistant,个人数字助理)、POS(Point of Sales,销售终端)、车载电脑、穿戴式设备等任意终端设备,以计算机设备为手机为例:The embodiments of the present application also provide a computer device. As shown in FIG. 17 , for the convenience of description, only the parts related to the embodiments of the present application are shown, and the specific technical details are not disclosed, please refer to the method part of the embodiments of the present application. The computer device can be any terminal device including a mobile phone, a tablet computer, a PDA (Personal Digital Assistant), a POS (Point of Sales, a sales terminal), a vehicle-mounted computer, a wearable device, etc. The computer device is a mobile phone as an example :

图17为与本申请实施例提供的计算机设备相关的手机的部分结构的框图。参考图17,手机包括:射频(Radio Frequency,RF)电路1710、存储器1720、输入单元1730、显示单元1740、传感器1750、音频电路1760、无线保真(wireless fidelity,WiFi)模块1770、处理器1780、以及电源1790等部件。本领域技术人员可以理解,图17所示的手机结构并不构成对手机的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。FIG. 17 is a block diagram of a partial structure of a mobile phone related to a computer device provided by an embodiment of the present application. 17 , the mobile phone includes: a radio frequency (RF) circuit 1710 , a memory 1720 , an input unit 1730 , a display unit 1740 , a sensor 1750 , an audio circuit 1760 , a wireless fidelity (WiFi) module 1770 , and a processor 1780 , and the power supply 1790 and other components. Those skilled in the art can understand that the structure of the mobile phone shown in FIG. 17 does not constitute a limitation on the mobile phone, and may include more or less components than shown, or combine some components, or arrange different components.

其中,RF电路1710可用于收发信息或通话过程中,信号的接收和发送,可将基站的下行信息接收后,给处理器1780处理;也可以将上行的数据发送给基站。通常,RF电路包括但不限于天线、至少一个放大器、收发信机、耦合器、低噪声放大器(Low Noise Amplifier,LNA)、双工器等。此外,RF电路1710还可以通过无线通信与网络和其他设备通信。上述无线通信可以使用任一通信标准或协议,包括但不限于全球移动通讯系统(Global System ofMobile communication,GSM)、通用分组无线服务(General Packet Radio Service,GPRS)、码分多址(Code Division Multiple Access,CDMA)、宽带码分多址(Wideband CodeDivision Multiple Access,WCDMA)、长期演进(Long Term Evolution,LTE))、电子邮件、短消息服务(Short Messaging Service,SMS)等。The RF circuit 1710 can be used for receiving and sending signals during sending and receiving of information or during a call. After receiving the downlink information of the base station, it can be processed by the processor 1780; it can also send the uplink data to the base station. Typically, the RF circuit includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a Low Noise Amplifier (LNA), a duplexer, and the like. In addition, RF circuitry 1710 may also communicate with networks and other devices via wireless communications. The above-mentioned wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access) Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE)), email, Short Messaging Service (Short Messaging Service, SMS) and the like.

存储器1720可用于存储软件程序以及模块,处理器1780通过运行存储在存储器1720的软件程序以及模块,从而执行手机的各种功能应用以及数据处理。存储器1720可主要包括程序存储区和数据存储区,其中,程序存储区可存储操作系统、至少一个功能所需的应用程序(比如声音播放功能的应用程序、图像播放功能的应用程序等)等;数据存储区可存储根据手机的使用所创建的数据(比如音频数据、通讯录等)等。此外,存储器1720可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。The memory 1720 can be used to store software programs and modules, and the processor 1780 executes various functional applications and data processing of the mobile phone by running the software programs and modules stored in the memory 1720 . The memory 1720 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function (such as an application program for a sound playback function, an application program for an image playback function, etc.), etc.; The data storage area may store data (such as audio data, address book, etc.) created according to the usage of the mobile phone, and the like. Additionally, memory 1720 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.

输入单元1730可用于接收输入的数字或字符信息,以及产生与手机1700的用户设置以及功能控制有关的键信号输入。具体地,输入单元1730可包括触控面板1731以及其他输入设备1732。触控面板1731,也可称为触摸屏,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触控面板1731上或在触控面板1731附近的操作),并根据预先设定的程式驱动相应的连接装置。在一个实施例中,触控面板1731可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给处理器1780,并能接收处理器1780发来的命令并加以执行。此外,可以采用电阻式、电容式、红外线以及表面声波等多种类型实现触控面板1731。除了触控面板1731,输入单元1730还可以包括其他输入设备1732。具体地,其他输入设备1732可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)等中的一种或多种。The input unit 1730 may be used to receive input numerical or character information, and generate key signal input related to user settings and function control of the mobile phone 1700 . Specifically, the input unit 1730 may include a touch panel 1731 and other input devices 1732 . The touch panel 1731, which may also be referred to as a touch screen, collects the user's touch operations on or near it (such as the user using a finger, a stylus, or any suitable object or accessory on or near the touch panel 1731 ). operation), and drive the corresponding connection device according to the preset program. In one embodiment, the touch panel 1731 may include two parts, a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into contact coordinates, and then sends it to the touch controller. To the processor 1780, and can receive the command sent by the processor 1780 and execute it. In addition, the touch panel 1731 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 1731 , the input unit 1730 may further include other input devices 1732 . Specifically, other input devices 1732 may include, but are not limited to, one or more of physical keyboards, function keys (such as volume control keys, switch keys, etc.), and the like.

显示单元1740可用于显示由用户输入的信息或提供给用户的信息以及手机的各种菜单。显示单元1740可包括显示面板1741。在一个实施例中,可以采用液晶显示器(Liquid Crystal Display,LCD)、有机发光二极管(Organic Light-Emitting Diode,OLED)等形式来配置显示面板1741。在一个实施例中,触控面板1731可覆盖显示面板1741,当触控面板1731检测到在其上或附近的触摸操作后,传送给处理器1780以确定触摸事件的类型,随后处理器1780根据触摸事件的类型在显示面板1741上提供相应的视觉输出。虽然在图17中,触控面板1731与显示面板1741是作为两个独立的部件来实现手机的输入和输入功能,但是在某些实施例中,可以将触控面板1731与显示面板1741集成而实现手机的输入和输出功能。The display unit 1740 may be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 1740 may include a display panel 1741 . In one embodiment, the display panel 1741 may be configured in the form of a Liquid Crystal Display (LCD), an Organic Light-Emitting Diode (OLED), or the like. In one embodiment, the touch panel 1731 may cover the display panel 1741, and when the touch panel 1731 detects a touch operation on or near it, the touch panel 1731 transmits it to the processor 1780 to determine the type of the touch event, and then the processor 1780 determines the type of the touch event according to the The type of touch event provides a corresponding visual output on the display panel 1741 . Although in FIG. 17, the touch panel 1731 and the display panel 1741 are used as two independent components to realize the input and input functions of the mobile phone, in some embodiments, the touch panel 1731 and the display panel 1741 can be integrated to form Realize the input and output functions of the mobile phone.

手机1700还可包括至少一种传感器1750,比如光传感器、运动传感器以及其他传感器。具体地,光传感器可包括环境光传感器及接近传感器,其中,环境光传感器可根据环境光线的明暗来调节显示面板1741的亮度,接近传感器可在手机移动到耳边时,关闭显示面板1741和/或背光。运动传感器可包括加速度传感器,通过加速度传感器可检测各个方向上加速度的大小,静止时可检测出重力的大小及方向,可用于识别手机姿态的应用(比如横竖屏切换)、振动识别相关功能(比如计步器、敲击)等;此外,手机还可配置陀螺仪、气压计、湿度计、温度计、红外线传感器等其他传感器等。Cell phone 1700 may also include at least one sensor 1750, such as light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 1741 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 1741 and/or when the mobile phone is moved to the ear. or backlight. Motion sensors can include acceleration sensors, which can detect the magnitude of acceleration in all directions, and can detect the magnitude and direction of gravity when stationary. It can be used for applications that recognize the posture of mobile phones (such as switching between horizontal and vertical screens), and vibration recognition related functions (such as Pedometer, tapping), etc.; in addition, the mobile phone can also be equipped with other sensors such as gyroscope, barometer, hygrometer, thermometer, infrared sensor, etc.

音频电路1760、扬声器1761和传声器1762可提供用户与手机之间的音频接口。音频电路1760可将接收到的音频数据转换后的电信号,传输到扬声器1761,由扬声器1761转换为声音信号输出;另一方面,传声器1762将收集的声音信号转换为电信号,由音频电路1760接收后转换为音频数据,再将音频数据输出处理器1780处理后,经RF电路1710可以发送给另一手机,或者将音频数据输出至存储器1720以便后续处理。Audio circuit 1760, speaker 1761 and microphone 1762 may provide an audio interface between the user and the cell phone. The audio circuit 1760 can transmit the received audio data converted electrical signal to the speaker 1761, and the speaker 1761 converts it into a sound signal for output; on the other hand, the microphone 1762 converts the collected sound signal into an electrical signal, which is converted by the audio circuit 1760 After receiving, the audio data is converted into audio data, and then the audio data is output to the processor 1780 for processing, and can be sent to another mobile phone via the RF circuit 1710, or the audio data can be output to the memory 1720 for subsequent processing.

WiFi属于短距离无线传输技术,手机通过WiFi模块1770可以帮助用户收发电子邮件、浏览网页和访问流式媒体等,它为用户提供了无线的宽带互联网访问。虽然图17示出了WiFi模块1770,但是可以理解的是,其并不属于手机1700的必须构成,可以根据需要而省略。WiFi is a short-distance wireless transmission technology. The mobile phone can help users to send and receive emails, browse web pages and access streaming media through the WiFi module 1770. It provides users with wireless broadband Internet access. Although FIG. 17 shows the WiFi module 1770, it can be understood that it is not a necessary component of the mobile phone 1700 and can be omitted as required.

处理器1780是手机的控制中心,利用各种接口和线路连接整个手机的各个部分,通过运行或执行存储在存储器1720内的软件程序和/或模块,以及调用存储在存储器1720内的数据,执行手机的各种功能和处理数据,从而对手机进行整体监控。在一个实施例中,处理器1780可包括一个或多个处理单元。在一个实施例中,处理器1780可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等;调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器1780中。The processor 1780 is the control center of the mobile phone, using various interfaces and lines to connect various parts of the entire mobile phone, by running or executing the software programs and/or modules stored in the memory 1720, and calling the data stored in the memory 1720. Various functions of the mobile phone and processing data, so as to monitor the mobile phone as a whole. In one embodiment, the processor 1780 may include one or more processing units. In one embodiment, the processor 1780 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface and application programs, etc.; the modem processor mainly handles wireless communication. It can be understood that, the above-mentioned modulation and demodulation processor may not be integrated into the processor 1780.

手机1700还包括给各个部件供电的电源1790(比如电池),优选的,电源可以通过电源管理系统与处理器1780逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。The mobile phone 1700 also includes a power supply 1790 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 1780 through a power management system, so as to manage charging, discharging, and power consumption management functions through the power management system.

在一个实施例中,手机1700还可以包括摄像头、蓝牙模块等。In one embodiment, the mobile phone 1700 may further include a camera, a Bluetooth module, and the like.

在本申请实施例中,该移动终端所包括的处理器1780执行存储在存储器上的计算机程序时实现上述实施例提供的流量统计方法。In this embodiment of the present application, when the processor 1780 included in the mobile terminal executes the computer program stored in the memory, the traffic statistics method provided in the foregoing embodiment is implemented.

一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述实施例提供的流量统计方法。A computer program product containing instructions, when running on a computer, causes the computer to execute the traffic statistics method provided by the above embodiments.

本申请所使用的对存储器、存储、数据库或其它介质的任何引用可包括非易失性和/或易失性存储器。合适的非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM),它用作外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDR SDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)。Any reference to a memory, storage, database, or other medium as used herein may include non-volatile and/or volatile memory. Suitable nonvolatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which acts as external cache memory. By way of illustration and not limitation, RAM is available in various forms such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous Link (Synchlink) DRAM (SLDRAM), Memory Bus (Rambus) Direct RAM (RDRAM), Direct Memory Bus Dynamic RAM (DRDRAM), and Memory Bus Dynamic RAM (RDRAM).

以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。The above-mentioned embodiments only represent several embodiments of the present application, and the descriptions thereof are relatively specific and detailed, but should not be construed as a limitation on the scope of the patent of the present application. It should be pointed out that for those skilled in the art, without departing from the concept of the present application, several modifications and improvements can be made, which all belong to the protection scope of the present application. Therefore, the scope of protection of the patent of the present application shall be subject to the appended claims.

Claims (10)

1. a kind of flow statistical method, which is characterized in that the described method includes:
The first moment and the second moment are obtained, first moment is later than second moment;
First flow data are read from the first file, first file is for saving terminal from the third moment to the first moment Consumed data on flows, first file are stored in the caching of the terminal, and the third moment is located at described first Between moment and the second moment, the first flow data indicate that the terminal flows consumed by from the third moment to the first moment Measure data;
Second flow data are read from the second file, second file is for saving terminal institute before the first moment The data on flows of consumption, second file are stored in the inner nuclear layer of the terminal, described in the second flow data expression Terminal data on flows consumed by from the second moment to the third moment;
According to the first flow data and second flow data statistics from first moment to institute second moment The data on flows of generation.
2. flow statistical method according to claim 1, which is characterized in that described to read first flow from the first file Data include:
First flow data are read from the memory of terminal, the first flow data are saved in the first file, and by institute The first file is stated to be stored in the caching of the terminal;
The first file is read from the caching of the terminal, and first flow data are read from first file.
3. flow statistical method according to claim 2, which is characterized in that described to read first flow from the first file Before data further include:
First flow data are read from the second file in the inner nuclear layer of the terminal, and the first flow data are saved Into the memory of the ccf layer of the terminal.
4. flow statistical method according to claim 1, which is characterized in that described to read second flow from the second file Data include:
Traffic statistics interface is called, second flow data are read from the second file by the traffic statistics interface, described the Two files are stored in the inner nuclear layer of the terminal.
5. flow statistical method according to claim 4, which is characterized in that the calling traffic statistics interface passes through institute It states traffic statistics interface and reads second flow data from the second file and include:
The second moment and third moment are inputted by the traffic statistics interface;
Second flow data are read from the second file according to second moment and third moment, are connect by the traffic statistics Mouth returns to second flow data.
6. flow statistical method according to claim 5, which is characterized in that it is described according to second moment and third when Carving the reading second flow data from the second file includes:
The second file is obtained from the file system in the inner nuclear layer of the terminal according to second moment and third moment, and Second flow data are read from second file.
7. flow statistical method according to claim 1, which is characterized in that the method also includes:
Obtain network type parameters and/or application identities;
The first flow data and second flow data are drawn according to the network type parameters and/or application identities Point;
It is described according to the first flow data and second flow data statistics data on flows:
According to the first flow data and second flow data, counts the network type parameters and/or application identities are corresponding Data on flows.
8. a kind of flow statistic device, which is characterized in that described device includes:
Parameter acquisition module is later than second moment for obtaining the first moment and the second moment, first moment;
First data acquisition module, for reading first flow data from the first file, first file is for saving end Data on flows consumed by from the third moment to the first moment is held, first file is stored in the caching of the terminal, institute The third moment is stated between first moment and the second moment, when the first flow data indicate the terminal from third It is carved into data on flows consumed by the first moment;
Second data acquisition module, for reading second flow data from the second file, second file is for saving institute Terminal consumed data on flows before the first moment is stated, second file is stored in the inner nuclear layer of the terminal, institute Stating second flow data indicates terminal data on flows consumed by from the second moment to the third moment;
Data on flows module was used for according to the first flow data and second flow data statistics from first moment to institute State generated data on flows between the second moment.
9. a kind of computer equipment, including memory and processor, computer-readable instruction is stored in the memory, it is described When instruction is executed by the processor, so that the processor executes the method as described in any one of claims 1 to 7.
10. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program The method as described in any one of claims 1 to 7 is realized when being executed by processor.
CN201710924596.8A 2017-09-30 2017-09-30 Flow statistical method and device, computer equipment and computer readable storage medium Active CN107743080B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710924596.8A CN107743080B (en) 2017-09-30 2017-09-30 Flow statistical method and device, computer equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710924596.8A CN107743080B (en) 2017-09-30 2017-09-30 Flow statistical method and device, computer equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN107743080A CN107743080A (en) 2018-02-27
CN107743080B true CN107743080B (en) 2019-10-25

Family

ID=61236728

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710924596.8A Active CN107743080B (en) 2017-09-30 2017-09-30 Flow statistical method and device, computer equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN107743080B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108650384B (en) * 2018-05-15 2020-07-07 Oppo(重庆)智能科技有限公司 Information processing method, device, mobile terminal and computer readable storage medium
CN111432077B (en) * 2020-03-27 2021-05-11 广西东信易联科技有限公司 CDR-based normalized flow statistical device and method
CN111966491B (en) * 2020-08-04 2023-07-21 Oppo广东移动通信有限公司 Method for counting occupied memory and terminal equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101388110A (en) * 2008-10-31 2009-03-18 深圳市同洲电子股份有限公司 Data rapidly-reading method and apparatus
CN103905260A (en) * 2012-12-25 2014-07-02 北京新媒传信科技有限公司 Terminal device network traffic monitoring method and device
CN104125596A (en) * 2014-07-07 2014-10-29 北京奇虎科技有限公司 A data traffic statistics method and device
CN104135399A (en) * 2014-07-09 2014-11-05 国家电网公司 Flow monitoring method based on wireless public network communication way for power distribution terminal
CN105022698A (en) * 2015-06-26 2015-11-04 上海新储集成电路有限公司 Method for storing special function data by using last level of hybrid cache
CN106230662A (en) * 2016-08-01 2016-12-14 北京小米移动软件有限公司 Network flux statistical method and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103379461A (en) * 2012-04-26 2013-10-30 华为终端有限公司 Data service traffic statistical method and terminal
US10367836B2 (en) * 2015-10-27 2019-07-30 Sk Planet Co., Ltd. Method and apparatus for detecting abnormal state of beacon device in wireless mesh network and recording medium storing computer program for executing the method

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101388110A (en) * 2008-10-31 2009-03-18 深圳市同洲电子股份有限公司 Data rapidly-reading method and apparatus
CN103905260A (en) * 2012-12-25 2014-07-02 北京新媒传信科技有限公司 Terminal device network traffic monitoring method and device
CN104125596A (en) * 2014-07-07 2014-10-29 北京奇虎科技有限公司 A data traffic statistics method and device
CN104135399A (en) * 2014-07-09 2014-11-05 国家电网公司 Flow monitoring method based on wireless public network communication way for power distribution terminal
CN105022698A (en) * 2015-06-26 2015-11-04 上海新储集成电路有限公司 Method for storing special function data by using last level of hybrid cache
CN106230662A (en) * 2016-08-01 2016-12-14 北京小米移动软件有限公司 Network flux statistical method and device

Also Published As

Publication number Publication date
CN107743080A (en) 2018-02-27

Similar Documents

Publication Publication Date Title
CN107770746B (en) Data processing method and device, computer equipment and computer readable storage medium
CN107682910B (en) Traffic resource sharing method and device, mobile terminal and storage medium
CN107708084B (en) Data processing method and device, computer equipment and computer readable storage medium
CN107707369A (en) Method and device for traffic order management, computer equipment, and readable storage medium
CN107484154B (en) Data switching method and device, terminal and computer readable storage medium
CN107734584A (en) Method and device for network connection switching, computer equipment, and readable storage medium
CN108616653B (en) Information processing method, device, mobile terminal, and computer-readable storage medium
WO2019072103A1 (en) Method and apparatus for obtaining target data
CN107679559A (en) Image processing method, device, computer-readable recording medium and mobile terminal
CN107682833A (en) Method and device for controlling flow use, mobile terminal and storage medium
CN107682851A (en) Information processing method, device, mobile terminal, and computer-readable storage medium
CN109445917B (en) Application processing method and apparatus, electronic device, computer-readable storage medium
CN107690131A (en) Information processing method, device, mobile terminal, and computer-readable storage medium
CN107743080B (en) Flow statistical method and device, computer equipment and computer readable storage medium
CN107992822A (en) Image processing method and device, computer equipment, computer-readable recording medium
CN107734495B (en) Information processing method, device, storage medium and terminal
CN107484201B (en) Traffic statistics method and device, terminal, and computer-readable storage medium
CN107623612B (en) Flow display method and device, computer equipment and computer readable storage medium
WO2015043163A1 (en) Method and apparatus for inputting account information
US11109226B2 (en) Information process method, computer readable storage medium and computer device
CN107635220A (en) Network communication processing method, device, storage medium and terminal
CN107734492B (en) Information processing method, device, mobile terminal and computer readable storage medium
CN107708107A (en) Network communication processing method, device, storage medium and terminal
CN107918529A (en) Image processing method and apparatus, computer device, computer-readable storage medium
CN107566398A (en) Flow control method and device, computer equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Changan town in Guangdong province Dongguan 523860 usha Beach Road No. 18

Applicant after: OPPO Guangdong Mobile Communications Co., Ltd.

Address before: Changan town in Guangdong province Dongguan 523860 usha Beach Road No. 18

Applicant before: Guangdong Opel Mobile Communications Co., Ltd.

GR01 Patent grant
GR01 Patent grant