Advanced Topics¶
Logging the Analyzer Events¶
MobileInsight analyzers provide built-in loggers to save the analysis/debugging results. The logger is implemented with Python logging module. All the analyzers share the single logger. The following code configures the log file path and logging level:
import logging
from analyzer import *
analyzer = LteRrcAnalyzer()
#Set log file path and level
analyzer.set_log("analyzers.log",logging.INFO)
Writing An Analyzer¶
MobieInsight analyzers are designed to be extensible. You can define your own analyzers for customized analysis. Your customized analyzers can be built on top of existing analyzers, which can help reduce the development complexity. Before writing your own analyzers, please first clarify the following questions:
What analysis functions do you want to perform?
What other analyzers you may want to use to faciliate the analysis?
As a example, consider writing a RRC (radio resource control) analyzer. Different from 3G/4G-only RRC analyzer, the purpose of this RRC analyzer is to offer a unified analysis for RRC, no matter whether the phone is in 3G or 4G (question 1). To achieve it, this analyzer is built on top of existing 4G LteRrcAnalyzer and 3G WcdmaRrcAnalyzer (question 2). The following code shows part of this implementation (the complete code can be found here ):
from analyzer import *
from wcdma_rrc_analyzer import WcdmaRrcAnalyzer
from lte_rrc_analyzer import LteRrcAnalyzer
class RrcAnalyzer(Analyzer):
def __init__(self):
Analyzer.__init__(self)
#include analyzers
self.__lte_rrc_analyzer=LteRrcAnalyzer()
self.__wcdma_rrc_analyzer=WcdmaRrcAnalyzer()
self.include_analyzer(self.__lte_rrc_analyzer,[self.__on_event])
self.include_analyzer(self.__wcdma_rrc_analyzer,[self.__on_event])
#init packet filters
self.add_source_callback(self.__rrc_filter)
def __rrc_filter(self,msg):
"""callbacks for the 3G/4G RRC messages"""
#...
In above example, we declare the dependency of LteRrcAnalyzer and WcdmaRrcAnalyzer in the initialization, and defines customized callback functions the react to the 3G/4G RRC messages and/or LteRrcAnalyzer/WcdmaRrcAnalyzer’s events.