Search in sources :

Example 1 with TableAllDataObserver

use of com.tencent.wstt.apt.chart.TableAllDataObserver in project GT by Tencent.

the class TestTaskManager method initTest.

/**
	* @Title: initTest  
	* @Description: 根据测试场景配置来初始化测试   
	* void 
	* @throws
	 */
public boolean initTest() {
    clear();
    //获取进程列表
    int pkgNumber = TestSence.getInstance().pkgInfos.size();
    String[] pkgNames = new String[pkgNumber];
    String[] pkgAbbreviation = new String[pkgNumber];
    //取进程名的后缀
    for (int i = 0; i < pkgNumber; i++) {
        pkgNames[i] = TestSence.getInstance().pkgInfos.get(i).contents[PkgInfo.NAME_INDEX];
        int index = pkgNames[i].lastIndexOf(".");
        ;
        pkgAbbreviation[i] = pkgNames[i].substring(index + 1, pkgNames[i].length());
    }
    CPUView cpuViewPart = (CPUView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CPUView.ID);
    MemoryView memViewPart = (MemoryView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(MemoryView.ID);
    //设置当前测试场景的结果保存目录
    Date curDate = new Date(System.currentTimeMillis());
    TestSence.getInstance().curDir = Constant.SIMPLE_DATE_FORMAT_SECOND.format(curDate);
    APTConsoleFactory.getInstance().APTPrint("测试开始时间:" + TestSence.getInstance().curDir);
    if (TestSence.getInstance().itemTestSwitch[Constant.CPU_INDEX]) {
        if (cpuViewPart == null) {
            return false;
        }
        //打开文件
        if (!(WriteFileUtil.getInstance().openWriteFile(TestSence.getInstance().curDir, Constant.TEXT_ITEM_TITLES[Constant.CPU_INDEX], TestSence.bufThreshold[0]))) {
            APTConsoleFactory.getInstance().APTPrint("创建CPU结果文件失败");
            return false;
        }
        //写文件头
        if (!APTLogFileParse.writeAPTLogFileHeader(Constant.CPU_INDEX)) {
            APTConsoleFactory.getInstance().APTPrint("写CPU文件头部失败");
            return false;
        }
        cpuViewPart.cpuRealTimeChart.initDataset(pkgAbbreviation, new String[] { Constant.CPU_ITEM_TITLES[Constant.CPU_PERSENT_INDEX] });
        DataProvider dataProvider = new CPUProvider(pkgNames, DeviceInfo.getInstance().androidVersion, TestSence.getInstance().cpuTestMethod);
        dataProvider.attach(new ChartObserver(cpuViewPart.cpuRealTimeChart));
        dataProvider.attach(new TableAllDataObserver(cpuViewPart.cpuViewer, pkgAbbreviation, new String[] { Constant.CPU_ITEM_TITLES[Constant.CPU_PERSENT_INDEX] }));
        dataProvider.attach(new FileObserver(Constant.TEXT_ITEM_TITLES[Constant.CPU_INDEX]));
        TestTask tt = new TestTask(dataProvider, TestSence.getInstance().itemTestPeriod[Constant.CPU_INDEX]);
        addTestTask(tt);
        cpuViewPart.setCpuTableViewerFilter(new TableViewFilter(pkgAbbreviation, new String[] { Constant.CPU_ITEM_TITLES[Constant.CPU_PERSENT_INDEX] }));
        if (TestSence.getInstance().isTestJiffies) {
            DevicesView dv = (DevicesView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DevicesView.ID);
            if (dv == null) {
                return false;
            }
            List<PkgInfo> pkgInfos = TestSence.getInstance().pkgInfos;
            String[] pids = new String[pkgInfos.size()];
            for (int i = 0; i < pids.length; i++) {
                pids[i] = pkgInfos.get(i).contents[PkgInfo.PID_INDEX];
            }
            DataProvider jiffiesDataProvider = new JiffiesProviderNew(pkgNumber);
            cpuViewPart.setJiffiesTableViewerFilter(new TableViewFilter(pkgAbbreviation, new String[] { Constant.CPU_ITEM_TITLES[Constant.CPU_JIFFIES_INDEX] }));
            //jiffiesDataProvider.attach(new TableAllDataObserver(cpuViewPart.jiffiesViewer, pkgAbbreviation, new String[]{Constant.CPU_ITEM_TITLES[Constant.CPU_JIFFIES_INDEX]}));
            jiffiesDataProvider.attach(new JiffiesTableObserver(cpuViewPart.jiffiesViewer, pkgAbbreviation));
            jiffiesDataProvider.attach(new PidUpdateObserver(dv.targetPkgTableViewer, pids));
            TestTask jiffiesTT = new TestTask(jiffiesDataProvider, TestSence.getInstance().itemTestPeriod[Constant.CPU_INDEX]);
            addTestTask(jiffiesTT);
        }
        APTConsoleFactory.getInstance().APTPrint("CPU测试Ready");
    }
    //内存测试
    if (TestSence.getInstance().itemTestSwitch[Constant.MEM_INDEX]) {
        if (memViewPart == null) {
            return false;
        }
        //打开文件
        if (!(WriteFileUtil.getInstance().openWriteFile(TestSence.getInstance().curDir, Constant.TEXT_ITEM_TITLES[Constant.MEM_INDEX], TestSence.bufThreshold[1]))) {
            APTConsoleFactory.getInstance().APTPrint("创建内存结果文件失败");
            return false;
        }
        //写文件头
        if (!APTLogFileParse.writeAPTLogFileHeader(Constant.MEM_INDEX)) {
            APTConsoleFactory.getInstance().APTPrint("写内存文件头部失败");
            return false;
        }
        //填充数据
        memViewPart.memRealTimeChart.initDataset(pkgAbbreviation, Constant.MEM_ITEM_TITLES);
        memViewPart.setTableViewerFilter(new TableViewFilter(pkgAbbreviation, Constant.MEM_ITEM_TITLES));
        //初始化内存视图的数据提供者
        DataProvider dataProvider = new MemProvider(pkgNames, DeviceInfo.getInstance().androidVersion);
        //主持内存数据的观察者
        dataProvider.attach(new ChartObserver(memViewPart.memRealTimeChart));
        dataProvider.attach(new TableAllDataObserver(memViewPart.viewer, pkgAbbreviation, Constant.MEM_ITEM_TITLES));
        dataProvider.attach(new FileObserver(Constant.TEXT_ITEM_TITLES[Constant.MEM_INDEX]));
        if (TestSence.getInstance().isDumpHprof) {
            dataProvider.attach(new HprofDumpObserver(pkgNames));
        }
        //构建测试任务
        TestTask tt = new TestTask(dataProvider, TestSence.getInstance().itemTestPeriod[Constant.MEM_INDEX]);
        addTestTask(tt);
        memViewPart.setTableViewerFilter(new TableViewFilter(pkgAbbreviation, Constant.MEM_ITEM_TITLES));
        APTConsoleFactory.getInstance().APTPrint("内存测试Ready");
    }
    APTConsoleFactory.getInstance().APTPrint("开始测试更新");
    GetCurCheckedStateUtil.update();
    return true;
}
Also used : PidUpdateObserver(com.tencent.wstt.apt.chart.PidUpdateObserver) MemoryView(com.tencent.wstt.apt.ui.views.MemoryView) ChartObserver(com.tencent.wstt.apt.chart.ChartObserver) MemProvider(com.tencent.wstt.apt.chart.MemProvider) JiffiesProviderNew(com.tencent.wstt.apt.chart.JiffiesProviderNew) TableAllDataObserver(com.tencent.wstt.apt.chart.TableAllDataObserver) Date(java.util.Date) FileObserver(com.tencent.wstt.apt.chart.FileObserver) TableViewFilter(com.tencent.wstt.apt.util.TableViewFilter) DataProvider(com.tencent.wstt.apt.chart.DataProvider) HprofDumpObserver(com.tencent.wstt.apt.chart.HprofDumpObserver) CPUView(com.tencent.wstt.apt.ui.views.CPUView) JiffiesTableObserver(com.tencent.wstt.apt.chart.JiffiesTableObserver) CPUProvider(com.tencent.wstt.apt.chart.CPUProvider) DevicesView(com.tencent.wstt.apt.ui.views.DevicesView)

Aggregations

CPUProvider (com.tencent.wstt.apt.chart.CPUProvider)1 ChartObserver (com.tencent.wstt.apt.chart.ChartObserver)1 DataProvider (com.tencent.wstt.apt.chart.DataProvider)1 FileObserver (com.tencent.wstt.apt.chart.FileObserver)1 HprofDumpObserver (com.tencent.wstt.apt.chart.HprofDumpObserver)1 JiffiesProviderNew (com.tencent.wstt.apt.chart.JiffiesProviderNew)1 JiffiesTableObserver (com.tencent.wstt.apt.chart.JiffiesTableObserver)1 MemProvider (com.tencent.wstt.apt.chart.MemProvider)1 PidUpdateObserver (com.tencent.wstt.apt.chart.PidUpdateObserver)1 TableAllDataObserver (com.tencent.wstt.apt.chart.TableAllDataObserver)1 CPUView (com.tencent.wstt.apt.ui.views.CPUView)1 DevicesView (com.tencent.wstt.apt.ui.views.DevicesView)1 MemoryView (com.tencent.wstt.apt.ui.views.MemoryView)1 TableViewFilter (com.tencent.wstt.apt.util.TableViewFilter)1 Date (java.util.Date)1